diff options
author | Dan Timoney <dt5972@att.com> | 2018-03-28 14:27:23 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-28 14:27:23 +0000 |
commit | 4c91b744068e1674f27aa6ffcf9667b82c887e74 (patch) | |
tree | 998e4ca592af01137210ff2664e9a45565560ba0 /dmaap-listener/src | |
parent | 563f9cea833f0af27b101ba8f60fc14df84fb7fe (diff) | |
parent | 7fc8f9fe913e35121c8e9f6e222c9b741beefdda (diff) |
Merge "coverage SdncAaiDmaapConsumer"
Diffstat (limited to 'dmaap-listener/src')
-rw-r--r-- | dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java index b9b20a6cd..ec01df534 100644 --- a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java +++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java @@ -11,8 +11,15 @@ package org.onap.ccsdk.sli.northbound.dmaapclient; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.Map; import java.util.Properties; +import org.apache.commons.io.FileUtils; + import org.junit.Before; import org.junit.Test; @@ -95,5 +102,88 @@ public class TestSdncPserverDmaapReceiver { assertEquals(aaiRootNode.get("input").get("action-identifiers").get("mode").textValue(), "async"); } + @Test + public void testProcessMsgFieldMap() throws Exception { + + + String DMAAPLISTENERROOT = "DMAAPLISTENERROOT"; + File directory = new File("lib"); + + if (! directory.exists()){ + directory.mkdir(); + } + + File source = new File("src/main/resources"); + File dest = new File("lib/"); + try { + FileUtils.copyDirectory(source, dest); + } catch (IOException 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); + } + Properties props = new Properties(); + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + + InputStream propStr = TestSdncPserverDmaapReceiver.class.getResourceAsStream("/dmaap-consumer-pserver.properties"); + + + props.load(propStr); + + consumer.init(props, "src/test/resources/dmaap-consumer-pserver.properties"); + consumer.processMsg(aaiInput); + } + + @Test(expected = InvalidMessageException.class) + public void testProcessMsgNullMessage() throws Exception { + Properties props = new Properties(); + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + consumer.processMsg(null); + } + + @Test(expected = InvalidMessageException.class) + public void testProcessMsgInvalidMessage() throws Exception { + Properties props = new Properties(); + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + consumer.processMsg("test"); + } + + @Test + public void testProcessMsgMissingEventHeader() throws Exception { + Properties props = new Properties(); + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + consumer.processMsg("{\n" + + " \"input\" : { \n" + + " }\n" + + "}"); + } + + @Test + public void testProcessMsgInvalidEventType() throws Exception { + Properties props = new Properties(); + + String msg = "{\"cambria.partition\": \"AAI\",\r\n" + + " \"event-header\": {\"event-type\": \"TEST-EVENT\"}}"; + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + consumer.processMsg(msg); + } + + + + } |