blob: 6054ed22bfc7e85b95b9b123deb6a803fbebe790 [file] [log] [blame]
Junxiao Shi034c1882016-06-24 18:06:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -08002/*
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"
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080026#include "util/dummy-client-face.hpp"
27#include "security/v2/certificate-fetcher-offline.hpp"
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000028
Junxiao Shi034c1882016-06-24 18:06:51 +000029#include "boost-test.hpp"
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080030#include "dummy-validator.hpp"
31#include "unit-tests/identity-management-time-fixture.hpp"
Junxiao Shi034c1882016-06-24 18:06:51 +000032
33namespace ndn {
34namespace nfd {
35namespace tests {
36
37using namespace ndn::tests;
38
Alexander Afanasyev80782e02017-01-04 13:16:54 -080039class ControllerFixture : public IdentityManagementTimeFixture
Junxiao Shi034c1882016-06-24 18:06:51 +000040{
41protected:
42 ControllerFixture()
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070043 : face(io, m_keyChain)
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080044 , m_validator(true)
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000045 , controller(face, m_keyChain, m_validator)
Junxiao Shie7c7f152016-08-20 22:36:22 +000046 , commandFailCallback(bind(&ControllerFixture::recordCommandFail, this, _1))
47 , datasetFailCallback(bind(&ControllerFixture::recordDatasetFail, this, _1, _2))
Junxiao Shi034c1882016-06-24 18:06:51 +000048 {
49 Name identityName("/localhost/ControllerFixture");
Alexander Afanasyev80782e02017-01-04 13:16:54 -080050 m_keyChain.setDefaultIdentity(this->addIdentity(identityName));
Junxiao Shi034c1882016-06-24 18:06:51 +000051 }
52
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000053 /** \brief controls whether Controller's validator should accept or reject validation requests
54 *
55 * Initially, the validator accepts all requests.
56 * Setting \p false causes validator to reject all requests.
57 */
58 void
59 setValidationResult(bool shouldAccept)
60 {
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080061 m_validator.getPolicy().setResult(shouldAccept);
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000062 }
63
Junxiao Shi034c1882016-06-24 18:06:51 +000064private:
65 void
Junxiao Shie7c7f152016-08-20 22:36:22 +000066 recordCommandFail(const ControlResponse& response)
67 {
68 failCodes.push_back(response.getCode());
69 }
70
71 void
72 recordDatasetFail(uint32_t code, const std::string& reason)
Junxiao Shi034c1882016-06-24 18:06:51 +000073 {
74 failCodes.push_back(code);
75 }
76
77protected:
78 ndn::util::DummyClientFace face;
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080079 DummyValidator m_validator;
Junxiao Shi034c1882016-06-24 18:06:51 +000080 Controller controller;
Junxiao Shie7c7f152016-08-20 22:36:22 +000081 Controller::CommandFailCallback commandFailCallback;
82 Controller::DatasetFailCallback datasetFailCallback;
Junxiao Shi034c1882016-06-24 18:06:51 +000083 std::vector<uint32_t> failCodes;
Junxiao Shi034c1882016-06-24 18:06:51 +000084};
85
86} // namespace tests
87} // namespace nfd
88} // namespace ndn
89
Junxiao Shi7357ef22016-09-07 02:39:37 +000090#endif // NDN_TESTS_MGMT_NFD_CONTROLLER_FIXTURE_HPP