Add unit test for dmaap-listener 11/17011/1
authorDan Timoney <dtimoney@att.com>
Tue, 3 Oct 2017 11:34:22 +0000 (07:34 -0400)
committerDan Timoney <dtimoney@att.com>
Tue, 3 Oct 2017 11:34:22 +0000 (07:34 -0400)
Add unit test case for dmaap-listener.

Change-Id: I501614016c96d8300bc15cdf1819691f95c467f4
Issue-ID: CCSDK-106
Signed-off-by: Dan Timoney <dtimoney@att.com>
dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java
dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestDmaapListener.java [new file with mode: 0644]
dmaap-listener/src/test/resources/dmaap-consumer-1.properties [new file with mode: 0755]
dmaap-listener/src/test/resources/dmaap-listener.preferredRoute.txt [new file with mode: 0755]
dmaap-listener/src/test/resources/dmaap-listener.properties [new file with mode: 0755]

index de76e45..ce099cd 100644 (file)
@@ -8,9 +8,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -96,7 +96,7 @@ public class DmaapListener {
         return threadsRunning;
     }
 
-    private static Properties loadProperties(String propPath, Properties properties) {
+    static Properties loadProperties(String propPath, Properties properties) {
         File propFile = new File(propPath);
 
         if (!propFile.canRead()) {
@@ -113,7 +113,7 @@ public class DmaapListener {
         return properties;
     }
 
-    private static boolean handleSubscriptions(String subscriptionStr, String propDir, Properties properties,
+    static boolean handleSubscriptions(String subscriptionStr, String propDir, Properties properties,
         List<SdncDmaapConsumer> consumers) {
         String[] subscriptions = subscriptionStr.split(";");
 
diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestDmaapListener.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestDmaapListener.java
new file mode 100644 (file)
index 0000000..943ef02
--- /dev/null
@@ -0,0 +1,52 @@
+package org.onap.ccsdk.sli.northbound.dmaapclient;
+
+import static org.junit.Assert.*;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestDmaapListener {
+
+       private static final String DMAAP_LISTENER_PROPERTIES = "dmaap-listener.properties";
+       private static final String DMAAP_LISTENER_PROPERTIES_DIR = "src/test/resources";
+
+       private static final Logger LOG = LoggerFactory.getLogger(TestDmaapListener.class);
+
+       @Before
+       public void setUp() throws Exception {
+       }
+
+       @Test
+       public void test() {
+               Properties properties = new Properties();
+               String propFileName = DMAAP_LISTENER_PROPERTIES;
+               String propPath = null;
+               String propDir = DMAAP_LISTENER_PROPERTIES_DIR;
+
+               List<SdncDmaapConsumer> consumers = new LinkedList<>();
+
+
+               propPath = propDir + "/" + propFileName;
+
+               if (propPath != null) {
+                       properties = DmaapListener.loadProperties(propPath, properties);
+
+                       String subscriptionStr = properties.getProperty("subscriptions");
+
+                       boolean threadsRunning = false;
+
+                       LOG.debug("Dmaap subscriptions : " + subscriptionStr);
+
+                       if (subscriptionStr != null) {
+                               threadsRunning = DmaapListener.handleSubscriptions(subscriptionStr, propDir, properties, consumers);
+                       }
+               }
+       }
+
+}
diff --git a/dmaap-listener/src/test/resources/dmaap-consumer-1.properties b/dmaap-listener/src/test/resources/dmaap-consumer-1.properties
new file mode 100755 (executable)
index 0000000..ae83ef8
--- /dev/null
@@ -0,0 +1,35 @@
+TransportType=HTTPAAF
+Latitude =40.397443
+Longitude =-74.135602
+Version =1.0
+ServiceName =localhost/events
+Environment =DEV
+Partner =
+SubContextPath =/
+Protocol =http
+MethodType =GET
+username =test
+password =test
+contenttype =application/json
+authKey=ABC123
+authDate=2016-05-10T13:13:50-0700
+host=localhost:3904
+topic=ccsdk-topic
+group=ccsdk-unittest
+id=ccsdk_unittest
+timeout=15000
+limit=1000
+filter=
+AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler
+AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler
+AFT_DME2_REQ_TRACE_ON=true
+AFT_ENVIRONMENT=AFTUAT
+AFT_DME2_EP_CONN_TIMEOUT=15000
+AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000
+AFT_DME2_EP_READ_TIMEOUT_MS=50000
+sessionstickinessrequired=NO
+DME2preferredRouterFilePath=src/test/resources/dmaap-listener.preferredRoute.txt
+sdnc.odl.user=admin
+sdnc.odl.password=admin
+sdnc.odl.url-base=http://localhost:8282/restconf/operations
+
diff --git a/dmaap-listener/src/test/resources/dmaap-listener.preferredRoute.txt b/dmaap-listener/src/test/resources/dmaap-listener.preferredRoute.txt
new file mode 100755 (executable)
index 0000000..88705f7
--- /dev/null
@@ -0,0 +1 @@
+preferredRouteKey=ABC123
\ No newline at end of file
diff --git a/dmaap-listener/src/test/resources/dmaap-listener.properties b/dmaap-listener/src/test/resources/dmaap-listener.properties
new file mode 100755 (executable)
index 0000000..ed180e5
--- /dev/null
@@ -0,0 +1 @@
+subscriptions=org.onap.ccsdk.sli.northbound.dmaapclient.DummyDmaapConsumer:dmaap-consumer-1.properties
\ No newline at end of file