From b96311a375b16d1c237f8e99b8eca6024638262b Mon Sep 17 00:00:00 2001 From: Ryan Young Date: Fri, 6 Apr 2018 17:32:41 -0400 Subject: Enhance DMaaP Adapter Configuration Change-Id: I5385cf2710fc33a85da9a67d5f4d31dce1e460aa Signed-off-by: Ryan Young Issue-ID: APPC-658 --- .../dmaap/impl/TestDmaapConsumerImpl.java | 136 +++++++++++ .../dmaap/impl/TestDmaapProducerImpl.java | 133 ++++++++++ .../messaging/dmaap/impl/TestDmaapUtil.java | 268 +++++++++++++++++++++ .../resources/org/onap/appc/consumer.properties | 54 +++++ .../resources/org/onap/appc/producer.properties | 52 ++++ 5 files changed, 643 insertions(+) create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapConsumerImpl.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/resources/org/onap/appc/consumer.properties create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/resources/org/onap/appc/producer.properties (limited to 'appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test') 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 hosts = new HashSet(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 hosts = new HashSet(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 topicNames = new HashSet(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); + } +} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/resources/org/onap/appc/consumer.properties b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/resources/org/onap/appc/consumer.properties new file mode 100644 index 000000000..709619452 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/resources/org/onap/appc/consumer.properties @@ -0,0 +1,54 @@ +### +# ============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========================================================= +### + +#TransportType-Specify which way user want to use. I.e. +TransportType=HTTPAAF +Latitude =50.000000 +Longitude =-100.000000 +Version =1.0 +ServiceName =dmaap-v1.dev.dmaap.dt.saat.acsi.openecomp.org/events +Environment =TEST +Partner=BOT_R +routeOffer=MR1 +SubContextPath =/ +Protocol =http +MethodType =GET +contenttype =application/json +#authKey=01234567890abcde:01234567890abcdefghijklmn +#authDate=2016-02-18T13:57:37-0800 +host=127.0.0.1 +topic=org.onap.appc.UNIT-TEST +group=jmsgrp +id=2 +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=preferredRoute.txt diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/resources/org/onap/appc/producer.properties b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/resources/org/onap/appc/producer.properties new file mode 100644 index 000000000..9cc7f2e55 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/resources/org/onap/appc/producer.properties @@ -0,0 +1,52 @@ +### +# ============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========================================================= +### + +#TransportType-Specify which way user want to use. I.e. +TransportType=HTTPAAF +Latitude =50.000000 +Longitude =-100.000000 +Version =1.0 +ServiceName =dmaap-v1.dev.dmaap.dt.saat.acsi.openecomp.org/events +Environment =TEST +Partner=BOT_R +SubContextPath =/ +Protocol =http +MethodType =POST +contenttype = application/json +authKey=01234567890abcde:01234567890abcdefghijklmn +authDate=2016-07-20T11:30:56-0700 +host=127.0.0.1 +topic=org.onap.appc.UNIT-TEST +partition=2 +maxBatchSize=100 +maxAgeMs=250 +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=preferredRoute.txt +MessageSentThreadOccurance=50 -- cgit 1.2.3-korg