From 161df8a94bb3b0c34ed16fd4fdba078bd1eeef9a Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:14:21 -0800 Subject: Second part of onap rename This is the second commit of the rename. The folder structure is renamed for appc-adapters and appc-config in this commit. Change-Id: Iaa2b8c937ff1ca1b5d1178128961fb115ee65d9b Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../messaging/dmaap/SimpleExamplePublisher.java | 137 ++++++++++++ .../dmaap/TestAppcDmaapAdapterActivator.java | 50 +++++ .../messaging/dmaap/TestDmaapConsuming.java | 87 ++++++++ .../messaging/dmaap/TestDmaapEventSender.java | 172 +++++++++++++++ .../messaging/dmaap/TestDmaapProducing.java | 83 +++++++ .../dmaap/impl/TestConsumerProducerImpl.java | 245 +++++++++++++++++++++ .../messaging/dmaap/SimpleExamplePublisher.java | 137 ------------ .../dmaap/TestAppcDmaapAdapterActivator.java | 50 ----- .../messaging/dmaap/TestDmaapConsuming.java | 87 -------- .../messaging/dmaap/TestDmaapEventSender.java | 172 --------------- .../messaging/dmaap/TestDmaapProducing.java | 83 ------- .../dmaap/impl/TestConsumerProducerImpl.java | 245 --------------------- 12 files changed, 774 insertions(+), 774 deletions(-) create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestAppcDmaapAdapterActivator.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapConsuming.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapEventSender.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapProducing.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestConsumerProducerImpl.java delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestAppcDmaapAdapterActivator.java delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapConsuming.java delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapEventSender.java delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapProducing.java delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/impl/TestConsumerProducerImpl.java (limited to 'appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org') diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java new file mode 100644 index 000000000..8c07c0b4a --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.messaging.dmaap; + +import java.io.*; +import java.util.List; +import java.util.Properties; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import com.att.nsa.mr.client.MRConsumer; +import org.json.JSONObject; +import org.onap.appc.adapter.messaging.dmaap.impl.DmaapUtil; + +import com.att.nsa.mr.client.MRBatchingPublisher; +import com.att.nsa.mr.client.MRClientFactory; +import com.att.nsa.mr.client.MRPublisher.message; + + +/** + *An example of how to use the Java publisher. + */ +public class SimpleExamplePublisher +{ + + public static void main(String []args) throws InterruptedException, Exception{ + int msgCount = 1; + SimpleExamplePublisher publisher = new SimpleExamplePublisher(); + + int i=0; + + String topicProducerPropFileName = DmaapUtil.createProducerPropFile("org.onap.appc.UNIT-TEST", null); + while (i< msgCount) + { + publisher.publishMessage(topicProducerPropFileName,i); + i++; + } + + fetchMessage(); + } + + + public void publishMessage( String producerFilePath,int count ) throws IOException, InterruptedException, Exception + { + // create our publisher + final MRBatchingPublisher pub = MRClientFactory.createBatchingPublisher (producerFilePath); + // publish some messages + final JSONObject msg1 = new JSONObject (); + msg1.put ( "Partition:2", "Message:" +count); + //msg1.put ( "greeting", "Hello .." ); + + pub.send ( "2", msg1.toString()); + // close the publisher to make sure everything's sent before exiting. The batching + // publisher interface allows the app to get the set of unsent messages. It could + // write them to disk, for example, to try to send them later. + final List stuck = pub.close ( 20, TimeUnit.SECONDS ); + if ( stuck.size () > 0 ) + { + System.err.println ( stuck.size() + " messages unsent" ); + } + else + { + System.out.println ( "Clean exit; all messages sent." ); + } + } + + + public static void fetchMessage() + { + int count = 0; + + try + { + String topic = "org.onap.appc.UNIT-TEST"; + Properties props = new Properties(); + props.put("id", "1"); + props.put("group", "group1"); + String topicConsumerPropFileName1 = DmaapUtil.createConsumerPropFile(topic,props); + final MRConsumer consumer1 = MRClientFactory.createConsumer ( topicConsumerPropFileName1); + + props = new Properties(); + props.put("id", "2"); + props.put("group", "group2"); + String topicConsumerPropFileName2 = DmaapUtil.createConsumerPropFile(topic,props); + final MRConsumer consumer2 = MRClientFactory.createConsumer ( topicConsumerPropFileName2); + + for ( String msg : consumer1.fetch () ) + { + count++; + System.out.println ( "consumer1 "+count + ": " + msg ); + } + for ( String msg : consumer2.fetch () ) + { + count++; + System.out.println ( "consumer1 "+count + ": " + msg ); + } + + + } + catch ( Exception x ) + { + System.out.println("inside cons exc"); + System.err.println ( x.getClass().getName () + ": " + x.getMessage () ); + } + } +} + + + + + + + + + diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestAppcDmaapAdapterActivator.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestAppcDmaapAdapterActivator.java new file mode 100644 index 000000000..5473bf7e0 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestAppcDmaapAdapterActivator.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.messaging.dmaap; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.appc.adapter.messaging.dmaap.AppcDmaapAdapterActivator; + +public class TestAppcDmaapAdapterActivator { + + // TODO commented out to allow build to pass, need to analyze and fix +// @Test + public void coverage() { + // This does nothing since the activator does nothing + AppcDmaapAdapterActivator appc = new AppcDmaapAdapterActivator(); + try { + appc.start(null); + appc.stop(null); + + } catch (Exception e) { + fail("Got exception when starting stopping. " + e.getMessage()); + } + assertNotNull(appc.getName()); + } + +} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapConsuming.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapConsuming.java new file mode 100644 index 000000000..28c2bc4e2 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapConsuming.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.messaging.dmaap; + + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.appc.adapter.message.Consumer; +import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapConsumerImpl; +import org.onap.appc.adapter.messaging.dmaap.impl.DmaapConsumerImpl; +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; +import org.junit.Ignore; + +import java.util.Arrays; +import java.util.List; + +/** + * Must have a DMaaP cluster or simulator up and running + * Update the hostname, topic, client properties in + * resources/org/onap/appc/default.properties + * + */ +public class TestDmaapConsuming { + + private static Consumer dmaapConsumer; + private static Consumer httpConsumer; + + @BeforeClass + public static void setUp() { + + Configuration configuration = ConfigurationFactory.getConfiguration(); + + List hosts = Arrays.asList(configuration.getProperty("poolMembers").split(",")); + String topic = configuration.getProperty("topic.read"); + String consumerName = configuration.getProperty("client.name"); + String consumerId = configuration.getProperty("client.name.id"); + String msgFilter = configuration.getProperty("message.filter"); + String user = configuration.getProperty("dmaap.appc.username"); + String password = configuration.getProperty("dmaap.appc.password"); + + httpConsumer = new HttpDmaapConsumerImpl(hosts, topic, consumerName, consumerId, msgFilter); + dmaapConsumer = new DmaapConsumerImpl(hosts, topic, consumerName, consumerId,user,password,msgFilter); + } + + @Test + @Ignore + public void testHttpFetchMessages() { + testFetchMessages(httpConsumer); + } + + @Test + @Ignore + public void testFetchMessages() { + testFetchMessages(dmaapConsumer); + } + + private void testFetchMessages(Consumer consumer) { + List messages = consumer.fetch(1000, 100); + Assert.assertNotNull(messages); + Assert.assertFalse(messages.isEmpty()); + } + +} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapEventSender.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapEventSender.java new file mode 100644 index 000000000..bdc786337 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapEventSender.java @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.messaging.dmaap; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.appc.adapter.message.MessageDestination; +import org.onap.appc.adapter.message.Producer; +import org.onap.appc.adapter.message.event.EventHeader; +import org.onap.appc.adapter.message.event.EventMessage; +import org.onap.appc.adapter.message.event.EventStatus; +import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl; +import org.onap.appc.adapter.messaging.dmaap.impl.EventSenderDmaapImpl; +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; +import org.onap.appc.exceptions.APPCException; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + + +public class TestDmaapEventSender { + + private static Properties props; + private static Map producerMap = new HashMap<>(); + private static EventMessage eventMessage; + + @BeforeClass + public static void setUp() { + + Configuration configuration = ConfigurationFactory.getConfiguration(); // test.properties file placed in home dir. + + props = new Properties(); + props.setProperty(EventSenderDmaapImpl.EVENT_POOL_MEMBERS, + configuration.getProperty(EventSenderDmaapImpl.EVENT_POOL_MEMBERS) != null ? + configuration.getProperty(EventSenderDmaapImpl.EVENT_POOL_MEMBERS) : "member1,member2,member3"); + props.setProperty(EventSenderDmaapImpl.EVENT_TOPIC_WRITE, + configuration.getProperty(EventSenderDmaapImpl.EVENT_TOPIC_WRITE) != null ? + configuration.getProperty(EventSenderDmaapImpl.EVENT_TOPIC_WRITE) : "topic1"); + + String eventClientKey = configuration.getProperty(EventSenderDmaapImpl.DMAAP_USERNAME); + if (eventClientKey != null) { + props.setProperty(EventSenderDmaapImpl.DMAAP_USERNAME,eventClientKey); + } + String eventClientSecret = configuration.getProperty(EventSenderDmaapImpl.DMAAP_PASSWORD); + if (eventClientSecret != null) { + props.setProperty(EventSenderDmaapImpl.DMAAP_PASSWORD, eventClientSecret); + } + + Producer producer = Mockito.mock(DmaapProducerImpl.class); + producerMap.put(MessageDestination.DCAE.toString(),producer); + Mockito.when(producer.post(Matchers.anyString(), Matchers.anyString())).thenReturn(true); + + eventMessage = new EventMessage( + new EventHeader("2016-03-15T10:59:33.79Z", "1.01", "17"), + new EventStatus(404, "No krokodil found")); + } + + @Test + @Ignore // requires connection to a live DMaaP server + public void testDmaapEventSenderWithProperties() { + EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); + eventSender.initialize(); + eventSender.setProducerMap(producerMap); + Assert.assertTrue(eventSender.sendEvent(MessageDestination.DCAE, eventMessage)); + } + + @Test + public void testDmaapEventSenderWithNullProperties() { + EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); +// eventSender.initialize(); + eventSender.setProducerMap(producerMap); + Assert.assertTrue(eventSender.sendEvent(MessageDestination.DCAE, eventMessage)); + } + + /* + * This test runs agains a real Dmaap (or a simulator) that should be cofigured in test.properties file. + */ + @Test + @Ignore // requires connection to a live DMaaP server + public void testDmaapEventSenderWithDmaapSim() { + EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); + eventSender.initialize(); + Assert.assertTrue(eventSender.sendEvent(MessageDestination.DCAE, eventMessage)); + } + + + @Test + @Ignore // requires connection to a live DMaaP server + public void testDmaapEventSenderDG() throws APPCException { + EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); + eventSender.initialize(); + eventSender.setProducerMap(producerMap); + Map params = new HashMap<>(); + + params.put("eventTime", eventMessage.getEventHeader().getEventTime()); + params.put("apiVer", eventMessage.getEventHeader().getApiVer()); + params.put("eventId", eventMessage.getEventHeader().getEventId()); + params.put("reason", eventMessage.getEventStatus().getReason()); + params.put("code", "200"); + + Assert.assertTrue(eventSender.sendEvent(MessageDestination.DCAE,params, new SvcLogicContext())); + } + + @Test(expected = APPCException.class) + @Ignore // requires connection to a live DMaaP server + public void testDmaapEventSenderDGNoParams() throws APPCException { + EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); + eventSender.initialize(); + eventSender.setProducerMap(producerMap); + Map params = new HashMap<>(); + + Assert.assertFalse(eventSender.sendEvent(MessageDestination.DCAE,params, new SvcLogicContext())); + } + + + @Test(expected = APPCException.class) + @Ignore // requires connection to a live DMaaP server + public void testDmaapEventSenderDGNullParam() throws APPCException { + EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); + eventSender.initialize(); + eventSender.setProducerMap(producerMap); + Map params = null; + + Assert.assertFalse(eventSender.sendEvent(MessageDestination.DCAE,params, new SvcLogicContext())); + } + + @Test(expected = APPCException.class) + @Ignore // requires connection to a live DMaaP server + public void testDmaapEventSenderDGNoParam() throws APPCException { + EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); + eventSender.initialize(); + eventSender.setProducerMap(producerMap); + Map params = new HashMap<>(); + +// params.put("apiVer", eventMessage.getEventHeader().getApiVer()); + params.put("eventId", eventMessage.getEventHeader().getEventId()); + params.put("reason", eventMessage.getEventStatus().getReason()); + params.put("code", "200"); + + eventSender.sendEvent(MessageDestination.DCAE,params, new SvcLogicContext()); + } + +} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapProducing.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapProducing.java new file mode 100644 index 000000000..bdfa93726 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/TestDmaapProducing.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.messaging.dmaap; + + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.appc.adapter.message.Producer; +import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapProducerImpl; +import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl; +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; + +import java.util.Arrays; +import java.util.List; + +/** + * Must have a DMaaP cluster or simulator up and running + * Update the hostname, topic, client properties in + * resources/org/onap/appc/default.properties + * + */ +public class TestDmaapProducing { + + private static Producer httpProducer; + private static Producer dmaapProducer; + + @BeforeClass + public static void setUp() { + + Configuration configuration = ConfigurationFactory.getConfiguration(); + + List hosts = Arrays.asList(configuration.getProperty("poolMembers").split(",")); + String topic = configuration.getProperty("topic.write"); + String user = configuration.getProperty("dmaap.appc.username"); + String password = configuration.getProperty("dmaap.appc.password"); + + dmaapProducer = new DmaapProducerImpl(hosts, topic,user,password); + httpProducer = new HttpDmaapProducerImpl(hosts, topic); + httpProducer.updateCredentials(user,password); + } + + @Test + @Ignore + public void testHttpPostMessage() { + testPostMessage(httpProducer); + } + + @Test + @Ignore + public void testPostMessages() { + testPostMessage(dmaapProducer); + } + + private void testPostMessage(Producer producer) { + Assert.assertTrue(producer.post("partition", "{\"message\": \"Hello, world!\"}")); + } + +} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestConsumerProducerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestConsumerProducerImpl.java new file mode 100644 index 000000000..cb318dc4e --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestConsumerProducerImpl.java @@ -0,0 +1,245 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============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 java.util.*; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.appc.adapter.message.Consumer; +import org.onap.appc.adapter.message.Producer; +import org.onap.appc.adapter.messaging.dmaap.impl.DmaapConsumerImpl; +import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl; +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; + +public class TestConsumerProducerImpl { + + private Collection urls; + private String topicRead; + private String topicWrite; + private String group; + private String groupId; + private String user; + private String password; + + @Before + public void setup() { + System.out.println("setup entry..."); +// urls = new HashSet(); +// urls.add("dmaaphost1"); +// urls.add("dmaaphost2"); +// //remove unavailable dmaap instance for build +// //urls.add("dmaaphost3"); +// +// topicRead = "APPC-UNIT-TEST"; +// topicWrite = "APPC-UNIT-TEST"; +// group = "APPC-CLIENT"; +// groupId = "0"; + Configuration configuration = ConfigurationFactory.getConfiguration(); + List hosts = Arrays.asList(configuration.getProperty("poolMembers").split(",")); + urls = new HashSet(hosts); + topicRead = configuration.getProperty("topic.read"); + topicWrite = configuration.getProperty("topic.write"); + user = configuration.getProperty("dmaap.appc.username"); + password = configuration.getProperty("dmaap.appc.password"); + group = "APPC-CLIENT"; + groupId = "0"; + + + runoff(); + } + + /** + * Test that we can read and write and that the messages come back in order + */ + @Ignore + @Test + public void testWriteRead() { + System.out.println("testWriteRead entry..."); + Producer p = new DmaapProducerImpl(urls, topicWrite,user,password); + + String s1 = UUID.randomUUID().toString(); + String s2 = UUID.randomUUID().toString(); + if (p.post("TEST", s1) == false) { + // try again - 2nd attempt may succeed if cambria client failed over + p.post("TEST", s1); + } + if (p.post("TEST", s2) == false) { + // try again - 2nd attempt may succeed if cambria client failed over + p.post("TEST", s2); + } + + Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); + List out = c.fetch(); + // if fetch is empty, try again - a 2nd attempt may succeed if + // cambria client has failed over + if ((out == null) || out.isEmpty()) { + out = c.fetch(); + } + + assertNotNull(out); + assertEquals(2, out.size()); + assertEquals(s1, out.get(0)); + assertEquals(s2, out.get(1)); + + } + + /** + * Test that we can read and write and that the messages come back in order + */ + @Test + @Ignore // Https Not support on jenkins server + public void testWriteReadHttps() { + System.out.println("testWriteReadHttps entry..."); + Producer p = new DmaapProducerImpl(urls, topicWrite,user,password); + p.useHttps(true); + + String s1 = UUID.randomUUID().toString(); + String s2 = UUID.randomUUID().toString(); + if (p.post("TEST", s1) == false) { + // try again - 2nd attempt may succeed if cambria client failed over + p.post("TEST", s1); + } + if (p.post("TEST", s2) == false) { + // try again - 2nd attempt may succeed if cambria client failed over + p.post("TEST", s2); + } + + Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); + c.useHttps(true); + + List out = c.fetch(); + // if fetch is empty, try again - a 2nd attempt may succeed if + // cambria client has failed over + if ((out == null) || out.isEmpty()) { + out = c.fetch(); + } + + assertNotNull(out); + assertEquals(2, out.size()); + assertEquals(s1, out.get(0)); + assertEquals(s2, out.get(1)); + + } + + @Test + @Ignore // requires connection to a live DMaaP server + public void testBadUrl() { + System.out.println("testBadUrl entry..."); + urls.clear(); + urls.add("something.local"); + + // Producer p = new DmaapProducerImpl(urls, topicWrite); + Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); + List result = c.fetch(1000, 1000); + + assertNotNull(result); + assertTrue(result.isEmpty()); + } + + @Test + @Ignore // requires connection to a live DMaaP server + public void testAuth() { + System.out.println("testAuth entry..."); + Producer p = new DmaapProducerImpl(urls, topicWrite,user,password); + Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); + + p.updateCredentials("key", "secret"); + c.updateCredentials("key", "secret"); + + // TODO - Do some protected dmaap queries when the apis are updated + } + + /** + * Test DMaaP client failover to another server when a bad url is encountered + + */ + @Ignore + @Test + public void testFailover() { + System.out.println("testFailover entry..."); + urls.clear(); + urls.add("openecomp2.org"); // bad url + urls.add("dmaaphost2"); + Producer p = new DmaapProducerImpl(urls, topicWrite,user,password); + + String s1 = UUID.randomUUID().toString(); + if (p.post("TEST", s1) == false) { + // try again - cambria client should have failed over + p.post("TEST", s1); + } + + urls.clear(); + urls.add("openecomp3.org"); // bad url + urls.add("dmaaphost3"); + + Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); + List out = c.fetch(1000, 1000); + // if fetch is empty, try again - cambria client should have failed over + if ((out == null) || out.isEmpty()) { + out = c.fetch(); + } + + assertNotNull(out); + assertEquals(1, out.size()); + assertEquals(s1, out.get(0)); + } + + /** + * Reads through the entire topic so it is clean for testing. WARNING - ONLY USE ON TOPICS WHERE YOU ARE THE ONLY + * WRITER. Could end in an infinite loop otherwise. + */ + private void runoff() { + Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); + List data; + do { + data = c.fetch(1000, 10000); + } while (!data.isEmpty() && data.size()!=1); + } + + @Test + @Ignore + public void testFilter() { + System.out.println("testFilter entry..."); + List res; + String filter = "{\"class\":\"Assigned\",\"field\":\"request\"}"; + Consumer c = new DmaapConsumerImpl(urls, "DCAE-CLOSED-LOOP-EVENTS-DEV1510SIM", group, groupId,user,password,filter); + res = c.fetch(2000, 10); + assertFalse(res.isEmpty()); + + res.clear(); + filter = "{\"class\":\"Assigned\",\"field\":\"response\"}"; + c = new DmaapConsumerImpl(urls, "DCAE-CLOSED-LOOP-EVENTS-DEV1510SIM", group, groupId,user,password, filter); + res = c.fetch(2000, 10); + assertTrue(res.isEmpty()); + } +} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java deleted file mode 100644 index 8c07c0b4a..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.messaging.dmaap; - -import java.io.*; -import java.util.List; -import java.util.Properties; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import com.att.nsa.mr.client.MRConsumer; -import org.json.JSONObject; -import org.onap.appc.adapter.messaging.dmaap.impl.DmaapUtil; - -import com.att.nsa.mr.client.MRBatchingPublisher; -import com.att.nsa.mr.client.MRClientFactory; -import com.att.nsa.mr.client.MRPublisher.message; - - -/** - *An example of how to use the Java publisher. - */ -public class SimpleExamplePublisher -{ - - public static void main(String []args) throws InterruptedException, Exception{ - int msgCount = 1; - SimpleExamplePublisher publisher = new SimpleExamplePublisher(); - - int i=0; - - String topicProducerPropFileName = DmaapUtil.createProducerPropFile("org.onap.appc.UNIT-TEST", null); - while (i< msgCount) - { - publisher.publishMessage(topicProducerPropFileName,i); - i++; - } - - fetchMessage(); - } - - - public void publishMessage( String producerFilePath,int count ) throws IOException, InterruptedException, Exception - { - // create our publisher - final MRBatchingPublisher pub = MRClientFactory.createBatchingPublisher (producerFilePath); - // publish some messages - final JSONObject msg1 = new JSONObject (); - msg1.put ( "Partition:2", "Message:" +count); - //msg1.put ( "greeting", "Hello .." ); - - pub.send ( "2", msg1.toString()); - // close the publisher to make sure everything's sent before exiting. The batching - // publisher interface allows the app to get the set of unsent messages. It could - // write them to disk, for example, to try to send them later. - final List stuck = pub.close ( 20, TimeUnit.SECONDS ); - if ( stuck.size () > 0 ) - { - System.err.println ( stuck.size() + " messages unsent" ); - } - else - { - System.out.println ( "Clean exit; all messages sent." ); - } - } - - - public static void fetchMessage() - { - int count = 0; - - try - { - String topic = "org.onap.appc.UNIT-TEST"; - Properties props = new Properties(); - props.put("id", "1"); - props.put("group", "group1"); - String topicConsumerPropFileName1 = DmaapUtil.createConsumerPropFile(topic,props); - final MRConsumer consumer1 = MRClientFactory.createConsumer ( topicConsumerPropFileName1); - - props = new Properties(); - props.put("id", "2"); - props.put("group", "group2"); - String topicConsumerPropFileName2 = DmaapUtil.createConsumerPropFile(topic,props); - final MRConsumer consumer2 = MRClientFactory.createConsumer ( topicConsumerPropFileName2); - - for ( String msg : consumer1.fetch () ) - { - count++; - System.out.println ( "consumer1 "+count + ": " + msg ); - } - for ( String msg : consumer2.fetch () ) - { - count++; - System.out.println ( "consumer1 "+count + ": " + msg ); - } - - - } - catch ( Exception x ) - { - System.out.println("inside cons exc"); - System.err.println ( x.getClass().getName () + ": " + x.getMessage () ); - } - } -} - - - - - - - - - diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestAppcDmaapAdapterActivator.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestAppcDmaapAdapterActivator.java deleted file mode 100644 index 5473bf7e0..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestAppcDmaapAdapterActivator.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.messaging.dmaap; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.junit.Test; -import org.onap.appc.adapter.messaging.dmaap.AppcDmaapAdapterActivator; - -public class TestAppcDmaapAdapterActivator { - - // TODO commented out to allow build to pass, need to analyze and fix -// @Test - public void coverage() { - // This does nothing since the activator does nothing - AppcDmaapAdapterActivator appc = new AppcDmaapAdapterActivator(); - try { - appc.start(null); - appc.stop(null); - - } catch (Exception e) { - fail("Got exception when starting stopping. " + e.getMessage()); - } - assertNotNull(appc.getName()); - } - -} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapConsuming.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapConsuming.java deleted file mode 100644 index 28c2bc4e2..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapConsuming.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.messaging.dmaap; - - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.appc.adapter.message.Consumer; -import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapConsumerImpl; -import org.onap.appc.adapter.messaging.dmaap.impl.DmaapConsumerImpl; -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; -import org.junit.Ignore; - -import java.util.Arrays; -import java.util.List; - -/** - * Must have a DMaaP cluster or simulator up and running - * Update the hostname, topic, client properties in - * resources/org/onap/appc/default.properties - * - */ -public class TestDmaapConsuming { - - private static Consumer dmaapConsumer; - private static Consumer httpConsumer; - - @BeforeClass - public static void setUp() { - - Configuration configuration = ConfigurationFactory.getConfiguration(); - - List hosts = Arrays.asList(configuration.getProperty("poolMembers").split(",")); - String topic = configuration.getProperty("topic.read"); - String consumerName = configuration.getProperty("client.name"); - String consumerId = configuration.getProperty("client.name.id"); - String msgFilter = configuration.getProperty("message.filter"); - String user = configuration.getProperty("dmaap.appc.username"); - String password = configuration.getProperty("dmaap.appc.password"); - - httpConsumer = new HttpDmaapConsumerImpl(hosts, topic, consumerName, consumerId, msgFilter); - dmaapConsumer = new DmaapConsumerImpl(hosts, topic, consumerName, consumerId,user,password,msgFilter); - } - - @Test - @Ignore - public void testHttpFetchMessages() { - testFetchMessages(httpConsumer); - } - - @Test - @Ignore - public void testFetchMessages() { - testFetchMessages(dmaapConsumer); - } - - private void testFetchMessages(Consumer consumer) { - List messages = consumer.fetch(1000, 100); - Assert.assertNotNull(messages); - Assert.assertFalse(messages.isEmpty()); - } - -} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapEventSender.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapEventSender.java deleted file mode 100644 index bdc786337..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapEventSender.java +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.messaging.dmaap; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.onap.appc.adapter.message.MessageDestination; -import org.onap.appc.adapter.message.Producer; -import org.onap.appc.adapter.message.event.EventHeader; -import org.onap.appc.adapter.message.event.EventMessage; -import org.onap.appc.adapter.message.event.EventStatus; -import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl; -import org.onap.appc.adapter.messaging.dmaap.impl.EventSenderDmaapImpl; -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; -import org.onap.appc.exceptions.APPCException; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - - -public class TestDmaapEventSender { - - private static Properties props; - private static Map producerMap = new HashMap<>(); - private static EventMessage eventMessage; - - @BeforeClass - public static void setUp() { - - Configuration configuration = ConfigurationFactory.getConfiguration(); // test.properties file placed in home dir. - - props = new Properties(); - props.setProperty(EventSenderDmaapImpl.EVENT_POOL_MEMBERS, - configuration.getProperty(EventSenderDmaapImpl.EVENT_POOL_MEMBERS) != null ? - configuration.getProperty(EventSenderDmaapImpl.EVENT_POOL_MEMBERS) : "member1,member2,member3"); - props.setProperty(EventSenderDmaapImpl.EVENT_TOPIC_WRITE, - configuration.getProperty(EventSenderDmaapImpl.EVENT_TOPIC_WRITE) != null ? - configuration.getProperty(EventSenderDmaapImpl.EVENT_TOPIC_WRITE) : "topic1"); - - String eventClientKey = configuration.getProperty(EventSenderDmaapImpl.DMAAP_USERNAME); - if (eventClientKey != null) { - props.setProperty(EventSenderDmaapImpl.DMAAP_USERNAME,eventClientKey); - } - String eventClientSecret = configuration.getProperty(EventSenderDmaapImpl.DMAAP_PASSWORD); - if (eventClientSecret != null) { - props.setProperty(EventSenderDmaapImpl.DMAAP_PASSWORD, eventClientSecret); - } - - Producer producer = Mockito.mock(DmaapProducerImpl.class); - producerMap.put(MessageDestination.DCAE.toString(),producer); - Mockito.when(producer.post(Matchers.anyString(), Matchers.anyString())).thenReturn(true); - - eventMessage = new EventMessage( - new EventHeader("2016-03-15T10:59:33.79Z", "1.01", "17"), - new EventStatus(404, "No krokodil found")); - } - - @Test - @Ignore // requires connection to a live DMaaP server - public void testDmaapEventSenderWithProperties() { - EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); - eventSender.initialize(); - eventSender.setProducerMap(producerMap); - Assert.assertTrue(eventSender.sendEvent(MessageDestination.DCAE, eventMessage)); - } - - @Test - public void testDmaapEventSenderWithNullProperties() { - EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); -// eventSender.initialize(); - eventSender.setProducerMap(producerMap); - Assert.assertTrue(eventSender.sendEvent(MessageDestination.DCAE, eventMessage)); - } - - /* - * This test runs agains a real Dmaap (or a simulator) that should be cofigured in test.properties file. - */ - @Test - @Ignore // requires connection to a live DMaaP server - public void testDmaapEventSenderWithDmaapSim() { - EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); - eventSender.initialize(); - Assert.assertTrue(eventSender.sendEvent(MessageDestination.DCAE, eventMessage)); - } - - - @Test - @Ignore // requires connection to a live DMaaP server - public void testDmaapEventSenderDG() throws APPCException { - EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); - eventSender.initialize(); - eventSender.setProducerMap(producerMap); - Map params = new HashMap<>(); - - params.put("eventTime", eventMessage.getEventHeader().getEventTime()); - params.put("apiVer", eventMessage.getEventHeader().getApiVer()); - params.put("eventId", eventMessage.getEventHeader().getEventId()); - params.put("reason", eventMessage.getEventStatus().getReason()); - params.put("code", "200"); - - Assert.assertTrue(eventSender.sendEvent(MessageDestination.DCAE,params, new SvcLogicContext())); - } - - @Test(expected = APPCException.class) - @Ignore // requires connection to a live DMaaP server - public void testDmaapEventSenderDGNoParams() throws APPCException { - EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); - eventSender.initialize(); - eventSender.setProducerMap(producerMap); - Map params = new HashMap<>(); - - Assert.assertFalse(eventSender.sendEvent(MessageDestination.DCAE,params, new SvcLogicContext())); - } - - - @Test(expected = APPCException.class) - @Ignore // requires connection to a live DMaaP server - public void testDmaapEventSenderDGNullParam() throws APPCException { - EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); - eventSender.initialize(); - eventSender.setProducerMap(producerMap); - Map params = null; - - Assert.assertFalse(eventSender.sendEvent(MessageDestination.DCAE,params, new SvcLogicContext())); - } - - @Test(expected = APPCException.class) - @Ignore // requires connection to a live DMaaP server - public void testDmaapEventSenderDGNoParam() throws APPCException { - EventSenderDmaapImpl eventSender = new EventSenderDmaapImpl(); - eventSender.initialize(); - eventSender.setProducerMap(producerMap); - Map params = new HashMap<>(); - -// params.put("apiVer", eventMessage.getEventHeader().getApiVer()); - params.put("eventId", eventMessage.getEventHeader().getEventId()); - params.put("reason", eventMessage.getEventStatus().getReason()); - params.put("code", "200"); - - eventSender.sendEvent(MessageDestination.DCAE,params, new SvcLogicContext()); - } - -} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapProducing.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapProducing.java deleted file mode 100644 index bdfa93726..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/TestDmaapProducing.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.messaging.dmaap; - - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.appc.adapter.message.Producer; -import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapProducerImpl; -import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl; -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; - -import java.util.Arrays; -import java.util.List; - -/** - * Must have a DMaaP cluster or simulator up and running - * Update the hostname, topic, client properties in - * resources/org/onap/appc/default.properties - * - */ -public class TestDmaapProducing { - - private static Producer httpProducer; - private static Producer dmaapProducer; - - @BeforeClass - public static void setUp() { - - Configuration configuration = ConfigurationFactory.getConfiguration(); - - List hosts = Arrays.asList(configuration.getProperty("poolMembers").split(",")); - String topic = configuration.getProperty("topic.write"); - String user = configuration.getProperty("dmaap.appc.username"); - String password = configuration.getProperty("dmaap.appc.password"); - - dmaapProducer = new DmaapProducerImpl(hosts, topic,user,password); - httpProducer = new HttpDmaapProducerImpl(hosts, topic); - httpProducer.updateCredentials(user,password); - } - - @Test - @Ignore - public void testHttpPostMessage() { - testPostMessage(httpProducer); - } - - @Test - @Ignore - public void testPostMessages() { - testPostMessage(dmaapProducer); - } - - private void testPostMessage(Producer producer) { - Assert.assertTrue(producer.post("partition", "{\"message\": \"Hello, world!\"}")); - } - -} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/impl/TestConsumerProducerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/impl/TestConsumerProducerImpl.java deleted file mode 100644 index cb318dc4e..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/openecomp/appc/adapter/messaging/dmaap/impl/TestConsumerProducerImpl.java +++ /dev/null @@ -1,245 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============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 java.util.*; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.appc.adapter.message.Consumer; -import org.onap.appc.adapter.message.Producer; -import org.onap.appc.adapter.messaging.dmaap.impl.DmaapConsumerImpl; -import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl; -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; - -public class TestConsumerProducerImpl { - - private Collection urls; - private String topicRead; - private String topicWrite; - private String group; - private String groupId; - private String user; - private String password; - - @Before - public void setup() { - System.out.println("setup entry..."); -// urls = new HashSet(); -// urls.add("dmaaphost1"); -// urls.add("dmaaphost2"); -// //remove unavailable dmaap instance for build -// //urls.add("dmaaphost3"); -// -// topicRead = "APPC-UNIT-TEST"; -// topicWrite = "APPC-UNIT-TEST"; -// group = "APPC-CLIENT"; -// groupId = "0"; - Configuration configuration = ConfigurationFactory.getConfiguration(); - List hosts = Arrays.asList(configuration.getProperty("poolMembers").split(",")); - urls = new HashSet(hosts); - topicRead = configuration.getProperty("topic.read"); - topicWrite = configuration.getProperty("topic.write"); - user = configuration.getProperty("dmaap.appc.username"); - password = configuration.getProperty("dmaap.appc.password"); - group = "APPC-CLIENT"; - groupId = "0"; - - - runoff(); - } - - /** - * Test that we can read and write and that the messages come back in order - */ - @Ignore - @Test - public void testWriteRead() { - System.out.println("testWriteRead entry..."); - Producer p = new DmaapProducerImpl(urls, topicWrite,user,password); - - String s1 = UUID.randomUUID().toString(); - String s2 = UUID.randomUUID().toString(); - if (p.post("TEST", s1) == false) { - // try again - 2nd attempt may succeed if cambria client failed over - p.post("TEST", s1); - } - if (p.post("TEST", s2) == false) { - // try again - 2nd attempt may succeed if cambria client failed over - p.post("TEST", s2); - } - - Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); - List out = c.fetch(); - // if fetch is empty, try again - a 2nd attempt may succeed if - // cambria client has failed over - if ((out == null) || out.isEmpty()) { - out = c.fetch(); - } - - assertNotNull(out); - assertEquals(2, out.size()); - assertEquals(s1, out.get(0)); - assertEquals(s2, out.get(1)); - - } - - /** - * Test that we can read and write and that the messages come back in order - */ - @Test - @Ignore // Https Not support on jenkins server - public void testWriteReadHttps() { - System.out.println("testWriteReadHttps entry..."); - Producer p = new DmaapProducerImpl(urls, topicWrite,user,password); - p.useHttps(true); - - String s1 = UUID.randomUUID().toString(); - String s2 = UUID.randomUUID().toString(); - if (p.post("TEST", s1) == false) { - // try again - 2nd attempt may succeed if cambria client failed over - p.post("TEST", s1); - } - if (p.post("TEST", s2) == false) { - // try again - 2nd attempt may succeed if cambria client failed over - p.post("TEST", s2); - } - - Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); - c.useHttps(true); - - List out = c.fetch(); - // if fetch is empty, try again - a 2nd attempt may succeed if - // cambria client has failed over - if ((out == null) || out.isEmpty()) { - out = c.fetch(); - } - - assertNotNull(out); - assertEquals(2, out.size()); - assertEquals(s1, out.get(0)); - assertEquals(s2, out.get(1)); - - } - - @Test - @Ignore // requires connection to a live DMaaP server - public void testBadUrl() { - System.out.println("testBadUrl entry..."); - urls.clear(); - urls.add("something.local"); - - // Producer p = new DmaapProducerImpl(urls, topicWrite); - Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); - List result = c.fetch(1000, 1000); - - assertNotNull(result); - assertTrue(result.isEmpty()); - } - - @Test - @Ignore // requires connection to a live DMaaP server - public void testAuth() { - System.out.println("testAuth entry..."); - Producer p = new DmaapProducerImpl(urls, topicWrite,user,password); - Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); - - p.updateCredentials("key", "secret"); - c.updateCredentials("key", "secret"); - - // TODO - Do some protected dmaap queries when the apis are updated - } - - /** - * Test DMaaP client failover to another server when a bad url is encountered - - */ - @Ignore - @Test - public void testFailover() { - System.out.println("testFailover entry..."); - urls.clear(); - urls.add("openecomp2.org"); // bad url - urls.add("dmaaphost2"); - Producer p = new DmaapProducerImpl(urls, topicWrite,user,password); - - String s1 = UUID.randomUUID().toString(); - if (p.post("TEST", s1) == false) { - // try again - cambria client should have failed over - p.post("TEST", s1); - } - - urls.clear(); - urls.add("openecomp3.org"); // bad url - urls.add("dmaaphost3"); - - Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); - List out = c.fetch(1000, 1000); - // if fetch is empty, try again - cambria client should have failed over - if ((out == null) || out.isEmpty()) { - out = c.fetch(); - } - - assertNotNull(out); - assertEquals(1, out.size()); - assertEquals(s1, out.get(0)); - } - - /** - * Reads through the entire topic so it is clean for testing. WARNING - ONLY USE ON TOPICS WHERE YOU ARE THE ONLY - * WRITER. Could end in an infinite loop otherwise. - */ - private void runoff() { - Consumer c = new DmaapConsumerImpl(urls, topicRead, group, groupId,user,password); - List data; - do { - data = c.fetch(1000, 10000); - } while (!data.isEmpty() && data.size()!=1); - } - - @Test - @Ignore - public void testFilter() { - System.out.println("testFilter entry..."); - List res; - String filter = "{\"class\":\"Assigned\",\"field\":\"request\"}"; - Consumer c = new DmaapConsumerImpl(urls, "DCAE-CLOSED-LOOP-EVENTS-DEV1510SIM", group, groupId,user,password,filter); - res = c.fetch(2000, 10); - assertFalse(res.isEmpty()); - - res.clear(); - filter = "{\"class\":\"Assigned\",\"field\":\"response\"}"; - c = new DmaapConsumerImpl(urls, "DCAE-CLOSED-LOOP-EVENTS-DEV1510SIM", group, groupId,user,password, filter); - res = c.fetch(2000, 10); - assertTrue(res.isEmpty()); - } -} -- cgit