aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshashikanth.vh <shashikanth.vh@huawei.com>2018-03-28 14:49:39 +0530
committershashikanth.vh <shashikanth.vh@huawei.com>2018-03-28 14:49:45 +0530
commit448607990ac6b73d21f8d1b781e37ec798d7e29e (patch)
tree41203fbe5e0fc9cf7b5222669ed2081b1fda49a5
parente290ebd8696ea897d20cf0234c33e9104fca3853 (diff)
coverage SdncFlatJsonDmaapConsumer
Coverage improvement for SdncFlatJsonDmaapConsumer https://jira.onap.org/browse/CCSDK-213?jql=project%20%3D%20CCSDK%20AND%20text%20~%20coverage Issue-ID: CCSDK-213 Change-Id: Idb08f426e1626f8aa2b12d2c53f1960474af59c2 Signed-off-by: shashikanth.vh <shashikanth.vh@huawei.com>
-rw-r--r--dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncJsonDmaapConsumer.java106
1 files changed, 105 insertions, 1 deletions
diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncJsonDmaapConsumer.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncJsonDmaapConsumer.java
index 01bd3cf2..620098cb 100644
--- a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncJsonDmaapConsumer.java
+++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncJsonDmaapConsumer.java
@@ -10,6 +10,16 @@ package org.onap.ccsdk.sli.northbound.dmaapclient;
import org.junit.Test;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+
+import java.util.Map;
+import java.util.Properties;
+
public class TestSdncJsonDmaapConsumer {
private static final String DMAAP_LISTENER_PROPERTIES = "dmaap-listener.properties";
private static final String DMAAP_LISTENER_PROPERTIES_DIR = "src/test/resources";
@@ -19,9 +29,103 @@ public class TestSdncJsonDmaapConsumer {
SdncFlatJsonDmaapConsumer consumer = new SdncFlatJsonDmaapConsumer();
consumer.processMsg(null);
}
+
+ @Test
+ public void testProcessMsgFieldMap() throws Exception {
+ SdncFlatJsonDmaapConsumer consumer = new SdncFlatJsonDmaapConsumer();
+
+ String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
+ File directory = new File("lib");
+
+ if (! directory.exists()){
+ directory.mkdir();
+ }
+
+ File file = new File("lib" + "/" + "input.map");
+ try{
+ FileWriter fw = new FileWriter(file.getAbsoluteFile());
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write("SDNC.endpoint=>http://localhost:8282/restconf/operations");
+ bw.close();
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ }
+
+ try {
+ Map<String, String> env = System.getenv();
+ Class<?> cl = env.getClass();
+ Field field = cl.getDeclaredField("m");
+ field.setAccessible(true);
+ Map<String, String> writableEnv = (Map<String, String>) field.get(env);
+ writableEnv.put(DMAAPLISTENERROOT, ".");
+ } catch (Exception e) {
+ throw new IllegalStateException("Failed to set environment variable", e);
+ }
+
+ String msg = "{\n" +
+ " \"input\" : { \n" +
+ " }\n" +
+ "}";
+
+ InputStream propStr = TestSdncJsonDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-pserver.properties");
+ Properties props = new Properties();
+
+ props.load(propStr);
+
+ consumer.init(props, "src/test/resources/dmaap-consumer-pserver.properties");
+ consumer.processMsg(msg);
+ }
+
+ @Test(expected = InvalidMessageException.class)
+ public void testProcessMsgFieldMapNoSdncEndPoint() throws Exception {
+ SdncFlatJsonDmaapConsumer consumer = new SdncFlatJsonDmaapConsumer();
+
+ String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
+ File directory = new File("lib");
+
+ if (! directory.exists()){
+ directory.mkdir();
+ }
+
+ File file = new File("lib" + "/" + "input.map");
+ try{
+ FileWriter fw = new FileWriter(file.getAbsoluteFile());
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write("SDNC");
+ bw.close();
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ }
+
+ try {
+ Map<String, String> env = System.getenv();
+ Class<?> cl = env.getClass();
+ Field field = cl.getDeclaredField("m");
+ field.setAccessible(true);
+ Map<String, String> writableEnv = (Map<String, String>) field.get(env);
+ writableEnv.put(DMAAPLISTENERROOT, ".");
+ } catch (Exception e) {
+ throw new IllegalStateException("Failed to set environment variable", e);
+ }
+
+ String msg = "{\n" +
+ " \"input\" : { \n" +
+ " }\n" +
+ "}";
+
+ InputStream propStr = TestSdncJsonDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-pserver.properties");
+ Properties props = new Properties();
+
+ props.load(propStr);
+
+ consumer.init(props, "src/test/resources/dmaap-consumer-pserver.properties");
+ consumer.processMsg(msg);
+ }
@Test(expected = InvalidMessageException.class)
- public void testProcessMsgNullFieldMap_shouldThrowException() throws Exception {
+ public void testProcessMsgFieldMapNoFieldMap() throws Exception {
SdncFlatJsonDmaapConsumer consumer = new SdncFlatJsonDmaapConsumer();
String msg = "{\n" +