Use ndn::mgmt::Dispatcher for repo commands

refs #4129

Change-Id: Idb7826fc76b6660ce76d69e7e88a9e922c55a2e1
diff --git a/tests/dataset-fixtures.hpp b/tests/dataset-fixtures.hpp
index fbed46d..bb03bd6 100644
--- a/tests/dataset-fixtures.hpp
+++ b/tests/dataset-fixtures.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-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -378,12 +378,12 @@
 };
 
 
-typedef boost::mpl::vector< BasicDataset,
-                            FetchByPrefixDataset,
-                            BasicChildSelectorDataset,
-                            ExtendedChildSelectorDataset,
-                            SamePrefixDataset<10>,
-                            SamePrefixDataset<100> > CommonDatasets;
+typedef boost::mpl::vector<BasicDataset,
+                           FetchByPrefixDataset,
+                           BasicChildSelectorDataset,
+                           ExtendedChildSelectorDataset,
+                           SamePrefixDataset<10>,
+                           SamePrefixDataset<100>> CommonDatasets;
 
 
 } // namespace tests
diff --git a/tests/integrated/command-fixture.cpp b/tests/integrated/command-fixture.cpp
index 1680dad..a803a51 100644
--- a/tests/integrated/command-fixture.cpp
+++ b/tests/integrated/command-fixture.cpp
@@ -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-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -25,6 +25,7 @@
 CommandFixture::CommandFixture()
   : scheduler(repoFace.getIoService())
   , keyChain(m_keyChain)
+  , dispatcher(repoFace, keyChain)
   , validator(repoFace)
 {
   this->saveIdentityCertificate(keyChain.getPib().getDefaultIdentity().getName(),
diff --git a/tests/integrated/command-fixture.hpp b/tests/integrated/command-fixture.hpp
index fa2fdd9..601f0b9 100644
--- a/tests/integrated/command-fixture.hpp
+++ b/tests/integrated/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-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -22,6 +22,7 @@
 
 #include "../identity-management-fixture.hpp"
 #include <ndn-cxx/security/validator-null.hpp>
+#include <ndn-cxx/mgmt/dispatcher.hpp>
 
 namespace repo {
 namespace tests {
@@ -35,7 +36,7 @@
   Face repoFace;
   Scheduler scheduler;
   KeyChain& keyChain;
-
+  ndn::mgmt::Dispatcher dispatcher;
   /// \todo #4091 switch to ValidatorPolicyConf and load insert-delete-validator-config.conf
   ValidatorConfig validator;
 };
diff --git a/tests/integrated/insert-delete-validator-config.conf b/tests/integrated/insert-delete-validator-config.conf
index 8a777c5..c97bb4c 100644
--- a/tests/integrated/insert-delete-validator-config.conf
+++ b/tests/integrated/insert-delete-validator-config.conf
@@ -15,19 +15,20 @@
   }
   checker
   {
-    type fixed-signer
+    type customized
     sig-type rsa-sha256
-    signer
+    key-locator
     {
-      type file
-      file-name "insert-delete-test.cert"
+      type name
+      name /DEFAULT
+      relation equal
     }
   }
 }
 
 rule
 {
-  id "Test Rule For Datat"
+  id "Test Rule For Data"
   for data
   filter
   {
@@ -37,12 +38,19 @@
   }
   checker
   {
-    type fixed-signer
+    type customized
     sig-type rsa-sha256
-    signer
+    key-locator
     {
-      type file
-      file-name "insert-delete-test.cert"
+      type name
+      name /DEFAULT
+      relation equal
     }
   }
-}
\ No newline at end of file
+}
+
+trust-anchor
+{
+  type file
+  file-name "insert-delete-test.cert"
+}
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index ff4b866..ea58abe 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -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-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -17,20 +17,28 @@
  * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "handles/write-handle.hpp"
 #include "handles/delete-handle.hpp"
-#include "storage/sqlite-storage.hpp"
+#include "handles/write-handle.hpp"
+
 #include "storage/repo-storage.hpp"
+#include "storage/sqlite-storage.hpp"
 
 #include "command-fixture.hpp"
 #include "../repo-storage-fixture.hpp"
 #include "../dataset-fixtures.hpp"
 
+#include <ndn-cxx/security/command-interest-signer.hpp>
+#include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/util/random.hpp>
+#include <ndn-cxx/util/time.hpp>
 
+#include <boost/asio/io_service.hpp>
 #include <boost/mpl/vector.hpp>
 #include <boost/test/unit_test.hpp>
 
+
+#include <iostream>
+
 namespace repo {
 namespace tests {
 
@@ -48,8 +56,8 @@
 {
 public:
   Fixture()
-    : writeHandle(repoFace, *handle, keyChain, scheduler, validator)
-    , deleteHandle(repoFace, *handle, keyChain, scheduler, validator)
+    : writeHandle(repoFace, *handle, dispatcher, scheduler, validator)
+    , deleteHandle(repoFace, *handle, dispatcher, scheduler, validator)
     , insertFace(repoFace.getIoService())
     , deleteFace(repoFace.getIoService())
   {
@@ -58,8 +66,6 @@
       [] (const Name& cmdPrefix, const std::string& reason) {
         BOOST_FAIL("Command prefix registration error: " << reason);
       });
-    writeHandle.listen(cmdPrefix);
-    deleteHandle.listen(cmdPrefix);
   }
 
   void
@@ -114,7 +120,7 @@
 {
   Data data(Name(interest.getName()));
   data.setContent(content, sizeof(content));
-  data.setFreshnessPeriod(milliseconds(0));
+  data.setFreshnessPeriod(0_ms);
   keyChain.sign(data);
   insertFace.put(data);
   std::map<Name, EventId>::iterator event = insertEvents.find(interest.getName());
@@ -123,7 +129,7 @@
     insertEvents.erase(event);
   }
   // schedule an event 50ms later to check whether insert is Ok
-  scheduler.scheduleEvent(milliseconds(500),
+  scheduler.scheduleEvent(500_ms,
                           bind(&Fixture<T>::checkInsertOk, this, interest));
 
 }
@@ -146,9 +152,8 @@
 {
   RepoCommandResponse response;
   response.wireDecode(data.getContent().blockFromValue());
-  int statusCode = response.getStatusCode();
+  int statusCode = response.getCode();
   BOOST_CHECK_EQUAL(statusCode, 100);
-  //  std::cout<<"statuse code of insert name = "<<response.getName()<<std::endl;
 }
 
 template<class T> void
@@ -156,11 +161,11 @@
 {
   RepoCommandResponse response;
   response.wireDecode(data.getContent().blockFromValue());
-  int statusCode = response.getStatusCode();
+  int statusCode = response.getCode();
   BOOST_CHECK_EQUAL(statusCode, 200);
 
   //schedlute an event to check whether delete is Ok.
-  scheduler.scheduleEvent(milliseconds(100),
+  scheduler.scheduleEvent(100_ms,
                           bind(&Fixture<T>::checkDeleteOk, this, interest));
 }
 
@@ -204,7 +209,7 @@
     BOOST_CHECK_EQUAL(rc, 0);
   }
   else {
-    std::cerr<<"Check Insert Failed"<<std::endl;
+    BOOST_ERROR("Check Insert Failed");
   }
 }
 
@@ -229,11 +234,11 @@
     insertCommandName.append(insertParameter.wireEncode());
     Interest insertInterest(insertCommandName);
     keyChain.sign(insertInterest);
-    //schedule a job to express insertInterest every 50ms
+
+    // schedule a job to express insertInterest every 50ms
     scheduler.scheduleEvent(milliseconds(timeCount * 50 + 1000),
                             bind(&Fixture<T>::sendInsertInterest, this, insertInterest));
-    //schedule what to do when interest timeout
-
+    // schedule what to do when interest timeout
     EventId delayEventId = scheduler.scheduleEvent(milliseconds(5000 + timeCount * 50),
                                                    bind(&Fixture<T>::delayedInterest, this));
     insertEvents[insertParameter.getName()] = delayEventId;
@@ -266,21 +271,21 @@
   }
 }
 
-typedef boost::mpl::vector< BasicDataset,
-                            FetchByPrefixDataset,
-                            BasicChildSelectorDataset,
-                            ExtendedChildSelectorDataset,
-                            SamePrefixDataset<10> > Datasets;
+typedef boost::mpl::vector<BasicDataset,
+                           FetchByPrefixDataset,
+                           BasicChildSelectorDataset,
+                           ExtendedChildSelectorDataset,
+                           SamePrefixDataset<10>> Datasets;
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertDelete, T, Datasets, Fixture<T>)
 {
   // schedule events
-  this->scheduler.scheduleEvent(seconds(0),
+  this->scheduler.scheduleEvent(0_s,
                                 bind(&Fixture<T>::scheduleInsertEvent, this));
-  this->scheduler.scheduleEvent(seconds(10),
+  this->scheduler.scheduleEvent(10_s,
                                 bind(&Fixture<T>::scheduleDeleteEvent, this));
 
-  this->repoFace.processEvents(seconds(30));
+  this->repoFace.processEvents(30_s);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/integrated/test-basic-command-watch.cpp b/tests/integrated/test-basic-command-watch.cpp
index 1e38da9..6fe677d 100644
--- a/tests/integrated/test-basic-command-watch.cpp
+++ b/tests/integrated/test-basic-command-watch.cpp
@@ -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-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -46,7 +46,7 @@
 {
 public:
   Fixture()
-    : watchHandle(repoFace, *handle, keyChain, scheduler, validator)
+    : watchHandle(repoFace, *handle, dispatcher, scheduler, validator)
     , watchFace(repoFace.getIoService())
   {
     Name cmdPrefix("/repo/command");
@@ -54,7 +54,6 @@
       [] (const Name& cmdPrefix, const std::string& reason) {
         BOOST_FAIL("Command prefix registration error: " << reason);
       });
-    watchHandle.listen(cmdPrefix);
   }
 
   void
@@ -99,12 +98,12 @@
   auto data = make_shared<Data>(Name(interest.getName())
                                 .appendNumber(ndn::random::generateWord64() + 100));
   data->setContent(content, sizeof(content));
-  data->setFreshnessPeriod(milliseconds(0));
+  data->setFreshnessPeriod(0_ms);
   keyChain.sign(*data);
   watchFace.put(*data);
 
   // schedule an event 50ms later to check whether watch is Ok
-  scheduler.scheduleEvent(milliseconds(10000),
+  scheduler.scheduleEvent(10000_ms,
                           bind(&Fixture<T>::checkWatchOk, this,
                                Interest(data->getName())));
 }
@@ -128,7 +127,7 @@
   RepoCommandResponse response;
   response.wireDecode(data.getContent().blockFromValue());
 
-  int statusCode = response.getStatusCode();
+  int statusCode = response.getCode();
   BOOST_CHECK_EQUAL(statusCode, 100);
 }
 
@@ -138,7 +137,7 @@
   RepoCommandResponse response;
   response.wireDecode(data.getContent().blockFromValue());
 
-  int statusCode = response.getStatusCode();
+  int statusCode = response.getCode();
   BOOST_CHECK_EQUAL(statusCode, 101);
 }
 
@@ -187,13 +186,13 @@
   RepoCommandParameter watchParameter;
   watchParameter.setName(Name("/a/b"));
   watchParameter.setMaxInterestNum(10);
-  watchParameter.setInterestLifetime(milliseconds(50000));
-  watchParameter.setWatchTimeout(milliseconds(1000000000));
+  watchParameter.setInterestLifetime(50000_ms);
+  watchParameter.setWatchTimeout(1000000000_ms);
   watchCommandName.append(watchParameter.wireEncode());
   Interest watchInterest(watchCommandName);
   keyChain.sign(watchInterest);
   //schedule a job to express watchInterest
-  scheduler.scheduleEvent(milliseconds(1000),
+  scheduler.scheduleEvent(1000_ms,
                           bind(&Fixture<T>::sendWatchStartInterest, this, watchInterest));
 
   Name watchStopName("/repo/command/watch/stop");
@@ -202,8 +201,6 @@
   Interest watchStopInterest(watchStopName);
   keyChain.sign(watchStopInterest);
 
- // scheduler.scheduleEvent(milliseconds(10000),
-  //                        bind(&Fixture<T>::sendWatchStopInterest, this, watchStopInterest));
   //The delayEvent will be canceled in onWatchInterest
   watchFace.setInterestFilter(watchParameter.getName(),
                               bind(&Fixture<T>::onWatchInterest, this, _2),
@@ -211,15 +208,15 @@
                               bind(&Fixture<T>::onRegisterFailed, this, _2));
 }
 
-typedef boost::mpl::vector< BasicDataset > Dataset;
+typedef boost::mpl::vector<BasicDataset> Dataset;
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(WatchDelete, T, Dataset, Fixture<T>)
 {
   // schedule events
-  this->scheduler.scheduleEvent(seconds(0),
+  this->scheduler.scheduleEvent(1_s,
                                 bind(&Fixture<T>::scheduleWatchEvent, this));
 
-  this->repoFace.processEvents(seconds(500));
+  this->repoFace.processEvents(500_s);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index 8028894..0ad2f3c 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -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-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -27,6 +27,8 @@
 #include <boost/asio/io_service.hpp>
 #include <boost/test/unit_test.hpp>
 
+#include <ndn-cxx/util/time.hpp>
+
 namespace repo {
 namespace tests {
 
@@ -41,7 +43,7 @@
 public:
   BasicInterestReadFixture()
     : scheduler(repoFace.getIoService())
-    , readHandle(repoFace, *handle, keyChain, scheduler, 0)
+    , readHandle(repoFace, *handle, 0)
     , readFace(repoFace.getIoService())
   {
   }
@@ -65,7 +67,7 @@
          i != this->data.end(); ++i) {
       //First insert a data into database;
       (*i)->setContent(content, sizeof(content));
-      (*i)->setFreshnessPeriod(ndn::time::milliseconds(36000));
+      (*i)->setFreshnessPeriod(36000_ms);
       keyChain.sign(**i);
       bool rc = handle->insertData(**i);
 
@@ -93,11 +95,17 @@
   }
 
   void
+  onReadNack(const ndn::Interest& interest, const ndn::lp::Nack& nack)
+  {
+    BOOST_ERROR("Read nacked");
+  }
+
+  void
   sendInterest(const ndn::Interest& interest)
   {
     readFace.expressInterest(interest,
                              bind(&BasicInterestReadFixture::onReadData, this, _1, _2),
-                             bind(&BasicInterestReadFixture::onReadTimeout, this, _1), // Nack
+                             bind(&BasicInterestReadFixture::onReadNack, this, _1, _2),
                              bind(&BasicInterestReadFixture::onReadTimeout, this, _1));
   }
 
@@ -109,28 +117,19 @@
   ndn::Face readFace;
 };
 
-
-typedef boost::mpl::vector< BasicDataset,
+typedef boost::mpl::vector<BasicDataset,
                             FetchByPrefixDataset,
                             BasicChildSelectorDataset,
                             ExtendedChildSelectorDataset,
-                            SamePrefixDataset<10> > Datasets;
+                            SamePrefixDataset<10>> Datasets;
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(Read, T, Datasets, BasicInterestReadFixture<T>)
 {
-  // Insert dataset
-  // for (typename T::DataContainer::iterator i = this->data.begin();
-  //      i != this->data.end(); ++i) {
-  //   BOOST_CHECK_EQUAL(this->handle.insertData(**i), true);
-  // }
-
-  // BOOST_CHECK_EQUAL(this->handle.size(), this->data.size());
-
   this->startListen();
-  this->scheduler.scheduleEvent(ndn::time::seconds(0),
+  this->scheduler.scheduleEvent(1_s,
                                 bind(&BasicInterestReadFixture<T>::scheduleReadEvent, this));
 
-  this->repoFace.processEvents(ndn::time::seconds(20));
+  this->repoFace.processEvents(20_s);
 
 }
 
diff --git a/tests/unit/read-handle.t.cpp b/tests/unit/read-handle.t.cpp
index cb9d233..9afc325 100644
--- a/tests/unit/read-handle.t.cpp
+++ b/tests/unit/read-handle.t.cpp
@@ -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-2018,  Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -53,7 +53,7 @@
     , subsetLength(1)
     , dataPrefix("/ndn/test/prefix")
     , identity("/ndn/test/identity")
-    , readHandle(face, *handle, keyChain, scheduler, subsetLength)
+    , readHandle(face, *handle, subsetLength)
     , numPrefixRegistrations(0)
     , numPrefixUnregistrations(0)
   {
@@ -103,32 +103,32 @@
   bool didMatch = false;
   face.sentInterests.clear();
   handle->insertData(*data1);
-  face.processEvents(ndn::time::milliseconds(-1));
+  face.processEvents(-1_ms);
   CHECK_INTERESTS(interest.getName(), name::Component{"register"}, true);
 
   face.sentInterests.clear();
   handle->deleteData(data1->getFullName());
-  face.processEvents(ndn::time::milliseconds(-1));
+  face.processEvents(-1_ms);
   CHECK_INTERESTS(interest.getName(), name::Component{"unregister"}, true);
 
   face.sentInterests.clear();
   handle->insertData(*data1);
-  face.processEvents(ndn::time::milliseconds(-1));
+  face.processEvents(-1_ms);
   CHECK_INTERESTS(interest.getName(), name::Component{"register"}, true);
 
   face.sentInterests.clear();
   handle->insertData(*data2);
-  face.processEvents(ndn::time::milliseconds(-1));
+  face.processEvents(-1_ms);
   CHECK_INTERESTS(interest.getName(), name::Component{"register"}, false);
 
   face.sentInterests.clear();
   handle->deleteData(data1->getFullName());
-  face.processEvents(ndn::time::milliseconds(-1));
+  face.processEvents(-1_ms);
   CHECK_INTERESTS(interest.getName(), name::Component{"unregister"}, false);
 
   face.sentInterests.clear();
   handle->deleteData(data2->getFullName());
-  face.processEvents(ndn::time::milliseconds(-1));
+  face.processEvents(-1_ms);
   CHECK_INTERESTS(interest.getName(), name::Component{"unregister"}, true);
 }
 
diff --git a/tests/unit/repo-command-response.cpp b/tests/unit/repo-command-response.cpp
index ab03207..7686c50 100644
--- a/tests/unit/repo-command-response.cpp
+++ b/tests/unit/repo-command-response.cpp
@@ -29,7 +29,7 @@
 BOOST_AUTO_TEST_CASE(EncodeDecode)
 {
   repo::RepoCommandResponse response;
-  response.setStatusCode(404);
+  response.setCode(404);
   response.setStartBlockId(1);
   response.setEndBlockId(100);
   response.setProcessId(1234567890);
@@ -53,7 +53,7 @@
                                   wire.begin(), wire.end());
 
   repo::RepoCommandResponse decoded(wire);
-  BOOST_CHECK_EQUAL(decoded.getStatusCode(), response.getStatusCode());
+  BOOST_CHECK_EQUAL(decoded.getCode(), response.getCode());
   BOOST_CHECK_EQUAL(decoded.getStartBlockId(), response.getStartBlockId());
   BOOST_CHECK_EQUAL(decoded.getEndBlockId(), response.getEndBlockId());
   BOOST_CHECK_EQUAL(decoded.getProcessId(), response.getProcessId());