management: process Nack in nfd::Controller

refs #3264

Change-Id: Ifaa73ac04e8838a89708fc63a578941d700712c6
diff --git a/tests/unit-tests/management/nfd-controller.t.cpp b/tests/unit-tests/management/nfd-controller.t.cpp
index 07c5894..6479cd6 100644
--- a/tests/unit-tests/management/nfd-controller.t.cpp
+++ b/tests/unit-tests/management/nfd-controller.t.cpp
@@ -26,6 +26,7 @@
 
 #include "boost-test.hpp"
 #include "util/dummy-client-face.hpp"
+#include "../make-interest-data.hpp"
 #include "../unit-test-time-fixture.hpp"
 
 namespace ndn {
@@ -35,7 +36,7 @@
 using ndn::util::DummyClientFace;
 using ndn::util::makeDummyClientFace;
 
-BOOST_AUTO_TEST_SUITE(ManagementNfdController)
+BOOST_AUTO_TEST_SUITE(Management)
 
 class CommandFixture : public ndn::tests::UnitTestTimeFixture
 {
@@ -75,7 +76,9 @@
   std::vector<CommandFailArgs> commandFailHistory;
 };
 
-BOOST_FIXTURE_TEST_CASE(CommandSuccess, CommandFixture)
+BOOST_FIXTURE_TEST_SUITE(TestNfdController, CommandFixture)
+
+BOOST_AUTO_TEST_CASE(CommandSuccess)
 {
   ControlParameters parameters;
   parameters.setUri("tcp4://192.0.2.1:6363");
@@ -108,10 +111,9 @@
   ControlResponse responsePayload(201, "created");
   responsePayload.setBody(responseBody.wireEncode());
 
-  Data responseData(requestInterest.getName());
-  responseData.setContent(responsePayload.wireEncode());
-  keyChain.sign(responseData);
-  face->receive(responseData);
+  auto responseData = util::makeData(requestInterest.getName());
+  responseData->setContent(responsePayload.wireEncode());
+  face->receive(*responseData);
 
   advanceClocks(time::milliseconds(1));
 
@@ -122,7 +124,7 @@
   BOOST_CHECK_EQUAL(response.getFaceId(), responseBody.getFaceId());
 }
 
-BOOST_FIXTURE_TEST_CASE(CommandInvalidRequest, CommandFixture)
+BOOST_AUTO_TEST_CASE(CommandInvalidRequest)
 {
   ControlParameters parameters;
   parameters.setName("ndn:/should-not-have-this-field");
@@ -135,7 +137,7 @@
                     ControlCommand::ArgumentError);
 }
 
-BOOST_FIXTURE_TEST_CASE(CommandErrorCode, CommandFixture)
+BOOST_AUTO_TEST_CASE(CommandErrorCode)
 {
   ControlParameters parameters;
   parameters.setUri("tcp4://192.0.2.1:6363");
@@ -151,10 +153,9 @@
 
   ControlResponse responsePayload(401, "Not Authenticated");
 
-  Data responseData(requestInterest.getName());
-  responseData.setContent(responsePayload.wireEncode());
-  keyChain.sign(responseData);
-  face->receive(responseData);
+  auto responseData = util::makeData(requestInterest.getName());
+  responseData->setContent(responsePayload.wireEncode());
+  face->receive(*responseData);
   advanceClocks(time::milliseconds(1));
 
   BOOST_CHECK_EQUAL(commandSucceedHistory.size(), 0);
@@ -162,7 +163,7 @@
   BOOST_CHECK_EQUAL(commandFailHistory[0].get<0>(), 401);
 }
 
-BOOST_FIXTURE_TEST_CASE(CommandInvalidResponse, CommandFixture)
+BOOST_AUTO_TEST_CASE(CommandInvalidResponse)
 {
   ControlParameters parameters;
   parameters.setUri("tcp4://192.0.2.1:6363");
@@ -183,17 +184,38 @@
   ControlResponse responsePayload(201, "created");
   responsePayload.setBody(responseBody.wireEncode());
 
-  Data responseData(requestInterest.getName());
-  responseData.setContent(responsePayload.wireEncode());
-  keyChain.sign(responseData);
-  face->receive(responseData);
+  auto responseData = util::makeData(requestInterest.getName());
+  responseData->setContent(responsePayload.wireEncode());
+  face->receive(*responseData);
   advanceClocks(time::milliseconds(1));
 
   BOOST_CHECK_EQUAL(commandSucceedHistory.size(), 0);
   BOOST_REQUIRE_EQUAL(commandFailHistory.size(), 1);
 }
 
-BOOST_FIXTURE_TEST_CASE(OptionsPrefix, CommandFixture)
+BOOST_AUTO_TEST_CASE(CommandNack)
+{
+  ControlParameters parameters;
+  parameters.setUri("tcp4://192.0.2.1:6363");
+
+  BOOST_CHECK_NO_THROW(controller.start<FaceCreateCommand>(
+                       parameters,
+                       commandSucceedCallback,
+                       commandFailCallback));
+  advanceClocks(time::milliseconds(1));
+
+  BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
+  const Interest& requestInterest = face->sentInterests[0];
+
+  auto responseNack = util::makeNack(requestInterest, lp::NackReason::NO_ROUTE);
+  face->receive(responseNack);
+  advanceClocks(time::milliseconds(1));
+
+  BOOST_REQUIRE_EQUAL(commandFailHistory.size(), 1);
+  BOOST_CHECK_EQUAL(commandFailHistory[0].get<0>(), Controller::ERROR_NACK);
+}
+
+BOOST_AUTO_TEST_CASE(OptionsPrefix)
 {
   ControlParameters parameters;
   parameters.setName("/ndn/com/example");
@@ -217,7 +239,7 @@
               requestInterest.getName()));
 }
 
-BOOST_FIXTURE_TEST_CASE(OptionsTimeout, CommandFixture)
+BOOST_AUTO_TEST_CASE(OptionsTimeout)
 {
   ControlParameters parameters;
   parameters.setUri("tcp4://192.0.2.1:6363");
@@ -236,7 +258,8 @@
   BOOST_CHECK_EQUAL(commandFailHistory[0].get<0>(), Controller::ERROR_TIMEOUT);
 }
 
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestController
+BOOST_AUTO_TEST_SUITE_END() // Management
 
 } // namespace tests
 } // namespace nfd