fw: refine pipelines, dispatch to strategy

refs #1345 #1255

Change-Id: If1cfc26049f87318103fc09c3b211ebf1eb3ebaa
diff --git a/tests/mgmt/strategy-choice-manager.cpp b/tests/mgmt/strategy-choice-manager.cpp
index dd3291b..6577f6d 100644
--- a/tests/mgmt/strategy-choice-manager.cpp
+++ b/tests/mgmt/strategy-choice-manager.cpp
@@ -12,7 +12,7 @@
 #include "fw/forwarder.hpp"
 #include "fw/strategy.hpp"
 #include "tests/face/dummy-face.hpp"
-
+#include "tests/fw/dummy-strategy.hpp"
 
 #include "tests/test-common.hpp"
 #include "validation-common.hpp"
@@ -22,73 +22,18 @@
 
 NFD_LOG_INIT("StrategyChoiceManagerTest");
 
-class DummyStrategy : public fw::Strategy
-{
-public:
-  DummyStrategy(Forwarder& forwarder, const Name& strategyName)
-    : fw::Strategy(forwarder, strategyName)
-  {
-
-  }
-
-  virtual
-  ~DummyStrategy()
-  {
-
-  }
-
-  virtual void
-  afterReceiveInterest(const Face& inFace,
-                       const Interest& interest,
-                       shared_ptr<fib::Entry> fibEntry,
-                       shared_ptr<pit::Entry> pitEntry)
-  {
-
-  }
-};
-
-class TestStrategyA : public DummyStrategy
-{
-public:
-  TestStrategyA(Forwarder& forwarder)
-    : DummyStrategy(forwarder, "/localhost/nfd/strategy/test-strategy-a")
-  {
-  }
-
-  virtual
-  ~TestStrategyA()
-  {
-
-  }
-};
-
-class TestStrategyB : public DummyStrategy
-{
-public:
-  TestStrategyB(Forwarder& forwarder)
-    : DummyStrategy(forwarder, "/localhost/nfd/strategy/test-strategy-b")
-  {
-  }
-
-  virtual
-  ~TestStrategyB()
-  {
-
-  }
-};
-
 class StrategyChoiceManagerFixture : protected BaseFixture
 {
 public:
 
   StrategyChoiceManagerFixture()
-    : m_nameTree(1024)
-    , m_strategyChoice(m_nameTree, make_shared<TestStrategyA>(boost::ref(m_forwarder)))
+    : m_strategyChoice(m_forwarder.getStrategyChoice())
     , m_face(make_shared<InternalFace>())
     , m_manager(m_strategyChoice, m_face)
     , m_callbackFired(false)
   {
-
+    m_strategyChoice.install(make_shared<DummyStrategy>(boost::ref(m_forwarder), "/localhost/nfd/strategy/test-strategy-a"));
+    m_strategyChoice.insert("ndn:/", "/localhost/nfd/strategy/test-strategy-a");
   }
 
   virtual
@@ -193,8 +138,7 @@
 
 protected:
   Forwarder m_forwarder;
-  NameTree m_nameTree;
-  StrategyChoice m_strategyChoice;
+  StrategyChoice& m_strategyChoice;
   shared_ptr<InternalFace> m_face;
   StrategyChoiceManager m_manager;
 
@@ -207,7 +151,7 @@
 public:
   AllStrategiesFixture()
   {
-    m_strategyChoice.install(make_shared<TestStrategyB>(boost::ref(m_forwarder)));
+    m_strategyChoice.install(make_shared<DummyStrategy>(boost::ref(m_forwarder), "/localhost/nfd/strategy/test-strategy-b"));
   }
 
   virtual
diff --git a/tests/mgmt/validation-common.cpp b/tests/mgmt/validation-common.cpp
new file mode 100644
index 0000000..3ad1701
--- /dev/null
+++ b/tests/mgmt/validation-common.cpp
@@ -0,0 +1,33 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "validation-common.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+namespace nfd {
+namespace tests {
+
+const Name CommandIdentityGlobalFixture::s_identityName("/unit-test/CommandFixture/id");
+shared_ptr<ndn::IdentityCertificate> CommandIdentityGlobalFixture::s_certificate;
+
+CommandIdentityGlobalFixture::CommandIdentityGlobalFixture()
+{
+  BOOST_ASSERT(!static_cast<bool>(s_certificate));
+  s_certificate = m_keys.getCertificate(m_keys.createIdentity(s_identityName));
+}
+
+CommandIdentityGlobalFixture::~CommandIdentityGlobalFixture()
+{
+  s_certificate.reset();
+  m_keys.deleteIdentity(s_identityName);
+}
+
+BOOST_GLOBAL_FIXTURE(CommandIdentityGlobalFixture);
+
+} // namespace tests
+} // namespace nfd
+
diff --git a/tests/mgmt/validation-common.hpp b/tests/mgmt/validation-common.hpp
index 8e16103..9b876d9 100644
--- a/tests/mgmt/validation-common.hpp
+++ b/tests/mgmt/validation-common.hpp
@@ -4,9 +4,10 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef VALIDATION_COMMON_HPP
-#define VALIDATION_COMMON_HPP
+#ifndef NFD_TEST_MGMT_VALIDATION_COMMON_HPP
+#define NFD_TEST_MGMT_VALIDATION_COMMON_HPP
 
+#include "common.hpp"
 #include <ndn-cpp-dev/util/command-interest-generator.hpp>
 
 namespace nfd {
@@ -29,6 +30,30 @@
 //   shared_ptr<ndn::CommandInterestValidator> m_validator;
 // };
 
+/// a global fixture that holds the identity for CommandFixture
+class CommandIdentityGlobalFixture
+{
+public:
+  CommandIdentityGlobalFixture();
+
+  ~CommandIdentityGlobalFixture();
+  
+  static const Name& getIdentityName()
+  {
+    return s_identityName;
+  }
+  
+  static shared_ptr<ndn::IdentityCertificate> getCertificate()
+  {
+    BOOST_ASSERT(static_cast<bool>(s_certificate));
+    return s_certificate;
+  }
+
+private:
+  ndn::KeyChain m_keys;
+  static const Name s_identityName;
+  static shared_ptr<ndn::IdentityCertificate> s_certificate;
+};
 
 template<typename T>
 class CommandFixture : public T
@@ -37,33 +62,27 @@
   virtual
   ~CommandFixture()
   {
-    m_keys.deleteIdentity(m_identityName);
-
   }
 
   void
   generateCommand(Interest& interest)
   {
-    m_generator.generateWithIdentity(interest, m_identityName);
+    m_generator.generateWithIdentity(interest, getIdentityName());
   }
 
   const Name&
   getIdentityName() const
   {
-    return m_identityName;
+    return CommandIdentityGlobalFixture::getIdentityName();
   }
 
 protected:
   CommandFixture()
-    : m_identityName("/unit-test/CommandFixture/id"),
-      m_certificate(m_keys.getCertificate(m_keys.createIdentity(m_identityName)))
+    : m_certificate(CommandIdentityGlobalFixture::getCertificate())
   {
-
   }
 
 protected:
-  ndn::KeyChain m_keys;
-  const Name m_identityName;
   shared_ptr<ndn::IdentityCertificate> m_certificate;
   ndn::CommandInterestGenerator m_generator;
 };
@@ -82,7 +101,7 @@
   }
 };
 
-} //namespace tests
+} // namespace tests
 } // namespace nfd
 
-#endif // VALIDATION_COMMON_HPP
+#endif // NFD_TEST_MGMT_VALIDATION_COMMON_HPP