Refactor for release; still need integration tests
diff --git a/src/test/java/com/intel/jndn/management/ControlResponseTest.java b/src/test/java/com/intel/jndn/management/ControlResponseTest.java
new file mode 100644
index 0000000..5d026e0
--- /dev/null
+++ b/src/test/java/com/intel/jndn/management/ControlResponseTest.java
@@ -0,0 +1,52 @@
+/*
+ * File name: ControlResponseTest.java
+ *
+ * Purpose: Test encoding/decoding of ControlResponses.
+ *
+ * © Copyright Intel Corporation. All rights reserved.
+ * Intel Corporation, 2200 Mission College Boulevard,
+ * Santa Clara, CA 95052-8119, USA
+ */
+package com.intel.jndn.management;
+
+import com.intel.jndn.management.types.ControlResponse;
+import junit.framework.Assert;
+import net.named_data.jndn.ControlParameters;
+import net.named_data.jndn.util.Blob;
+import org.junit.Test;
+
+/**
+ * Test encoding/decoding of ControlResponses.
+ *
+ * @author Andrew Brown <andrew.brown@intel.com>
+ */
+public class ControlResponseTest {
+
+ /**
+ * Test encoding/decoding
+ *
+ * @throws java.lang.Exception
+ */
+ @Test
+ public void testEncodeDecode() throws Exception {
+ ControlParameters parameters = new ControlParameters();
+ parameters.setFaceId(3);
+ ControlResponse response = new ControlResponse();
+ response.setStatusCode(404);
+ response.setStatusText("Not Found");
+ response.getBody().add(parameters);
+
+ // encode
+ Blob encoded = response.wireEncode();
+
+ // decode
+ ControlResponse decoded = new ControlResponse();
+ decoded.wireDecode(encoded.buf());
+
+ // test
+ Assert.assertEquals(response.getStatusCode(), decoded.getStatusCode());
+ Assert.assertEquals(response.getStatusText(), decoded.getStatusText());
+ Assert.assertEquals(response.getBody().size(), decoded.getBody().size());
+ Assert.assertEquals(response.getBody().get(0).getFaceId(), decoded.getBody().get(0).getFaceId());
+ }
+}
diff --git a/src/test/java/com/intel/jndn/management/FaceStatusTest.java b/src/test/java/com/intel/jndn/management/FaceStatusTest.java
index c4d5ba0..f0d3eaf 100644
--- a/src/test/java/com/intel/jndn/management/FaceStatusTest.java
+++ b/src/test/java/com/intel/jndn/management/FaceStatusTest.java
@@ -10,8 +10,11 @@
*/
package com.intel.jndn.management;
+import com.intel.jndn.management.types.StatusDataset;
+import com.intel.jndn.management.types.FaceStatus;
import com.intel.jndn.utils.Client;
import java.util.List;
+import junit.framework.Assert;
import net.named_data.jndn.Data;
import net.named_data.jndn.Face;
import net.named_data.jndn.Interest;
@@ -30,24 +33,55 @@
* @author Andrew Brown <andrew.brown@intel.com>
*/
public class FaceStatusTest {
-
+
private static final Logger logger = LogManager.getLogger();
/**
+ * Test encoding/decoding
+ *
+ * @throws java.lang.Exception
+ */
+ @Test
+ public void testEncodeDecode() throws Exception {
+ FaceStatus status = new FaceStatus();
+ status.setFaceId(42);
+ status.setUri("...");
+ status.setLocalUri("...");
+
+ // encode
+ Blob encoded = status.wireEncode();
+
+ // decode
+ FaceStatus decoded = new FaceStatus();
+ decoded.wireDecode(encoded.buf());
+
+ // test
+ Assert.assertEquals(status.getFaceId(), decoded.getFaceId());
+ Assert.assertEquals(status.getUri(), decoded.getUri());
+ Assert.assertEquals(status.getLocalUri(), decoded.getLocalUri());
+ Assert.assertEquals(status.getExpirationPeriod(), decoded.getExpirationPeriod());
+ Assert.assertEquals(status.getFaceScope(), decoded.getFaceScope());
+ Assert.assertEquals(status.getFacePersistency(), decoded.getFacePersistency());
+ Assert.assertEquals(status.getLinkType(), decoded.getLinkType());
+ Assert.assertEquals(status.getInBytes(), decoded.getInBytes());
+ Assert.assertEquals(status.getOutBytes(), decoded.getOutBytes());
+ }
+
+ /**
* Test of decode method, of class FaceStatus.
*
* @throws java.lang.Exception
*/
@Test
- public void testDecode() throws Exception {
+ public void testDecodeFakeData() throws Exception {
Data data = getFaceData(true);
- List<FaceStatus> results = FaceStatus.decode(data);
+ List<FaceStatus> results = StatusDataset.wireDecode(data.getContent(), FaceStatus.class);
assertTrue(results.size() > 4);
for (FaceStatus f : results) {
// the first face (face 1) should always be the internal face
- if (f.faceId == 1) {
- assertEquals("internal://", f.uri);
- assertEquals("internal://", f.localUri);
+ if (f.getFaceId() == 1) {
+ assertEquals("internal://", f.getUri());
+ assertEquals("internal://", f.getLocalUri());
}
}
}
@@ -58,15 +92,15 @@
* @param args
* @throws EncodingException
*/
- public static void main(String[] args) throws EncodingException {
+ public static void main(String[] args) throws Exception {
Data data = getFaceData(false);
- List<FaceStatus> results = FaceStatus.decode(data);
+ List<FaceStatus> results = StatusDataset.wireDecode(data.getContent(), FaceStatus.class);
assertTrue(results.size() > 4);
for (FaceStatus f : results) {
// the first face (face 1) should always be the internal face
- if (f.faceId == 1) {
- assertEquals("internal://", f.uri);
- assertEquals("internal://", f.localUri);
+ if (f.getFaceId() == 1) {
+ assertEquals("internal://", f.getUri());
+ assertEquals("internal://", f.getLocalUri());
}
}
}
diff --git a/src/test/java/com/intel/jndn/management/FibEntryTest.java b/src/test/java/com/intel/jndn/management/FibEntryTest.java
new file mode 100644
index 0000000..85ac273
--- /dev/null
+++ b/src/test/java/com/intel/jndn/management/FibEntryTest.java
@@ -0,0 +1,85 @@
+/*
+ * File name: FibEntryTest.java
+ *
+ * Purpose: Test encode/decode of FibEntry and NextHopRecord
+ *
+ * © Copyright Intel Corporation. All rights reserved.
+ * Intel Corporation, 2200 Mission College Boulevard,
+ * Santa Clara, CA 95052-8119, USA
+ */
+package com.intel.jndn.management;
+
+import com.intel.jndn.management.types.StatusDataset;
+import com.intel.jndn.management.types.NextHopRecord;
+import com.intel.jndn.management.types.FibEntry;
+import com.intel.jndn.utils.Client;
+import java.util.List;
+import junit.framework.Assert;
+import net.named_data.jndn.Data;
+import net.named_data.jndn.Face;
+import net.named_data.jndn.Interest;
+import net.named_data.jndn.Name;
+import net.named_data.jndn.encoding.EncodingException;
+import net.named_data.jndn.util.Blob;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+/**
+ * Test encode/decode of FibEntry and NextHopRecord
+ *
+ * @author Andrew Brown <andrew.brown@intel.com>
+ */
+public class FibEntryTest {
+
+ /**
+ * Test encoding/decoding
+ *
+ * @throws java.lang.Exception
+ */
+ @Test
+ public void testEncodeDecode() throws Exception {
+ NextHopRecord nextHopRecord = new NextHopRecord();
+ nextHopRecord.setFaceId(42);
+ nextHopRecord.setCost(100);
+ FibEntry entry = new FibEntry();
+ entry.setName(new Name("/fib/entry/test"));
+ entry.getRecords().add(nextHopRecord);
+
+ // encode
+ Blob encoded = entry.wireEncode();
+
+ // decode
+ FibEntry decoded = new FibEntry();
+ decoded.wireDecode(encoded.buf());
+
+ // test
+ Assert.assertEquals(entry.getName().toUri(), decoded.getName().toUri());
+ Assert.assertEquals(entry.getRecords().get(0).getFaceId(), decoded.getRecords().get(0).getFaceId());
+ Assert.assertEquals(entry.getRecords().get(0).getCost(), decoded.getRecords().get(0).getCost());
+ }
+
+ /**
+ * Integration test to run on actual system
+ *
+ * @param args
+ * @throws EncodingException
+ */
+ public static void main(String[] args) throws Exception {
+ Face forwarder = new Face("localhost");
+
+ // build management Interest packet; see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
+ Interest interest = new Interest(new Name("/localhost/nfd/fib/list"));
+ interest.setMustBeFresh(true);
+ interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
+ interest.setInterestLifetimeMilliseconds(2000.0);
+
+ // send packet
+ Data data = Client.getDefault().getSync(forwarder, interest);
+
+ // decode results
+ List<FibEntry> results = StatusDataset.wireDecode(data.getContent(), FibEntry.class);
+ assertTrue(results.size() > 0);
+ assertEquals("/localhost/nfd", results.get(0).getName().toUri());
+ }
+}
diff --git a/src/test/java/com/intel/jndn/management/RibEntryTest.java b/src/test/java/com/intel/jndn/management/RibEntryTest.java
new file mode 100644
index 0000000..96dd70b
--- /dev/null
+++ b/src/test/java/com/intel/jndn/management/RibEntryTest.java
@@ -0,0 +1,87 @@
+/*
+ * File name: RibEntryTest.java
+ *
+ * Purpose: Test encoding/decoding for RibEntry.
+ *
+ * © Copyright Intel Corporation. All rights reserved.
+ * Intel Corporation, 2200 Mission College Boulevard,
+ * Santa Clara, CA 95052-8119, USA
+ */
+package com.intel.jndn.management;
+
+import com.intel.jndn.management.types.StatusDataset;
+import com.intel.jndn.management.types.RibEntry;
+import com.intel.jndn.management.types.Route;
+import com.intel.jndn.utils.Client;
+import java.util.List;
+import junit.framework.Assert;
+import net.named_data.jndn.Data;
+import net.named_data.jndn.Face;
+import net.named_data.jndn.Interest;
+import net.named_data.jndn.Name;
+import net.named_data.jndn.encoding.EncodingException;
+import net.named_data.jndn.util.Blob;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+/**
+ * Test encoding/decoding for RibEntry.
+ *
+ * @author Andrew Brown <andrew.brown@intel.com>
+ */
+public class RibEntryTest {
+
+ /**
+ * Test encoding/decoding
+ *
+ * @throws java.lang.Exception
+ */
+ @Test
+ public void testEncodeDecode() throws Exception {
+ Route route = new Route();
+ route.setFaceId(42);
+ route.setCost(100);
+ route.setOrigin(0);
+ RibEntry entry = new RibEntry();
+ entry.setName(new Name("/rib/entry/test"));
+ entry.getRoutes().add(route);
+
+ // encode
+ Blob encoded = entry.wireEncode();
+
+ // decode
+ RibEntry decoded = new RibEntry();
+ decoded.wireDecode(encoded.buf());
+
+ // test
+ Assert.assertEquals(entry.getName().toUri(), decoded.getName().toUri());
+ Assert.assertEquals(entry.getRoutes().get(0).getFaceId(), decoded.getRoutes().get(0).getFaceId());
+ Assert.assertEquals(entry.getRoutes().get(0).getCost(), decoded.getRoutes().get(0).getCost());
+ Assert.assertEquals(entry.getRoutes().get(0).getOrigin(), decoded.getRoutes().get(0).getOrigin());
+ }
+
+ /**
+ * Integration test to run on actual system
+ *
+ * @param args
+ * @throws EncodingException
+ */
+ public static void main(String[] args) throws Exception {
+ Face forwarder = new Face("localhost");
+
+ // build management Interest packet; see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
+ Interest interest = new Interest(new Name("/localhost/nfd/rib/list"));
+ interest.setMustBeFresh(true);
+ interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
+ interest.setInterestLifetimeMilliseconds(2000.0);
+
+ // send packet
+ Data data = Client.getDefault().getSync(forwarder, interest);
+
+ // decode results
+ List<RibEntry> results = StatusDataset.wireDecode(data.getContent(), RibEntry.class);
+ assertTrue(results.size() > 0);
+ assertEquals("/localhost/nfd", results.get(0).getName().toUri());
+ }
+}