aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java111
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java119
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java216
3 files changed, 446 insertions, 0 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java
new file mode 100644
index 000000000..4c10cefe9
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java
@@ -0,0 +1,111 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.apex.plugins.event.carrier.jms;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import javax.jms.Message;
+import javax.jms.Session;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventProducer;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class ApexJmsConsumerTest {
+
+ ApexJmsConsumer apexJmsConsumer = null;
+ EventHandlerParameters consumerParameters = null;
+ ApexEventReceiver incomingEventReceiver = null;
+ ApexEventProducer apexJmsProducer = null;
+ Session jmsSession = null;
+ JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
+
+ /**
+ * Set up testing.
+ *
+ * @throws Exception on test set up errors.
+ */
+ @Before
+ public void setUp() throws Exception {
+ apexJmsConsumer = new ApexJmsConsumer();
+ consumerParameters = new EventHandlerParameters();
+ apexJmsProducer = new ApexJmsProducer();
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithNonJmsCarrierTechnologyParameters() throws ApexEventException {
+ consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
+ apexJmsConsumer.init("TestApexJmsConsumer", consumerParameters, incomingEventReceiver);
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithJmsCarrierTechnologyParameters() throws ApexEventException {
+ jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
+ consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
+ apexJmsConsumer.init("TestApexJmsConsumer", consumerParameters, incomingEventReceiver);
+ }
+
+ @Test
+ public void testStart() {
+ apexJmsConsumer.start();
+ }
+
+ @Test
+ public void testGetName() {
+ assertNull(apexJmsConsumer.getName());
+ }
+
+ @Test
+ public void testGetPeeredReference() {
+ assertNull(apexJmsConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testSetPeeredReference() {
+ PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ apexJmsConsumer, apexJmsProducer);
+ apexJmsConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
+ assertNotNull(apexJmsConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test(expected = ApexEventRuntimeException.class)
+ public void testRun() {
+ apexJmsConsumer.run();
+
+ }
+
+ @Test(expected = ApexEventRuntimeException.class)
+ public void testOnMessage() {
+ Message jmsMessage = null;
+ apexJmsConsumer.onMessage(jmsMessage);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testStop() {
+ apexJmsConsumer.stop();
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
new file mode 100644
index 000000000..4773296d9
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.apex.plugins.event.carrier.jms;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import javax.jms.Session;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEvent;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventProducer;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
+import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class ApexJmsProducerTest {
+
+ ApexJmsConsumer apexJmsConsumer = null;
+ EventHandlerParameters producerParameters = null;
+ ApexEventReceiver incomingEventReceiver = null;
+ ApexEventProducer apexJmsProducer = null;
+ Session jmsSession = null;
+ JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
+ SynchronousEventCache synchronousEventCache = null;
+ private static final long DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT = 1000;
+
+ /**
+ * Set up testing.
+ *
+ * @throws Exception on test set up errors.
+ */
+ @Before
+ public void setUp() throws Exception {
+ apexJmsConsumer = new ApexJmsConsumer();
+ producerParameters = new EventHandlerParameters();
+ apexJmsProducer = new ApexJmsProducer();
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithNonJmsCarrierTechnologyParameters() throws ApexEventException {
+ producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
+ apexJmsProducer.init("TestApexJmsProducer", producerParameters);
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithJmsCarrierTechnologyParameters() throws ApexEventException {
+ jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
+ producerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
+ apexJmsProducer.init("TestApexJmsProducer", producerParameters);
+ }
+
+ @Test
+ public void testGetName() {
+ assertNull(apexJmsProducer.getName());
+ }
+
+ @Test
+ public void testGetPeeredReference() {
+ assertNull(apexJmsProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testSetPeeredReference() {
+ PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ apexJmsConsumer, apexJmsProducer);
+ apexJmsProducer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
+ assertNotNull(apexJmsProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testSendEvent() throws ApexEventException {
+ producerParameters.setCarrierTechnologyParameters(new JmsCarrierTechnologyParameters() {});
+ synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS,
+ apexJmsConsumer, apexJmsProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT);
+ apexJmsProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS,
+ synchronousEventCache);
+ ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace",
+ "testSource", "testTarget");
+ apexJmsProducer.sendEvent(1000L, "TestApexJmsProducer", apexEvent);
+ }
+
+ @Test(expected = ApexEventRuntimeException.class)
+ public void testSendEventWithNonSerializableObject() throws ApexEventException {
+ producerParameters.setCarrierTechnologyParameters(new JmsCarrierTechnologyParameters() {});
+ synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS,
+ apexJmsConsumer, apexJmsProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT);
+ apexJmsProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS,
+ synchronousEventCache);
+ apexJmsProducer.sendEvent(-1L, "TestApexJmsProducer", new ApexJmsProducerTest());
+ }
+
+ @Test
+ public void testStop() {
+ apexJmsProducer.stop();
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
new file mode 100644
index 000000000..32d712411
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
@@ -0,0 +1,216 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.apex.plugins.event.carrier.jms;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Base64;
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterRuntimeException;
+
+public class JmsCarrierTechnologyParametersTest {
+
+ JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
+ Properties jmsProducerProperties = null;
+ Properties jmsConsumerProperties = null;
+ GroupValidationResult result = null;
+
+ public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
+
+ public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS =
+ ApexJmsProducer.class.getCanonicalName();
+
+ public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS =
+ ApexJmsConsumer.class.getCanonicalName();
+
+ private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
+ private static final String DEFAULT_INITIAL_CTXT_FACTORY =
+ "org.jboss.naming.remote.client.InitialContextFactory";
+ private static final String DEFAULT_PROVIDER_URL = "remote://localhost:4447";
+ private static final String DEFAULT_SECURITY_PRINCIPAL = "userid";
+ private static final String DEFAULT_SECURITY_CREDENTIALS = "cGFzc3dvcmQ=";
+ private static final String DEFAULT_CONSUMER_TOPIC = "apex-in";
+ private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
+ private static final int DEFAULT_CONSUMER_WAIT_TIME = 100;
+ private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true;
+
+ /**
+ * Set up testing.
+ *
+ * @throws Exception on test set up errors.
+ */
+ @Before
+ public void setUp() throws Exception {
+ jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
+ }
+
+ @Test
+ public void testValidate() {
+ result = jmsCarrierTechnologyParameters.validate();
+ assertNotNull(result);
+ assertTrue(result.getStatus().isValid());
+ }
+
+ @Test
+ public void testJmsCarrierTechnologyParameters() {
+ assertNotNull(jmsCarrierTechnologyParameters);
+ }
+
+ @Test
+ public void testGetJmsProducerProperties() {
+ assertNotNull(jmsCarrierTechnologyParameters.getJmsConsumerProperties());
+ }
+
+ @Test
+ public void testGetJmsConsumerProperties() {
+ assertNotNull(jmsCarrierTechnologyParameters.getJmsProducerProperties());
+ }
+
+ @Test
+ public void testEqualityOfJmsConsumerAndProducerProperties() {
+ assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
+ jmsCarrierTechnologyParameters.getJmsConsumerProperties());
+ }
+
+ @Test
+ public void testGetConnectionFactory() {
+ assertEquals(DEFAULT_CONNECTION_FACTORY,
+ jmsCarrierTechnologyParameters.getConnectionFactory());
+ }
+
+ @Test
+ public void testSetConnectionFactory() {
+ jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
+ assertNotEquals(DEFAULT_CONNECTION_FACTORY,
+ jmsCarrierTechnologyParameters.getConnectionFactory());
+ }
+
+ @Test
+ public void testSetConsumerTopic() {
+ assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
+ jmsCarrierTechnologyParameters.setConsumerTopic(null);
+ result = jmsCarrierTechnologyParameters.validate();
+ assertFalse(result.getStatus().isValid());
+ }
+
+ @Test
+ public void testSetConsumerWaitTime() {
+ assertEquals(DEFAULT_CONSUMER_WAIT_TIME,
+ jmsCarrierTechnologyParameters.getConsumerWaitTime());
+ jmsCarrierTechnologyParameters.setConsumerWaitTime(-1);
+ assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME,
+ jmsCarrierTechnologyParameters.getConsumerWaitTime());
+ }
+
+ @Test
+ public void testSetEventConsumerPluginClass() {
+ assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS,
+ jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
+ jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass");
+ assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS,
+ jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
+ }
+
+ @Test
+ public void testSetEventProducerPluginClass() {
+ assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS,
+ jmsCarrierTechnologyParameters.getEventProducerPluginClass());
+ jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass");
+ assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS,
+ jmsCarrierTechnologyParameters.getEventProducerPluginClass());
+ }
+
+ @Test
+ public void testSetLabel() {
+ assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
+ jmsCarrierTechnologyParameters.setLabel("TestLable");
+ assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
+
+ }
+
+ @Test
+ public void testSetObjectMessageSending() {
+ assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
+ jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
+ assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
+ }
+
+ @Test
+ public void testSetProducerTopic() {
+ assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
+ jmsCarrierTechnologyParameters.setProducerTopic("");
+ result = jmsCarrierTechnologyParameters.validate();
+ assertFalse(result.getStatus().isValid());
+ }
+
+ @Test
+ public void testSetProviderUrl() {
+ assertEquals(DEFAULT_PROVIDER_URL, jmsCarrierTechnologyParameters.getProviderUrl());
+ jmsCarrierTechnologyParameters.setProviderUrl(null);
+ result = jmsCarrierTechnologyParameters.validate();
+ assertFalse(result.getStatus().isValid());
+ }
+
+ @Test
+ public void testSetSecurityCredentials() {
+ assertEquals(
+ new String(Base64.getDecoder().decode(DEFAULT_SECURITY_CREDENTIALS.getBytes())),
+ jmsCarrierTechnologyParameters.getSecurityCredentials());
+ jmsCarrierTechnologyParameters.setSecurityCredentials("");
+ result = jmsCarrierTechnologyParameters.validate();
+ assertFalse(result.getStatus().isValid());
+ }
+
+ @Test
+ public void testSetSecurityPrincipal() {
+ assertEquals(DEFAULT_SECURITY_PRINCIPAL,
+ jmsCarrierTechnologyParameters.getSecurityPrincipal());
+ jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
+ result = jmsCarrierTechnologyParameters.validate();
+ assertFalse(result.getStatus().isValid());
+ }
+
+ @Test
+ public void testSetInitialContextFactory() {
+
+ assertEquals(DEFAULT_INITIAL_CTXT_FACTORY,
+ jmsCarrierTechnologyParameters.getInitialContextFactory());
+
+ jmsCarrierTechnologyParameters.setInitialContextFactory(null);
+ result = jmsCarrierTechnologyParameters.validate();
+ assertFalse(result.getStatus().isValid());
+
+ jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory");
+ assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY,
+ jmsCarrierTechnologyParameters.getInitialContextFactory());
+ }
+
+ @Test(expected = ParameterRuntimeException.class)
+ public void testSetName() {
+ jmsCarrierTechnologyParameters.setName("TestName");
+ }
+}