Fix integration test key chain; add ability to parse segmented status datasets
diff --git a/src/main/java/com/intel/jndn/management/NFD.java b/src/main/java/com/intel/jndn/management/NFD.java
index e05b2a9..5b7442f 100644
--- a/src/main/java/com/intel/jndn/management/NFD.java
+++ b/src/main/java/com/intel/jndn/management/NFD.java
@@ -17,6 +17,7 @@
 import com.intel.jndn.management.types.FibEntry;
 import com.intel.jndn.management.types.RibEntry;
 import com.intel.jndn.utils.Client;
+import com.intel.jndn.utils.SegmentedClient;
 import java.io.IOException;
 import java.util.List;
 import net.named_data.jndn.ControlParameters;
@@ -90,12 +91,8 @@
     interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
     interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
 
-    // TODO verify that all faces are being returned; right now they don't
-    // match up with the results from nfd-status-http-server but no 
-    // additional segments are present;  
-    // see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
     // send packet
-    Data data = Client.getDefault().getSync(forwarder, interest);
+    Data data = SegmentedClient.getDefault().getSync(forwarder, interest);
     if (data == null) {
       throw new Exception("Failed to retrieve list of faces from the forwarder.");
     }
@@ -125,7 +122,7 @@
     // additional segments are present;  
     // see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
     // send packet
-    Data data = Client.getDefault().getSync(forwarder, interest);
+    Data data = SegmentedClient.getDefault().getSync(forwarder, interest);
     if (data == null) {
       throw new Exception("Failed to retrieve list of fib entries from the forwarder.");
     }
@@ -151,7 +148,7 @@
     interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
 
     // send packet
-    Data data = Client.getDefault().getSync(forwarder, interest);
+    Data data = SegmentedClient.getDefault().getSync(forwarder, interest);
     if (data == null) {
       throw new Exception("Failed to retrieve list of faces from the forwarder.");
     }
@@ -289,14 +286,10 @@
    * been set up (e.g. forwarder.setCommandSigningInfo()
    *
    * @param forwarder
-   * @param route
+   * @param controlParameters
    * @return
    */
-  public static boolean unregister(Face forwarder, Name route) throws Exception{
-     // build command name
-    ControlParameters controlParameters = new ControlParameters();
-    controlParameters.setName(route);
-
+  public static boolean unregister(Face forwarder, ControlParameters controlParameters) throws Exception {
     // build command name
     Name command = new Name("/localhost/nfd/rib/unregister");
     command.append(controlParameters.wireEncode());
@@ -306,6 +299,80 @@
   }
 
   /**
+   * Unregister a route on a forwarder; see
+   * http://named-data.net/doc/NFD/current/manpages/nfdc.html for command-line
+   * usage and http://redmine.named-data.net/projects/nfd/wiki/RibMgmt for
+   * protocol documentation. Ensure the forwarding face is on the local machine
+   * (management requests are to /localhost/...) and that command signing has
+   * been set up (e.g. forwarder.setCommandSigningInfo()
+   *
+   * @param forwarder
+   * @param route
+   * @return
+   */
+  public static boolean unregister(Face forwarder, Name route) throws Exception {
+    // build command name
+    ControlParameters controlParameters = new ControlParameters();
+    controlParameters.setName(route);
+
+    // send the interest
+    return unregister(forwarder, controlParameters);
+  }
+
+  /**
+   * Unregister a route on a forwarder; see
+   * http://named-data.net/doc/NFD/current/manpages/nfdc.html for command-line
+   * usage and http://redmine.named-data.net/projects/nfd/wiki/RibMgmt for
+   * protocol documentation. Ensure the forwarding face is on the local machine
+   * (management requests are to /localhost/...) and that command signing has
+   * been set up (e.g. forwarder.setCommandSigningInfo()
+   *
+   * @param forwarder
+   * @param route
+   * @param faceId
+   * @return
+   */
+  public static boolean unregister(Face forwarder, Name route, int faceId) throws Exception {
+    // build command name
+    ControlParameters controlParameters = new ControlParameters();
+    controlParameters.setName(route);
+    controlParameters.setFaceId(faceId);
+
+    // send the interest
+    return unregister(forwarder, controlParameters);
+  }
+
+  /**
+   * Unregister a route on a forwarder; see
+   * http://named-data.net/doc/NFD/current/manpages/nfdc.html for command-line
+   * usage and http://redmine.named-data.net/projects/nfd/wiki/RibMgmt for
+   * protocol documentation. Ensure the forwarding face is on the local machine
+   * (management requests are to /localhost/...) and that command signing has
+   * been set up (e.g. forwarder.setCommandSigningInfo()
+   *
+   * @param forwarder
+   * @param route
+   * @param uri
+   * @return
+   */
+  public static boolean unregister(Face forwarder, Name route, String uri) throws Exception {
+    int faceId = -1;
+    for(FaceStatus face : getFaceList(forwarder)){
+      if(face.getUri().matches(uri)){
+        faceId = face.getFaceId();
+        break;
+      }
+    }
+    
+    if(faceId == -1){
+      throw new Exception("Face not found: " + uri);
+    }
+
+    // send the interest
+    return unregister(forwarder, route, faceId);
+  }
+
+  /**
    * Set a strategy on the forwarder; see
    * http://named-data.net/doc/NFD/current/manpages/nfdc.html for command-line
    * usage and http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice
diff --git a/src/test/java/com/intel/jndn/management/IntegrationSuite.java b/src/test/java/com/intel/jndn/management/IntegrationSuite.java
index a2263f2..05d59b0 100644
--- a/src/test/java/com/intel/jndn/management/IntegrationSuite.java
+++ b/src/test/java/com/intel/jndn/management/IntegrationSuite.java
@@ -14,6 +14,7 @@
 import junit.framework.Assert;
 import net.named_data.jndn.Face;
 import net.named_data.jndn.Name;
+import net.named_data.jndn.security.KeyChain;
 
 /**
  * Tests to run with a local NFD as part of integration testing; will not run in
@@ -25,19 +26,46 @@
 
   private static final Logger logger = Logger.getLogger(IntegrationSuite.class.getName());
 
+  /**
+   * Test NFD methods
+   *
+   * @param args
+   * @throws Exception
+   */
   public static void main(String[] args) throws Exception {
     Face face = new Face("localhost");
+    KeyChain keyChain = buildTestKeyChain();
+    face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName());
+
     Assert.assertTrue(NFD.pingLocal(face));
-    
+
     // grab datasets
     Assert.assertFalse(NFD.getFaceList(face).isEmpty());
     Assert.assertFalse(NFD.getFibList(face).isEmpty());
     Assert.assertFalse(NFD.getRouteList(face).isEmpty());
-    
+
     // create a new route
-    Assert.assertTrue(NFD.register(face, "contentstore://", new Name("/my/cache/route"), 999));
-    
+    Assert.assertTrue(NFD.register(face, "udp4://127.0.0.1:56363", new Name("/my/test/route"), 999));
+
     // remove the route
-    Assert.assertTrue(NFD.unregister(face, new Name("/my/cache/route")));
+    Assert.assertTrue(NFD.unregister(face, new Name("/my/test/route"), "udp4://127.0.0.1:56363"));
+  }
+
+  /**
+   * Setup the KeyChain with a default identity; TODO move this to
+   * MemoryIdentityStorage once it can handle getting/setting defaults
+   *
+   * @return
+   * @throws net.named_data.jndn.security.SecurityException
+   */
+  public static KeyChain buildTestKeyChain() throws net.named_data.jndn.security.SecurityException {
+    KeyChain keyChain = new KeyChain();
+    try {
+      keyChain.getDefaultCertificateName();
+    } catch (net.named_data.jndn.security.SecurityException e) {
+      keyChain.createIdentity(new Name("/test/identity"));
+      keyChain.getIdentityManager().setDefaultIdentity(new Name("/test/identity"));
+    }
+    return keyChain;
   }
 }