summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-06-17 15:31:12 +0100
committeradheli.tavares <adheli.tavares@est.tech>2024-06-17 16:05:42 +0100
commitfe6bb57982677177f85daa5f893868556b18e63c (patch)
tree54a2f6f5a3e31469c4ea703a777399fb30fc9cfc /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src
parente9b746340711ddfccee7ac0f669ace626b1b3d46 (diff)
Convert junit4 to junit5
- plugins module Issue-ID: POLICY-5041 Change-Id: Iebff0a2e6898a5dfe9679662dd2be4c5067a4008 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src')
-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.java61
-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.java46
-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.java32
3 files changed, 70 insertions, 69 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 bd4103f92..fd447a205 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,59 +21,59 @@
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import org.assertj.core.api.Assertions;
-import org.junit.Before;
-import org.junit.Test;
+import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.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 {
+class ApexGrpcConsumerTest {
private static final String CONSUMER_NAME = "TestApexGrpcConsumer";
private ApexGrpcConsumer grpcConsumer = null;
private ApexGrpcProducer grpcProducer = null;
private EventHandlerParameters consumerParameters = null;
- private ApexEventReceiver incomingEventReceiver = null;
+ private final ApexEventReceiver incomingEventReceiver = null;
/**
* Set up testing.
- *
- * @throws ApexEventException on test set up errors.
*/
- @Before
- public void setUp() throws ApexEventException {
+ @BeforeEach
+ void setUp() {
grpcConsumer = new ApexGrpcConsumer();
grpcProducer = new ApexGrpcProducer();
}
@Test
- public void testInit() {
- consumerParameters = populateConsumerParameters(true, true);
+ void testInit() {
+ consumerParameters = populateConsumerParameters(true);
Assertions.assertThatCode(() -> grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.doesNotThrowAnyException();
}
@Test
- public void testInit_invalidPeeredMode() {
- consumerParameters = populateConsumerParameters(true, false);
+ void testInit_invalidPeeredMode() {
+ consumerParameters = populateConsumerParameters(false);
assertThatThrownBy(() -> grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.hasMessageContaining(
"gRPC consumer (" + CONSUMER_NAME + ") must run in peered requestor mode with a gRPC producer");
}
@Test
- public void testGetName() {
- assertEquals(null, new ApexGrpcConsumer().getName());
+ void testGetName() {
+ assertNull(new ApexGrpcConsumer().getName());
}
@Test
- public void testPeeredReference() throws ApexEventException {
- consumerParameters = populateConsumerParameters(true, true);
+ void testPeeredReference() throws ApexEventException {
+ consumerParameters = populateConsumerParameters(true);
grpcConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
new PeeredReference(EventHandlerPeeredMode.REQUESTOR, grpcConsumer, grpcProducer));
grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver);
@@ -83,19 +83,10 @@ public class ApexGrpcConsumerTest {
assertEquals(grpcProducer, peeredReference.getPeeredProducer());
}
- private EventHandlerParameters populateConsumerParameters(boolean isConsumer, boolean isPeeredMode) {
+ private EventHandlerParameters populateConsumerParameters(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);
- }
+ GrpcCarrierTechnologyParameters params =
+ getGrpcCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(params);
if (isPeeredMode) {
consumerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
@@ -103,4 +94,12 @@ public class ApexGrpcConsumerTest {
}
return consumerParameters;
}
+
+ private static @NotNull GrpcCarrierTechnologyParameters getGrpcCarrierTechnologyParameters() {
+ GrpcCarrierTechnologyParameters params = new GrpcCarrierTechnologyParameters();
+ params.setLabel("GRPC");
+ params.setEventProducerPluginClass(ApexGrpcProducer.class.getName());
+ params.setEventConsumerPluginClass(ApexGrpcConsumer.class.getName());
+ return 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/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
index 31be69e3a..7411737fe 100644
--- 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -22,61 +22,61 @@
package org.onap.policy.apex.plugins.event.carrier.grpc;
+import static org.junit.jupiter.api.Assertions.assertThrows;
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.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
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 {
+@ExtendWith(MockitoExtension.class)
+class ApexGrpcProducerTest {
private static final String PRODUCER_NAME = "TestApexGrpcProducer";
private static final String HOST = "localhost";
@Mock
private CdsProcessorGrpcClient grpcClient;
- private ApexGrpcProducer apexGrpcProducer = spy(new ApexGrpcProducer());
+ private final 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);
+ @BeforeEach
+ void setUp() {
+ populateEventHandlerParameters();
}
- @Test(expected = ApexEventException.class)
- public void testInit_fail() throws ApexEventException {
- apexGrpcProducer.init(PRODUCER_NAME, new EventHandlerParameters());
+ @Test
+ void testInit_fail() {
+ assertThrows(ApexEventException.class,
+ () -> apexGrpcProducer.init(PRODUCER_NAME, new EventHandlerParameters()));
}
@Test
- public void testInit_pass() {
+ void testInit_pass() {
// should not throw an exception
Assertions.assertThatCode(() -> apexGrpcProducer.init(PRODUCER_NAME, eventHandlerParameters))
.doesNotThrowAnyException();
}
@Test
- public void testStop() throws ApexEventException {
+ void testStop() throws ApexEventException {
apexGrpcProducer.init(PRODUCER_NAME, eventHandlerParameters);
// should not throw an exception
- Assertions.assertThatCode(() -> apexGrpcProducer.stop()).doesNotThrowAnyException();
+ Assertions.assertThatCode(apexGrpcProducer::stop).doesNotThrowAnyException();
}
@Test
- public void testSendEvent() throws ApexEventException {
+ void testSendEvent() throws ApexEventException {
apexGrpcProducer.init(PRODUCER_NAME, eventHandlerParameters);
Assertions
.assertThatCode(() -> apexGrpcProducer.sendEvent(123, null, "grpcEvent",
@@ -84,17 +84,17 @@ public class ApexGrpcProducerTest {
.doesNotThrowAnyException();
}
- private void populateEventHandlerParameters(String host, int timeout) {
+ private void populateEventHandlerParameters() {
eventHandlerParameters = new EventHandlerParameters();
GrpcCarrierTechnologyParameters params = new GrpcCarrierTechnologyParameters();
params.setLabel("GRPC");
params.setEventProducerPluginClass(ApexGrpcProducer.class.getName());
params.setEventConsumerPluginClass(ApexGrpcConsumer.class.getName());
- params.setHost(host);
+ params.setHost(ApexGrpcProducerTest.HOST);
params.setPort(3214);
params.setUsername("dummyUser");
params.setPassword("dummyPassword");
- params.setTimeout(timeout);
+ params.setTimeout(5);
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
index 7c79e95b6..22643fedd 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,16 +22,15 @@
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.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.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.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
-public class GrpcCarrierTechnologyParametersTest {
+class GrpcCarrierTechnologyParametersTest {
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
@@ -39,23 +38,26 @@ public class GrpcCarrierTechnologyParametersTest {
private GrpcCarrierTechnologyParameters params;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
params = new GrpcCarrierTechnologyParameters();
}
@Test
- public void testGrpcCarrierTechnologyParameters_invalid_producer_params() throws ApexEventException {
+ void testGrpcCarrierTechnologyParameters_invalid_producer_params() {
ValidationResult result = params.validate();
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");
+ .hasMessageContaining("Issues in specifying gRPC Producer parameters")
+ .hasMessageContaining("timeout should have a positive value")
+ .hasMessageContaining("port range should be between 1024 and 65535")
+ .hasMessageContaining("host should be specified")
+ .hasMessageContaining("username should be specified")
+ .hasMessageContaining("password should be specified");
}
@Test
- public void testGrpcCarrierTechnologyParameters_valid() {
+ void testGrpcCarrierTechnologyParameters_valid() {
assertEquals("GRPC", params.getName());
assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
@@ -71,7 +73,7 @@ public class GrpcCarrierTechnologyParametersTest {
}
@Test
- public void testGrpcCarrierTechnologyParameters_invalid_values() {
+ void testGrpcCarrierTechnologyParameters_invalid_values() {
params.setHost(HOST);
params.setPassword(PASSWORD);
params.setTimeout(1000);