aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java
diff options
context:
space:
mode:
authorRyan Young <ry303t@att.com>2018-04-06 17:32:41 -0400
committerPatrick Brady <pb071s@att.com>2018-04-09 17:52:45 +0000
commitb96311a375b16d1c237f8e99b8eca6024638262b (patch)
tree394a32a1106cb7790f10e7ee4aca12b2857e26e1 /appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java
parent674e3b93deddb432513f5860ebf595367f2ea292 (diff)
Enhance DMaaP Adapter Configuration
Change-Id: I5385cf2710fc33a85da9a67d5f4d31dce1e460aa Signed-off-by: Ryan Young <ry303t@att.com> Issue-ID: APPC-658
Diffstat (limited to 'appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java')
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapConsumerImpl.java136
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java133
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java268
3 files changed, 537 insertions, 0 deletions
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapConsumerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapConsumerImpl.java
new file mode 100644
index 000000000..25fac1645
--- /dev/null
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapConsumerImpl.java
@@ -0,0 +1,136 @@
+package org.onap.appc.adapter.messaging.dmaap.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Properties;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class TestDmaapConsumerImpl {
+ String[] hostList = { "192.168.1.1" };
+ Collection<String> hosts = new HashSet<String>(Arrays.asList(hostList));
+
+ String topic = "JunitTopicOne";
+ String group = "junit-client";
+ String id = "junit-consumer-one";
+ String key = "key";
+ String secret = "secret";
+ String filter = null;
+
+ @Test
+ public void testDmaapConsumerImplNoFilter() {
+
+ DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
+
+ assertNotNull(consumer);
+
+ Properties props = consumer.getProperties();
+
+ assertEquals("192.168.1.1", props.getProperty("host"));
+ assertEquals("key", props.getProperty("username"));
+ assertEquals("secret", props.getProperty("password"));
+ }
+
+ @Test
+ public void testDmaapConsumerImplwithFilter() {
+
+ DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret, filter);
+
+ assertNotNull(consumer);
+
+ }
+
+ @Test
+ public void testDmaapConsumerImplNoUserPassword() {
+
+ DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
+
+ assertNotNull(consumer);
+
+ Properties props = consumer.getProperties();
+
+ assertEquals("192.168.1.1", props.getProperty("host"));
+ assertNull(props.getProperty("username"));
+ assertNull(props.getProperty("password"));
+ assertEquals("HTTPNOAUTH", props.getProperty("TransportType"));
+ }
+
+ @Test
+ public void testUpdateCredentials() {
+ DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
+
+ assertNotNull(consumer);
+
+ Properties props = consumer.getProperties();
+
+ assertEquals("192.168.1.1", props.getProperty("host"));
+ assertNull(props.getProperty("username"));
+ assertNull(props.getProperty("password"));
+
+ consumer.updateCredentials(key, secret);
+
+ props = consumer.getProperties();
+ assertEquals("192.168.1.1", props.getProperty("host"));
+ assertEquals("key", props.getProperty("username"));
+ assertEquals("secret", props.getProperty("password"));
+ }
+
+ @Ignore
+ @Test
+ public void testFetch() {
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testFetchIntInt() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testCloseNoClient() {
+ DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
+
+ assertNotNull(consumer);
+
+ consumer.close();
+ }
+
+ @Ignore
+ @Test
+ public void testCloseWithClient() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testToString() {
+ DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
+
+ assertNotNull(consumer);
+
+ assertEquals("Consumer junit-client/junit-consumer-one listening to JunitTopicOne on [192.168.1.1]",
+ consumer.toString());
+ }
+
+ @Test
+ public void testUseHttps() {
+ DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
+
+ assertNotNull(consumer);
+
+ assertEquals(false, consumer.isHttps());
+
+ consumer.useHttps(true);
+
+ assertEquals(true, consumer.isHttps());
+
+ }
+
+}
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java
new file mode 100644
index 000000000..956d620c6
--- /dev/null
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java
@@ -0,0 +1,133 @@
+package org.onap.appc.adapter.messaging.dmaap.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class TestDmaapProducerImpl {
+ String[] hostList = { "192.168.1.1" };
+ Collection<String> hosts = new HashSet<String>(Arrays.asList(hostList));
+
+ String topic = "JunitTopicOne";
+ String group = "junit-client";
+ String id = "junit-consumer-one";
+ String key = "key";
+ String secret = "secret";
+ String filter = null;
+
+ @Test
+ public void testDmaapProducerImplSingleTopic() {
+ DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
+
+ assertNotNull(producer);
+
+ Properties props = producer.getProperties();
+
+ assertNotNull(props);
+
+ assertEquals("key", props.getProperty("username"));
+ assertEquals("secret", props.getProperty("password"));
+ }
+
+ @Test
+ public void testDmaapProducerImplMultipleTopic() {
+ String[] topicList = { "topic1", "topic2" };
+ Set<String> topicNames = new HashSet<String>(Arrays.asList(topicList));
+
+ DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topicNames, key, secret);
+
+ assertNotNull(producer);
+
+ Properties props = producer.getProperties();
+
+ assertNotNull(props);
+
+ assertEquals("key", props.getProperty("username"));
+ assertEquals("secret", props.getProperty("password"));
+
+ }
+
+ @Test
+ public void testDmaapProducerImplNoUserPass() {
+ DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, null, null);
+
+ assertNotNull(producer);
+
+ Properties props = producer.getProperties();
+
+ assertNotNull(props);
+
+ assertNull(props.getProperty("username"));
+ assertNull(props.getProperty("password"));
+ }
+
+ @Test
+ public void testUpdateCredentials() {
+ DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, null, null);
+
+ assertNotNull(producer);
+
+ Properties props = producer.getProperties();
+
+ assertNotNull(props);
+
+ assertNull(props.getProperty("username"));
+ assertNull(props.getProperty("password"));
+
+ producer.updateCredentials(key, secret);
+
+ props = producer.getProperties();
+
+ assertNotNull(props);
+
+ assertEquals("key", props.getProperty("username"));
+ assertEquals("secret", props.getProperty("password"));
+
+ }
+
+ @Ignore
+ @Test
+ public void testPost() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testCloseNoClient() {
+ DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
+
+ assertNotNull(producer);
+
+ producer.close();
+ }
+
+ @Ignore
+ @Test
+ public void testCloseWithClient() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testUseHttps() {
+ DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
+
+ assertNotNull(producer);
+
+ assertEquals(false, producer.isHttps());
+
+ producer.useHttps(true);
+
+ assertEquals(true, producer.isHttps());
+
+ }
+
+}
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java
new file mode 100644
index 000000000..03e61916b
--- /dev/null
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java
@@ -0,0 +1,268 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.adapter.messaging.dmaap.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.Properties;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.appc.configuration.ConfigurationFactory;
+
+public class TestDmaapUtil {
+ private static Class<?> configurationFactoryClass;
+ private static Field configField;
+
+ @Test
+ public void testCreateConsumerPropFile() {
+ String topic = "JunitTopicOne";
+ Properties junitProps = new Properties();
+ junitProps.put("host", "192.168.10.10");
+ junitProps.put("group", "junit-client");
+ junitProps.put("id", "junit-consumer-one");
+ junitProps.put("filter", "none");
+
+ String junitFile = null;
+
+ // ensure file path property is not set
+ if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) {
+ System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH);
+
+ // set configuration to null to force reloading of properties
+ try {
+ configField.set(null, null);
+ } catch (IllegalArgumentException | IllegalAccessException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ try {
+ junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Exception creating consumer property file");
+ }
+
+ assertNotNull(junitFile);
+
+ // open file and verify properties
+ File testFile = new File(junitFile);
+ assertTrue(testFile.exists());
+
+ InputStream is = null;
+ Properties testProps = new Properties();
+ try {
+ is = new FileInputStream(testFile);
+ testProps.load(is);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ fail("Exception opening consumer property file");
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Exception opening consumer property file");
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ fail("Exception closing consumer property file");
+ }
+ }
+
+ assertFalse(testProps.isEmpty());
+
+ assertEquals(testProps.get("host"), "192.168.10.10");
+ assertEquals(testProps.get("group"), "junit-client");
+ assertEquals(testProps.get("id"), "junit-consumer-one");
+ assertEquals(testProps.get("filter"), "none");
+ assertEquals(testProps.get("TransportType"), "HTTPNOAUTH");
+ }
+
+ @Test
+ public void testCreateConsumerPropFileWithCustomProfile() {
+ String topic = "JunitTopicOne";
+ Properties junitProps = new Properties();
+ junitProps.put("host", "192.168.10.10");
+ junitProps.put("group", "junit-client");
+ junitProps.put("id", "junit-consumer-two");
+ junitProps.put("filter", "none");
+
+ String junitFile = null;
+
+ // set property for DMaaP profile
+ System.setProperty(DmaapUtil.DMAAP_PROPERTIES_PATH, "src/test/resources/org/onap/appc");
+
+ // set configuration to null to force reloading of properties
+ try {
+ configField.set(null, null);
+ } catch (IllegalArgumentException | IllegalAccessException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ try {
+ junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Exception creating consumer property file");
+ }
+
+ assertNotNull(junitFile);
+
+ // open file and verify properties
+ File testFile = new File(junitFile);
+ assertTrue(testFile.exists());
+
+ InputStream is = null;
+ Properties testProps = new Properties();
+ try {
+ is = new FileInputStream(testFile);
+ testProps.load(is);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ fail("Exception opening consumer property file");
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Exception opening consumer property file");
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ fail("Exception closing consumer property file");
+ }
+ }
+
+ assertFalse(testProps.isEmpty());
+
+ assertEquals(testProps.get("host"), "192.168.10.10");
+ assertEquals(testProps.get("group"), "junit-client");
+ assertEquals(testProps.get("id"), "junit-consumer-two");
+ assertEquals(testProps.get("filter"), "none");
+ assertEquals(testProps.get("TransportType"), "HTTPAAF");
+ }
+
+ @Test
+ public void testCreateProducerPropFile() {
+ String topic = "JunitTopicOne";
+ Properties junitProps = new Properties();
+ junitProps.put("host", "192.168.10.10");
+ junitProps.put("group", "junit-client");
+ junitProps.put("id", "junit-producer-one");
+ junitProps.put("filter", "none");
+
+ String junitFile = null;
+
+ // ensure file path property is not set
+ if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) {
+ System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH);
+
+ // set configuration to null to force reloading of properties
+ try {
+ configField.set(null, null);
+ } catch (IllegalArgumentException | IllegalAccessException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+
+ try {
+ junitFile = DmaapUtil.createProducerPropFile(topic, junitProps);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Exception creating consumer property file");
+ }
+
+ assertNotNull(junitFile);
+
+ // open file and verify properties
+ File testFile = new File(junitFile);
+ assertTrue(testFile.exists());
+
+ InputStream is = null;
+ Properties testProps = new Properties();
+ try {
+ is = new FileInputStream(testFile);
+ testProps.load(is);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ fail("Exception opening consumer property file");
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Exception opening consumer property file");
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ fail("Exception closing consumer property file");
+ }
+ }
+
+ assertFalse(testProps.isEmpty());
+
+ assertEquals(testProps.get("host"), "192.168.10.10");
+ assertEquals(testProps.get("group"), "junit-client");
+ assertEquals(testProps.get("id"), "junit-producer-one");
+ assertEquals(testProps.get("filter"), "none");
+ assertEquals("HTTPNOAUTH", testProps.get("TransportType"));
+ }
+
+ /**
+ * Use reflection to locate fields and methods so that they can be
+ * manipulated during the test to change the internal state accordingly.
+ *
+ * @throws NoSuchFieldException
+ * if the field(s) dont exist
+ * @throws SecurityException
+ * if reflective access is not allowed
+ * @throws NoSuchMethodException
+ * If the method(s) dont exist
+ */
+ @SuppressWarnings("nls")
+ @BeforeClass
+ public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
+ configurationFactoryClass = ConfigurationFactory.class;
+
+ configField = configurationFactoryClass.getDeclaredField("config");
+ configField.setAccessible(true);
+ }
+}