aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java93
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java98
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java87
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/resources/executionServiceInputEvent.json25
4 files changed, 303 insertions, 0 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java
new file mode 100644
index 000000000..dc5cc3809
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+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.ApexEventReceiver;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class ApexGrpcConsumerTest {
+ ApexGrpcConsumer grpcConsumer = null;
+ EventHandlerParameters consumerParameters = null;
+ ApexEventReceiver incomingEventReceiver = null;
+
+ private static final String GRPC_CONSUMER_ERROR_MSG =
+ "A gRPC Consumer may not be specified. Only sending events is possible using gRPC";
+
+ /**
+ * Set up testing.
+ *
+ * @throws ApexEventException on test set up errors.
+ */
+ @Before
+ public void setUp() throws ApexEventException {
+ grpcConsumer = new ApexGrpcConsumer();
+ consumerParameters = new EventHandlerParameters();
+ consumerParameters.setCarrierTechnologyParameters(new GrpcCarrierTechnologyParameters() {});
+ }
+
+ @Test
+ public void testInit() {
+ assertThatThrownBy(() -> {
+ grpcConsumer.init("TestApexGrpcConsumer", consumerParameters, incomingEventReceiver);
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Test
+ public void testStart() {
+ assertThatThrownBy(() -> {
+ grpcConsumer.start();
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Test
+ public void testGetName() {
+ assertEquals(null, new ApexGrpcConsumer().getName());
+ }
+
+ @Test
+ public void testGetPeeredReference() {
+ assertThatThrownBy(() -> {
+ grpcConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR);
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Test
+ public void testSetPeeredReference() {
+ assertThatThrownBy(() -> {
+ grpcConsumer.setPeeredReference(null, null);
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Test()
+ public void testStop() {
+ assertThatThrownBy(() -> {
+ new ApexGrpcConsumer().stop();
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java
new file mode 100644
index 000000000..53d191e14
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.spy;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.assertj.core.api.Assertions;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.cds.client.CdsProcessorGrpcClient;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ApexGrpcProducerTest {
+ private static final String HOST = "localhost";
+ @Mock
+ private CdsProcessorGrpcClient grpcClient;
+ private ApexGrpcProducer apexGrpcProducer = spy(new ApexGrpcProducer());
+ @Mock
+ private EventHandlerParameters eventHandlerParameters;
+
+ /**
+ * Set up testing.
+ *
+ * @throws ApexEventException on test set up errors.
+ */
+ @Before
+ public void setUp() throws ApexEventException {
+ populateEventHandlerParameters(HOST, 5);
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInit_fail() throws ApexEventException {
+ apexGrpcProducer.init("TestApexGrpcProducer", new EventHandlerParameters());
+ }
+
+ @Test
+ public void testInit_pass() {
+ // should not throw an exception
+ Assertions.assertThatCode(() -> apexGrpcProducer.init("TestApexGrpcProducer", eventHandlerParameters))
+ .doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testStop() throws ApexEventException {
+ apexGrpcProducer.init("TestApexGrpcProducer", eventHandlerParameters);
+ // should not throw an exception
+ Assertions.assertThatCode(() -> apexGrpcProducer.stop()).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testSendEvent() throws ApexEventException {
+ apexGrpcProducer.init("TestApexGrpcProducer", eventHandlerParameters);
+ assertThatThrownBy(() -> {
+ apexGrpcProducer.sendEvent(123, null, "grpcEvent",
+ Files.readString(Paths.get("src/test/resources/executionServiceInputEvent.json")));
+ }).hasMessageContaining("UNAVAILABLE: io exception");
+ }
+
+ private void populateEventHandlerParameters(String host, int timeout) {
+ eventHandlerParameters = new EventHandlerParameters();
+ GrpcCarrierTechnologyParameters params = new GrpcCarrierTechnologyParameters();
+ params.setLabel("GRPC");
+ params.setEventProducerPluginClass(ApexGrpcProducer.class.getName());
+ params.setEventConsumerPluginClass(ApexGrpcConsumer.class.getName());
+ params.setHost(host);
+ params.setPort(3214);
+ params.setUsername("dummyUser");
+ params.setPassword("dummyPassword");
+ params.setTimeout(timeout);
+ eventHandlerParameters.setCarrierTechnologyParameters(params);
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
new file mode 100644
index 000000000..a3994c29e
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+public class GrpcCarrierTechnologyParametersTest {
+
+ private static final String USERNAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String HOST = "localhost";
+
+ private GrpcCarrierTechnologyParameters params;
+
+ @Before
+ public void setUp() {
+ params = new GrpcCarrierTechnologyParameters();
+ }
+
+ @Test
+ public void testGrpcCarrierTechnologyParameters_invalid() {
+ GroupValidationResult result = params.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().contains("field \"timeout\" type \"int\" value \"0\" INVALID, must be >= 1"));
+ assertTrue(result.getResult().contains("field \"port\" type \"int\" value \"0\" INVALID, must be >= 1024"));
+ assertTrue(
+ result.getResult().contains("field \"host\" type \"java.lang.String\" value \"null\" INVALID, is null"));
+ assertTrue(result.getResult()
+ .contains("field \"username\" type \"java.lang.String\" value \"null\" INVALID, is null"));
+ assertTrue(result.getResult()
+ .contains("field \"password\" type \"java.lang.String\" value \"null\" INVALID, is null"));
+ assertTrue(result.getResult().contains(""));
+ assertTrue(result.getResult().contains(""));
+ }
+
+ @Test
+ public void testGrpcCarrierTechnologyParameters_valid() {
+ assertEquals("GRPC", params.getName());
+ assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
+ assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
+
+ params.setHost(HOST);
+ params.setPassword(PASSWORD);
+ params.setPort(2233);
+ params.setTimeout(1000);
+ params.setUsername(USERNAME);
+ GroupValidationResult result = params.validate();
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ public void testGrpcCarrierTechnologyParameters_invalid_values() {
+ params.setHost(HOST);
+ params.setPassword(PASSWORD);
+ params.setTimeout(1000);
+ params.setUsername(USERNAME);
+
+ params.setPort(23); // invalid value
+ GroupValidationResult result = params.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().contains("field \"port\" type \"int\" value \"23\" INVALID, must be >= 1024"));
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/resources/executionServiceInputEvent.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/resources/executionServiceInputEvent.json
new file mode 100644
index 000000000..1054af14a
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/resources/executionServiceInputEvent.json
@@ -0,0 +1,25 @@
+{
+ "actionIdentifiers": {
+ "actionName": "actionName",
+ "blueprintName": "bluePrintName",
+ "blueprintVersion": "1.0.0",
+ "mode": "sync"
+ },
+ "commonHeader": {
+ "originatorId": "sdnc",
+ "requestId": "1234567",
+ "subRequestId": "subReqId"
+ },
+ "payload": {
+ "config-assign-request": {
+ "resolution-key": "RES-KEY",
+ "config-assign-properties": {
+ "service-instance-id": "sid12",
+ "pnf-id": "pnf-id",
+ "pnf-address": "1.2.3.4",
+ "service-uuid": "service-uuid",
+ "customization-uuid": "customization-uuid"
+ }
+ }
+ }
+}