mgmt: merge ManagerBase with NfdManagerBase

Refs: #4528
Change-Id: I2ecb4af68927157a9eafc269399855cff192bb54
diff --git a/tests/daemon/mgmt/command-authenticator.t.cpp b/tests/daemon/mgmt/command-authenticator.t.cpp
index 5f55451..fc24ccd 100644
--- a/tests/daemon/mgmt/command-authenticator.t.cpp
+++ b/tests/daemon/mgmt/command-authenticator.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -25,8 +25,7 @@
 
 #include "mgmt/command-authenticator.hpp"
 
-#include "tests/test-common.hpp"
-#include "tests/manager-common-fixture.hpp"
+#include "manager-common-fixture.hpp"
 
 #include <boost/filesystem.hpp>
 
diff --git a/tests/daemon/mgmt/cs-manager.t.cpp b/tests/daemon/mgmt/cs-manager.t.cpp
index 1a485725..50c82b9 100644
--- a/tests/daemon/mgmt/cs-manager.t.cpp
+++ b/tests/daemon/mgmt/cs-manager.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -25,14 +25,14 @@
 
 #include "mgmt/cs-manager.hpp"
 
-#include "nfd-manager-common-fixture.hpp"
+#include "manager-common-fixture.hpp"
 
 #include <ndn-cxx/mgmt/nfd/cs-info.hpp>
 
 namespace nfd {
 namespace tests {
 
-class CsManagerFixture : public NfdManagerCommonFixture
+class CsManagerFixture : public ManagerFixtureWithAuthenticator
 {
 public:
   CsManagerFixture()
diff --git a/tests/daemon/mgmt/face-manager-command-fixture.hpp b/tests/daemon/mgmt/face-manager-command-fixture.hpp
index b00b9cc..5864ad2 100644
--- a/tests/daemon/mgmt/face-manager-command-fixture.hpp
+++ b/tests/daemon/mgmt/face-manager-command-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -29,7 +29,7 @@
 #include "mgmt/face-manager.hpp"
 #include "fw/face-table.hpp"
 
-#include "tests/manager-common-fixture.hpp"
+#include "manager-common-fixture.hpp"
 
 namespace nfd {
 namespace tests {
@@ -50,7 +50,7 @@
 
 public:
   ndn::util::DummyClientFace face;
-  ndn::mgmt::Dispatcher dispatcher;
+  Dispatcher dispatcher;
   shared_ptr<CommandAuthenticator> authenticator;
 
   FaceTable faceTable;
diff --git a/tests/daemon/mgmt/face-manager-create-face.t.cpp b/tests/daemon/mgmt/face-manager-create-face.t.cpp
index 41c68c2..ac42dc9 100644
--- a/tests/daemon/mgmt/face-manager-create-face.t.cpp
+++ b/tests/daemon/mgmt/face-manager-create-face.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -29,7 +29,6 @@
 #include "mgmt/face-manager.hpp"
 #include "face/generic-link-service.hpp"
 #include "face-manager-command-fixture.hpp"
-#include "nfd-manager-common-fixture.hpp"
 
 namespace nfd {
 namespace tests {
diff --git a/tests/daemon/mgmt/face-manager-update-face.t.cpp b/tests/daemon/mgmt/face-manager-update-face.t.cpp
index 15bf6dd..1be0647 100644
--- a/tests/daemon/mgmt/face-manager-update-face.t.cpp
+++ b/tests/daemon/mgmt/face-manager-update-face.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,6 @@
 #include "mgmt/face-manager.hpp"
 #include "face/generic-link-service.hpp"
 #include "face-manager-command-fixture.hpp"
-#include "nfd-manager-common-fixture.hpp"
 
 #include <ndn-cxx/lp/tags.hpp>
 
diff --git a/tests/daemon/mgmt/face-manager.t.cpp b/tests/daemon/mgmt/face-manager.t.cpp
index cebbfd4..8a418e5 100644
--- a/tests/daemon/mgmt/face-manager.t.cpp
+++ b/tests/daemon/mgmt/face-manager.t.cpp
@@ -26,9 +26,9 @@
 #include "mgmt/face-manager.hpp"
 #include "face/protocol-factory.hpp"
 
-#include "nfd-manager-common-fixture.hpp"
-#include "../face/dummy-face.hpp"
-#include "../face/dummy-transport.hpp"
+#include "manager-common-fixture.hpp"
+#include "tests/daemon/face/dummy-face.hpp"
+#include "tests/daemon/face/dummy-transport.hpp"
 
 #include <ndn-cxx/encoding/tlv.hpp>
 #include <ndn-cxx/encoding/tlv-nfd.hpp>
@@ -42,7 +42,7 @@
 namespace nfd {
 namespace tests {
 
-class FaceManagerFixture : public NfdManagerCommonFixture
+class FaceManagerFixture : public ManagerFixtureWithAuthenticator
 {
 public:
   FaceManagerFixture()
diff --git a/tests/daemon/mgmt/fib-manager.t.cpp b/tests/daemon/mgmt/fib-manager.t.cpp
index 5fd193d..1002e44 100644
--- a/tests/daemon/mgmt/fib-manager.t.cpp
+++ b/tests/daemon/mgmt/fib-manager.t.cpp
@@ -26,8 +26,8 @@
 #include "mgmt/fib-manager.hpp"
 #include "table/fib-nexthop.hpp"
 
-#include "nfd-manager-common-fixture.hpp"
-#include "../face/dummy-face.hpp"
+#include "manager-common-fixture.hpp"
+#include "tests/daemon/face/dummy-face.hpp"
 
 #include <ndn-cxx/lp/tags.hpp>
 #include <ndn-cxx/mgmt/nfd/fib-entry.hpp>
@@ -35,7 +35,7 @@
 namespace nfd {
 namespace tests {
 
-class FibManagerFixture : public NfdManagerCommonFixture
+class FibManagerFixture : public ManagerFixtureWithAuthenticator
 {
 public:
   FibManagerFixture()
diff --git a/tests/daemon/mgmt/forwarder-status-manager.t.cpp b/tests/daemon/mgmt/forwarder-status-manager.t.cpp
index 3df77ec..bb728f2 100644
--- a/tests/daemon/mgmt/forwarder-status-manager.t.cpp
+++ b/tests/daemon/mgmt/forwarder-status-manager.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,24 +26,25 @@
 #include "mgmt/forwarder-status-manager.hpp"
 #include "core/version.hpp"
 
-#include "nfd-manager-common-fixture.hpp"
+#include "manager-common-fixture.hpp"
 
 namespace nfd {
 namespace tests {
 
-class ForwarderStatusManagerFixture : public NfdManagerCommonFixture
+class ForwarderStatusManagerFixture : public ManagerCommonFixture
 {
 protected:
   ForwarderStatusManagerFixture()
-    : manager(m_forwarder, m_dispatcher)
-    , startTime(time::system_clock::now())
+    : m_manager(m_forwarder, m_dispatcher)
+    , m_startTime(time::system_clock::now())
   {
     setTopPrefix();
   }
 
 protected:
-  ForwarderStatusManager manager;
-  time::system_clock::TimePoint startTime;
+  Forwarder m_forwarder;
+  ForwarderStatusManager m_manager;
+  time::system_clock::TimePoint m_startTime;
 };
 
 BOOST_AUTO_TEST_SUITE(Mgmt)
@@ -78,11 +79,9 @@
   BOOST_CHECK_EQUAL(m_forwarder.getCounters().nUnsatisfiedInterests, 1);
 
   // request
-  time::system_clock::TimePoint beforeRequest = time::system_clock::now();
-  Interest request("/localhost/nfd/status/general");
-  request.setMustBeFresh(true).setChildSelector(1);
-  this->receiveInterest(request);
-  time::system_clock::TimePoint afterRequest = time::system_clock::now();
+  auto beforeRequest = time::system_clock::now();
+  receiveInterest(Interest("/localhost/nfd/status/general").setCanBePrefix(true));
+  auto afterRequest = time::system_clock::now();
 
   // verify
   Block response = this->concatenateResponses(0, m_responses.size());
@@ -90,7 +89,7 @@
   BOOST_REQUIRE_NO_THROW(status.wireDecode(response));
 
   BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION_BUILD_STRING);
-  BOOST_CHECK_EQUAL(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(startTime));
+  BOOST_CHECK_EQUAL(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(m_startTime));
   BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(beforeRequest));
   BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(afterRequest));
 
diff --git a/tests/daemon/mgmt/manager-base.t.cpp b/tests/daemon/mgmt/manager-base.t.cpp
new file mode 100644
index 0000000..3aeeb9e
--- /dev/null
+++ b/tests/daemon/mgmt/manager-base.t.cpp
@@ -0,0 +1,172 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mgmt/manager-base.hpp"
+
+#include "manager-common-fixture.hpp"
+
+#include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/security/pib/identity.hpp>
+#include <ndn-cxx/security/pib/key.hpp>
+#include <ndn-cxx/security/pib/pib.hpp>
+
+namespace nfd {
+namespace tests {
+
+class TestCommandVoidParameters : public ControlCommand
+{
+public:
+  TestCommandVoidParameters()
+    : ControlCommand("test-module", "test-void-parameters")
+  {
+  }
+};
+
+class TestCommandRequireName : public ControlCommand
+{
+public:
+  TestCommandRequireName()
+    : ControlCommand("test-module", "test-require-name")
+  {
+    m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
+  }
+};
+
+class DummyManager : public ManagerBase
+{
+public:
+  explicit
+  DummyManager(Dispatcher& dispatcher)
+    : ManagerBase("test-module", dispatcher)
+  {
+  }
+
+private:
+  ndn::mgmt::Authorization
+  makeAuthorization(const std::string& verb) override
+  {
+    return [] (const Name& prefix, const Interest& interest,
+               const ndn::mgmt::ControlParameters* params,
+               ndn::mgmt::AcceptContinuation accept,
+               ndn::mgmt::RejectContinuation reject) {
+      accept("requester");
+    };
+  }
+};
+
+class ManagerBaseFixture : public ManagerCommonFixture
+{
+protected:
+  DummyManager m_manager{m_dispatcher};
+};
+
+BOOST_AUTO_TEST_SUITE(Mgmt)
+BOOST_FIXTURE_TEST_SUITE(TestManagerBase, ManagerBaseFixture)
+
+BOOST_AUTO_TEST_CASE(RegisterCommandHandler)
+{
+  bool wasCommandHandlerCalled = false;
+  auto handler = bind([&] { wasCommandHandlerCalled = true; });
+
+  m_manager.registerCommandHandler<TestCommandVoidParameters>("test-void", handler);
+  m_manager.registerCommandHandler<TestCommandRequireName>("test-require-name", handler);
+  setTopPrefix();
+
+  auto testRegisterCommandHandler = [&wasCommandHandlerCalled, this] (const Name& commandName) {
+    wasCommandHandlerCalled = false;
+    receiveInterest(makeControlCommandRequest(commandName, ControlParameters()));
+  };
+
+  testRegisterCommandHandler("/localhost/nfd/test-module/test-void");
+  BOOST_CHECK(wasCommandHandlerCalled);
+
+  testRegisterCommandHandler("/localhost/nfd/test-module/test-require-name");
+  BOOST_CHECK(!wasCommandHandlerCalled);
+}
+
+BOOST_AUTO_TEST_CASE(RegisterStatusDataset)
+{
+  bool isStatusDatasetCalled = false;
+  auto handler = bind([&] { isStatusDatasetCalled = true; });
+
+  m_manager.registerStatusDatasetHandler("test-status", handler);
+  setTopPrefix();
+
+  receiveInterest(Interest("/localhost/nfd/test-module/test-status"));
+  BOOST_CHECK(isStatusDatasetCalled);
+}
+
+BOOST_AUTO_TEST_CASE(RegisterNotificationStream)
+{
+  auto post = m_manager.registerNotificationStream("test-notification");
+  setTopPrefix();
+
+  const uint8_t buf[] = {0x82, 0x01, 0x02};
+  post(Block(buf, sizeof(buf)));
+  advanceClocks(time::milliseconds(1));
+
+  BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
+  BOOST_CHECK_EQUAL(m_responses[0].getName(),
+                    Name("/localhost/nfd/test-module/test-notification/%FE%00"));
+}
+
+BOOST_AUTO_TEST_CASE(ExtractRequester)
+{
+  std::string requesterName;
+  auto testAccept = [&] (const std::string& requester) { requesterName = requester; };
+
+  m_manager.extractRequester(Interest("/test/interest/unsigned"), testAccept);
+  BOOST_CHECK(requesterName.empty());
+
+  requesterName = "";
+  m_manager.extractRequester(makeControlCommandRequest("/test/interest/signed", ControlParameters()), testAccept);
+  auto keyLocator = m_keyChain.getPib().getIdentity(DEFAULT_COMMAND_SIGNER_IDENTITY).getDefaultKey().getName();
+  BOOST_CHECK_EQUAL(requesterName, keyLocator.toUri());
+}
+
+BOOST_AUTO_TEST_CASE(ValidateParameters)
+{
+  ControlParameters params;
+  TestCommandVoidParameters commandVoidParams;
+  TestCommandRequireName commandRequireName;
+
+  BOOST_CHECK_EQUAL(ManagerBase::validateParameters(commandVoidParams, params), true); // succeeds
+  BOOST_CHECK_EQUAL(ManagerBase::validateParameters(commandRequireName, params), false); // fails
+
+  params.setName("test-name");
+  BOOST_CHECK_EQUAL(ManagerBase::validateParameters(commandRequireName, params), true); // succeeds
+}
+
+BOOST_AUTO_TEST_CASE(MakeRelPrefix)
+{
+  auto generatedRelPrefix = m_manager.makeRelPrefix("test-verb");
+  BOOST_CHECK_EQUAL(generatedRelPrefix, PartialName("/test-module/test-verb"));
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestManagerBase
+BOOST_AUTO_TEST_SUITE_END() // Mgmt
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/mgmt/manager-common-fixture.cpp b/tests/daemon/mgmt/manager-common-fixture.cpp
new file mode 100644
index 0000000..ee8d543
--- /dev/null
+++ b/tests/daemon/mgmt/manager-common-fixture.cpp
@@ -0,0 +1,221 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "manager-common-fixture.hpp"
+
+#include <ndn-cxx/security/signing-helpers.hpp>
+
+namespace nfd {
+namespace tests {
+
+const Name CommandInterestSignerFixture::DEFAULT_COMMAND_SIGNER_IDENTITY("/CommandInterestSignerFixture-identity");
+
+CommandInterestSignerFixture::CommandInterestSignerFixture()
+  : m_commandInterestSigner(m_keyChain)
+{
+  BOOST_REQUIRE(this->addIdentity(DEFAULT_COMMAND_SIGNER_IDENTITY));
+}
+
+Interest
+CommandInterestSignerFixture::makeCommandInterest(const Name& name, const Name& identity)
+{
+  return m_commandInterestSigner.makeCommandInterest(name, ndn::security::signingByIdentity(identity));
+}
+
+Interest
+CommandInterestSignerFixture::makeControlCommandRequest(Name commandName,
+                                                        const ControlParameters& params,
+                                                        const Name& identity)
+{
+  commandName.append(params.wireEncode());
+  return this->makeCommandInterest(commandName, identity);
+}
+
+ManagerCommonFixture::ManagerCommonFixture()
+  : m_face(getGlobalIoService(), m_keyChain, {true, true})
+  , m_dispatcher(m_face, m_keyChain, ndn::security::SigningInfo())
+  , m_responses(m_face.sentData)
+{
+}
+
+void
+ManagerCommonFixture::setTopPrefix()
+{
+  m_dispatcher.addTopPrefix("/localhost/nfd");
+  advanceClocks(1_ms); // so that all filters are added
+}
+
+void
+ManagerCommonFixture::receiveInterest(const Interest& interest)
+{
+  m_face.receive(interest);
+  advanceClocks(1_ms);
+}
+
+ControlResponse
+ManagerCommonFixture::makeResponse(uint32_t code, const std::string& text,
+                                   const ControlParameters& parameters)
+{
+  return ControlResponse(code, text).setBody(parameters.wireEncode());
+}
+
+ManagerCommonFixture::CheckResponseResult
+ManagerCommonFixture::checkResponse(size_t idx,
+                                    const Name& expectedName,
+                                    const ControlResponse& expectedResponse,
+                                    int expectedContentType /*= -1*/)
+{
+  Data data;
+  try {
+    data = m_responses.at(idx);
+  }
+  catch (const std::out_of_range&) {
+    BOOST_TEST_MESSAGE("response[" << idx << "] does not exist");
+    return CheckResponseResult::OUT_OF_BOUNDARY;
+  }
+
+  if (data.getName() != expectedName) {
+    BOOST_TEST_MESSAGE("response[" << idx << "] has wrong name " << data.getName());
+    return CheckResponseResult::WRONG_NAME;
+  }
+
+  if (expectedContentType != -1 &&
+      data.getContentType() != static_cast<uint32_t>(expectedContentType)) {
+    BOOST_TEST_MESSAGE("response[" << idx << "] has wrong ContentType " << data.getContentType());
+    return CheckResponseResult::WRONG_CONTENT_TYPE;
+  }
+
+  ControlResponse response;
+  try {
+    response.wireDecode(data.getContent().blockFromValue());
+  }
+  catch (const tlv::Error&) {
+    BOOST_TEST_MESSAGE("response[" << idx << "] cannot be decoded");
+    return CheckResponseResult::INVALID_RESPONSE;
+  }
+
+  if (response.getCode() != expectedResponse.getCode()) {
+    BOOST_TEST_MESSAGE("response[" << idx << "] has wrong StatusCode " << response.getCode());
+    return CheckResponseResult::WRONG_CODE;
+  }
+
+  if (response.getText() != expectedResponse.getText()) {
+    BOOST_TEST_MESSAGE("response[" << idx << "] has wrong StatusText " << response.getText());
+    return CheckResponseResult::WRONG_TEXT;
+  }
+
+  const Block& body = response.getBody();
+  const Block& expectedBody = expectedResponse.getBody();
+  if (body.value_size() != expectedBody.value_size()) {
+    BOOST_TEST_MESSAGE("response[" << idx << "] has wrong body size " << body.value_size());
+    return CheckResponseResult::WRONG_BODY_SIZE;
+  }
+  if (body.value_size() > 0 && memcmp(body.value(), expectedBody.value(), body.value_size()) != 0) {
+    BOOST_TEST_MESSAGE("response[" << idx << "] has wrong body value");
+    return CheckResponseResult::WRONG_BODY_VALUE;
+  }
+
+  return CheckResponseResult::OK;
+}
+
+Block
+ManagerCommonFixture::concatenateResponses(size_t startIndex, size_t nResponses)
+{
+  while (m_responses.back().getName().at(-1) != m_responses.back().getFinalBlock()) {
+    const Name& name = m_responses.back().getName();
+    Name prefix = name.getPrefix(-1);
+    uint64_t segmentNo = name.at(-1).toSegment() + 1;
+    // request for the next segment
+    receiveInterest(Interest(prefix.appendSegment(segmentNo)));
+  }
+
+  size_t endIndex = startIndex + nResponses; // not included
+  if (nResponses == startIndex || endIndex > m_responses.size()) {
+    endIndex = m_responses.size();
+  }
+
+  ndn::EncodingBuffer encoder;
+  size_t valueLength = 0;
+  for (size_t i = startIndex; i < endIndex ; i ++) {
+    valueLength += encoder.appendByteArray(m_responses[i].getContent().value(),
+                                           m_responses[i].getContent().value_size());
+  }
+  encoder.prependVarNumber(valueLength);
+  encoder.prependVarNumber(tlv::Content);
+  return encoder.block();
+}
+
+std::ostream&
+operator<<(std::ostream& os, ManagerCommonFixture::CheckResponseResult result)
+{
+  switch (result) {
+    case ManagerCommonFixture::CheckResponseResult::OK:
+      return os << "OK";
+    case ManagerCommonFixture::CheckResponseResult::OUT_OF_BOUNDARY:
+      return os << "OUT_OF_BOUNDARY";
+    case ManagerCommonFixture::CheckResponseResult::WRONG_NAME:
+      return os << "WRONG_NAME";
+    case ManagerCommonFixture::CheckResponseResult::WRONG_CONTENT_TYPE:
+      return os << "WRONG_CONTENT_TYPE";
+    case ManagerCommonFixture::CheckResponseResult::INVALID_RESPONSE:
+      return os << "INVALID_RESPONSE";
+    case ManagerCommonFixture::CheckResponseResult::WRONG_CODE:
+      return os << "WRONG_CODE";
+    case ManagerCommonFixture::CheckResponseResult::WRONG_TEXT:
+      return os << "WRONG_TEXT";
+    case ManagerCommonFixture::CheckResponseResult::WRONG_BODY_SIZE:
+      return os << "WRONG_BODY_SIZE";
+    case ManagerCommonFixture::CheckResponseResult::WRONG_BODY_VALUE:
+      return os << "WRONG_BODY_VALUE";
+  }
+  return os << static_cast<int>(result);
+}
+
+void
+ManagerFixtureWithAuthenticator::setPrivilege(const std::string& privilege)
+{
+  saveIdentityCertificate(DEFAULT_COMMAND_SIGNER_IDENTITY, "ManagerCommonFixture.ndncert");
+
+  const std::string& config = R"CONFIG(
+    authorizations
+    {
+      authorize
+      {
+        certfile "ManagerCommonFixture.ndncert"
+        privileges
+        {
+          )CONFIG" + privilege + R"CONFIG(
+        }
+      }
+    }
+  )CONFIG";
+
+  ConfigFile cf;
+  m_authenticator->setConfigFile(cf);
+  cf.parse(config, false, "ManagerCommonFixture.authenticator.conf");
+}
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/mgmt/manager-common-fixture.hpp b/tests/daemon/mgmt/manager-common-fixture.hpp
new file mode 100644
index 0000000..8725680
--- /dev/null
+++ b/tests/daemon/mgmt/manager-common-fixture.hpp
@@ -0,0 +1,204 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_TESTS_DAEMON_MGMT_MANAGER_COMMON_FIXTURE_HPP
+#define NFD_TESTS_DAEMON_MGMT_MANAGER_COMMON_FIXTURE_HPP
+
+#include "mgmt/manager-base.hpp"
+#include "fw/forwarder.hpp"
+
+#include "tests/identity-management-fixture.hpp"
+
+#include <ndn-cxx/security/command-interest-signer.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
+
+namespace nfd {
+namespace tests {
+
+/** \brief A fixture that provides a CommandInterestSigner.
+ */
+class CommandInterestSignerFixture : public IdentityManagementTimeFixture
+{
+protected:
+  CommandInterestSignerFixture();
+
+  /** \brief sign a command Interest
+   *  \param name command name include prefix and parameters
+   *  \param identity signing identity
+   *  \return a command Interest
+   */
+  Interest
+  makeCommandInterest(const Name& name, const Name& identity = DEFAULT_COMMAND_SIGNER_IDENTITY);
+
+  /** \brief create a ControlCommand request
+   *  \param commandName command name including prefix, such as "/localhost/nfd/fib/add-nexthop"
+   *  \param params command parameters
+   *  \param identity signing identity
+   *  \return a command Interest
+   */
+  Interest
+  makeControlCommandRequest(Name commandName, const ControlParameters& params,
+                            const Name& identity = DEFAULT_COMMAND_SIGNER_IDENTITY);
+
+protected:
+  static const Name DEFAULT_COMMAND_SIGNER_IDENTITY;
+
+private:
+  ndn::security::CommandInterestSigner m_commandInterestSigner;
+};
+
+/**
+ * @brief A collection of common functions shared by all manager's test fixtures.
+ */
+class ManagerCommonFixture : public CommandInterestSignerFixture
+{
+public: // initialize
+  ManagerCommonFixture();
+
+  /**
+   * @brief Add `/localhost/nfd` as a top prefix to the dispatcher.
+   *
+   * Afterwards, advanceClocks() is called to ensure all added filters take effect.
+   */
+  void
+  setTopPrefix();
+
+public: // test
+  /**
+   * @brief cause management to receive an Interest
+   *
+   * call DummyClientFace::receive to receive Interest and then call advanceClocks to ensure
+   * the Interest dispatched
+   *
+   * @param interest the Interest to receive
+   */
+  void
+  receiveInterest(const Interest& interest);
+
+public: // verify
+  ControlResponse
+  makeResponse(uint32_t code, const std::string& text, const ControlParameters& parameters);
+
+  enum class CheckResponseResult
+  {
+    OK,
+    OUT_OF_BOUNDARY,
+    WRONG_NAME,
+    WRONG_CONTENT_TYPE,
+    INVALID_RESPONSE,
+    WRONG_CODE,
+    WRONG_TEXT,
+    WRONG_BODY_SIZE,
+    WRONG_BODY_VALUE
+  };
+
+  /**
+   * @brief check a specified response data with the expected ControlResponse
+   *
+   * @param idx the index of the specified Data in m_responses
+   * @param expectedDataName the expected name of this Data
+   * @param expectedResponse the expected ControlResponse
+   * @param expectedContentType the expected content type of this Data, use -1 to skip this check
+   *
+   * @retval OK the response at the specified index can be decoded from the response data,
+   *            and its code, text and response body are all matched with the expected response
+   * @retval OUT_OF_BOUNDARY the specified index out of boundary
+   * @retval WRONG_NAME the name of the specified response data does not match
+   * @retval WRONG_CONTENT_TYPE the content type of the specified response data does not match
+   * @retval INVALID_RESPONSE the data name matches but it fails in decoding a ControlResponse from
+   *                          the content of the specified response data
+   * @retval WRONG_CODE a valid ControlResponse can be decoded but has a wrong code
+   * @retval WRONG_TEXT a valid ControlResponse can be decoded but has a wrong text
+   * @retval WRONG_BODY_SIZE the body size of decoded ControlResponse does not match
+   * @retval WRONT_BODY_VALUE the body value of decoded ControlResponse does not match
+   */
+  CheckResponseResult
+  checkResponse(size_t idx,
+                const Name& expectedName,
+                const ControlResponse& expectedResponse,
+                int expectedContentType = -1);
+
+  /**
+   * @brief concatenate specified response Data into a single block
+   *
+   * @param startIndex the start index in m_responses
+   * @param nResponses the number of response to concatenate
+   *
+   * @return the generated block
+   */
+  Block
+  concatenateResponses(size_t startIndex = 0, size_t nResponses = 0);
+
+protected:
+  ndn::util::DummyClientFace m_face;
+  Dispatcher m_dispatcher;
+  std::vector<Data>& m_responses; ///< a reference to m_face.sentData
+};
+
+std::ostream&
+operator<<(std::ostream& os, ManagerCommonFixture::CheckResponseResult result);
+
+class ManagerFixtureWithAuthenticator : public ManagerCommonFixture
+{
+public:
+  /** \brief grant m_identityName privilege to sign commands for the management module
+   */
+  void
+  setPrivilege(const std::string& privilege);
+
+protected:
+  Forwarder m_forwarder;
+  shared_ptr<CommandAuthenticator> m_authenticator = CommandAuthenticator::create();
+};
+
+class CommandSuccess
+{
+public:
+  static ControlResponse
+  getExpected()
+  {
+    return ControlResponse()
+        .setCode(200)
+        .setText("OK");
+  }
+};
+
+template<int CODE>
+class CommandFailure
+{
+public:
+  static ControlResponse
+  getExpected()
+  {
+    return ControlResponse()
+        .setCode(CODE);
+    // error description should not be checked
+  }
+};
+
+} // namespace tests
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_MGMT_MANAGER_COMMON_FIXTURE_HPP
diff --git a/tests/daemon/mgmt/nfd-manager-common-fixture.cpp b/tests/daemon/mgmt/nfd-manager-common-fixture.cpp
deleted file mode 100644
index f39e983..0000000
--- a/tests/daemon/mgmt/nfd-manager-common-fixture.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
- *                           Arizona Board of Regents,
- *                           Colorado State University,
- *                           University Pierre & Marie Curie, Sorbonne University,
- *                           Washington University in St. Louis,
- *                           Beijing Institute of Technology,
- *                           The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "nfd-manager-common-fixture.hpp"
-
-namespace nfd {
-namespace tests {
-
-NfdManagerCommonFixture::NfdManagerCommonFixture()
-  : m_authenticator(CommandAuthenticator::create())
-{
-}
-
-void
-NfdManagerCommonFixture::setTopPrefix()
-{
-  this->ManagerCommonFixture::setTopPrefix("/localhost/nfd");
-}
-
-void
-NfdManagerCommonFixture::setPrivilege(const std::string& privilege)
-{
-  this->saveIdentityCertificate(DEFAULT_COMMAND_SIGNER_IDENTITY, "ManagerCommonFixture.ndncert");
-
-  const std::string& config = R"CONFIG(
-    authorizations
-    {
-      authorize
-      {
-        certfile "ManagerCommonFixture.ndncert"
-        privileges
-        {
-          )CONFIG" + privilege + R"CONFIG(
-        }
-      }
-    }
-  )CONFIG";
-
-  ConfigFile cf;
-  m_authenticator->setConfigFile(cf);
-  cf.parse(config, false, "ManagerCommonFixture.authenticator.conf");
-}
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/mgmt/nfd-manager-common-fixture.hpp b/tests/daemon/mgmt/nfd-manager-common-fixture.hpp
deleted file mode 100644
index fb2dbc2..0000000
--- a/tests/daemon/mgmt/nfd-manager-common-fixture.hpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
- *                           Arizona Board of Regents,
- *                           Colorado State University,
- *                           University Pierre & Marie Curie, Sorbonne University,
- *                           Washington University in St. Louis,
- *                           Beijing Institute of Technology,
- *                           The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_TESTS_DAEMON_MGMT_NFD_MANAGER_COMMON_FIXTURE_HPP
-#define NFD_TESTS_DAEMON_MGMT_NFD_MANAGER_COMMON_FIXTURE_HPP
-
-#include "tests/manager-common-fixture.hpp"
-#include "fw/forwarder.hpp"
-#include "mgmt/command-authenticator.hpp"
-
-namespace nfd {
-namespace tests {
-
-/** \brief base fixture for testing an NFD Manager
- */
-class NfdManagerCommonFixture : public ManagerCommonFixture
-{
-public:
-  NfdManagerCommonFixture();
-
-  /** \brief add /localhost/nfd as a top prefix to the dispatcher
-   */
-  void
-  setTopPrefix();
-
-  /** \brief grant m_identityName privilege to sign commands for the management module
-   */
-  void
-  setPrivilege(const std::string& privilege);
-
-protected:
-  Forwarder m_forwarder;
-  shared_ptr<CommandAuthenticator> m_authenticator;
-};
-
-class CommandSuccess
-{
-public:
-  static ControlResponse
-  getExpected()
-  {
-    return ControlResponse()
-      .setCode(200)
-      .setText("OK");
-  }
-};
-
-template<int CODE>
-class CommandFailure
-{
-public:
-  static ControlResponse
-  getExpected()
-  {
-    return ControlResponse()
-      .setCode(CODE);
-    // error description should not be checked
-  }
-};
-
-} // namespace tests
-} // namespace nfd
-
-#endif // NFD_TESTS_DAEMON_MGMT_NFD_MANAGER_COMMON_FIXTURE_HPP
diff --git a/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp b/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
index 06e3d5e..452d758 100644
--- a/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
+++ b/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
@@ -165,7 +165,7 @@
   ndn::util::DummyClientFace m_face;
   ndn::util::Scheduler m_scheduler;
   ndn::nfd::Controller m_nfdController;
-  ndn::mgmt::Dispatcher m_dispatcher;
+  Dispatcher m_dispatcher;
   rib::FibUpdater m_fibUpdater;
 
   ndn::security::SigningInfo m_trustedSigner;
diff --git a/tests/daemon/mgmt/rib-manager.t.cpp b/tests/daemon/mgmt/rib-manager.t.cpp
index 46da6a1..c3c5dd6 100644
--- a/tests/daemon/mgmt/rib-manager.t.cpp
+++ b/tests/daemon/mgmt/rib-manager.t.cpp
@@ -27,7 +27,7 @@
 #include "core/fib-max-depth.hpp"
 #include "rib/fib-updater.hpp"
 
-#include "tests/manager-common-fixture.hpp"
+#include "manager-common-fixture.hpp"
 
 #include <ndn-cxx/lp/tags.hpp>
 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
@@ -93,10 +93,10 @@
     advanceClocks(1_ms);
 
     auto replyFibAddCommand = [this] (const Interest& interest) {
-      nfd::ControlParameters params(interest.getName().get(-5).blockFromValue());
+      ControlParameters params(interest.getName().get(-5).blockFromValue());
       BOOST_CHECK(params.getName() == "/localhost/nfd/rib" || params.getName() == "/localhop/nfd/rib");
       params.setFaceId(1).setCost(0);
-      nfd::ControlResponse resp;
+      ControlResponse resp;
 
       resp.setCode(200).setBody(params.wireEncode());
       shared_ptr<Data> data = make_shared<Data>(interest.getName());
diff --git a/tests/daemon/mgmt/strategy-choice-manager.t.cpp b/tests/daemon/mgmt/strategy-choice-manager.t.cpp
index 817966e..6b7e390 100644
--- a/tests/daemon/mgmt/strategy-choice-manager.t.cpp
+++ b/tests/daemon/mgmt/strategy-choice-manager.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,15 +26,15 @@
 #include "mgmt/strategy-choice-manager.hpp"
 #include "table/strategy-choice.hpp"
 
-#include "nfd-manager-common-fixture.hpp"
-#include "../fw/dummy-strategy.hpp"
+#include "manager-common-fixture.hpp"
+#include "tests/daemon/fw/dummy-strategy.hpp"
 
 #include <ndn-cxx/mgmt/nfd/strategy-choice.hpp>
 
 namespace nfd {
 namespace tests {
 
-class StrategyChoiceManagerFixture : public NfdManagerCommonFixture
+class StrategyChoiceManagerFixture : public ManagerFixtureWithAuthenticator
 {
 public:
   StrategyChoiceManagerFixture()