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

refs: #1972

Change-Id: I1616574a4643884dac050d240b771423ec2a0846
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;