Remove dependency on Selectors and refactor codebase.

Change-Id: Ic3024b76ba0eea61f790c91c36090b4aa68702a3
Refs: #4522
diff --git a/tests/integrated/command-fixture.cpp b/tests/integrated/command-fixture.cpp
index a803a51..ad7955a 100644
--- a/tests/integrated/command-fixture.cpp
+++ b/tests/integrated/command-fixture.cpp
@@ -28,8 +28,8 @@
   , dispatcher(repoFace, keyChain)
   , validator(repoFace)
 {
-  this->saveIdentityCertificate(keyChain.getPib().getDefaultIdentity().getName(),
-                                "tests/integrated/insert-delete-test.cert");
+  this->addIdentity("/ndn/test/repo");
+  this->saveIdentityCertificate("/ndn/test/repo", "tests/integrated/insert-delete-test.cert");
   validator.load("tests/integrated/insert-delete-validator-config.conf");
 }
 
diff --git a/tests/integrated/insert-delete-validator-config.conf b/tests/integrated/insert-delete-validator-config.conf
index c97bb4c..0820266 100644
--- a/tests/integrated/insert-delete-validator-config.conf
+++ b/tests/integrated/insert-delete-validator-config.conf
@@ -1,8 +1,7 @@
 ; The test rules below are for test suite TestBasicCommandInsertDelete.
 ; Signed interests and data packets are signed by default certificate.
 ; In these test rules, the type of checker is fixed signer and signer type is file.
-; So user who wants to run this test could use security tool to dump the defualt
-; certificate into a file named "insert-delete-test.cert"
+
 rule
 {
   id "Test Rule For Signed Interest"
@@ -20,7 +19,7 @@
     key-locator
     {
       type name
-      name /DEFAULT
+      name /ndn/test/repo
       relation equal
     }
   }
@@ -43,7 +42,7 @@
     key-locator
     {
       type name
-      name /DEFAULT
+      name /ndn/test/repo
       relation equal
     }
   }
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index ea58abe..f3685f6 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -36,9 +36,6 @@
 #include <boost/mpl/vector.hpp>
 #include <boost/test/unit_test.hpp>
 
-
-#include <iostream>
-
 namespace repo {
 namespace tests {
 
@@ -46,6 +43,7 @@
 using ndn::time::seconds;
 using ndn::EventId;
 
+
 // All the test cases in this test suite should be run at once.
 BOOST_AUTO_TEST_SUITE(TestBasicCommandInsertDelete)
 
@@ -60,6 +58,7 @@
     , deleteHandle(repoFace, *handle, dispatcher, scheduler, validator)
     , insertFace(repoFace.getIoService())
     , deleteFace(repoFace.getIoService())
+    , signer(keyChain)
   {
     Name cmdPrefix("/repo/command");
     repoFace.registerPrefix(cmdPrefix, nullptr,
@@ -113,6 +112,8 @@
   Face insertFace;
   Face deleteFace;
   std::map<Name, EventId> insertEvents;
+  std::map<Name, Name> deleteNamePairs;
+  ndn::security::CommandInterestSigner signer;
 };
 
 template<class T> void
@@ -129,9 +130,7 @@
     insertEvents.erase(event);
   }
   // schedule an event 50ms later to check whether insert is Ok
-  scheduler.scheduleEvent(500_ms,
-                          bind(&Fixture<T>::checkInsertOk, this, interest));
-
+  scheduler.scheduleEvent(500_ms, std::bind(&Fixture<T>::checkInsertOk, this, interest));
 }
 
 
@@ -165,8 +164,7 @@
   BOOST_CHECK_EQUAL(statusCode, 200);
 
   //schedlute an event to check whether delete is Ok.
-  scheduler.scheduleEvent(100_ms,
-                          bind(&Fixture<T>::checkDeleteOk, this, interest));
+  scheduler.scheduleEvent(100_ms, std::bind(&Fixture<T>::checkDeleteOk, this, interest));
 }
 
 template<class T> void
@@ -185,25 +183,25 @@
 Fixture<T>::sendInsertInterest(const Interest& insertInterest)
 {
   insertFace.expressInterest(insertInterest,
-                             bind(&Fixture<T>::onInsertData, this, _1, _2),
-                             bind(&Fixture<T>::onInsertTimeout, this, _1), // Nack
-                             bind(&Fixture<T>::onInsertTimeout, this, _1));
+                             std::bind(&Fixture<T>::onInsertData, this, _1, _2),
+                             std::bind(&Fixture<T>::onInsertTimeout, this, _1), // Nack
+                             std::bind(&Fixture<T>::onInsertTimeout, this, _1));
 }
 
 template<class T> void
 Fixture<T>::sendDeleteInterest(const Interest& deleteInterest)
 {
   deleteFace.expressInterest(deleteInterest,
-                             bind(&Fixture<T>::onDeleteData, this, _1, _2),
-                             bind(&Fixture<T>::onDeleteTimeout, this, _1), // Nack
-                             bind(&Fixture<T>::onDeleteTimeout, this, _1));
+                             std::bind(&Fixture<T>::onDeleteData, this, _1, _2),
+                             std::bind(&Fixture<T>::onDeleteTimeout, this, _1), // Nack
+                             std::bind(&Fixture<T>::onDeleteTimeout, this, _1));
 }
 
 template<class T> void
 Fixture<T>::checkInsertOk(const Interest& interest)
 {
   BOOST_TEST_MESSAGE(interest);
-  shared_ptr<Data> data = handle->readData(interest);
+  std::shared_ptr<Data> data = handle->readData(interest);
   if (data) {
     int rc = memcmp(data->getContent().value(), content, sizeof(content));
     BOOST_CHECK_EQUAL(rc, 0);
@@ -216,10 +214,14 @@
 template<class T> void
 Fixture<T>::checkDeleteOk(const Interest& interest)
 {
-  shared_ptr<Data> data = handle->readData(interest);
-  BOOST_CHECK_EQUAL(data, shared_ptr<Data>());
+  std::map<Name, Name>::iterator name = deleteNamePairs.find(interest.getName());
+  BOOST_CHECK_MESSAGE(name != deleteNamePairs.end(), "Delete name not found: " << interest.getName());
+  Interest dataInterest(name->second);
+  std::shared_ptr<Data> data = handle->readData(dataInterest);
+  BOOST_CHECK(!data);
 }
 
+
 template<class T> void
 Fixture<T>::scheduleInsertEvent()
 {
@@ -230,24 +232,20 @@
     RepoCommandParameter insertParameter;
     insertParameter.setName(Name((*i)->getName())
                             .appendNumber(ndn::random::generateWord64()));
-
     insertCommandName.append(insertParameter.wireEncode());
-    Interest insertInterest(insertCommandName);
-    keyChain.sign(insertInterest);
-
+    Interest insertInterest = signer.makeCommandInterest(insertCommandName);
     // schedule a job to express insertInterest every 50ms
     scheduler.scheduleEvent(milliseconds(timeCount * 50 + 1000),
-                            bind(&Fixture<T>::sendInsertInterest, this, insertInterest));
+                            std::bind(&Fixture<T>::sendInsertInterest, this, insertInterest));
     // schedule what to do when interest timeout
     EventId delayEventId = scheduler.scheduleEvent(milliseconds(5000 + timeCount * 50),
-                                                   bind(&Fixture<T>::delayedInterest, this));
+                                                   std::bind(&Fixture<T>::delayedInterest, this));
     insertEvents[insertParameter.getName()] = delayEventId;
-
-    //The delayEvent will be canceled in onInsertInterest
+    // The delayEvent will be canceled in onInsertInterest
     insertFace.setInterestFilter(insertParameter.getName(),
-                                 bind(&Fixture<T>::onInsertInterest, this, _2),
+                                 std::bind(&Fixture<T>::onInsertInterest, this, _2),
                                  ndn::RegisterPrefixSuccessCallback(),
-                                 bind(&Fixture<T>::onRegisterFailed, this, _2));
+                                 std::bind(&Fixture<T>::onRegisterFailed, this, _2));
     timeCount++;
   }
 }
@@ -263,27 +261,23 @@
     deleteParameter.setProcessId(ndn::random::generateWord64());
     deleteParameter.setName((*i)->getName());
     deleteCommandName.append(deleteParameter.wireEncode());
-    Interest deleteInterest(deleteCommandName);
-    keyChain.sign(deleteInterest);
+    Interest deleteInterest = signer.makeCommandInterest(deleteCommandName);
+    deleteNamePairs[deleteInterest.getName()] = (*i)->getName();
     scheduler.scheduleEvent(milliseconds(4000 + timeCount * 50),
-                            bind(&Fixture<T>::sendDeleteInterest, this, deleteInterest));
+                            std::bind(&Fixture<T>::sendDeleteInterest, this, deleteInterest));
     timeCount++;
   }
 }
 
-typedef boost::mpl::vector<BasicDataset,
-                           FetchByPrefixDataset,
-                           BasicChildSelectorDataset,
-                           ExtendedChildSelectorDataset,
-                           SamePrefixDataset<10>> Datasets;
+using Datasets = boost::mpl::vector<BasicDataset,
+                                    FetchByPrefixDataset,
+                                    SamePrefixDataset<10>>;
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertDelete, T, Datasets, Fixture<T>)
 {
   // schedule events
-  this->scheduler.scheduleEvent(0_s,
-                                bind(&Fixture<T>::scheduleInsertEvent, this));
-  this->scheduler.scheduleEvent(10_s,
-                                bind(&Fixture<T>::scheduleDeleteEvent, this));
+  this->scheduler.scheduleEvent(0_s, std::bind(&Fixture<T>::scheduleInsertEvent, this));
+  this->scheduler.scheduleEvent(10_s, std::bind(&Fixture<T>::scheduleDeleteEvent, this));
 
   this->repoFace.processEvents(30_s);
 }
diff --git a/tests/integrated/test-basic-command-watch.cpp b/tests/integrated/test-basic-command-watch.cpp
deleted file mode 100644
index 6fe677d..0000000
--- a/tests/integrated/test-basic-command-watch.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * 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.
- *
- * repo-ng 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.
- *
- * repo-ng 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
- * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "handles/watch-handle.hpp"
-#include "storage/sqlite-storage.hpp"
-
-#include "command-fixture.hpp"
-#include "../repo-storage-fixture.hpp"
-#include "../dataset-fixtures.hpp"
-
-#include <ndn-cxx/util/random.hpp>
-
-#include <boost/mpl/vector.hpp>
-#include <boost/test/unit_test.hpp>
-
-namespace repo {
-namespace tests {
-
-using ndn::time::milliseconds;
-using ndn::time::seconds;
-using ndn::EventId;
-
-// All the test cases in this test suite should be run at once.
-BOOST_AUTO_TEST_SUITE(TestBasicCommandWatchDelete)
-
-const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
-
-template<class Dataset>
-class Fixture : public CommandFixture, public RepoStorageFixture, public Dataset
-{
-public:
-  Fixture()
-    : watchHandle(repoFace, *handle, dispatcher, scheduler, validator)
-    , watchFace(repoFace.getIoService())
-  {
-    Name cmdPrefix("/repo/command");
-    repoFace.registerPrefix(cmdPrefix, nullptr,
-      [] (const Name& cmdPrefix, const std::string& reason) {
-        BOOST_FAIL("Command prefix registration error: " << reason);
-      });
-  }
-
-  void
-  scheduleWatchEvent();
-
-  void
-  onWatchInterest(const Interest& interest);
-
-  void
-  onRegisterFailed(const std::string& reason);
-
-  void
-  delayedInterest();
-
-  void
-  onWatchData(const Interest& interest, const Data& data);
-
-  void
-  onWatchStopData(const Interest& interest, const Data& data);
-
-  void
-  onWatchTimeout(const Interest& interest);
-
-  void
-  sendWatchStartInterest(const Interest& interest);
-
-  void
-  sendWatchStopInterest(const Interest& interest);
-
-  void
-  checkWatchOk(const Interest& interest);
-
-public:
-  WatchHandle watchHandle;
-  Face watchFace;
-  std::map<Name, EventId> watchEvents;
-};
-
-template<class T> void
-Fixture<T>::onWatchInterest(const Interest& interest)
-{
-  auto data = make_shared<Data>(Name(interest.getName())
-                                .appendNumber(ndn::random::generateWord64() + 100));
-  data->setContent(content, sizeof(content));
-  data->setFreshnessPeriod(0_ms);
-  keyChain.sign(*data);
-  watchFace.put(*data);
-
-  // schedule an event 50ms later to check whether watch is Ok
-  scheduler.scheduleEvent(10000_ms,
-                          bind(&Fixture<T>::checkWatchOk, this,
-                               Interest(data->getName())));
-}
-
-
-template<class T> void
-Fixture<T>::onRegisterFailed(const std::string& reason)
-{
-  BOOST_ERROR("ERROR: Failed to register prefix in local hub's daemon" + reason);
-}
-
-template<class T> void
-Fixture<T>::delayedInterest()
-{
-  BOOST_ERROR("Fetching interest does not come. It may be satisfied in CS or something is wrong");
-}
-
-template<class T> void
-Fixture<T>::onWatchData(const Interest& interest, const Data& data)
-{
-  RepoCommandResponse response;
-  response.wireDecode(data.getContent().blockFromValue());
-
-  int statusCode = response.getCode();
-  BOOST_CHECK_EQUAL(statusCode, 100);
-}
-
-template<class T> void
-Fixture<T>::onWatchStopData(const Interest& interest, const Data& data)
-{
-  RepoCommandResponse response;
-  response.wireDecode(data.getContent().blockFromValue());
-
-  int statusCode = response.getCode();
-  BOOST_CHECK_EQUAL(statusCode, 101);
-}
-
-template<class T> void
-Fixture<T>::onWatchTimeout(const Interest& interest)
-{
-  BOOST_ERROR("Watch command timeout");
-}
-
-template<class T> void
-Fixture<T>::sendWatchStartInterest(const Interest& watchInterest)
-{
-  watchFace.expressInterest(watchInterest,
-                            bind(&Fixture<T>::onWatchData, this, _1, _2),
-                            bind(&Fixture<T>::onWatchTimeout, this, _1), // Nack
-                            bind(&Fixture<T>::onWatchTimeout, this, _1));
-}
-
-template<class T> void
-Fixture<T>::sendWatchStopInterest(const Interest& watchInterest)
-{
-  watchFace.expressInterest(watchInterest,
-                            bind(&Fixture<T>::onWatchStopData, this, _1, _2),
-                            bind(&Fixture<T>::onWatchTimeout, this, _1), // Nack
-                            bind(&Fixture<T>::onWatchTimeout, this, _1));
-}
-
-template<class T> void
-Fixture<T>::checkWatchOk(const Interest& interest)
-{
-  BOOST_TEST_MESSAGE(interest);
-  shared_ptr<Data> data = handle->readData(interest);
-  if (data) {
-    int rc = memcmp(data->getContent().value(), content, sizeof(content));
-    BOOST_CHECK_EQUAL(rc, 0);
-  }
-  else {
-    std::cerr<<"Check Watch Failed"<<std::endl;
-  }
-}
-
-template<class T> void
-Fixture<T>::scheduleWatchEvent()
-{
-  Name watchCommandName("/repo/command/watch/start");
-  RepoCommandParameter watchParameter;
-  watchParameter.setName(Name("/a/b"));
-  watchParameter.setMaxInterestNum(10);
-  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(1000_ms,
-                          bind(&Fixture<T>::sendWatchStartInterest, this, watchInterest));
-
-  Name watchStopName("/repo/command/watch/stop");
-  RepoCommandParameter watchStopParameter;
-  watchStopName.append(watchStopParameter.wireEncode());
-  Interest watchStopInterest(watchStopName);
-  keyChain.sign(watchStopInterest);
-
-  //The delayEvent will be canceled in onWatchInterest
-  watchFace.setInterestFilter(watchParameter.getName(),
-                              bind(&Fixture<T>::onWatchInterest, this, _2),
-                              ndn::RegisterPrefixSuccessCallback(),
-                              bind(&Fixture<T>::onRegisterFailed, this, _2));
-}
-
-typedef boost::mpl::vector<BasicDataset> Dataset;
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(WatchDelete, T, Dataset, Fixture<T>)
-{
-  // schedule events
-  this->scheduler.scheduleEvent(1_s,
-                                bind(&Fixture<T>::scheduleWatchEvent, this));
-
-  this->repoFace.processEvents(500_s);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace repo
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index 0ad2f3c..d73b0d1 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -27,12 +27,14 @@
 #include <boost/asio/io_service.hpp>
 #include <boost/test/unit_test.hpp>
 
+#include <ndn-cxx/util/logger.hpp>
 #include <ndn-cxx/util/time.hpp>
 
 namespace repo {
 namespace tests {
 
-// All the test cases in this test suite should be run at once.
+NDN_LOG_INIT(repo.tests.read);
+
 BOOST_AUTO_TEST_SUITE(TestBasicInerestRead)
 
 const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
@@ -69,13 +71,16 @@
       (*i)->setContent(content, sizeof(content));
       (*i)->setFreshnessPeriod(36000_ms);
       keyChain.sign(**i);
+      NDN_LOG_DEBUG(**i);
       bool rc = handle->insertData(**i);
 
       BOOST_CHECK_EQUAL(rc, true);
+      NDN_LOG_DEBUG("Inserted Data " << (**i).getName());
+
       Interest readInterest((*i)->getName());
       readInterest.setMustBeFresh(true);
       scheduler.scheduleEvent(ndn::time::milliseconds(timeCount * 50),
-                              bind(&BasicInterestReadFixture<Dataset>::sendInterest, this,
+                              std::bind(&BasicInterestReadFixture<Dataset>::sendInterest, this,
                                         readInterest));
       timeCount++;
     }
@@ -91,22 +96,25 @@
   void
   onReadTimeout(const ndn::Interest& interest)
   {
-    BOOST_ERROR("Insert not successfull or Read data does not successfull");
+    NDN_LOG_DEBUG("Timed out " << interest.getName());
+    BOOST_ERROR("Insert or read not successfull");
   }
 
   void
   onReadNack(const ndn::Interest& interest, const ndn::lp::Nack& nack)
   {
+    NDN_LOG_DEBUG("Nacked " << interest.getName() << nack.getReason());
     BOOST_ERROR("Read nacked");
   }
 
   void
   sendInterest(const ndn::Interest& interest)
   {
+    NDN_LOG_DEBUG("Sending Interest " << interest.getName());
     readFace.expressInterest(interest,
-                             bind(&BasicInterestReadFixture::onReadData, this, _1, _2),
-                             bind(&BasicInterestReadFixture::onReadNack, this, _1, _2),
-                             bind(&BasicInterestReadFixture::onReadTimeout, this, _1));
+                             std::bind(&BasicInterestReadFixture::onReadData, this, _1, _2),
+                             std::bind(&BasicInterestReadFixture::onReadNack, this, _1, _2),
+                             std::bind(&BasicInterestReadFixture::onReadTimeout, this, _1));
   }
 
 public:
@@ -117,17 +125,16 @@
   ndn::Face readFace;
 };
 
-typedef boost::mpl::vector<BasicDataset,
-                            FetchByPrefixDataset,
-                            BasicChildSelectorDataset,
-                            ExtendedChildSelectorDataset,
-                            SamePrefixDataset<10>> Datasets;
+
+using Datasets = boost::mpl::vector<BasicDataset,
+                                    FetchByPrefixDataset,
+                                    SamePrefixDataset<10>>;
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(Read, T, Datasets, BasicInterestReadFixture<T>)
 {
   this->startListen();
   this->scheduler.scheduleEvent(1_s,
-                                bind(&BasicInterestReadFixture<T>::scheduleReadEvent, this));
+                                std::bind(&BasicInterestReadFixture<T>::scheduleReadEvent, this));
 
   this->repoFace.processEvents(20_s);