summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2020-03-09 10:56:39 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2020-03-11 15:49:31 +0000
commit31ece44c935c76252cf0835e91290e88999c4f1d (patch)
treed50ce35d57786a46df2b981f083187b1d2fb0066 /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test
parent6bda5d7e4e80d1aefb4f19203361b7199448e70f (diff)
Fixing the gRPC consumer side
Change-Id: I21d9253f41eee9b958e8fb723f6c19f266502cef Issue-ID: POLICY-1656 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
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.java78
-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.java28
2 files changed, 59 insertions, 47 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
index dc5cc3809..48fce1bee 100644
--- 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
@@ -22,21 +22,24 @@ package org.onap.policy.apex.plugins.event.carrier.grpc;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.assertj.core.api.Assertions;
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.engine.event.PeeredReference;
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";
+ private static final String CONSUMER_NAME = "TestApexGrpcConsumer";
+ private ApexGrpcConsumer grpcConsumer = null;
+ private ApexGrpcProducer grpcProducer = null;
+ private EventHandlerParameters consumerParameters = null;
+ private ApexEventReceiver incomingEventReceiver = null;
/**
* Set up testing.
@@ -46,22 +49,22 @@ public class ApexGrpcConsumerTest {
@Before
public void setUp() throws ApexEventException {
grpcConsumer = new ApexGrpcConsumer();
- consumerParameters = new EventHandlerParameters();
- consumerParameters.setCarrierTechnologyParameters(new GrpcCarrierTechnologyParameters() {});
+ grpcProducer = new ApexGrpcProducer();
}
@Test
public void testInit() {
- assertThatThrownBy(() -> {
- grpcConsumer.init("TestApexGrpcConsumer", consumerParameters, incomingEventReceiver);
- }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ consumerParameters = populateConsumerParameters(true, true);
+ Assertions.assertThatCode(() -> grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
+ .doesNotThrowAnyException();
}
@Test
- public void testStart() {
- assertThatThrownBy(() -> {
- grpcConsumer.start();
- }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ public void testInit_invalidPeeredMode() {
+ consumerParameters = populateConsumerParameters(true, false);
+ assertThatThrownBy(() -> grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
+ .hasMessageContaining(
+ "gRPC consumer (" + CONSUMER_NAME + ") must run in peered requestor mode with a gRPC producer");
}
@Test
@@ -70,24 +73,35 @@ public class ApexGrpcConsumerTest {
}
@Test
- public void testGetPeeredReference() {
- assertThatThrownBy(() -> {
- grpcConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR);
- }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ public void testPeeredReference() throws ApexEventException {
+ consumerParameters = populateConsumerParameters(true, true);
+ grpcConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ new PeeredReference(EventHandlerPeeredMode.REQUESTOR, grpcConsumer, grpcProducer));
+ grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver);
+ PeeredReference peeredReference = grpcConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR);
+ assertNotNull(peeredReference);
+ assertTrue(peeredReference.getPeeredConsumer().equals(grpcConsumer));
+ assertTrue(peeredReference.getPeeredProducer().equals(grpcProducer));
}
- @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);
+ private EventHandlerParameters populateConsumerParameters(boolean isConsumer, boolean isPeeredMode) {
+ consumerParameters = new EventHandlerParameters();
+ GrpcCarrierTechnologyParameters params = new GrpcCarrierTechnologyParameters();
+ params.setLabel("GRPC");
+ params.setEventProducerPluginClass(ApexGrpcProducer.class.getName());
+ params.setEventConsumerPluginClass(ApexGrpcConsumer.class.getName());
+ if (!isConsumer) {
+ params.setHost("hostname");
+ params.setPort(3214);
+ params.setUsername("dummyUser");
+ params.setPassword("dummyPassword");
+ params.setTimeout(1);
+ }
+ consumerParameters.setCarrierTechnologyParameters(params);
+ if (isPeeredMode) {
+ consumerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
+ consumerParameters.setPeer(EventHandlerPeeredMode.REQUESTOR, "requestorPeerName");
+ }
+ return consumerParameters;
}
-
}
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
index a3994c29e..480d8423b 100644
--- 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
@@ -20,12 +20,14 @@
package org.onap.policy.apex.plugins.event.carrier.grpc;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.common.parameters.GroupValidationResult;
public class GrpcCarrierTechnologyParametersTest {
@@ -42,19 +44,13 @@ public class GrpcCarrierTechnologyParametersTest {
}
@Test
- public void testGrpcCarrierTechnologyParameters_invalid() {
+ public void testGrpcCarrierTechnologyParameters_invalid_producer_params() throws ApexEventException {
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(""));
+ assertTrue(result.isValid());
+ assertThatThrownBy(() -> params.validateGrpcParameters(true))
+ .hasMessage("Issues in specifying gRPC Producer parameters:\ntimeout should have a positive value.\n"
+ + "port range should be between 1024 and 65535\n" + "host should be specified.\n"
+ + "username should be specified.\n" + "password should be specified.\n");
}
@Test
@@ -70,6 +66,7 @@ public class GrpcCarrierTechnologyParametersTest {
params.setUsername(USERNAME);
GroupValidationResult result = params.validate();
assertTrue(result.isValid());
+ Assertions.assertThatCode(() -> params.validateGrpcParameters(true)).doesNotThrowAnyException();
}
@Test
@@ -81,7 +78,8 @@ public class GrpcCarrierTechnologyParametersTest {
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"));
+ assertTrue(result.isValid());
+ assertThatThrownBy(() -> params.validateGrpcParameters(true))
+ .hasMessageContaining("port range should be between 1024 and 65535");
}
}