src: decouple classes from Nlsr object

refs: #1952, #2803, #3960, #4288

Change-Id: Ibe3ac3820f11e8107ee4b13e510d53c27467a6cb
diff --git a/tests/update/test-prefix-update-processor.cpp b/tests/update/test-prefix-update-processor.cpp
index 4713eb3..3cdb8c4 100644
--- a/tests/update/test-prefix-update-processor.cpp
+++ b/tests/update/test-prefix-update-processor.cpp
@@ -31,11 +31,12 @@
 #include <ndn-cxx/security/signing-helpers.hpp>
 
 #include <boost/filesystem.hpp>
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/info_parser.hpp>
 
 using namespace ndn;
 
 namespace nlsr {
-namespace update {
 namespace test {
 
 class PrefixUpdateFixture : public nlsr::test::UnitTestTimeFixture
@@ -43,11 +44,12 @@
 public:
   PrefixUpdateFixture()
     : face(m_ioService, m_keyChain, {true, true})
-    , siteIdentityName(ndn::Name("/edu/test-site"))
-    , opIdentityName(ndn::Name("/edu/test-site").append(ndn::Name("%C1.Operator")))
-    , nlsr(m_ioService, m_scheduler, face, m_keyChain)
-    , namePrefixList(nlsr.getNamePrefixList())
-    , updatePrefixUpdateProcessor(nlsr.getPrefixUpdateProcessor())
+    , siteIdentityName(ndn::Name("site"))
+    , opIdentityName(ndn::Name("site").append(ndn::Name("%C1.Operator")))
+    , conf(face)
+    , confProcessor(conf)
+    , nlsr(face, m_keyChain, conf)
+    , namePrefixList(conf.getNamePrefixList())
     , SITE_CERT_PATH(boost::filesystem::current_path() / std::string("site.cert"))
   {
     // Site cert
@@ -57,65 +59,28 @@
     // Operator cert
     opIdentity = addSubCertificate(opIdentityName, siteIdentity);
 
-    const std::string CONFIG = R"CONF(
-        rule
-        {
-          id "NLSR ControlCommand Rule"
-          for interest
-          filter
-          {
-            type name
-            regex ^(<localhost><nlsr>)<prefix-update>[<advertise><withdraw>]<><><>$
-          }
-          checker
-          {
-            type customized
-            sig-type rsa-sha256
-            key-locator
-            {
-              type name
-              regex ^<>*<KEY><>$
-            }
-          }
-        }
-        rule
-        {
-          id "NLSR Hierarchy Rule"
-          for data
-          filter
-          {
-            type name
-            regex ^[^<KEY>]*<KEY><><><>$
-          }
-          checker
-          {
-            type hierarchical
-            sig-type rsa-sha256
-          }
-        }
-        trust-anchor
-        {
-         type file
-         file-name "site.cert"
-        }
-    )CONF";
+    std::ifstream inputFile;
+    inputFile.open(std::string("nlsr.conf"));
 
-    const boost::filesystem::path CONFIG_PATH =
-      (boost::filesystem::current_path() / std::string("unit-test.conf"));
+    BOOST_REQUIRE(inputFile.is_open());
 
-    updatePrefixUpdateProcessor.getValidator().load(CONFIG, CONFIG_PATH.native());
+    boost::property_tree::ptree pt;
+
+    boost::property_tree::read_info(inputFile, pt);
+    for (const auto& tn : pt) {
+      if (tn.first == "security") {
+        for (const auto& it : tn.second) {
+          if (it.first == "prefix-update-validator") {
+            conf.getPrefixUpdateValidator().load(it.second, std::string("nlsr.conf"));
+          }
+        }
+      }
+    }
+    inputFile.close();
 
     nlsr.loadCertToPublish(opIdentity.getDefaultKey().getDefaultCertificate());
 
-    // Set the network so the LSA prefix is constructed
-    nlsr.getConfParameter().setNetwork("/ndn");
-    nlsr.getConfParameter().setSiteName("/edu/test-site");
-    nlsr.getConfParameter().setRouterName("/%C1.Router/this-router");
-    nlsr.getConfParameter().buildRouterPrefix();
-    // Otherwise code coverage node fails with default 60 seconds lifetime
-    nlsr.getConfParameter().setSyncInterestLifetime(1000);
-
-    addIdentity(ndn::Name("/ndn/edu/test-site/%C1.Router/this-router"));
+    addIdentity(conf.getRouterPrefix());
 
     // Initialize NLSR so a sync socket is created
     nlsr.initialize();
@@ -130,12 +95,12 @@
     // Need to send an interest now since ChronoSync
     // no longer does face->put(*data) in publishData.
     // Instead it does it in onInterest
-    ndn::Name lsaInterestName = nlsr.getConfParameter().getLsaPrefix();
-    lsaInterestName.append(nlsr.getConfParameter().getSiteName());
-    lsaInterestName.append(nlsr.getConfParameter().getRouterName());
+    ndn::Name lsaInterestName = conf.getLsaPrefix();
+    lsaInterestName.append(conf.getSiteName());
+    lsaInterestName.append(conf.getRouterName());
     lsaInterestName.append(std::to_string(Lsa::Type::NAME));
 
-    lsaInterestName.appendNumber(nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
+    lsaInterestName.appendNumber(nlsr.m_lsdb.getSequencingManager().getNameLsaSeq());
 
     auto lsaInterest = std::make_shared<Interest>(lsaInterestName);
     lsaInterest->setCanBePrefix(true);
@@ -148,7 +113,7 @@
   {
     sendInterestForPublishedData();
 
-    const ndn::Name& lsaPrefix = nlsr.getConfParameter().getLsaPrefix();
+    const ndn::Name& lsaPrefix = conf.getLsaPrefix();
 
     const auto& it = std::find_if(face.sentData.begin(), face.sentData.end(),
       [lsaPrefix] (const ndn::Data& data) {
@@ -168,9 +133,10 @@
   ndn::Name opIdentityName;
   ndn::security::pib::Identity opIdentity;
 
+  ConfParameter conf;
+  DummyConfFileProcessor confProcessor;
   Nlsr nlsr;
   NamePrefixList& namePrefixList;
-  PrefixUpdateProcessor& updatePrefixUpdateProcessor;
 
   const boost::filesystem::path SITE_CERT_PATH;
 };
@@ -179,7 +145,7 @@
 
 BOOST_AUTO_TEST_CASE(Basic)
 {
-  uint64_t nameLsaSeqNoBeforeInterest = nlsr.getLsdb().getSequencingManager().getNameLsaSeq();
+  uint64_t nameLsaSeqNoBeforeInterest = nlsr.m_lsdb.getSequencingManager().getNameLsaSeq();
 
   ndn::nfd::ControlParameters parameters;
   parameters.setName("/prefix/to/advertise/");
@@ -205,16 +171,16 @@
 
   this->advanceClocks(ndn::time::milliseconds(10));
 
-  NamePrefixList& namePrefixList = nlsr.getNamePrefixList();
+  NamePrefixList& namePrefixList = conf.getNamePrefixList();
 
   BOOST_REQUIRE_EQUAL(namePrefixList.size(), 1);
   BOOST_CHECK_EQUAL(namePrefixList.getNames().front(), parameters.getName());
 
   BOOST_CHECK(wasRoutingUpdatePublished());
-  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.getSequencingManager().getNameLsaSeq());
 
   face.sentData.clear();
-  nameLsaSeqNoBeforeInterest = nlsr.getLsdb().getSequencingManager().getNameLsaSeq();
+  nameLsaSeqNoBeforeInterest = nlsr.m_lsdb.getSequencingManager().getNameLsaSeq();
 
   //Withdraw
   ndn::Name withdrawCommand("/localhost/nlsr/prefix-update/withdraw");
@@ -230,11 +196,10 @@
   BOOST_CHECK_EQUAL(namePrefixList.size(), 0);
 
   BOOST_CHECK(wasRoutingUpdatePublished());
-  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.getSequencingManager().getNameLsaSeq());
 }
 
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace test
-} // namespace update
 } // namespace nlsr