aboutsummaryrefslogtreecommitdiffstats
path: root/dmaap-listener/src/test/java
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <ks6305@att.com>2018-07-02 20:01:02 +0000
committerSmokowski, Kevin (ks6305) <ks6305@att.com>2018-07-02 20:01:02 +0000
commitb13fc8a9b134c43a437d7a48ceb509295df4713a (patch)
treef84c2832c0e6451073330ab16157dafb9859bd38 /dmaap-listener/src/test/java
parentbef4edce8d51394a33fb0de4e57de6f1a39c3b39 (diff)
Increase code coverage for MR clients
Increase code coverage for MR clients Change-Id: I4493b13070f967bc6b20e6770fa16c4df97c2b8c Issue-ID: CCSDK-328 Signed-off-by: Smokowski, Kevin (ks6305) <ks6305@att.com>
Diffstat (limited to 'dmaap-listener/src/test/java')
-rw-r--r--dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientJdkTest.java100
-rw-r--r--dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientTest.java97
2 files changed, 197 insertions, 0 deletions
diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientJdkTest.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientJdkTest.java
new file mode 100644
index 00000000..03f83280
--- /dev/null
+++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientJdkTest.java
@@ -0,0 +1,100 @@
+package org.onap.ccsdk.sli.northbound.dmaapclient;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+import org.junit.Test;
+
+public class MessageRouterHttpClientJdkTest {
+ public MessageRouterHttpClientJdk getClient() throws MalformedURLException {
+ Properties properties = new Properties();
+ properties.put("username", "my_user");
+ properties.put("password", "my_password");
+ properties.put("topic", "network_automation");
+ properties.put("group", "message_processors");
+ properties.put("host", "dmaap-server.com");
+ properties.put("id", "machine_one");
+ properties.put("fetchPause", "3000");
+ MessageRouterHttpClientJdk client = new MessageRouterHttpClientJdk();
+ client.processProperties(properties);
+ return client;
+ }
+
+ @Test
+ public void processMsg() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClientJdk client = getClient();
+ client.processMsg(null);
+ }
+
+ @Test
+ public void isReady() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClientJdk client = getClient();
+ assertEquals(true, client.isReady());
+ }
+
+ @Test
+ public void isRunning() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClientJdk client = getClient();
+ assertEquals(false, client.isRunning());
+ }
+
+ @Test
+ public void buidUrl() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClientJdk client = getClient();
+ assertEquals(new URL(
+ "http://dmaap-server.com/events/network_automation/message_processors/machine_one?timeout=15000"),
+ client.url);
+ }
+
+ @Test
+ public void buidUrlWithFilter() throws InvalidMessageException, MalformedURLException {
+ Properties properties = new Properties();
+ properties.put("username", "my_user");
+ properties.put("password", "my_password");
+ properties.put("topic", "network_automation");
+ properties.put("group", "message_processors");
+ properties.put("host", "dmaap-server.com");
+ properties.put("id", "machine_one");
+ properties.put("filter", "{\"class\":\"Contains\",\"string\":\"hello\",\"value\":\"world\"}");
+ properties.put("fetchPause", "3000");
+ MessageRouterHttpClientJdk client = new MessageRouterHttpClientJdk();
+ client.processProperties(properties);
+ assertEquals(new URL(
+ "http://dmaap-server.com/events/network_automation/message_processors/machine_one?timeout=15000&filter=%7B%22class%22%3A%22Contains%22%2C%22string%22%3A%22hello%22%2C%22value%22%3A%22world%22%7D"),
+ client.url);
+ }
+
+ @Test
+ public void buildAuthorizationString() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClientJdk client = getClient();
+ String authString = client.buildAuthorizationString("Hello", "World");
+ assertEquals("Basic SGVsbG86V29ybGQ=", authString);
+ }
+
+ @Test
+ public void clientFromProperties() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClientJdk client = new MessageRouterHttpClientJdk();
+ Properties props = new Properties();
+ client.init(props, "src/test/resources/dmaap-consumer-1.properties");
+ assertEquals(new URL(
+ "http://localhost:3904/events/ccsdk-topic/ccsdk-unittest/ccsdk_unittest?timeout=15000&limit=1000"),
+ client.url);
+ }
+
+ @Test
+ public void buildHttpURLConnection() throws InvalidMessageException, IOException {
+ MessageRouterHttpClientJdk client = getClient();
+ HttpURLConnection connection = client.buildHttpURLConnection();
+ assertEquals("GET", connection.getRequestMethod());
+ assertTrue(connection.getRequestProperties().get("Accept").contains("application/json"));
+ assertEquals(false, connection.getUseCaches());
+ Integer defaultConnectTimeout = Integer.valueOf(client.DEFAULT_CONNECT_TIMEOUT);
+ Integer defaultReadTimeout = Integer.valueOf(client.DEFAULT_READ_TIMEOUT);
+ assertEquals(defaultConnectTimeout.intValue(), connection.getConnectTimeout());
+ assertEquals(defaultReadTimeout.intValue(), connection.getReadTimeout());
+ }
+}
diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientTest.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientTest.java
new file mode 100644
index 00000000..7567e2a9
--- /dev/null
+++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientTest.java
@@ -0,0 +1,97 @@
+package org.onap.ccsdk.sli.northbound.dmaapclient;
+
+import static org.junit.Assert.assertEquals;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Properties;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import org.junit.Test;
+
+public class MessageRouterHttpClientTest {
+
+ class MockMessageRouterHttpClient extends MessageRouterHttpClient {
+ protected Client getClient(Integer connectTimeoutSeconds, Integer readTimeoutMinutes) {
+ ClientBuilder clientBuilder = ClientBuilder.newBuilder();
+ return clientBuilder.build();
+ }
+ }
+
+ public MessageRouterHttpClient getClient() {
+ Properties properties = new Properties();
+ properties.put("username", "my_user");
+ properties.put("password", "my_password");
+ properties.put("topic", "network_automation");
+ properties.put("group", "message_processors");
+ properties.put("host", "dmaap-server.com");
+ properties.put("id", "machine_one");
+ properties.put("fetch", "machine_one");
+
+ MockMessageRouterHttpClient client = new MockMessageRouterHttpClient();
+ client.processProperties(properties);
+ return client;
+ }
+
+ @Test
+ public void processMsg() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClient client = getClient();
+ client.processMsg(null);
+ }
+
+ @Test
+ public void isReady() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClient client = getClient();
+ assertEquals(true, client.isReady());
+ }
+
+ @Test
+ public void isRunning() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClient client = getClient();
+ assertEquals(false, client.isRunning());
+ }
+
+ @Test
+ public void buidUrl() throws InvalidMessageException, MalformedURLException, URISyntaxException {
+ MessageRouterHttpClient client = getClient();
+ assertEquals(new URI(
+ "http://dmaap-server.com/events/network_automation/message_processors/machine_one?timeout=15000"),
+ client.uri);
+ }
+
+ @Test
+ public void buidUrlWithFilter() throws InvalidMessageException, MalformedURLException, URISyntaxException {
+ Properties properties = new Properties();
+ properties.put("username", "my_user");
+ properties.put("password", "my_password");
+ properties.put("topic", "network_automation");
+ properties.put("group", "message_processors");
+ properties.put("host", "dmaap-server.com");
+ properties.put("id", "machine_one");
+ properties.put("filter", "{\"class\":\"Contains\",\"string\":\"hello\",\"value\":\"world\"}");
+ properties.put("fetchPause", "3000");
+ MessageRouterHttpClient client = new MockMessageRouterHttpClient();
+ client.processProperties(properties);
+ assertEquals(new URI(
+ "http://dmaap-server.com/events/network_automation/message_processors/machine_one?timeout=15000&filter=%7B%22class%22%3A%22Contains%22%2C%22string%22%3A%22hello%22%2C%22value%22%3A%22world%22%7D"),
+ client.uri);
+ }
+
+ @Test
+ public void buildAuthorizationString() throws InvalidMessageException, MalformedURLException {
+ MessageRouterHttpClient client = getClient();
+ String authString = client.buildAuthorizationString("Hello", "World");
+ assertEquals("Basic SGVsbG86V29ybGQ=", authString);
+ }
+
+ @Test
+ public void clientFromProperties() throws InvalidMessageException, MalformedURLException, URISyntaxException {
+ MessageRouterHttpClient client = new MockMessageRouterHttpClient();
+ Properties props = new Properties();
+ client.init(props, "src/test/resources/dmaap-consumer-1.properties");
+ assertEquals(new URI(
+ "http://localhost:3904/events/ccsdk-topic/ccsdk-unittest/ccsdk_unittest?timeout=15000&limit=1000"),
+ client.uri);
+ }
+
+}