summaryrefslogtreecommitdiffstats
path: root/message-router/consumer/provider/src
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>2019-07-26 20:24:59 +0000
committerKevin Smokowski <kevin.smokowski@att.com>2019-07-26 21:03:10 +0000
commitdd48a8a5083e3a65c8b47ce45ce7517afc47c1ff (patch)
tree7b774e48531e16a703ac1a901e1437ad8c9c7907 /message-router/consumer/provider/src
parent145a984ea7b2376e1d187ca0ad9ff0b62e7adae0 (diff)
Improve code coverage in sli adaptors
increase code coverage in message router in sli adaptors Issue-ID: CCSDK-1548 Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> Change-Id: I64f0e025a759b219ce4c7e017b500952d1c7f30b
Diffstat (limited to 'message-router/consumer/provider/src')
-rw-r--r--message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/AbstractBaseConsumerTest.java90
-rw-r--r--message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/ConsumerFactoryTest.java164
2 files changed, 254 insertions, 0 deletions
diff --git a/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/AbstractBaseConsumerTest.java b/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/AbstractBaseConsumerTest.java
new file mode 100644
index 00000000..99a4f3ff
--- /dev/null
+++ b/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/AbstractBaseConsumerTest.java
@@ -0,0 +1,90 @@
+package org.onap.ccsdk.sli.adaptors.messagerouter.consumer.provider.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.messagerouter.consumer.api.RequestHandler;
+
+public class AbstractBaseConsumerTest {
+ private class DummyConsumer extends AbstractBaseConsumer {
+
+ public DummyConsumer(String username, String password, String host, String authentication, Integer connectTimeout, Integer readTimeout, String group, String id, String filter, Integer limit, Integer timeoutQueryParamValue) {
+ super(username, password, host, authentication, connectTimeout, readTimeout, group, id, filter, limit, timeoutQueryParamValue);
+ }
+
+ }
+
+ public DummyConsumer getAuthDummy() {
+ String username = "deadpool";
+ String password = "notSECURE";
+ String host = "http://localhost:7001";
+ String group = "myCluster";
+ String id = "node1";
+ Integer connectTimeout = 10000;
+ Integer readTimeout = 20000;
+ String authentication = "basic";
+ String filter = null;
+ Integer limit = 3;
+ Integer timeoutQueryParamValue = 5000;
+ return new DummyConsumer(username, password, host, authentication, connectTimeout, readTimeout, group, id, filter, limit, timeoutQueryParamValue);
+ }
+
+ @Test
+ public void createDummyWithAuth() {
+ assertNotNull(getAuthDummy());
+ }
+
+ @Test
+ public void createDummyNohAuth() {
+ String username = null;
+ String password = null;
+ String host = "http://localhost:7001";
+ String group = "myCluster";
+ String id = "node1";
+ Integer connectTimeout = 10000;
+ Integer readTimeout = 20000;
+ String authentication = "noauth";
+ String filter = null;
+ Integer limit = 3;
+ Integer timeoutQueryParamValue = 5000;
+ assertNotNull(new DummyConsumer(username, password, host, authentication, connectTimeout, readTimeout, group, id, filter, limit, timeoutQueryParamValue));
+ }
+
+ @Test
+ public void callClose() throws Exception {
+ DummyConsumer dummy = getAuthDummy();
+ dummy.close();
+ }
+
+ @Test
+ public void registerDummyHandler() throws Exception {
+ DummyConsumer dummy = getAuthDummy();
+ String topic = "politics";
+ RequestHandler requestHandler = new RequestHandler() {
+
+ @Override
+ public void handleRequest(String topic, String requestBody) {
+ // TODO Auto-generated method stub
+
+ };
+
+ };
+ dummy.registerHandler(topic, requestHandler);
+ assertEquals(new URL("http://localhost:7001/events/politics/myCluster/node1?timeout=5000&limit=3"), dummy.url);
+ assertEquals(topic, dummy.topic);
+
+ }
+
+ @Test
+ public void buildURL() throws Exception {
+ DummyConsumer dummy = getAuthDummy();
+ HttpURLConnection connection = dummy.buildHttpURLConnection(new URL("http://localhost:7001/events/politics/myCluster/node1?timeout=5000&limit=3"));
+ assertNotNull(connection);
+ assertEquals("application/json", connection.getRequestProperty("Accept"));
+ }
+
+}
diff --git a/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/ConsumerFactoryTest.java b/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/ConsumerFactoryTest.java
new file mode 100644
index 00000000..d1018a01
--- /dev/null
+++ b/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/ConsumerFactoryTest.java
@@ -0,0 +1,164 @@
+package org.onap.ccsdk.sli.adaptors.messagerouter.consumer.provider.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Properties;
+
+import org.junit.Test;
+
+public class ConsumerFactoryTest {
+
+ @Test
+ public void testFactoryClientCreation() throws Exception {
+ Properties props = new Properties();
+ String userName = "deadpool";
+ String password = "notSECURE";
+ String host = "http://localhost:7001";
+ String group = "myCluster";
+ String id = "node1";
+ Integer connectTimeout = 10000;
+ Integer readTimeout = 20000;
+ props.put("username", userName);
+ props.put("password", password);
+ props.put("host", host);
+ props.put("group", group);
+
+ ConsumerFactory factory = new ConsumerFactory(userName, password, host, group, id, connectTimeout, readTimeout);
+ assertNotNull(factory.createPollingClient());
+ assertNotNull(factory.createPullingClient());
+ }
+
+ @Test
+ public void testFactoryDefaults() throws Exception {
+ Properties props = new Properties();
+ String userName = "deadpool";
+ String password = "notSECURE";
+ String host = "http://localhost:7001";
+ String group = "myCluster";
+ String id = "node1";
+ Integer connectTimeout = 10000;
+ Integer readTimeout = 20000;
+ props.put("username", userName);
+ props.put("password", password);
+ props.put("host", host);
+ props.put("group", group);
+
+ ConsumerFactory factory = new ConsumerFactory(userName, password, host, group, id, connectTimeout, readTimeout);
+
+ assertNotNull(factory.getAuth());
+ assertNotNull(factory.getConnectTimeout());
+ assertNotNull(factory.getReadTimeout());
+ assertNotNull(factory.getFetchPause());
+ assertNotNull(factory.getLimit());
+ assertNotNull(factory.getTimeoutQueryParamValue());
+ }
+
+ @Test
+ public void testFactoryDefaultsWithProps() {
+ Properties props = new Properties();
+ String userName = "deadpool";
+ String password = "notSECURE";
+ String host = "http://localhost:7001";
+ String auth = "basic";
+ String group = "myCluster";
+ props.put("username", userName);
+ props.put("password", password);
+ props.put("host", host);
+ props.put("group", group);
+
+ ConsumerFactory factory = new ConsumerFactory(props);
+
+ assertNotNull(factory.getAuth());
+ assertNotNull(factory.getConnectTimeout());
+ assertNotNull(factory.getReadTimeout());
+ assertNotNull(factory.getFetchPause());
+ assertNotNull(factory.getLimit());
+ assertNotNull(factory.getTimeoutQueryParamValue());
+ }
+
+ @Test
+ public void testFactoryOverrides() throws Exception {
+ Properties props = new Properties();
+ String userName = "deadpool";
+ String password = "notSECURE";
+ String host = "http://localhost:7001";
+ String group = "myCluster";
+ props.put("username", userName);
+ props.put("password", password);
+ props.put("host", host);
+ props.put("group", group);
+
+ String connectTimeout = "200";
+ String readTimeout = "300";
+ String fetchPause = "1000";
+ String auth = "noauth";
+ String timeoutQueryParamValue = "50";
+ String limit = "2";
+ props.put("connectTimeoutSeconds", connectTimeout);
+ props.put("readTimeoutMinutes", readTimeout);
+ props.put("fetchPause", fetchPause);
+ props.put("auth", auth);
+ props.put("timeout", timeoutQueryParamValue);
+ props.put("limit", limit);
+
+ ConsumerFactory factory = new ConsumerFactory(props);
+
+ assertEquals(auth, factory.getAuth());
+ assertEquals(Integer.valueOf(connectTimeout), factory.getConnectTimeout());
+ assertEquals(Integer.valueOf(readTimeout), factory.getReadTimeout());
+ assertEquals(Integer.valueOf(fetchPause), factory.getFetchPause());
+ assertEquals(Integer.valueOf(limit), factory.getLimit());
+ assertEquals(Integer.valueOf(timeoutQueryParamValue), factory.getTimeoutQueryParamValue());
+ }
+
+ @Test
+ public void testManualOverrides() {
+ Properties props = new Properties();
+ String userName = "deadpool";
+ String password = "notSECURE";
+ String host = "http://localhost:7001";
+ String auth = "basic";
+ String group = "myCluster";
+ props.put("username", userName);
+ props.put("password", password);
+ props.put("host", host);
+ props.put("group", group);
+
+ ConsumerFactory factory = new ConsumerFactory(props);
+
+ assertNotNull(factory.getAuth());
+ assertNotNull(factory.getConnectTimeout());
+ assertNotNull(factory.getReadTimeout());
+ assertNotNull(factory.getFetchPause());
+ assertNotNull(factory.getLimit());
+ assertNotNull(factory.getTimeoutQueryParamValue());
+ String newAuth = "noauth";
+ factory.setAuth(newAuth);
+ assertEquals(newAuth, factory.getAuth());
+
+ Integer connectTimeout = 1;
+ factory.setConnectTimeout(connectTimeout);
+ assertEquals(connectTimeout, factory.getConnectTimeout());
+
+ Integer fetchPause = 5;
+ factory.setFetchPause(fetchPause);
+ assertEquals(fetchPause, factory.getFetchPause());
+
+ factory.setFilter("\"filter\":{\n" + "\"class\":\"And\",\n" + "\"filters\":\n" + "[\n" + "{ \"class\":\"Equals\", \"foo\":\"abc\" },\n" + "{ \"class\":\"Assigned\", \"field\":\"bar\" }\n" + "]\n" + "}");
+ assertNotNull(factory.getFilter());
+
+ Integer limit = 3;
+ factory.setLimit(limit);
+ assertEquals(limit, factory.getLimit());
+
+ Integer readTimeout = 2;
+ factory.setReadTimeout(readTimeout);
+ assertEquals(readTimeout, factory.getReadTimeout());
+
+ Integer timeoutQueryParamValue = 47;
+ factory.setTimeoutQueryParamValue(timeoutQueryParamValue);
+ assertEquals(timeoutQueryParamValue, factory.getTimeoutQueryParamValue());
+ }
+
+}