Add server capabilities, refactor observer pattern
diff --git a/src/test/java/com/intel/jndn/utils/ClientTest.java b/src/test/java/com/intel/jndn/utils/ClientTest.java
index a294817..88c39cc 100644
--- a/src/test/java/com/intel/jndn/utils/ClientTest.java
+++ b/src/test/java/com/intel/jndn/utils/ClientTest.java
@@ -70,7 +70,7 @@
// retrieve data
logger.info("Client expressing interest asynchronously: /test/async");
Client client = new Client();
- ClientObserver observer = client.get(face, new Name("/test/async"));
+ NDNObserver observer = client.get(face, new Name("/test/async"));
// wait
while (observer.eventCount() == 0) {
@@ -95,7 +95,7 @@
// retrieve non-existent data, should timeout
logger.info("Client expressing interest asynchronously: /test/timeout");
- ClientObserver observer = Client.getDefault().get(face, new Name("/test/timeout"));
+ NDNObserver observer = Client.getDefault().get(face, new Name("/test/timeout"));
// wait
while (observer.errorCount() == 0) {
@@ -122,10 +122,10 @@
// retrieve non-existent data, should timeout
logger.info("Client expressing interest asynchronously: /test/callback");
- ClientObserver observer = Client.getDefault().get(face, new Name("/test/callback"));
+ NDNObserver observer = Client.getDefault().get(face, new Name("/test/callback"));
observer.then(new OnEvent(){
@Override
- public void onEvent(ClientEvent event) {
+ public void onEvent(NDNEvent event) {
assertEquals(new Blob("...").buf(), ((Data) event.getPacket()).getContent().buf());
}
});
diff --git a/src/test/java/com/intel/jndn/utils/ServerTest.java b/src/test/java/com/intel/jndn/utils/ServerTest.java
new file mode 100644
index 0000000..a2b1880
--- /dev/null
+++ b/src/test/java/com/intel/jndn/utils/ServerTest.java
@@ -0,0 +1,58 @@
+/*
+ * File name: ServerTest.java
+ *
+ * Purpose: Test Server.java
+ *
+ * © Copyright Intel Corporation. All rights reserved.
+ * Intel Corporation, 2200 Mission College Boulevard,
+ * Santa Clara, CA 95052-8119, USA
+ */
+package com.intel.jndn.utils;
+
+import com.intel.jndn.mock.MockTransport;
+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.util.Blob;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test Server.java
+ * @author Andrew Brown <andrew.brown@intel.com>
+ */
+public class ServerTest {
+
+ private static final Logger logger = LogManager.getLogger();
+
+ /**
+ * Test on functionality
+ * TODO more comprehensive tests with InternalFace
+ * @throws java.lang.InterruptedException
+ */
+ @Test
+ public void testOn() throws InterruptedException {
+ // setup face
+ MockTransport transport = new MockTransport();
+ Face face = new Face(transport, null);
+
+ // setup server
+ NDNObserver observer = Server.getDefault().on(face, new Name("/test/server/on"), new OnServeInterest() {
+ @Override
+ public Data onInterest(Name prefix, Interest interest) {
+ Data data = new Data(interest.getName());
+ data.setContent(new Blob("..."));
+ return data;
+ }
+ });
+
+ // wait for background threads to run
+ Thread.sleep(100);
+
+ // check
+ assertEquals(1, transport.getSentInterestPackets().size());
+ }
+}