aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2019-03-06 13:58:47 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-06 13:58:47 +0000
commit251785c1bbb3beedd4f3ed7607a552de38638c88 (patch)
tree4701f94876c4d30960620a06c22851f148c75d28 /plugins/plugins-event
parentf0872b20425c66adeb14487c8f9e1c79f6bd3ddf (diff)
parent3463902489417686c2915e305ea97e3d365cd8d7 (diff)
Merge "Increase test coverage for plugins-event"
Diffstat (limited to 'plugins/plugins-event')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/pom.xml8
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumerTest.java113
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducerTest.java123
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java56
4 files changed, 300 insertions, 0 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/pom.xml
index 3a959f64a..8c3842dc0 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/pom.xml
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/pom.xml
@@ -29,6 +29,14 @@
<name>${project.artifactId}</name>
<description>[${project.parent.artifactId}] Plugin for handling events being transported over web sockets</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
<profiles>
<profile>
<id>apexSite</id>
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumerTest.java
new file mode 100644
index 000000000..cb04adc05
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumerTest.java
@@ -0,0 +1,113 @@
+/*-
+ * ============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.websocket;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.Answer;
+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.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 ApexWebSocketConsumerTest {
+
+ ApexWebSocketConsumer apexWebSocketConsumer = null;
+ EventHandlerParameters consumerParameters = null;
+ ApexEventReceiver incomingEventReceiver = null;
+ ApexEventProducer apexWebSocketProducer = null;
+ WebSocketCarrierTechnologyParameters webSocketCarrierTechnologyParameters = null;
+
+ /**
+ * Set up testing.
+ *
+ * @throws Exception on test set up errors.
+ */
+ @Before
+ public void setUp() throws Exception {
+ apexWebSocketConsumer = new ApexWebSocketConsumer();
+ consumerParameters = new EventHandlerParameters();
+ apexWebSocketProducer = new ApexWebSocketProducer();
+ apexWebSocketConsumer.start();
+ }
+
+ @After
+ public void tearDown() {
+ apexWebSocketConsumer.stop();
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithNonWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
+ apexWebSocketConsumer.init("TestApexWebSocketConsumer", consumerParameters,
+ incomingEventReceiver);
+ }
+
+ @Test
+ public void testInitWithWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ webSocketCarrierTechnologyParameters = new WebSocketCarrierTechnologyParameters();
+ consumerParameters.setCarrierTechnologyParameters(webSocketCarrierTechnologyParameters);
+ apexWebSocketConsumer.init("TestApexWebSocketConsumer", consumerParameters,
+ incomingEventReceiver);
+ assertEquals("TestApexWebSocketConsumer", apexWebSocketConsumer.getName());
+ }
+
+ @Test
+ public void testGetName() {
+ assertNull(apexWebSocketConsumer.getName());
+ }
+
+ @Test
+ public void testGetPeeredReference() {
+ assertNull(apexWebSocketConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testSetPeeredReference() {
+ PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ apexWebSocketConsumer, apexWebSocketProducer);
+ apexWebSocketConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
+ assertNotNull(apexWebSocketConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testReceiveString() {
+ MockitoAnnotations.initMocks(this);
+ ApexWebSocketConsumer apexWebSocketConsumerMock = Mockito.mock(ApexWebSocketConsumer.class);
+
+ Mockito.doAnswer((Answer<?>) invocation -> {
+ Object[] args = invocation.getArguments();
+ assertEquals("TestRecieveString", args[0]);
+ return null;
+ }).when(apexWebSocketConsumerMock).receiveString("TestRecieveString");
+
+ apexWebSocketConsumerMock.receiveString("TestRecieveString");
+
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducerTest.java
new file mode 100644
index 000000000..21069fc91
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducerTest.java
@@ -0,0 +1,123 @@
+/*-
+ * ============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.websocket;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.Answer;
+import org.onap.policy.apex.service.engine.event.ApexEventConsumer;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+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 ApexWebSocketProducerTest {
+
+ ApexWebSocketProducer apexWebSocketProducer = null;
+ EventHandlerParameters producerParameters = null;
+ ApexEventReceiver incomingEventReceiver = null;
+ ApexEventConsumer apexWebSocketConsumer = null;
+ WebSocketCarrierTechnologyParameters webSocketCarrierTechnologyParameters = 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 {
+ apexWebSocketConsumer = new ApexWebSocketConsumer();
+ producerParameters = new EventHandlerParameters();
+ apexWebSocketProducer = new ApexWebSocketProducer();
+ }
+
+ @After
+ public void tearDown() {
+ apexWebSocketProducer.stop();
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithNonWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
+ apexWebSocketProducer.init("TestApexWebSocketProducer", producerParameters);
+ }
+
+ @Test
+ public void testInitWithWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ webSocketCarrierTechnologyParameters = new WebSocketCarrierTechnologyParameters();
+ producerParameters.setCarrierTechnologyParameters(webSocketCarrierTechnologyParameters);
+ apexWebSocketProducer.init("TestApexWebSocketProducer", producerParameters);
+ assertEquals("TestApexWebSocketProducer", apexWebSocketProducer.getName());
+ }
+
+ @Test
+ public void testGetName() {
+ assertNull(apexWebSocketProducer.getName());
+ }
+
+ @Test
+ public void testGetPeeredReference() {
+ assertNull(apexWebSocketProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testSetPeeredReference() {
+ PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ apexWebSocketConsumer, apexWebSocketProducer);
+ apexWebSocketProducer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
+ assertNotNull(apexWebSocketProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testSendEvent() throws ApexEventException {
+ producerParameters
+ .setCarrierTechnologyParameters(new WebSocketCarrierTechnologyParameters() {});
+ synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS,
+ apexWebSocketConsumer, apexWebSocketProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT);
+ apexWebSocketProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS,
+ synchronousEventCache);
+ apexWebSocketProducer.sendEvent(1000L, "TestApexWebSocketProducer", "apexEvent");
+ }
+
+ @Test
+ public void testReceiveString() {
+ MockitoAnnotations.initMocks(this);
+ ApexWebSocketProducer apexWebSocketProducerMock = Mockito.mock(ApexWebSocketProducer.class);
+
+ Mockito.doAnswer((Answer<?>) invocation -> {
+ Object[] args = invocation.getArguments();
+ assertEquals("TestRecieveString", args[0]);
+ return null;
+ }).when(apexWebSocketProducerMock).receiveString("TestRecieveString");
+
+ apexWebSocketProducerMock.receiveString("TestRecieveString");
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java
new file mode 100644
index 000000000..fc449fc1f
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============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.websocket;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+public class WebSocketCarrierTechnologyParametersTest {
+
+ WebSocketCarrierTechnologyParameters webSocketCarrierTechnologyParameters = null;
+ GroupValidationResult result = null;
+
+ /**
+ * Set up testing.
+ *
+ * @throws Exception on test set up errors.
+ */
+ @Before
+ public void setUp() throws Exception {
+ webSocketCarrierTechnologyParameters = new WebSocketCarrierTechnologyParameters();
+ }
+
+ @Test
+ public void testWebSocketCarrierTechnologyParameters() {
+ assertNotNull(webSocketCarrierTechnologyParameters);
+ }
+
+ @Test
+ public void testValidate() {
+ result = webSocketCarrierTechnologyParameters.validate();
+ assertNotNull(result);
+ assertFalse(result.getStatus().isValid());
+ }
+
+}