aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src
diff options
context:
space:
mode:
authorGanesh Chandrasekaran <ganesh.c@samsung.com>2018-08-31 08:57:24 +0900
committerTakamune Cho <tc012c@att.com>2018-09-05 23:19:27 +0000
commit16dc89fdfea1c6f72f10eb20586b16da79962aea (patch)
tree5d7f5e9f03dde039da07df28a1b61b1dc0576d7a /appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src
parent98cc619c1bb1cd59121bb862c8c48f4125319ba5 (diff)
covered cases for NetconfAdaptor2
Issue-ID: APPC-1182 Change-Id: Ib3e96b5869ce95299cf6e83a6f25ad04f7373382 Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
Diffstat (limited to 'appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src')
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter2.java13
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter2.java83
2 files changed, 96 insertions, 0 deletions
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter2.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter2.java
index 567a45a96..be286cd48 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter2.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter2.java
@@ -53,6 +53,19 @@ public class NetconfAdapter2 {
}
/**
+ * Constructor.
+ *
+ * @param in InputStream this instance will read netconf messages from
+ * @param out OutputStream this instance will write netconf messages to
+ * @throws IOException
+ */
+ public NetconfAdapter2(PipedInputStream in, PipedOutputStream out) throws IOException {
+ this.in = in;
+ this.out = out;
+
+ }
+
+ /**
* @return InputStream this instance will read netconf messages from.
*/
public InputStream getIn() {
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter2.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter2.java
new file mode 100644
index 000000000..344170967
--- /dev/null
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter2.java
@@ -0,0 +1,83 @@
+package org.onap.appc.adapter.netconf.internal;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+
+public class TestNetconfAdapter2 {
+
+ private static final String EOM = "]]>]]>";
+
+ @Test (expected = IOException.class)
+ public void testReceiveMessage() throws IOException {
+ PipedOutputStream pos = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(pos);
+
+ PipedInputStream pis = new PipedInputStream();
+ PipedOutputStream os = new PipedOutputStream(pis);
+
+ NetconfAdapter2 netconfAdapter = new NetconfAdapter2(is, os);
+
+ String request = "Hello, netconf!";
+ pos.write(request.getBytes());
+ pos.write(EOM.getBytes());
+ String response = netconfAdapter.receiveMessage();
+ Assert.assertNotNull(response);
+ Assert.assertEquals(request, response.trim());
+ }
+
+ @Test (expected = IOException.class)
+ public void testSendMessage() throws IOException {
+ PipedOutputStream pos = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(pos);
+
+ PipedInputStream pis = new PipedInputStream();
+ PipedOutputStream os = new PipedOutputStream(pis);
+
+ NetconfAdapter2 netconfAdapter = new NetconfAdapter2(is, os);
+
+ String request = "Hello, netconf!";
+ netconfAdapter.sendMessage(request);
+ byte[] bytes = new byte[request.length()+EOM.length()+2];
+ int count = pis.read(bytes);
+ String response = new String(bytes, 0, count);
+ Assert.assertNotNull(response);
+ Assert.assertTrue(response.endsWith(EOM));
+ response = response.substring(0, response.length() - EOM.length()).trim();
+ Assert.assertEquals(request, response);
+ }
+
+ @Test (expected = IOException.class)
+ public void testSendReceive() throws IOException {
+ PipedOutputStream os = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(os);
+
+ NetconfAdapter2 netconfAdapter = new NetconfAdapter2(is, os);
+
+ String request = "Hello, netconf!";
+ netconfAdapter.sendMessage(request);
+ String response = netconfAdapter.receiveMessage();
+ Assert.assertNotNull(response);
+ Assert.assertEquals(request, response.trim());
+ }
+
+ @Test
+ public void testDefaultSendReceive() throws IOException {
+
+ NetconfAdapter2 netconfAdapter = new NetconfAdapter2();
+
+ String request = "Hello, netconf!";
+ netconfAdapter.sendMessage(request);
+
+ InputStream in = netconfAdapter.getIn();
+ OutputStream out = netconfAdapter.getOut();
+
+ Assert.assertNotNull(in);
+ Assert.assertNotNull(out);
+ }
+} \ No newline at end of file