mgmt: update strategy-choice/set to return a versioned strategy name

refs: #1972

Change-Id: I1616574a4643884dac050d240b771423ec2a0846
diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp
index 1193900..962349d 100644
--- a/daemon/mgmt/strategy-choice-manager.cpp
+++ b/daemon/mgmt/strategy-choice-manager.cpp
@@ -162,6 +162,7 @@
   if (m_strategyChoice.insert(prefix, selectedStrategy))
     {
       NFD_LOG_DEBUG("strategy-choice result: SUCCESS");
+      parameters.setStrategy(*m_strategyChoice.get(prefix));
       setResponse(response, 200, "Success", parameters.wireEncode());
     }
   else
diff --git a/daemon/table/strategy-choice.cpp b/daemon/table/strategy-choice.cpp
index 6500191..eedbc91 100644
--- a/daemon/table/strategy-choice.cpp
+++ b/daemon/table/strategy-choice.cpp
@@ -158,7 +158,7 @@
     return shared_ptr<const Name>();
   }
 
-  return entry->getStrategy().getName().shared_from_this();
+  return make_shared<const Name>(entry->getStrategy().getName());
 }
 
 static inline bool
diff --git a/tests/daemon/mgmt/strategy-choice-manager.cpp b/tests/daemon/mgmt/strategy-choice-manager.cpp
index 587c576..f8af3bb 100644
--- a/tests/daemon/mgmt/strategy-choice-manager.cpp
+++ b/tests/daemon/mgmt/strategy-choice-manager.cpp
@@ -41,7 +41,7 @@
 namespace nfd {
 namespace tests {
 
-NFD_LOG_INIT("StrategyChoiceManagerTest");
+NFD_LOG_INIT("MgmtStrategyChoiceManager");
 
 class StrategyChoiceManagerFixture : protected BaseFixture
 {
@@ -185,6 +185,14 @@
   {
     m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
                                                         "/localhost/nfd/strategy/test-strategy-b"));
+
+    const Name strategyCVersion1("/localhost/nfd/strategy/test-strategy-c/%FD%01");
+    m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
+                                                        strategyCVersion1));
+
+    const Name strategyCVersion2("/localhost/nfd/strategy/test-strategy-c/%FD%02");
+    m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
+                                                        strategyCVersion2));
   }
 
   virtual
@@ -355,6 +363,60 @@
   BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
 }
 
+BOOST_AUTO_TEST_CASE(SetStrategySpecifiedVersion)
+{
+  ControlParameters parameters;
+  parameters.setName("/test");
+  parameters.setStrategy("/localhost/nfd/strategy/test-strategy-c/%FD%01");
+
+  Block encodedParameters(parameters.wireEncode());
+
+  Name commandName("/localhost/nfd/strategy-choice");
+  commandName.append("set");
+  commandName.append(encodedParameters);
+
+  shared_ptr<Interest> command(make_shared<Interest>(commandName));
+
+  getFace()->onReceiveData +=
+    bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
+         command->getName(), 200, "Success", encodedParameters);
+
+  getManager().onValidatedStrategyChoiceRequest(command);
+
+  BOOST_REQUIRE(didCallbackFire());
+  fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
+  BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-c/%FD%01");
+}
+
+BOOST_AUTO_TEST_CASE(SetStrategyLatestVersion)
+{
+  ControlParameters parameters;
+  parameters.setName("/test");
+  parameters.setStrategy("/localhost/nfd/strategy/test-strategy-c");
+
+  Block encodedParameters(parameters.wireEncode());
+
+  Name commandName("/localhost/nfd/strategy-choice");
+  commandName.append("set");
+  commandName.append(encodedParameters);
+
+  shared_ptr<Interest> command(make_shared<Interest>(commandName));
+
+  ControlParameters responseParameters;
+  responseParameters.setName("/test");
+  responseParameters.setStrategy("/localhost/nfd/strategy/test-strategy-c/%FD%02");
+
+  getFace()->onReceiveData +=
+    bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
+         command->getName(), 200, "Success", responseParameters.wireEncode());
+
+  getManager().onValidatedStrategyChoiceRequest(command);
+
+  BOOST_REQUIRE(didCallbackFire());
+  fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
+  BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-c/%FD%02");
+}
+
 BOOST_AUTO_TEST_CASE(SetStrategiesMissingName)
 {
   ControlParameters parameters;
diff --git a/tests/daemon/table/strategy-choice.cpp b/tests/daemon/table/strategy-choice.cpp
index cf19138..cc7b279 100644
--- a/tests/daemon/table/strategy-choice.cpp
+++ b/tests/daemon/table/strategy-choice.cpp
@@ -35,6 +35,23 @@
 
 using fw::Strategy;
 
+BOOST_AUTO_TEST_CASE(Get)
+{
+  Forwarder forwarder;
+  Name nameP("ndn:/strategy/P");
+  shared_ptr<Strategy> strategyP = make_shared<DummyStrategy>(ref(forwarder), nameP);
+
+  StrategyChoice& table = forwarder.getStrategyChoice();
+
+  // install
+  BOOST_CHECK_EQUAL(table.install(strategyP), true);
+
+  BOOST_CHECK(table.insert("ndn:/", nameP));
+  // { '/'=>P }
+
+  BOOST_CHECK_EQUAL(*table.get("ndn:/"), nameP);
+}
+
 BOOST_AUTO_TEST_CASE(Effective)
 {
   Forwarder forwarder;