Ensure prefix registration connects the underlying transport
diff --git a/pom.xml b/pom.xml
index 8fe99a7..14f13ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.intel.jndn.mock</groupId>
<artifactId>jndn-mock</artifactId>
- <version>0.9.6</version>
+ <version>0.9.7</version>
<name>jndn-mock</name>
<description>Tools for testing NDN Java code without using network IO.</description>
<url>https://github.com/01org/jndn-utils</url>
diff --git a/src/main/java/com/intel/jndn/mock/MockFace.java b/src/main/java/com/intel/jndn/mock/MockFace.java
index e1a62de..6a9a11a 100644
--- a/src/main/java/com/intel/jndn/mock/MockFace.java
+++ b/src/main/java/com/intel/jndn/mock/MockFace.java
@@ -497,6 +497,10 @@
@Override
public long registerPrefix(Name prefix, OnInterest onInterest, OnRegisterFailed onRegisterFailed,
ForwardingFlags flags, WireFormat wireFormat) throws IOException, net.named_data.jndn.security.SecurityException {
+ // since we don't send an Interest, ensure the transport is connected
+ if (!getTransport().getIsConnected())
+ getTransport().connect(node_.getConnectionInfo(), node_);
+
lastRegisteredId++;
handlerMap.put(lastRegisteredId, new MockOnInterestHandler(prefix, onInterest, flags));
return lastRegisteredId;
diff --git a/src/test/java/com/intel/jndn/mock/MockFaceTest.java b/src/test/java/com/intel/jndn/mock/MockFaceTest.java
index 8c51a6e..6bbbdda 100644
--- a/src/test/java/com/intel/jndn/mock/MockFaceTest.java
+++ b/src/test/java/com/intel/jndn/mock/MockFaceTest.java
@@ -21,6 +21,7 @@
import net.named_data.jndn.OnData;
import net.named_data.jndn.OnInterest;
import net.named_data.jndn.encoding.EncodingException;
+import net.named_data.jndn.security.SecurityException;
import net.named_data.jndn.transport.Transport;
import net.named_data.jndn.util.Blob;
import org.junit.Test;
@@ -138,4 +139,18 @@
return count;
}
}
+
+ /**
+ * Ensure registering a prefix connects the underlying transport
+ *
+ * @throws IOException
+ * @throws SecurityException
+ */
+ @Test
+ public void testRegistrationConnectsTransport() throws IOException, SecurityException {
+ MockFace face = new MockFace();
+ assertFalse(face.getTransport().getIsConnected());
+ face.registerPrefix(new Name("/fake/prefix"), null, null);
+ assertTrue(face.getTransport().getIsConnected());
+ }
}