summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java
diff options
context:
space:
mode:
authorParshad Patel <pars.patel@samsung.com>2019-02-27 10:37:57 +0900
committerParshad Patel <pars.patel@samsung.com>2019-03-05 10:59:43 +0900
commit3463902489417686c2915e305ea97e3d365cd8d7 (patch)
treeb35e0a99e3ef368f537edad5caeaeba40d9352b3 /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java
parent94db579b98a2432fe592d09be9c96fd82ab63ad3 (diff)
Increase test coverage for plugins-event
Add JUnit test cases for plugins-event-carrier-websocket Issue-ID: POLICY-1513 Change-Id: I5f2a8dacfff4c14cf4a24e9258b5a551cecc1489 Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java')
-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
3 files changed, 292 insertions, 0 deletions
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());
+ }
+
+}