blob: d64d77ebb4c65c0ad3b9dbeeb577e0061b8ccd76 [file] [log] [blame]
Junxiao Shi034c1882016-06-24 18:06:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevfc99b512017-01-04 11:10:36 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Junxiao Shi034c1882016-06-24 18:06:51 +00004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Junxiao Shi7357ef22016-09-07 02:39:37 +000022#ifndef NDN_TESTS_MGMT_NFD_CONTROLLER_FIXTURE_HPP
23#define NDN_TESTS_MGMT_NFD_CONTROLLER_FIXTURE_HPP
Junxiao Shi034c1882016-06-24 18:06:51 +000024
Junxiao Shi7357ef22016-09-07 02:39:37 +000025#include "mgmt/nfd/controller.hpp"
26#include "../../../dummy-validator.hpp"
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000027
Junxiao Shi034c1882016-06-24 18:06:51 +000028#include "boost-test.hpp"
29#include "util/dummy-client-face.hpp"
Junxiao Shi7357ef22016-09-07 02:39:37 +000030#include "../../identity-management-time-fixture.hpp"
Junxiao Shi034c1882016-06-24 18:06:51 +000031
32namespace ndn {
33namespace nfd {
34namespace tests {
35
36using namespace ndn::tests;
37
Alexander Afanasyev70244f42017-01-04 12:47:12 -080038class ControllerFixture : public IdentityManagementV1TimeFixture
Junxiao Shi034c1882016-06-24 18:06:51 +000039{
40protected:
41 ControllerFixture()
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070042 : face(io, m_keyChain)
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000043 , controller(face, m_keyChain, m_validator)
Junxiao Shie7c7f152016-08-20 22:36:22 +000044 , commandFailCallback(bind(&ControllerFixture::recordCommandFail, this, _1))
45 , datasetFailCallback(bind(&ControllerFixture::recordDatasetFail, this, _1, _2))
Junxiao Shi034c1882016-06-24 18:06:51 +000046 {
47 Name identityName("/localhost/ControllerFixture");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080048 this->addIdentity(identityName);
49 m_keyChain.setDefaultIdentity(identityName);
Junxiao Shi034c1882016-06-24 18:06:51 +000050 }
51
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000052 /** \brief controls whether Controller's validator should accept or reject validation requests
53 *
54 * Initially, the validator accepts all requests.
55 * Setting \p false causes validator to reject all requests.
56 */
57 void
58 setValidationResult(bool shouldAccept)
59 {
60 m_validator.setResult(shouldAccept);
61 }
62
Junxiao Shi034c1882016-06-24 18:06:51 +000063private:
64 void
Junxiao Shie7c7f152016-08-20 22:36:22 +000065 recordCommandFail(const ControlResponse& response)
66 {
67 failCodes.push_back(response.getCode());
68 }
69
70 void
71 recordDatasetFail(uint32_t code, const std::string& reason)
Junxiao Shi034c1882016-06-24 18:06:51 +000072 {
73 failCodes.push_back(code);
74 }
75
76protected:
77 ndn::util::DummyClientFace face;
78 Controller controller;
Junxiao Shie7c7f152016-08-20 22:36:22 +000079 Controller::CommandFailCallback commandFailCallback;
80 Controller::DatasetFailCallback datasetFailCallback;
Junxiao Shi034c1882016-06-24 18:06:51 +000081 std::vector<uint32_t> failCodes;
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000082
83private:
84 DummyValidator m_validator;
Junxiao Shi034c1882016-06-24 18:06:51 +000085};
86
87} // namespace tests
88} // namespace nfd
89} // namespace ndn
90
Junxiao Shi7357ef22016-09-07 02:39:37 +000091#endif // NDN_TESTS_MGMT_NFD_CONTROLLER_FIXTURE_HPP