diff options
Diffstat (limited to 'plugins/plugins-event')
29 files changed, 893 insertions, 887 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); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java index ab1155641..5ea2fab05 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. - * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2021, 2023-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. @@ -23,8 +23,8 @@ package org.onap.policy.apex.plugins.event.carrier.jms; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; @@ -34,8 +34,9 @@ import jakarta.jms.Topic; import java.util.Properties; import javax.naming.InitialContext; import javax.naming.NamingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.onap.policy.apex.service.engine.event.ApexEventException; @@ -47,7 +48,7 @@ import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnolo import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; -public class ApexJmsConsumerTest { +class ApexJmsConsumerTest { private static final String CONSUMER_NAME = "TestApexJmsConsumer"; private ApexJmsConsumer apexJmsConsumer = null; @@ -56,38 +57,36 @@ public class ApexJmsConsumerTest { private ApexEventProducer apexJmsProducer = null; private JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null; + AutoCloseable closeable; + /** * Set up testing. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { apexJmsConsumer = Mockito.spy(new ApexJmsConsumer()); consumerParameters = new EventHandlerParameters(); apexJmsProducer = new ApexJmsProducer(); } @Test - public void testInitWithNonJmsCarrierTechnologyParameters() { + void testInitWithNonJmsCarrierTechnologyParameters() { consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() { }); - assertThatThrownBy( - () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver) - ) + assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) .isInstanceOf(ApexEventException.class); } @Test - public void testInitWithJmsCarrierTechnologyParameters() { + void testInitWithJmsCarrierTechnologyParameters() { jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); - assertThatThrownBy( - () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver) - ) + assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) .isInstanceOf(ApexEventException.class); } @Test - public void testInitNoConnectionFactory() throws NamingException { + void testInitNoConnectionFactory() throws NamingException { jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); @@ -95,14 +94,12 @@ public class ApexJmsConsumerTest { Mockito.doReturn(null).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory()); Mockito.doReturn(context).when(apexJmsConsumer).getInitialContext(); - assertThatThrownBy( - () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver) - ) + assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) .isInstanceOf(ApexEventException.class); } @Test - public void testInitNoConsumerTopic() throws NamingException { + void testInitNoConsumerTopic() throws NamingException { jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); @@ -113,14 +110,12 @@ public class ApexJmsConsumerTest { Mockito.doReturn(null).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic()); Mockito.doReturn(context).when(apexJmsConsumer).getInitialContext(); - assertThatThrownBy( - () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver) - ) + assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) .isInstanceOf(ApexEventException.class); } @Test - public void testInitNoConnection() throws NamingException, JMSException { + void testInitNoConnection() throws NamingException, JMSException { jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); @@ -130,21 +125,18 @@ public class ApexJmsConsumerTest { Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory()); Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic()); - Mockito.doThrow(JMSException.class) - .when(connectionFactory) + closeable = Mockito.doThrow(JMSException.class).when(connectionFactory) .createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(), jmsCarrierTechnologyParameters.getSecurityCredentials()); Mockito.doReturn(context).when(apexJmsConsumer).getInitialContext(); - assertThatThrownBy( - () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver) - ) + assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) .isInstanceOf(ApexEventException.class); } @Test - public void testInitConnectionError() throws NamingException, JMSException { + void testInitConnectionError() throws NamingException, JMSException { jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); @@ -155,21 +147,18 @@ public class ApexJmsConsumerTest { Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory()); Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic()); - Mockito.doReturn(connection) - .when(connectionFactory) + closeable = Mockito.doReturn(connection).when(connectionFactory) .createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(), jmsCarrierTechnologyParameters.getSecurityCredentials()); Mockito.doThrow(JMSException.class).when(connection).start(); Mockito.doReturn(context).when(apexJmsConsumer).getInitialContext(); - assertThatThrownBy( - () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver) - ) + assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) .isInstanceOf(ApexEventException.class); } @Test - public void testInit() throws NamingException, JMSException, ApexEventException { + void testInit() throws NamingException, JMSException, ApexEventException { jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); @@ -180,8 +169,7 @@ public class ApexJmsConsumerTest { Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory()); Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic()); - Mockito.doReturn(connection) - .when(connectionFactory) + closeable = Mockito.doReturn(connection).when(connectionFactory) .createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(), jmsCarrierTechnologyParameters.getSecurityCredentials()); Mockito.doNothing().when(connection).start(); @@ -193,22 +181,22 @@ public class ApexJmsConsumerTest { } @Test - public void testStart() { + void testStart() { assertThatCode(apexJmsConsumer::start).doesNotThrowAnyException(); } @Test - public void testGetName() { + void testGetName() { assertNull(apexJmsConsumer.getName()); } @Test - public void testGetPeeredReference() { + void testGetPeeredReference() { assertNull(apexJmsConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); } @Test - public void testSetPeeredReference() { + void testSetPeeredReference() { PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, apexJmsConsumer, apexJmsProducer); apexJmsConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference); @@ -216,19 +204,19 @@ public class ApexJmsConsumerTest { } @Test - public void testRun() { + void testRun() { assertThatThrownBy(apexJmsConsumer::run).isInstanceOf(ApexEventRuntimeException.class); } @Test - public void testOnMessageUninitialized() { + void testOnMessageUninitialized() { Message jmsMessage = null; assertThatThrownBy(() -> apexJmsConsumer.onMessage(jmsMessage)) .isInstanceOf(ApexEventRuntimeException.class); } @Test - public void testOnMessage() throws JMSException, NamingException, ApexEventException { + void testOnMessage() throws JMSException, NamingException, ApexEventException { // prepare ApexJmsConsumer jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); @@ -242,8 +230,7 @@ public class ApexJmsConsumerTest { Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory()); Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic()); - Mockito.doReturn(connection) - .when(connectionFactory) + closeable = Mockito.doReturn(connection).when(connectionFactory) .createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(), jmsCarrierTechnologyParameters.getSecurityCredentials()); Mockito.doNothing().when(connection).start(); @@ -260,7 +247,7 @@ public class ApexJmsConsumerTest { } @Test - public void testConnectionError() throws NamingException, JMSException, ApexEventException { + void testConnectionError() throws NamingException, JMSException, ApexEventException { // prepare ApexJmsConsumer jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); @@ -272,8 +259,7 @@ public class ApexJmsConsumerTest { Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory()); Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic()); - Mockito.doReturn(connection) - .when(connectionFactory) + closeable = Mockito.doReturn(connection).when(connectionFactory) .createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(), jmsCarrierTechnologyParameters.getSecurityCredentials()); Mockito.doNothing().when(connection).start(); @@ -290,7 +276,7 @@ public class ApexJmsConsumerTest { } @Test - public void testStop() throws NamingException, JMSException, ApexEventException { + void testStop() throws NamingException, JMSException, ApexEventException { // prepare ApexJmsConsumer jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters); @@ -302,8 +288,7 @@ public class ApexJmsConsumerTest { Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory()); Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic()); - Mockito.doReturn(connection) - .when(connectionFactory) + closeable = Mockito.doReturn(connection).when(connectionFactory) .createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(), jmsCarrierTechnologyParameters.getSecurityCredentials()); Mockito.doNothing().when(connection).start(); @@ -321,7 +306,14 @@ public class ApexJmsConsumerTest { } @Test - public void testStopNoJmsProperties() { + void testStopNoJmsProperties() { assertThatThrownBy(apexJmsConsumer::stop).isInstanceOf(NullPointerException.class); } + + @AfterEach + void after() throws Exception { + if (closeable != null) { + closeable.close(); + } + } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java index ffc5c5b1e..35130648f 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. - * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2021, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,8 +25,8 @@ package org.onap.policy.apex.plugins.event.carrier.jms; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; @@ -43,9 +43,9 @@ import java.util.Random; import javax.naming.InitialContext; import javax.naming.NamingException; import org.apache.commons.lang3.RandomStringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.engine.event.ApexEventException; @@ -71,14 +71,14 @@ public class ApexJmsProducerTest { * Set up testing. * */ - @Before + @BeforeEach public void setUp() { apexJmsConsumer = new ApexJmsConsumer(); producerParameters = new EventHandlerParameters(); apexJmsProducer = Mockito.spy(new ApexJmsProducer()); } - @After + @AfterEach public void tearDown() { // restore system.out System.setOut(out); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java index 36f2e31ce..e8c223482 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. - * Modifications Copyright (C) 2019,2021 Nordix Foundation. + * Modifications Copyright (C) 2019, 2021, 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,32 +22,31 @@ package org.onap.policy.apex.plugins.event.carrier.jms; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Properties; import javax.naming.Context; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ParameterRuntimeException; import org.onap.policy.common.parameters.ValidationResult; -public class JmsCarrierTechnologyParametersTest { +class JmsCarrierTechnologyParametersTest { JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null; - Properties jmsProducerProperties = null; - Properties jmsConsumerProperties = null; ValidationResult result = null; - public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS"; + static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS"; - public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJmsProducer.class.getName(); + static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJmsProducer.class.getName(); - public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName(); + static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName(); private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory"; private static final String DEFAULT_INITIAL_CTXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory"; @@ -61,13 +60,13 @@ public class JmsCarrierTechnologyParametersTest { * * @throws Exception on test set up errors. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters(); } @Test - public void testValidate() { + void testValidate() { result = jmsCarrierTechnologyParameters.validate(); assertNotNull(result); assertFalse(result.getStatus().isValid()); @@ -82,12 +81,12 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testJmsCarrierTechnologyParameters() { + void testJmsCarrierTechnologyParameters() { assertNotNull(jmsCarrierTechnologyParameters); } @Test - public void testGetJmsProducerProperties() { + void testGetJmsProducerProperties() { Properties producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties(); assertNotNull(producerProperties); @@ -117,7 +116,7 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testGetJmsConsumerProperties() { + void testGetJmsConsumerProperties() { Properties consumerProperties = jmsCarrierTechnologyParameters.getJmsConsumerProperties(); assertNotNull(consumerProperties); assertNull(consumerProperties.get(Context.SECURITY_CREDENTIALS)); @@ -128,24 +127,24 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testEqualityOfJmsConsumerAndProducerProperties() { + void testEqualityOfJmsConsumerAndProducerProperties() { assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(), - jmsCarrierTechnologyParameters.getJmsConsumerProperties()); + jmsCarrierTechnologyParameters.getJmsConsumerProperties()); } @Test - public void testGetConnectionFactory() { + void testGetConnectionFactory() { assertEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory()); } @Test - public void testSetConnectionFactory() { + void testSetConnectionFactory() { jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory"); assertNotEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory()); } @Test - public void testSetConsumerTopic() { + void testSetConsumerTopic() { assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic()); jmsCarrierTechnologyParameters.setConsumerTopic(null); result = jmsCarrierTechnologyParameters.validate(); @@ -153,28 +152,28 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testSetConsumerWaitTime() { + void testSetConsumerWaitTime() { assertEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime()); jmsCarrierTechnologyParameters.setConsumerWaitTime(-1); assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime()); } @Test - public void testSetEventConsumerPluginClass() { + void testSetEventConsumerPluginClass() { assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass()); jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass"); assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass()); } @Test - public void testSetEventProducerPluginClass() { + void testSetEventProducerPluginClass() { assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass()); jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass"); assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass()); } @Test - public void testSetLabel() { + void testSetLabel() { assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel()); jmsCarrierTechnologyParameters.setLabel("TestLable"); assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel()); @@ -182,14 +181,14 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testSetObjectMessageSending() { + void testSetObjectMessageSending() { assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending()); jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING); assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending()); } @Test - public void testSetProducerTopic() { + void testSetProducerTopic() { assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic()); jmsCarrierTechnologyParameters.setProducerTopic(""); result = jmsCarrierTechnologyParameters.validate(); @@ -197,7 +196,7 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testSetProviderUrl() { + void testSetProviderUrl() { assertNull(jmsCarrierTechnologyParameters.getProviderUrl()); jmsCarrierTechnologyParameters.setProviderUrl(null); result = jmsCarrierTechnologyParameters.validate(); @@ -205,7 +204,7 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testSetSecurityCredentials() { + void testSetSecurityCredentials() { assertNull(jmsCarrierTechnologyParameters.getSecurityCredentials()); jmsCarrierTechnologyParameters.setSecurityCredentials(""); result = jmsCarrierTechnologyParameters.validate(); @@ -213,7 +212,7 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testSetSecurityPrincipal() { + void testSetSecurityPrincipal() { assertNull(jmsCarrierTechnologyParameters.getSecurityPrincipal()); jmsCarrierTechnologyParameters.setSecurityPrincipal(null); result = jmsCarrierTechnologyParameters.validate(); @@ -221,7 +220,7 @@ public class JmsCarrierTechnologyParametersTest { } @Test - public void testSetInitialContextFactory() { + void testSetInitialContextFactory() { assertEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory()); @@ -233,8 +232,8 @@ public class JmsCarrierTechnologyParametersTest { assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory()); } - @Test(expected = ParameterRuntimeException.class) - public void testSetName() { - jmsCarrierTechnologyParameters.setName("TestName"); + @Test + void testSetName() { + assertThrows(ParameterRuntimeException.class, () -> jmsCarrierTechnologyParameters.setName("TestName")); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java index 1ef3550e4..f1e420bf0 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2024 Nordix Foundation * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,12 +23,13 @@ package org.onap.policy.apex.plugins.event.carrier.kafka; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +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 static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Before; -import org.junit.Test; +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.ApexEventProducer; import org.onap.policy.apex.service.engine.event.ApexEventReceiver; @@ -37,7 +38,7 @@ import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnolo import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; -public class ApexKafkaConsumerTest { +class ApexKafkaConsumerTest { ApexKafkaConsumer apexKafkaConsumer = null; ApexKafkaConsumer apexKafkaConsumer2 = null; EventHandlerParameters consumerParameters = null; @@ -51,13 +52,14 @@ public class ApexKafkaConsumerTest { * * @throws ApexEventException on test set up errors. */ - @Before - public void setUp() throws ApexEventException { + @BeforeEach + void setUp() throws ApexEventException { apexKafkaConsumer = new ApexKafkaConsumer(); consumerParameters = new EventHandlerParameters(); apexKafkaProducer = new ApexKafkaProducer(); consumerParameters - .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {}); + .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() { + }); apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver); apexKafkaConsumer2 = new ApexKafkaConsumer(); @@ -65,63 +67,66 @@ public class ApexKafkaConsumerTest { kafkaParameters = new KafkaCarrierTechnologyParameters(); String[][] kafkaProperties = { {"value.deserializer", "io.confluent.kafka.serializers.KafkaAvroDeserializer"}, - {"schema.registry.url", "[http://test-registory:8080]"} + {"schema.registry.url", "[https://test-registory:8080]"} }; kafkaParameters.setKafkaProperties(kafkaProperties); consumerParameters2 - .setCarrierTechnologyParameters(kafkaParameters); + .setCarrierTechnologyParameters(kafkaParameters); apexKafkaConsumer2.init("TestApexKafkaConsumer2", consumerParameters2, incomingEventReceiver); } @Test - public void testStart() { + void testStart() { assertThatCode(apexKafkaConsumer::start).doesNotThrowAnyException(); assertThatCode(apexKafkaConsumer2::start).doesNotThrowAnyException(); } @Test - public void testGetName() { + void testGetName() { assertEquals("TestApexKafkaConsumer", apexKafkaConsumer.getName()); assertEquals("TestApexKafkaConsumer2", apexKafkaConsumer2.getName()); } @Test - public void testGetPeeredReference() { + void testGetPeeredReference() { assertNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); assertNull(apexKafkaConsumer2.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); } @Test - public void testSetPeeredReference() { + void testSetPeeredReference() { PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, - apexKafkaConsumer, apexKafkaProducer); + apexKafkaConsumer, apexKafkaProducer); apexKafkaConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference); assertNotNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); PeeredReference peeredReference2 = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, - apexKafkaConsumer2, apexKafkaProducer); + apexKafkaConsumer2, apexKafkaProducer); apexKafkaConsumer2.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference2); assertNotNull(apexKafkaConsumer2.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); } - @Test(expected = java.lang.NullPointerException.class) - public void testRun() { - apexKafkaConsumer.run(); - apexKafkaConsumer2.run(); + @Test + void testRun() { + assertThrows(NullPointerException.class, () -> apexKafkaConsumer.run()); + assertThrows(NullPointerException.class, () -> apexKafkaConsumer2.run()); } - @Test(expected = java.lang.NullPointerException.class) - public void testStop() { - apexKafkaConsumer.stop(); - apexKafkaConsumer2.stop(); + @Test + void testStop() { + assertThrows(NullPointerException.class, () -> apexKafkaConsumer.stop()); + assertThrows(NullPointerException.class, () -> apexKafkaConsumer2.stop()); } - @Test(expected = ApexEventException.class) - public void testInitWithNonKafkaCarrierTechnologyParameters() throws ApexEventException { - consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {}); - apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver); - apexKafkaConsumer2.init("TestApexKafkaConsumer2", consumerParameters, incomingEventReceiver); + @Test + void testInitWithNonKafkaCarrierTechnologyParameters() { + consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() { + }); + assertThrows(ApexEventException.class, () -> + apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver)); + assertThrows(ApexEventException.class, () -> + apexKafkaConsumer2.init("TestApexKafkaConsumer2", consumerParameters, incomingEventReceiver)); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java index 7300474c7..f5606eb57 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. + * Modifications Copyright (C) 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. @@ -20,19 +21,20 @@ package org.onap.policy.apex.plugins.event.carrier.kafka; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +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 static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Before; -import org.junit.Test; +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.PeeredReference; import org.onap.policy.apex.service.engine.event.SynchronousEventCache; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; -public class ApexKafkaProducerTest { +class ApexKafkaProducerTest { ApexKafkaProducer apexKafkaProducer = null; ApexKafkaConsumer apexKafkaConsumer = null; EventHandlerParameters producerParameters = null; @@ -43,37 +45,38 @@ public class ApexKafkaProducerTest { /** * Set up testing. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { apexKafkaProducer = new ApexKafkaProducer(); apexKafkaConsumer = new ApexKafkaConsumer(); producerParameters = new EventHandlerParameters(); } - @Test(expected = ApexEventException.class) - public void testInit() throws ApexEventException { - apexKafkaProducer.init("TestApexKafkaProducer", producerParameters); + @Test + void testInit() { + assertThrows(ApexEventException.class, + () -> apexKafkaProducer.init("TestApexKafkaProducer", producerParameters)); } @Test - public void testGetName() { + void testGetName() { assertNull(apexKafkaProducer.getName()); } @Test - public void testGetPeeredReference() { + void testGetPeeredReference() { assertNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); } @Test - public void testWithProperValues() throws ApexEventException { + void testWithProperValues() throws ApexEventException { producerParameters - .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {}); + .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() { }); synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, - apexKafkaConsumer, apexKafkaProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT); + apexKafkaConsumer, apexKafkaProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT); apexKafkaProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, - synchronousEventCache); + synchronousEventCache); apexKafkaProducer.init("TestApexKafkaProducer", producerParameters); assertEquals("TestApexKafkaProducer", apexKafkaProducer.getName()); assertNotNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java index 6b0f7d920..11bafc9b1 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. - * Modifications Copyright (C) 2019,2023 Nordix Foundation. + * Modifications Copyright (C) 2019, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,17 +22,18 @@ package org.onap.policy.apex.plugins.event.carrier.kafka; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class KafkaCarrierTechnologyParametersTest { +class KafkaCarrierTechnologyParametersTest { @Test - public void testKafkaCarrierTechnologyParameters() { + void testKafkaCarrierTechnologyParameters() { KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters(); assertNotNull(kafkaCarrierTechnologyParameters); @@ -40,17 +41,17 @@ public class KafkaCarrierTechnologyParametersTest { } @Test - public void testGetKafkaProducerProperties() { + void testGetKafkaProducerProperties() { KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters(); Properties kafkaProducerProperties = kafkaCarrierTechnologyParameters.getKafkaProducerProperties(); assertNotNull(kafkaProducerProperties); assertEquals("localhost:9092", kafkaProducerProperties.get("bootstrap.servers")); assertEquals("1", kafkaProducerProperties.get("linger.ms")); - assertEquals(null, kafkaProducerProperties.get("group.id")); - assertEquals(null, kafkaProducerProperties.get("Property0")); - assertEquals(null, kafkaProducerProperties.get("Property1")); - assertEquals(null, kafkaProducerProperties.get("Property2")); + assertNull(kafkaProducerProperties.get("group.id")); + assertNull(kafkaProducerProperties.get("Property0")); + assertNull(kafkaProducerProperties.get("Property1")); + assertNull(kafkaProducerProperties.get("Property2")); // @formatter:off String[][] kafkaProperties = { @@ -68,24 +69,24 @@ public class KafkaCarrierTechnologyParametersTest { assertNotNull(kafkaProducerProperties); assertEquals("localhost:9092", kafkaProducerProperties.get("bootstrap.servers")); assertEquals("1", kafkaProducerProperties.get("linger.ms")); - assertEquals(null, kafkaProducerProperties.get("group.id")); + assertNull(kafkaProducerProperties.get("group.id")); assertEquals("Value0", kafkaProducerProperties.get("Property0")); assertEquals("Value1", kafkaProducerProperties.get("Property1")); - assertEquals(null, kafkaProducerProperties.get("Property2")); + assertNull(kafkaProducerProperties.get("Property2")); } @Test - public void testGetKafkaConsumerProperties() { + void testGetKafkaConsumerProperties() { KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters(); Properties kafkaConsumerProperties = kafkaCarrierTechnologyParameters.getKafkaConsumerProperties(); assertNotNull(kafkaConsumerProperties); assertEquals("localhost:9092", kafkaConsumerProperties.get("bootstrap.servers")); assertEquals("default-group-id", kafkaConsumerProperties.get("group.id")); - assertEquals(null, kafkaConsumerProperties.get("linger.ms")); - assertEquals(null, kafkaConsumerProperties.get("Property0")); - assertEquals(null, kafkaConsumerProperties.get("Property1")); - assertEquals(null, kafkaConsumerProperties.get("Property2")); + assertNull(kafkaConsumerProperties.get("linger.ms")); + assertNull(kafkaConsumerProperties.get("Property0")); + assertNull(kafkaConsumerProperties.get("Property1")); + assertNull(kafkaConsumerProperties.get("Property2")); // @formatter:off String[][] kafkaProperties = { @@ -103,204 +104,30 @@ public class KafkaCarrierTechnologyParametersTest { assertNotNull(kafkaConsumerProperties); assertEquals("localhost:9092", kafkaConsumerProperties.get("bootstrap.servers")); assertEquals("default-group-id", kafkaConsumerProperties.get("group.id")); - assertEquals(null, kafkaConsumerProperties.get("linger.ms")); + assertNull(kafkaConsumerProperties.get("linger.ms")); assertEquals("Value0", kafkaConsumerProperties.get("Property0")); assertEquals("Value1", kafkaConsumerProperties.get("Property1")); - assertEquals(null, kafkaConsumerProperties.get("Property2")); + assertNull(kafkaConsumerProperties.get("Property2")); } @Test - public void testValidate() { + void testValidate() { KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters(); assertNotNull(kafkaCarrierTechnologyParameters); assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - String origStringValue = kafkaCarrierTechnologyParameters.getBootstrapServers(); - kafkaCarrierTechnologyParameters.setBootstrapServers(" "); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setBootstrapServers(origStringValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origStringValue = kafkaCarrierTechnologyParameters.getAcks(); - kafkaCarrierTechnologyParameters.setAcks(" "); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setAcks(origStringValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origStringValue = kafkaCarrierTechnologyParameters.getGroupId(); - kafkaCarrierTechnologyParameters.setGroupId(" "); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setGroupId(origStringValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origStringValue = kafkaCarrierTechnologyParameters.getProducerTopic(); - kafkaCarrierTechnologyParameters.setProducerTopic(" "); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setProducerTopic(origStringValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - int origIntValue = kafkaCarrierTechnologyParameters.getRetries(); - kafkaCarrierTechnologyParameters.setRetries(-1); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setRetries(origIntValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origIntValue = kafkaCarrierTechnologyParameters.getBatchSize(); - kafkaCarrierTechnologyParameters.setBatchSize(-1); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setBatchSize(origIntValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origIntValue = kafkaCarrierTechnologyParameters.getLingerTime(); - kafkaCarrierTechnologyParameters.setLingerTime(-1); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setLingerTime(origIntValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - long origLongValue = kafkaCarrierTechnologyParameters.getBufferMemory(); - kafkaCarrierTechnologyParameters.setBufferMemory(-1); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setBufferMemory(origLongValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origIntValue = kafkaCarrierTechnologyParameters.getAutoCommitTime(); - kafkaCarrierTechnologyParameters.setAutoCommitTime(-1); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setAutoCommitTime(origIntValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origIntValue = kafkaCarrierTechnologyParameters.getSessionTimeout(); - kafkaCarrierTechnologyParameters.setSessionTimeout(-1); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setSessionTimeout(origIntValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origIntValue = kafkaCarrierTechnologyParameters.getConsumerPollTime(); - kafkaCarrierTechnologyParameters.setConsumerPollTime(-1); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setConsumerPollTime(origIntValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origStringValue = kafkaCarrierTechnologyParameters.getKeySerializer(); - kafkaCarrierTechnologyParameters.setKeySerializer(" "); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setKeySerializer(origStringValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origStringValue = kafkaCarrierTechnologyParameters.getValueSerializer(); - kafkaCarrierTechnologyParameters.setValueSerializer(" "); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setValueSerializer(origStringValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origStringValue = kafkaCarrierTechnologyParameters.getKeyDeserializer(); - kafkaCarrierTechnologyParameters.setKeyDeserializer(" "); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setKeyDeserializer(origStringValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - origStringValue = kafkaCarrierTechnologyParameters.getValueDeserializer(); - kafkaCarrierTechnologyParameters.setValueDeserializer(" "); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setValueDeserializer(origStringValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - String[] origConsumerTopcList = kafkaCarrierTechnologyParameters.getConsumerTopicList(); - kafkaCarrierTechnologyParameters.setConsumerTopicList(null); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setConsumerTopicList(origConsumerTopcList); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - kafkaCarrierTechnologyParameters.setConsumerTopicList(new String[0]); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setConsumerTopicList(origConsumerTopcList); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - String[] blankStringList = { null, "" }; - kafkaCarrierTechnologyParameters.setConsumerTopicList(blankStringList); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setConsumerTopicList(origConsumerTopcList); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - String[][] origKafkaProperties = kafkaCarrierTechnologyParameters.getKafkaProperties(); - kafkaCarrierTechnologyParameters.setKafkaProperties(null); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); + assertValidateStringProperties(kafkaCarrierTechnologyParameters); - kafkaCarrierTechnologyParameters.setKafkaProperties(new String[0][0]); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); + assertValidateNumberProperties(kafkaCarrierTechnologyParameters); - // @formatter:offkafkaCarrierTechnologyParameters - String[][] kafkaProperties0 = { - { - null, "Value0" - } - }; - // @formatter:on + assertValidateTopicList(kafkaCarrierTechnologyParameters); - kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaProperties0); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - // @formatter:off - String[][] kafkaProperties1 = { - { - "Property1", null - } - }; - // @formatter:on - - kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaProperties1); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - // @formatter:off - String[][] kafkaProperties2 = { - { - "Property1", null - } - }; - // @formatter:on - - kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaProperties2); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - - // @formatter:off - String[][] kafkaPropertiesWithEmptyValue = { - { - "Property1", "" - } - }; - // @formatter:on - - kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaPropertiesWithEmptyValue); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); - - // @formatter:off - String[][] kafkaProperties3 = { - { - "Property1", "Value0", "Value1" - } - }; - // @formatter:on - - kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaProperties3); - assertFalse(kafkaCarrierTechnologyParameters.validate().isValid()); - kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties); - assertTrue(kafkaCarrierTechnologyParameters.validate().isValid()); + assertValidateKafkaProperties(kafkaCarrierTechnologyParameters); } @Test - public void testExplicitImplicit() { + void testExplicitImplicit() { KafkaCarrierTechnologyParameters kafkaCtp = new KafkaCarrierTechnologyParameters(); assertNotNull(kafkaCtp); @@ -378,4 +205,194 @@ public class KafkaCarrierTechnologyParametersTest { kafkaCtp.setKafkaProperties(kafkaProperties3); assertEquals("localhost:7777", kafkaCtp.getKafkaConsumerProperties().get("bootstrap.servers")); } + + private static void assertValidateStringProperties(KafkaCarrierTechnologyParameters kafkaParameters) { + String origStringValue = kafkaParameters.getBootstrapServers(); + kafkaParameters.setBootstrapServers(" "); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setBootstrapServers(origStringValue); + assertTrue(kafkaParameters.validate().isValid()); + + origStringValue = kafkaParameters.getAcks(); + kafkaParameters.setAcks(" "); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setAcks(origStringValue); + assertTrue(kafkaParameters.validate().isValid()); + + origStringValue = kafkaParameters.getGroupId(); + kafkaParameters.setGroupId(" "); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setGroupId(origStringValue); + assertTrue(kafkaParameters.validate().isValid()); + + origStringValue = kafkaParameters.getProducerTopic(); + kafkaParameters.setProducerTopic(" "); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setProducerTopic(origStringValue); + assertTrue(kafkaParameters.validate().isValid()); + + origStringValue = kafkaParameters.getKeySerializer(); + kafkaParameters.setKeySerializer(" "); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setKeySerializer(origStringValue); + assertTrue(kafkaParameters.validate().isValid()); + + origStringValue = kafkaParameters.getValueSerializer(); + kafkaParameters.setValueSerializer(" "); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setValueSerializer(origStringValue); + assertTrue(kafkaParameters.validate().isValid()); + + origStringValue = kafkaParameters.getKeyDeserializer(); + kafkaParameters.setKeyDeserializer(" "); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setKeyDeserializer(origStringValue); + assertTrue(kafkaParameters.validate().isValid()); + + origStringValue = kafkaParameters.getValueDeserializer(); + kafkaParameters.setValueDeserializer(" "); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setValueDeserializer(origStringValue); + assertTrue(kafkaParameters.validate().isValid()); + } + + private static void assertValidateTopicList(KafkaCarrierTechnologyParameters kafkaParameters) { + String[] origConsumerTopicList = kafkaParameters.getConsumerTopicList(); + kafkaParameters.setConsumerTopicList(null); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setConsumerTopicList(origConsumerTopicList); + assertTrue(kafkaParameters.validate().isValid()); + + kafkaParameters.setConsumerTopicList(new String[0]); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setConsumerTopicList(origConsumerTopicList); + assertTrue(kafkaParameters.validate().isValid()); + + String[] blankStringList = { null, "" }; + kafkaParameters.setConsumerTopicList(blankStringList); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setConsumerTopicList(origConsumerTopicList); + assertTrue(kafkaParameters.validate().isValid()); + } + + private static void assertValidateNumberProperties(KafkaCarrierTechnologyParameters kafkaParameters) { + int origIntValue = kafkaParameters.getRetries(); + kafkaParameters.setRetries(-1); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setRetries(origIntValue); + assertTrue(kafkaParameters.validate().isValid()); + + origIntValue = kafkaParameters.getBatchSize(); + kafkaParameters.setBatchSize(-1); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setBatchSize(origIntValue); + assertTrue(kafkaParameters.validate().isValid()); + + origIntValue = kafkaParameters.getLingerTime(); + kafkaParameters.setLingerTime(-1); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setLingerTime(origIntValue); + assertTrue(kafkaParameters.validate().isValid()); + + long origLongValue = kafkaParameters.getBufferMemory(); + kafkaParameters.setBufferMemory(-1); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setBufferMemory(origLongValue); + assertTrue(kafkaParameters.validate().isValid()); + + origIntValue = kafkaParameters.getAutoCommitTime(); + kafkaParameters.setAutoCommitTime(-1); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setAutoCommitTime(origIntValue); + assertTrue(kafkaParameters.validate().isValid()); + + origIntValue = kafkaParameters.getSessionTimeout(); + kafkaParameters.setSessionTimeout(-1); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setSessionTimeout(origIntValue); + assertTrue(kafkaParameters.validate().isValid()); + + origIntValue = kafkaParameters.getConsumerPollTime(); + kafkaParameters.setConsumerPollTime(-1); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setConsumerPollTime(origIntValue); + assertTrue(kafkaParameters.validate().isValid()); + } + + private static void assertValidateKafkaProperties(KafkaCarrierTechnologyParameters kafkaParameters) { + String[][] origKafkaProperties = kafkaParameters.getKafkaProperties(); + kafkaParameters.setKafkaProperties(null); + assertTrue(kafkaParameters.validate().isValid()); + kafkaParameters.setKafkaProperties(origKafkaProperties); + assertTrue(kafkaParameters.validate().isValid()); + + kafkaParameters.setKafkaProperties(new String[0][0]); + assertTrue(kafkaParameters.validate().isValid()); + kafkaParameters.setKafkaProperties(origKafkaProperties); + assertTrue(kafkaParameters.validate().isValid()); + + // @formatter:off + String[][] kafkaProperties0 = { + { + null, "Value0" + } + }; + // @formatter:on + + kafkaParameters.setKafkaProperties(kafkaProperties0); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setKafkaProperties(origKafkaProperties); + assertTrue(kafkaParameters.validate().isValid()); + + // @formatter:off + String[][] kafkaProperties1 = { + { + "Property1", null + } + }; + // @formatter:on + + kafkaParameters.setKafkaProperties(kafkaProperties1); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setKafkaProperties(origKafkaProperties); + assertTrue(kafkaParameters.validate().isValid()); + + // @formatter:off + String[][] kafkaProperties2 = { + { + "Property1", null + } + }; + // @formatter:on + + kafkaParameters.setKafkaProperties(kafkaProperties2); + assertFalse(kafkaParameters.validate().isValid()); + + // @formatter:off + String[][] kafkaPropertiesWithEmptyValue = { + { + "Property1", "" + } + }; + // @formatter:on + + kafkaParameters.setKafkaProperties(kafkaPropertiesWithEmptyValue); + assertTrue(kafkaParameters.validate().isValid()); + + kafkaParameters.setKafkaProperties(origKafkaProperties); + assertTrue(kafkaParameters.validate().isValid()); + + // @formatter:off + String[][] kafkaProperties3 = { + { + "Property1", "Value0", "Value1" + } + }; + // @formatter:on + + kafkaParameters.setKafkaProperties(kafkaProperties3); + assertFalse(kafkaParameters.validate().isValid()); + kafkaParameters.setKafkaProperties(origKafkaProperties); + assertTrue(kafkaParameters.validate().isValid()); + } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumerTest.java index 61155c8cf..b3a6bca06 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,9 +24,10 @@ package org.onap.policy.apex.plugins.event.carrier.restclient; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +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 static org.junit.jupiter.api.Assertions.assertTrue; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.Invocation.Builder; @@ -35,22 +36,23 @@ import jakarta.ws.rs.core.Response; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -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.apex.service.parameters.eventhandler.EventHandlerPeeredMode; /** - * This class tests the ApexRestClientConusmer class. - * + * This class tests the ApexRestClientConsumer class. */ -@RunWith(MockitoJUnitRunner.class) -public class ApexRestClientConusmerTest { +@ExtendWith(MockitoExtension.class) +class ApexRestClientConsumerTest { private final PrintStream stdout = System.out; @Mock @@ -65,13 +67,13 @@ public class ApexRestClientConusmerTest { @Mock private Response responseMock; - @After - public void after() { + @AfterEach + void after() { System.setOut(stdout); } @Test - public void testApexRestClientConsumerErrors() throws ApexEventException { + void testApexRestClientConsumerErrors() throws ApexEventException { ApexRestClientConsumer arcc = new ApexRestClientConsumer(); assertNotNull(arcc); @@ -99,7 +101,7 @@ public class ApexRestClientConusmerTest { assertEquals("RestClientConsumer", arcc.getName()); arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); rcctp.setUrl("http://some.place.that.does.not/exist"); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); @@ -120,7 +122,7 @@ public class ApexRestClientConusmerTest { } @Test - public void testApexRestClientConsumerHttpError() throws ApexEventException { + void testApexRestClientConsumerHttpError() throws ApexEventException { ApexRestClientConsumer arcc = new ApexRestClientConsumer(); assertNotNull(arcc); @@ -139,7 +141,7 @@ public class ApexRestClientConusmerTest { assertEquals("RestClientConsumer", arcc.getName()); arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); Mockito.doReturn(Response.Status.BAD_REQUEST.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).get(); @@ -159,7 +161,7 @@ public class ApexRestClientConusmerTest { } @Test - public void testApexRestClientConsumerJsonError() throws ApexEventException { + void testApexRestClientConsumerJsonError() throws ApexEventException { ApexRestClientConsumer arcc = new ApexRestClientConsumer(); assertNotNull(arcc); @@ -175,7 +177,7 @@ public class ApexRestClientConusmerTest { arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); rcctp.setUrl("http://some.place.that.does.not/exist"); Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); @@ -197,7 +199,7 @@ public class ApexRestClientConusmerTest { } @Test - public void testApexRestClientConsumerJsonEmpty() throws ApexEventException { + void testApexRestClientConsumerJsonEmpty() throws ApexEventException { ApexRestClientConsumer arcc = new ApexRestClientConsumer(); assertNotNull(arcc); @@ -214,7 +216,7 @@ public class ApexRestClientConusmerTest { arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); rcctp.setUrl("http://some.place.that.does.not/exist"); Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); @@ -242,7 +244,7 @@ public class ApexRestClientConusmerTest { } @Test - public void testApexRestClientConsumerJsonOk() throws ApexEventException { + void testApexRestClientConsumerJsonOk() throws ApexEventException { ApexRestClientConsumer arcc = new ApexRestClientConsumer(); assertNotNull(arcc); @@ -259,7 +261,7 @@ public class ApexRestClientConusmerTest { arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); rcctp.setUrl("http://some.place.that.does.not/exist"); Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); @@ -278,7 +280,7 @@ public class ApexRestClientConusmerTest { } @Test - public void testApexRestClientConsumerInvalidStatusCode() throws ApexEventException { + void testApexRestClientConsumerInvalidStatusCode() throws ApexEventException { ApexRestClientConsumer arcc = new ApexRestClientConsumer(); assertNotNull(arcc); @@ -295,7 +297,7 @@ public class ApexRestClientConusmerTest { arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); rcctp.setUrl("http://some.place.that.does.not/exist"); Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java index cc5ebbb9f..ec454af00 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,19 +23,23 @@ package org.onap.policy.apex.plugins.event.carrier.restclient; 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 jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.Invocation.Builder; import jakarta.ws.rs.client.WebTarget; import jakarta.ws.rs.core.Response; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; 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.SynchronousEventCache; @@ -47,8 +51,8 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo * Test the ApexRestClientProducer class. * */ -@RunWith(MockitoJUnitRunner.class) -public class ApexRestClientProducerTest { +@ExtendWith(MockitoExtension.class) +class ApexRestClientProducerTest { @Mock private Client httpClientMock; @@ -61,8 +65,10 @@ public class ApexRestClientProducerTest { @Mock private Response responseMock; + AutoCloseable closeable; + @Test - public void testApexRestClientProducerErrors() throws ApexEventException { + void testApexRestClientProducerErrors() throws ApexEventException { ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -84,7 +90,7 @@ public class ApexRestClientProducerTest { assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.POST, rcctp.getHttpMethod()); assertEquals("RestClientConsumer", arcp.getName()); arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); arcp.stop(); rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST); @@ -92,7 +98,7 @@ public class ApexRestClientProducerTest { assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.POST, rcctp.getHttpMethod()); assertEquals("RestClientConsumer", arcp.getName()); arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); arcp.stop(); rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.PUT); @@ -100,12 +106,12 @@ public class ApexRestClientProducerTest { assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.PUT, rcctp.getHttpMethod()); assertEquals("RestClientConsumer", arcp.getName()); arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null); - assertEquals(null, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + assertNull(arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); arcp.stop(); } @Test - public void testApexRestClientProducerPutEvent() throws ApexEventException { + void testApexRestClientProducerPutEvent() throws ApexEventException { ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -120,7 +126,7 @@ public class ApexRestClientProducerTest { rcctp.setUrl("http://some.place.that.does.not/exist"); Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); - Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any()); + closeable = Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); @@ -131,7 +137,7 @@ public class ApexRestClientProducerTest { } @Test - public void testApexRestClientProducerPostEventFail() throws ApexEventException { + void testApexRestClientProducerPostEventFail() throws ApexEventException { ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -160,7 +166,7 @@ public class ApexRestClientProducerTest { } @Test - public void testApexRestClientProducerPostEventOK() throws ApexEventException { + void testApexRestClientProducerPostEventOK() throws ApexEventException { ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -179,7 +185,7 @@ public class ApexRestClientProducerTest { properties.put("tag", "exist"); properties.put("key", "that"); Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); - Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any()); + closeable = Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target("http://some.place.that.does.not/exist"); @@ -190,7 +196,7 @@ public class ApexRestClientProducerTest { } @Test - public void testApexRestClientProducerPostEventAccepted() throws ApexEventException { + void testApexRestClientProducerPostEventAccepted() throws ApexEventException { ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -219,7 +225,7 @@ public class ApexRestClientProducerTest { } @Test - public void testApexRestClientProducerPostEventCache() throws ApexEventException { + void testApexRestClientProducerPostEventCache() throws ApexEventException { ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -251,39 +257,7 @@ public class ApexRestClientProducerTest { } @Test - public void testApexRestClientProducerPostEventCacheTrace() throws ApexEventException { - ApexRestClientProducer arcp = new ApexRestClientProducer(); - assertNotNull(arcp); - - EventHandlerParameters producerParameters = new EventHandlerParameters(); - RestClientCarrierTechnologyParameters rcctp = new RestClientCarrierTechnologyParameters(); - producerParameters.setCarrierTechnologyParameters(rcctp); - - rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST); - - ApexEventConsumer consumer = new ApexFileEventConsumer(); - SynchronousEventCache cache = - new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp, 1000); - arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, cache); - assertEquals(cache, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); - arcp.init("RestClientConsumer", producerParameters); - assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.POST, rcctp.getHttpMethod()); - assertEquals("RestClientConsumer", arcp.getName()); - - rcctp.setUrl("http://some.place.that.does.not/exist"); - Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); - Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); - Mockito.doReturn(builderMock).when(targetMock).request("application/json"); - Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); - Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); - arcp.setClient(httpClientMock); - - arcp.sendEvent(123, null, "EventName", "This is an Event"); - arcp.stop(); - } - - @Test - public void testApexRestClientProducerHttpError() throws ApexEventException { + void testApexRestClientProducerHttpError() throws ApexEventException { ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -298,7 +272,7 @@ public class ApexRestClientProducerTest { rcctp.setUrl("http://some.place.that.does.not/exist"); Mockito.doReturn(Response.Status.BAD_REQUEST.getStatusCode()).when(responseMock).getStatus(); - Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); + closeable = Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); @@ -308,4 +282,11 @@ public class ApexRestClientProducerTest { .hasMessageContaining("send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" " + "failed with status code 400"); } + + @AfterEach + void after() throws Exception { + if (closeable != null) { + closeable.close(); + } + } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java index 58d265a97..4539c5181 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -25,12 +25,13 @@ package org.onap.policy.apex.plugins.event.carrier.restclient; import static org.assertj.core.api.Assertions.assertThatCode; 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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments; import org.onap.policy.apex.service.parameters.ApexParameterHandler; import org.onap.policy.apex.service.parameters.ApexParameters; @@ -39,10 +40,10 @@ import org.onap.policy.common.parameters.ParameterException; /** * Test REST client carrier technology parameters. */ -public class RestClientCarrierTechnologyParametersTest { +class RestClientCarrierTechnologyParametersTest { @Test - public void testRestClientCarrierTechnologyParametersBadList() { + void testRestClientCarrierTechnologyParametersBadList() { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderBadList.json"); arguments.setRelativeFileRoot("."); @@ -55,7 +56,7 @@ public class RestClientCarrierTechnologyParametersTest { } @Test - public void testRestClientCarrierTechnologyParametersNotKvPairs() { + void testRestClientCarrierTechnologyParametersNotKvPairs() { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderNotKvPairs.json"); arguments.setRelativeFileRoot("."); @@ -67,7 +68,7 @@ public class RestClientCarrierTechnologyParametersTest { } @Test - public void testRestClientCarrierTechnologyParametersNulls() { + void testRestClientCarrierTechnologyParametersNulls() { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderNulls.json"); arguments.setRelativeFileRoot("."); @@ -79,7 +80,7 @@ public class RestClientCarrierTechnologyParametersTest { } @Test - public void testRestClientCarrierTechnologyParameterFilterInvalid() { + void testRestClientCarrierTechnologyParameterFilterInvalid() { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPFilterInvalid.json"); arguments.setRelativeFileRoot("."); @@ -92,7 +93,7 @@ public class RestClientCarrierTechnologyParametersTest { } @Test - public void testRestClientCarrierTechnologyParametersOk() throws ParameterException { + void testRestClientCarrierTechnologyParametersOk() throws ParameterException { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderOK.json"); arguments.setRelativeFileRoot("."); @@ -111,11 +112,11 @@ public class RestClientCarrierTechnologyParametersTest { assertEquals("fff", rrctp1.getHttpHeadersAsMultivaluedMap().get("eee").get(0)); rrctp1.setHttpHeaders(null); - assertEquals(null, rrctp1.getHttpHeadersAsMultivaluedMap()); + assertNull(rrctp1.getHttpHeadersAsMultivaluedMap()); } @Test - public void testRestClientCarrierTechnologyHttpCodeFilterOk() throws ParameterException { + void testRestClientCarrierTechnologyHttpCodeFilterOk() throws ParameterException { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderOK.json"); arguments.setRelativeFileRoot("."); @@ -128,7 +129,7 @@ public class RestClientCarrierTechnologyParametersTest { } @Test - public void testGettersAndSetters() { + void testGettersAndSetters() { RestClientCarrierTechnologyParameters rrctp = new RestClientCarrierTechnologyParameters(); rrctp.setUrl("http://some.where"); @@ -168,7 +169,7 @@ public class RestClientCarrierTechnologyParametersTest { } @Test - public void testUrlValidation() { + void testUrlValidation() { RestClientCarrierTechnologyParameters rrctp = new RestClientCarrierTechnologyParameters(); rrctp.setUrl("http://some.where.no.tag.in.url"); @@ -186,29 +187,27 @@ public class RestClientCarrierTechnologyParametersTest { assertEquals("ccc", rrctp.getHttpHeaders()[1][0]); assertEquals("ddd", rrctp.getHttpHeaders()[1][1]); - assertEquals(true, rrctp.validate().isValid()); + assertTrue(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/is{that}.{one}"); - assertEquals(true, rrctp.validate().isValid()); + assertTrue(rrctp.validate().isValid()); Set<String> keymap = rrctp.getKeysFromUrl(); - assertEquals(true, keymap.contains("place")); - assertEquals(true, keymap.contains("that")); - assertEquals(true, keymap.contains("one")); + assertTrue(keymap.contains("place") && keymap.contains("that") && keymap.contains("one")); rrctp.setUrl("http://{place.{that}/{is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{is}.{not}/{what}.{exist"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://place.that/is.not/what.{exist"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://place}.{that}/{is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{ }.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java index d7b418a78..fe779eb89 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 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,18 +22,18 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test the ApexRestRequest class. */ -public class ApexRestRequestTest { +class ApexRestRequestTest { @Test - public void testApexRestRequest() { + void testApexRestRequest() { final String eventName = "EventName"; final String eventString = "The Event String"; @@ -50,6 +50,6 @@ public class ApexRestRequestTest { assertEquals(1234567, rr.getTimestamp()); assertEquals("ApexRestRequest(executionId=1, eventName=EventName, event=The Event String, timestamp=1234567)", - rr.toString()); + rr.toString()); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java index e72fa9030..47f90454c 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java @@ -23,13 +23,13 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +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 java.util.Properties; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventReceiver; @@ -38,45 +38,40 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo /** * Test the ApexRestRequestorConsumer class. - * */ -public class ApexRestRequestorConsumerTest { +class ApexRestRequestorConsumerTest { // String constants private static final String CONSUMER_NAME = "ConsumerName"; private static final String EVENT_NAME = "EventName"; private static final String EVENT_BODY = "Event body"; @Test - public void testApexRestRequestorConsumerSetup() throws ApexEventException { + void testApexRestRequestorConsumerSetup() throws ApexEventException { ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer(); assertNotNull(consumer); EventHandlerParameters consumerParameters = new EventHandlerParameters(); ApexEventReceiver incomingEventReceiver = null; - assertThatThrownBy(() -> { - consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver); - }).hasMessage("specified consumer properties are not applicable to REST Requestor consumer (ConsumerName)"); + assertThatThrownBy(() -> consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) + .hasMessage("specified consumer properties are not applicable to REST Requestor consumer (ConsumerName)"); RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(rrctp); - assertThatThrownBy(() -> { - consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver); - }).hasMessage("REST Requestor consumer (ConsumerName) must run in peered requestor mode " - + "with a REST Requestor producer"); + assertThatThrownBy(() -> consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) + .hasMessage("REST Requestor consumer (ConsumerName) must run in peered requestor mode " + + "with a REST Requestor producer"); consumerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true); rrctp.setHttpMethod(null); - assertThatThrownBy(() -> { - consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver); - }).hasMessage("no URL has been specified on REST Requestor consumer (ConsumerName)"); + assertThatThrownBy(() -> consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) + .hasMessage("no URL has been specified on REST Requestor consumer (ConsumerName)"); rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET); rrctp.setUrl("ZZZZ"); - assertThatThrownBy(() -> { - consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver); - }).hasMessage("invalid URL has been specified on REST Requestor consumer (ConsumerName)"); + assertThatThrownBy(() -> consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)) + .hasMessage("invalid URL has been specified on REST Requestor consumer (ConsumerName)"); rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET); rrctp.setUrl("http://www.onap.org"); @@ -85,9 +80,8 @@ public class ApexRestRequestorConsumerTest { consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver); - assertThatThrownBy(() -> { - consumer.processRestRequest(null); - }).hasMessage("could not queue request \"null\" on REST Requestor consumer (ConsumerName)"); + assertThatThrownBy(() -> consumer.processRestRequest(null)) + .hasMessage("could not queue request \"null\" on REST Requestor consumer (ConsumerName)"); assertEquals(CONSUMER_NAME, consumer.getName()); assertEquals(0, consumer.getEventsReceived()); @@ -95,7 +89,7 @@ public class ApexRestRequestorConsumerTest { } @Test - public void testApexRestRequestorConsumerRequest() throws ApexEventException { + void testApexRestRequestorConsumerRequest() throws ApexEventException { ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer(); assertNotNull(consumer); @@ -119,7 +113,7 @@ public class ApexRestRequestorConsumerTest { } @Test - public void testApexRestRequestorConsumerUrlUpdate() throws ApexEventException { + void testApexRestRequestorConsumerUrlUpdate() throws ApexEventException { ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer(); assertNotNull(consumer); @@ -145,7 +139,7 @@ public class ApexRestRequestorConsumerTest { } @Test - public void testApexRestRequestorConsumerUrlUpdateError() throws ApexEventException { + void testApexRestRequestorConsumerUrlUpdateError() throws ApexEventException { ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer(); assertNotNull(consumer); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java index 450a21f01..0e57a31e9 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications 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. @@ -22,11 +22,12 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor; 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.fail; +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 static org.junit.jupiter.api.Assertions.fail; -import org.junit.Test; +import org.junit.jupiter.api.Test; 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.PeeredReference; @@ -38,33 +39,30 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo /** * Test the ApexRestRequestorProducer class. */ -public class ApexRestRequestorProducerTest { +class ApexRestRequestorProducerTest { // String constants private static final String PRODUCER_NAME = "ProducerName"; @Test - public void testApexRestRequestorProducerMethods() throws ApexEventException { + void testApexRestRequestorProducerMethods() throws ApexEventException { ApexRestRequestorProducer producer = new ApexRestRequestorProducer(); assertNotNull(producer); EventHandlerParameters producerParameters = new EventHandlerParameters(); - assertThatThrownBy(() -> { - producer.init(PRODUCER_NAME, producerParameters); - }).hasMessage("specified producer properties are not applicable to REST requestor producer (ProducerName)"); + assertThatThrownBy(() -> producer.init(PRODUCER_NAME, producerParameters)) + .hasMessage("specified producer properties are not applicable to REST requestor producer (ProducerName)"); RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters(); producerParameters.setCarrierTechnologyParameters(rrctp); - assertThatThrownBy(() -> { - producer.init(PRODUCER_NAME, producerParameters); - }).hasMessage("REST Requestor producer (ProducerName) must run in peered requestor mode " - + "with a REST Requestor consumer"); + assertThatThrownBy(() -> producer.init(PRODUCER_NAME, producerParameters)) + .hasMessage("REST Requestor producer (ProducerName) must run in peered requestor mode " + + "with a REST Requestor consumer"); producerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true); rrctp.setUrl("ZZZZ"); - assertThatThrownBy(() -> { - producer.init(PRODUCER_NAME, producerParameters); - }).hasMessage("URL may not be specified on REST Requestor producer (ProducerName)"); + assertThatThrownBy(() -> producer.init(PRODUCER_NAME, producerParameters)) + .hasMessage("URL may not be specified on REST Requestor producer (ProducerName)"); rrctp.setUrl(null); rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET); @@ -80,11 +78,11 @@ public class ApexRestRequestorProducerTest { assertEquals(PRODUCER_NAME, producer.getName()); assertEquals(0, producer.getEventsSent()); - assertEquals(null, producer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + assertNull(producer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); } @Test - public void testApexRestRequestorProducerRequest() throws ApexEventException { + void testApexRestRequestorProducerRequest() throws ApexEventException { EventHandlerParameters producerParameters = new EventHandlerParameters(); RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters(); @@ -100,9 +98,8 @@ public class ApexRestRequestorProducerTest { String eventName = "EventName"; String event = "This is the event"; - assertThatThrownBy(() -> { - producer.sendEvent(12345, null, eventName, event); - }).hasMessage("send of event failed, REST response consumer is not defined\n" + "This is the event"); + assertThatThrownBy(() -> producer.sendEvent(12345, null, eventName, event)) + .hasMessage("send of event failed, REST response consumer is not defined\n" + "This is the event"); ApexEventConsumer consumer = new ApexFileEventConsumer(); SynchronousEventCache eventCache = @@ -111,9 +108,8 @@ public class ApexRestRequestorProducerTest { PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, consumer, producer); producer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference); - assertThatThrownBy(() -> { - producer.sendEvent(12345, null, eventName, event); - }).hasMessage("send of event failed, REST response consumer " - + "is not an instance of ApexRestRequestorConsumer\n" + "This is the event"); + assertThatThrownBy(() -> producer.sendEvent(12345, null, eventName, event)) + .hasMessage("send of event failed, REST response consumer " + + "is not an instance of ApexRestRequestorConsumer\n" + "This is the event"); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java index f17721bdc..d953cf8ce 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -24,12 +24,13 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor; 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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments; import org.onap.policy.apex.service.parameters.ApexParameterHandler; import org.onap.policy.apex.service.parameters.ApexParameters; @@ -38,24 +39,24 @@ import org.onap.policy.common.parameters.ParameterException; /** * Test REST Requestor carrier technology parameters. */ -public class RestRequestorCarrierTechnologyParametersTest { +class RestRequestorCarrierTechnologyParametersTest { @Test - public void testRestRequestorCarrierTechnologyParametersBadList() { + void testRestRequestorCarrierTechnologyParametersBadList() { verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderBadList.json", - "item \"entry 2\" value \"null\" INVALID, is null"); + "item \"entry 2\" value \"null\" INVALID, is null"); } @Test - public void testRestRequestorCarrierTechnologyParametersNotKvPairs() { + void testRestRequestorCarrierTechnologyParametersNotKvPairs() { verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNotKvPairs.json", - "item \"entry 0\" value \"[aaa, bbb, ccc]\" INVALID, must have one key"); + "item \"entry 0\" value \"[aaa, bbb, ccc]\" INVALID, must have one key"); } @Test - public void testRestRequestorCarrierTechnologyParametersNulls() { + void testRestRequestorCarrierTechnologyParametersNulls() { verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNulls.json", - "\"key\""); + "\"key\""); } private void verifyException(String fileName, String expectedMsg) { @@ -64,11 +65,11 @@ public class RestRequestorCarrierTechnologyParametersTest { arguments.setRelativeFileRoot("."); assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments)).describedAs(fileName) - .hasMessageContaining(expectedMsg); + .hasMessageContaining(expectedMsg); } @Test - public void testRestRequestorCarrierTechnologyParametersOk() throws ParameterException { + void testRestRequestorCarrierTechnologyParametersOk() throws ParameterException { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderOK.json"); arguments.setRelativeFileRoot("."); @@ -88,7 +89,7 @@ public class RestRequestorCarrierTechnologyParametersTest { } @Test - public void testRestClientCarrierTechnologyParameterFilterInvalid() { + void testRestClientCarrierTechnologyParameterFilterInvalid() { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPFilterInvalid.json"); arguments.setRelativeFileRoot("."); @@ -103,11 +104,11 @@ public class RestRequestorCarrierTechnologyParametersTest { } @Test - public void testGettersAndSetters() { + void testGettersAndSetters() { RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters(); rrctp.setHttpHeaders(null); - assertEquals(null, rrctp.getHttpHeadersAsMultivaluedMap()); + assertNull(rrctp.getHttpHeadersAsMultivaluedMap()); rrctp.setUrl("http://some.where"); assertEquals("http://some.where", rrctp.getUrl()); @@ -146,7 +147,7 @@ public class RestRequestorCarrierTechnologyParametersTest { } @Test - public void testUrlValidation() { + void testUrlValidation() { RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters(); rrctp.setUrl("http://some.where.no.tag.in.url"); @@ -164,30 +165,28 @@ public class RestRequestorCarrierTechnologyParametersTest { assertEquals("ccc", rrctp.getHttpHeaders()[1][0]); assertEquals("ddd", rrctp.getHttpHeaders()[1][1]); - assertEquals(true, rrctp.validate().isValid()); + assertTrue(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/is{that}.{one}"); - assertEquals(true, rrctp.validate().isValid()); + assertTrue(rrctp.validate().isValid()); Set<String> keymap = rrctp.getKeysFromUrl(); - assertEquals(true, keymap.contains("place")); - assertEquals(true, keymap.contains("that")); - assertEquals(true, keymap.contains("one")); + assertTrue(keymap.contains("place") && keymap.contains("that") && keymap.contains("one")); rrctp.setUrl("http://{place.{that}/{is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{is}.{not}/{what}.{exist"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://place.that/is.not/what.{exist"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://place}.{that}/{is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{ }.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validate().isValid()); + assertFalse(rrctp.validate().isValid()); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java index 257e533c4..3fe836485 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java @@ -24,7 +24,7 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import jakarta.ws.rs.client.Client; @@ -34,11 +34,11 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.service.engine.main.ApexMain; @@ -50,12 +50,12 @@ import org.onap.policy.common.utils.network.NetworkUtil; /** * The Class TestRestRequestor. */ -public class RestRequestorTest { +class RestRequestorTest { private static final int PORT = 32801; private static HttpServletServer server; - private ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - private ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); private final PrintStream stdout = System.out; private final PrintStream stderr = System.err; @@ -65,8 +65,8 @@ public class RestRequestorTest { * * @throws Exception the exception */ - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { server = HttpServletServerFactoryInstance.getServerFactory().build(null, false, null, PORT, false, "/TestRESTRequestor", false, false); @@ -82,10 +82,9 @@ public class RestRequestorTest { /** * Tear down. - * */ - @AfterClass - public static void tearDown() { + @AfterAll + static void tearDown() { if (server != null) { server.stop(); } @@ -94,8 +93,8 @@ public class RestRequestorTest { /** * Before test. */ - @Before - public void beforeTest() { + @BeforeEach + void beforeTest() { SupportRestRequestorEndpoint.resetCounters(); System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); @@ -104,8 +103,8 @@ public class RestRequestorTest { /** * After test. */ - @After - public void afterTest() { + @AfterEach + void afterTest() { System.setOut(stdout); System.setErr(stderr); } @@ -114,10 +113,10 @@ public class RestRequestorTest { * Test rest requestor get. * * @throws MessagingException the messaging exception - * @throws Exception an exception + * @throws Exception an exception */ @Test - public void testRestRequestorGet() throws Exception { + void testRestRequestorGet() throws Exception { final Client client = ClientBuilder.newClient(); final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGet.json"}; @@ -139,7 +138,7 @@ public class RestRequestorTest { * @throws ApexException the apex exception */ @Test - public void testRestRequestorGetEmpty() throws ApexException { + void testRestRequestorGetEmpty() throws ApexException { final Client client = ClientBuilder.newClient(); final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json"}; @@ -149,7 +148,7 @@ public class RestRequestorTest { Response response = null; // Wait for the required amount of events to be received or for 10 seconds - double getsSoFar = 0.0; + double getsSoFar; for (int i = 0; i < 40; i++) { response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") .request("application/json").get(); @@ -160,8 +159,8 @@ public class RestRequestorTest { final String responseString = response.readEntity(String.class); - @SuppressWarnings("unchecked") - final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class); + @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = + new Gson().fromJson(responseString, Map.class); getsSoFar = Double.parseDouble(jsonMap.get("GET").toString()); if (getsSoFar >= 50.0) { @@ -183,7 +182,7 @@ public class RestRequestorTest { * @throws ApexException the apex exception */ @Test - public void testRestRequestorPut() throws ApexException { + void testRestRequestorPut() throws ApexException { final Client client = ClientBuilder.newClient(); final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FilePut.json"}; @@ -205,7 +204,7 @@ public class RestRequestorTest { * @throws ApexException the apex exception */ @Test - public void testRestRequestorPost() throws ApexException { + void testRestRequestorPost() throws ApexException { final Client client = ClientBuilder.newClient(); final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FilePost.json"}; @@ -227,7 +226,7 @@ public class RestRequestorTest { * @throws ApexException the apex exception */ @Test - public void testRestRequestorDelete() throws ApexException { + void testRestRequestorDelete() throws ApexException { final Client client = ClientBuilder.newClient(); final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileDelete.json"}; @@ -250,7 +249,7 @@ public class RestRequestorTest { * @throws ApexException the apex exception */ @Test - public void testRestRequestorMultiInputs() throws ApexException { + void testRestRequestorMultiInputs() throws ApexException { final Client client = ClientBuilder.newClient(); final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json"}; @@ -272,7 +271,7 @@ public class RestRequestorTest { * @throws ApexException the apex exception */ @Test - public void testRestRequestorProducerAlone() throws ApexException { + void testRestRequestorProducerAlone() throws ApexException { final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json"}; @@ -291,7 +290,7 @@ public class RestRequestorTest { * @throws ApexException the apex exception */ @Test - public void testRestRequestorConsumerAlone() throws ApexException { + void testRestRequestorConsumerAlone() throws ApexException { final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json"}; ApexMain apexMain = new ApexMain(args); apexMain.shutdown(); @@ -307,8 +306,8 @@ public class RestRequestorTest { assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); - @SuppressWarnings("unchecked") - final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class); + @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = + new Gson().fromJson(responseString, Map.class); return Double.parseDouble(jsonMap.get(statToGet).toString()); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java index b05c24333..f82add13f 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java @@ -46,9 +46,9 @@ public class SupportRestRequestorEndpoint { private static int getMessagesReceived = 0; private static int deleteMessagesReceived = 0; - private static String EVENT_STRING = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.events\",\n" - + "\"name\": \"ResponseEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" - + getMessagesReceived + "\",\n" + "\"target\": \"apex\",\n" + "\"intPar\": 9080\n" + "}"; + private static final String EVENT_STRING = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.events\",\n" + + "\"name\": \"ResponseEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + + getMessagesReceived + "\",\n" + "\"target\": \"apex\",\n" + "\"intPar\": 9080\n" + "}"; /** * Reset counters. @@ -73,10 +73,10 @@ public class SupportRestRequestorEndpoint { statMessagesReceived++; } return Response.status(200) - .entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": " - + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + ",\"DELETE\": " - + deleteMessagesReceived + "}") - .build(); + .entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": " + + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + ",\"DELETE\": " + + deleteMessagesReceived + "}") + .build(); } /** @@ -129,8 +129,7 @@ public class SupportRestRequestorEndpoint { postMessagesReceived++; } - @SuppressWarnings("unchecked") - final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class); + @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class); assertTrue(jsonMap.containsKey("name")); assertEquals("0.0.1", jsonMap.get("version")); assertEquals("org.onap.policy.apex.events", jsonMap.get("nameSpace")); @@ -165,8 +164,7 @@ public class SupportRestRequestorEndpoint { putMessagesReceived++; } - @SuppressWarnings("unchecked") - final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class); + @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class); assertTrue(jsonMap.containsKey("name")); assertEquals("0.0.1", jsonMap.get("version")); assertEquals("org.onap.policy.apex.events", jsonMap.get("nameSpace")); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java index 1ec0d52bb..b2e158f1a 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021, 2023 Nordix Foundation. + * Copyright (C) 2021, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ package org.onap.policy.apex.plugins.event.carrier.restserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import jakarta.ws.rs.container.ContainerRequestContext; import jakarta.ws.rs.container.ContainerResponseContext; @@ -29,16 +29,16 @@ import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; import java.io.IOException; import org.apache.commons.lang3.RandomStringUtils; -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.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) -public class AccessControlFilterTest { +@ExtendWith(MockitoExtension.class) +class AccessControlFilterTest { private AccessControlFilter acf; @@ -47,13 +47,13 @@ public class AccessControlFilterTest { @Mock private ContainerResponseContext responseContext; - @Before + @BeforeEach public void beforeEach() { acf = new AccessControlFilter(); } @Test - public void filterAddToExisting() throws IOException { + void filterAddToExisting() throws IOException { // prepare mocks final String origin = RandomStringUtils.randomAlphanumeric(14, 16); final MultivaluedHashMap<String, Object> map = new MultivaluedHashMap<>(); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java index 5f7cb257b..291a97c70 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. - * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2021, 2023-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,84 +21,84 @@ package org.onap.policy.apex.plugins.event.carrier.restserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import jakarta.ws.rs.core.Response; import java.io.IOException; import java.lang.reflect.Field; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +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.ApexPluginsEventConsumer; 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; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.utils.network.NetworkUtil; -public class ApexRestServerConsumerTest { +class ApexRestServerConsumerTest { ApexRestServerConsumer apexRestServerConsumer = null; EventHandlerParameters consumerParameters = null; ApexEventReceiver incomingEventReceiver = null; ApexRestServerProducer apexRestServerProducer = null; RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null; - SynchronousEventCache synchronousEventCache = null; + + AutoCloseable closeable; /** * Set up testing. - * - * @throws Exception on test set up errors. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { apexRestServerConsumer = new ApexRestServerConsumer(); consumerParameters = new EventHandlerParameters(); apexRestServerProducer = new ApexRestServerProducer(); apexRestServerConsumer.start(); } - @After - public void tearDown() { + @AfterEach + void tearDown() { apexRestServerConsumer.stop(); } - @Test(expected = ApexEventException.class) - public void testInitWithNonWebSocketCarrierTechnologyParameters() throws ApexEventException { - consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {}); - apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, - incomingEventReceiver); + @Test + void testInitWithNonWebSocketCarrierTechnologyParameters() { + consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() { + }); + assertThrows(ApexEventException.class, () -> + apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, incomingEventReceiver)); } - @Test(expected = ApexEventException.class) - public void testInitWithWebSocketCarrierTechnologyParameters() throws ApexEventException { + @Test + void testInitWithWebSocketCarrierTechnologyParameters() { restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters(); consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters); - apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, - incomingEventReceiver); + assertThrows(ApexEventException.class, () -> + apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, incomingEventReceiver)); } - @Test(expected = ApexEventException.class) - public void testInitWithSynchronousMode() throws ApexEventException, SecurityException, IllegalArgumentException { + @Test + void testInitWithSynchronousMode() throws SecurityException, IllegalArgumentException { restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters(); restServerCarrierTechnologyParameters.setStandalone(true); consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters); consumerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true); - apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, - incomingEventReceiver); + + assertThrows(ApexEventException.class, () -> apexRestServerConsumer.init("TestApexRestServerConsumer", + consumerParameters, incomingEventReceiver)); } - @Test(expected = IllegalArgumentException.class) - public void testInitWithSynchronousModeAndProperValues() - throws ApexEventException, SecurityException, IllegalArgumentException { + @Test + void testInitWithSynchronousModeAndProperValues() throws SecurityException, IllegalArgumentException { restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters(); @@ -109,12 +109,14 @@ public class ApexRestServerConsumerTest { consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters); consumerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true); - apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, - incomingEventReceiver); + + assertThrows(IllegalArgumentException.class, + () -> apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, + incomingEventReceiver)); } @Test - public void testInitAndStop() throws ApexEventException, IOException { + void testInitAndStop() throws ApexEventException, IOException { restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters(); restServerCarrierTechnologyParameters.setStandalone(true); @@ -138,39 +140,39 @@ public class ApexRestServerConsumerTest { } @Test - public void testGetName() { + void testGetName() { assertNull(apexRestServerConsumer.getName()); } @Test - public void testGetPeeredReference() { + void testGetPeeredReference() { assertNull(apexRestServerConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); } @Test - public void testSetPeeredReference() { + void testSetPeeredReference() { PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, - apexRestServerConsumer, apexRestServerProducer); + apexRestServerConsumer, apexRestServerProducer); apexRestServerConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, - peeredReference); + peeredReference); assertNotNull(apexRestServerConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); } @Test - public void testReceiveEvent() throws ApexEventException { + void testReceiveEvent() { Response response = apexRestServerConsumer.receiveEvent(""); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + response.close(); } - @Test(expected = NullPointerException.class) - public void testReceiveEventWithNonDefaultValues() - throws ApexEventException, NoSuchFieldException, SecurityException, - IllegalArgumentException, IllegalAccessException { + @Test + void testReceiveEventWithNonDefaultValues() throws NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, - apexRestServerConsumer, apexRestServerProducer); + apexRestServerConsumer, apexRestServerProducer); apexRestServerConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, - peeredReference); + peeredReference); ApexEventReceiver apexEventReceiver = new SupportApexEventReceiver(); @@ -178,8 +180,14 @@ public class ApexRestServerConsumerTest { Field field = ApexPluginsEventConsumer.class.getDeclaredField("name"); field.setAccessible(true); field.set(apexRestServerConsumer, "TestApexRestServerConsumer"); + assertThrows(NullPointerException.class, () -> + closeable = apexRestServerConsumer.receiveEvent("TestApexRestServerConsumer")); + } - apexRestServerConsumer.receiveEvent("TestApexRestServerConsumer"); - + @AfterEach + void after() throws Exception { + if (closeable != null) { + closeable.close(); + } } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java index 34992ff1d..435af0996 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. - * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2019-2021, 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,34 +21,32 @@ package org.onap.policy.apex.plugins.event.carrier.restserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.lang.reflect.Field; import java.util.Random; import org.apache.commons.lang3.RandomStringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +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.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 ApexRestServerProducerTest { +class ApexRestServerProducerTest { ApexRestServerProducer apexRestServerProducer = null; EventHandlerParameters producerParameters = null; - ApexEventReceiver incomingEventReceiver = null; ApexRestServerConsumer apexRestServerConsumer = null; RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null; - SynchronousEventCache synchronousEventCache = null; Random random = new Random(); /** @@ -56,35 +54,38 @@ public class ApexRestServerProducerTest { * * @throws Exception on test set up errors. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { apexRestServerConsumer = new ApexRestServerConsumer(); producerParameters = new EventHandlerParameters(); apexRestServerProducer = new ApexRestServerProducer(); } - @After - public void tearDown() { + @AfterEach + void tearDown() { apexRestServerProducer.stop(); } - @Test(expected = ApexEventException.class) - public void testInitWithNonWebSocketCarrierTechnologyParameters() throws ApexEventException { - producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {}); - apexRestServerProducer.init("TestApexRestServerProducer", producerParameters); + @Test + void testInitWithNonWebSocketCarrierTechnologyParameters() { + producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() { + }); + assertThrows(ApexEventException.class, () -> + apexRestServerProducer.init("TestApexRestServerProducer", producerParameters)); } - @Test(expected = ApexEventException.class) - public void testInitWithWebSocketCarrierTechnologyParameters() throws ApexEventException { + @Test + void testInitWithWebSocketCarrierTechnologyParameters() { restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters(); producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters); - apexRestServerProducer.init("TestApexRestServerProducer", producerParameters); + assertThrows(ApexEventException.class, () -> + apexRestServerProducer.init("TestApexRestServerProducer", producerParameters)); } - @Test(expected = ApexEventException.class) - public void testInitWithNonDefaultValue() throws ApexEventException, NoSuchFieldException, - SecurityException, IllegalArgumentException, IllegalAccessException { + @Test + void testInitWithNonDefaultValue() throws NoSuchFieldException, + SecurityException, IllegalArgumentException, IllegalAccessException { restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters(); Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host"); field.setAccessible(true); @@ -93,11 +94,12 @@ public class ApexRestServerProducerTest { field.setAccessible(true); field.set(restServerCarrierTechnologyParameters, 65535); producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters); - apexRestServerProducer.init("TestApexRestServerProducer", producerParameters); + assertThrows(ApexEventException.class, () -> + apexRestServerProducer.init("TestApexRestServerProducer", producerParameters)); } @Test - public void testInitWithSynchronousMode() throws ApexEventException { + void testInitWithSynchronousMode() throws ApexEventException { restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters(); producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters); producerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true); @@ -106,26 +108,26 @@ public class ApexRestServerProducerTest { } @Test - public void testGetName() { + void testGetName() { assertNull(apexRestServerProducer.getName()); } @Test - public void testGetPeeredReference() { + void testGetPeeredReference() { assertNull(apexRestServerProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); } @Test - public void testSetPeeredReference() { + void testSetPeeredReference() { PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, - apexRestServerConsumer, apexRestServerProducer); + apexRestServerConsumer, apexRestServerProducer); apexRestServerProducer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, - peeredReference); + peeredReference); assertNotNull(apexRestServerProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); } @Test - public void testSendEventNotExistingEventToApex() { + void testSendEventNotExistingEventToApex() { final long executionId = random.nextLong(); final String eventName = RandomStringUtils.randomAlphabetic(7); final Object event = new Object(); @@ -143,7 +145,7 @@ public class ApexRestServerProducerTest { } @Test - public void testSendEvent() { + void testSendEvent() { final long executionId = random.nextLong(); final String eventName = RandomStringUtils.randomAlphabetic(7); final Object expected = new Object(); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java index ef78d3211..ab7a54cdd 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,16 +23,16 @@ package org.onap.policy.apex.plugins.event.carrier.restserver; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Field; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationResult; -public class RestServerCarrierTechnologyParametersTest { +class RestServerCarrierTechnologyParametersTest { RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null; ValidationResult result = null; @@ -40,28 +40,27 @@ public class RestServerCarrierTechnologyParametersTest { /** * Set up testing. * - * @throws Exception on test set up errors. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters(); } @Test - public void testRestServerCarrierTechnologyParameters() { + void testRestServerCarrierTechnologyParameters() { assertNotNull(restServerCarrierTechnologyParameters); assertFalse(restServerCarrierTechnologyParameters.isStandalone()); } @Test - public void testValidate() { + void testValidate() { result = restServerCarrierTechnologyParameters.validate(); assertNotNull(result); assertTrue(result.isValid()); } @Test - public void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException, + void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone"); @@ -89,7 +88,7 @@ public class RestServerCarrierTechnologyParametersTest { } @Test - public void testValidateWithValidValues() throws NoSuchFieldException, SecurityException, + void testValidateWithValidValues() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone"); @@ -119,7 +118,7 @@ public class RestServerCarrierTechnologyParametersTest { } @Test - public void testValidateWithInvalidValues() throws NoSuchFieldException, SecurityException, + void testValidateWithInvalidValues() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone"); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java index 773ecafb2..b10eecf21 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java @@ -27,7 +27,7 @@ import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventReceiver; /** - * Support Apex event reveiver for unit test. + * Support Apex event receiver for unit test. * */ @Getter diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml index 5f643c04a..2ca3cf24d 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml @@ -21,6 +21,12 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId> + <artifactId>plugins-event-protocol</artifactId> + <version>4.0.0-SNAPSHOT</version> + </parent> + <artifactId>plugins-event-protocol-jms</artifactId> <name>${project.artifactId}</name> <description>[${project.parent.artifactId}] Plugins for handling events that are being transported as JMS messages @@ -33,10 +39,10 @@ <version>${version.activemq}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>jakarta.jms</groupId> + <artifactId>jakarta.jms-api</artifactId> + <version>${version.jms}</version> + </dependency> </dependencies> - <parent> - <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId> - <artifactId>plugins-event-protocol</artifactId> - <version>4.0.0-SNAPSHOT</version> - </parent> </project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java index 701326f71..c828f789a 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021, 2023 Nordix Foundation. + * Copyright (C) 2021, 2023-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. @@ -22,9 +22,9 @@ package org.onap.policy.apex.plugins.event.protocol.jms; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import jakarta.jms.JMSException; import jakarta.jms.ObjectMessage; @@ -33,39 +33,39 @@ import java.io.PrintStream; import java.util.List; import org.apache.activemq.command.ActiveMQObjectMessage; import org.apache.commons.lang3.RandomStringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; import org.onap.policy.apex.service.engine.event.impl.apexprotocolplugin.ApexEventProtocolParameters; -public class Apex2JmsObjectEventConverterTest { +class Apex2JmsObjectEventConverterTest { private Apex2JmsObjectEventConverter converter; private final PrintStream orgOutBuffer = System.out; private ByteArrayOutputStream testOutStream; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { converter = new Apex2JmsObjectEventConverter(); testOutStream = new ByteArrayOutputStream(); System.setOut(new PrintStream(testOutStream)); } - @After - public void tearDown() { + @AfterEach + void tearDown() { System.setOut(orgOutBuffer); } @Test - public void initNull() { + void initNull() { assertThatThrownBy(() -> converter.init(null)) .isInstanceOf(NullPointerException.class); } @Test - public void initWrongClass() { + void initWrongClass() { converter.init(new ApexEventProtocolParameters()); final String actual = testOutStream.toString(); assertThat(actual).contains("specified Event Protocol Parameters properties of typ"); @@ -73,7 +73,7 @@ public class Apex2JmsObjectEventConverterTest { } @Test - public void init() { + void init() { final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters(); converter.init(parameters); final JmsObjectEventProtocolParameters actual = converter.getEventProtocolParameters(); @@ -81,7 +81,7 @@ public class Apex2JmsObjectEventConverterTest { } @Test - public void toApexEventNull() { + void toApexEventNull() { final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters(); converter.init(parameters); final String eventName = RandomStringUtils.randomAlphabetic(4); @@ -90,7 +90,7 @@ public class Apex2JmsObjectEventConverterTest { } @Test - public void toApexEventObject() { + void toApexEventObject() { final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters(); converter.init(parameters); final String eventName = RandomStringUtils.randomAlphabetic(4); @@ -99,31 +99,31 @@ public class Apex2JmsObjectEventConverterTest { } @Test - public void toApexEventNoParams() { + void toApexEventNoParams() { final String eventName = RandomStringUtils.randomAlphabetic(4); - ObjectMessage object = new ActiveMQObjectMessage(); + ObjectMessage object = (ObjectMessage) new ActiveMQObjectMessage(); assertThatThrownBy(() -> converter.toApexEvent(eventName, object)) .isInstanceOf(ApexEventRuntimeException.class); } @Test - public void toApexEventIncomingObjectIsNull() { + void toApexEventIncomingObjectIsNull() { final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters(); converter.init(parameters); final String eventName = RandomStringUtils.randomAlphabetic(4); - ObjectMessage object = new ActiveMQObjectMessage(); + ObjectMessage object = (ObjectMessage) new ActiveMQObjectMessage(); assertThatThrownBy(() -> converter.toApexEvent(eventName, object)) .isInstanceOf(NullPointerException.class); } @Test - public void toApexEvent() throws ApexEventException, JMSException { + void toApexEvent() throws ApexEventException, JMSException { final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters(); converter.init(parameters); final String eventName = RandomStringUtils.randomAlphabetic(4); - final ObjectMessage object = new ActiveMQObjectMessage(); + final ObjectMessage object = (ObjectMessage) new ActiveMQObjectMessage(); final String value = RandomStringUtils.randomAlphabetic(3); object.setObject(value); @@ -145,13 +145,12 @@ public class Apex2JmsObjectEventConverterTest { } @Test - public void fromApexEventNull() { - assertThatThrownBy(() -> converter.fromApexEvent(null)) - .isInstanceOf(ApexEventException.class); + void fromApexEventNull() { + assertThatThrownBy(() -> converter.fromApexEvent(null)).isInstanceOf(ApexEventException.class); } @Test - public void fromApexEventEmptyEvent() throws ApexEventException { + void fromApexEventEmptyEvent() throws ApexEventException { final ApexEvent apexEvent = new ApexEvent( "a" + RandomStringUtils.randomAlphabetic(3), "a" + RandomStringUtils.randomAlphabetic(3), @@ -163,7 +162,7 @@ public class Apex2JmsObjectEventConverterTest { } @Test - public void fromApexEventMultipleEvents() throws ApexEventException { + void fromApexEventMultipleEvents() throws ApexEventException { final ApexEvent apexEvent = new ApexEvent( "a" + RandomStringUtils.randomAlphabetic(3), "a" + RandomStringUtils.randomAlphabetic(4), @@ -176,7 +175,7 @@ public class Apex2JmsObjectEventConverterTest { } @Test - public void fromApexEventSingleEvent() throws ApexEventException { + void fromApexEventSingleEvent() throws ApexEventException { final ApexEvent apexEvent = new ApexEvent( "a" + RandomStringUtils.randomAlphabetic(3), "a" + RandomStringUtils.randomAlphabetic(3), diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java index 9f68b49df..a2ff9d02f 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021, 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,15 +21,14 @@ package org.onap.policy.apex.plugins.event.protocol.jms; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; import org.apache.commons.lang3.RandomStringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.context.parameters.ContextParameterConstants; import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -45,40 +44,41 @@ import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters; import org.onap.policy.common.parameters.ParameterService; -public class Apex2JmsTextEventConverterTest { +class Apex2JmsTextEventConverterTest { private Apex2JmsTextEventConverter converter; - @Before - public void setUp() { + @BeforeEach + void setUp() { converter = new Apex2JmsTextEventConverter(); ModelService.registerModel(AxContextSchemas.class, new AxContextSchemas()); ModelService.registerModel(AxEvents.class, new AxEvents()); ParameterService.register(new SchemaParameters()); } - @After - public void tearDown() { + @AfterEach + void tearDown() { ModelService.deregisterModel(AxContextSchema.class); ModelService.deregisterModel(AxEvents.class); ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME); } @Test - public void toApexEventNull() { + void toApexEventNull() { final String eventName = RandomStringUtils.randomAlphabetic(4); assertThatThrownBy(() -> converter.toApexEvent(eventName, null)) .isInstanceOf(ApexEventRuntimeException.class); } @Test - public void toApexEventObject() { + void toApexEventObject() { final String eventName = RandomStringUtils.randomAlphabetic(4); - assertThatThrownBy(() -> converter.toApexEvent(eventName, new Object())) - .isInstanceOf(ApexEventRuntimeException.class); + var object = new Object(); + assertThatThrownBy(() -> converter.toApexEvent(eventName, object)).isInstanceOf( + ApexEventRuntimeException.class); } @Test - public void toApexEventJsonString() throws ApexEventException { + void toApexEventJsonString() throws ApexEventException { final String eventName = RandomStringUtils.randomAlphabetic(4); final String eventVersion = "0.0.1"; final String source = RandomStringUtils.randomAlphabetic(5); @@ -113,12 +113,12 @@ public class Apex2JmsTextEventConverterTest { } @Test - public void fromApexNull() { + void fromApexNull() { assertThatThrownBy(() -> converter.fromApexEvent(null)).isInstanceOf(ApexEventException.class); } @Test - public void fromApex() throws ApexEventException { + void fromApex() throws ApexEventException { final String name = RandomStringUtils.randomAlphabetic(4); final String version = "0.2.3"; final String nameSpace = "a.name.space"; diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java index 8baa9d5b1..1f480a654 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021, 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. @@ -20,15 +20,15 @@ package org.onap.policy.apex.plugins.event.protocol.jms; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; -import org.junit.Test; -public class JmsObjectEventProtocolParametersTest { +class JmsObjectEventProtocolParametersTest { @Test - public void getIncomingEventVersion() { + void getIncomingEventVersion() { final JmsObjectEventProtocolParameters jmsObjectEventProtocolParameters = new JmsObjectEventProtocolParameters(); final String actual = jmsObjectEventProtocolParameters.getIncomingEventVersion(); @@ -36,7 +36,7 @@ public class JmsObjectEventProtocolParametersTest { } @Test - public void getIncomingEventSource() { + void getIncomingEventSource() { final JmsObjectEventProtocolParameters jmsObjectEventProtocolParameters = new JmsObjectEventProtocolParameters(); final String actual = jmsObjectEventProtocolParameters.getIncomingEventSource(); @@ -44,7 +44,7 @@ public class JmsObjectEventProtocolParametersTest { } @Test - public void getIncomingEventTarget() { + void getIncomingEventTarget() { final JmsObjectEventProtocolParameters jmsObjectEventProtocolParameters = new JmsObjectEventProtocolParameters(); final String actual = jmsObjectEventProtocolParameters.getIncomingEventTarget(); diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java index 2fbae65e4..b0da163f8 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications 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. @@ -22,16 +22,15 @@ package org.onap.policy.apex.plugins.event.protocol.yaml; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -52,15 +51,14 @@ import org.onap.policy.common.utils.resources.TextFileUtils; /** * The Class TestYamlEventProtocol. */ -public class YamlEventProtocolTest { +class YamlEventProtocolTest { /** * Register test events and schemas. * - * @throws IOException Signals that an I/O exception has occurred. */ - @BeforeClass - public static void registerTestEventsAndSchemas() throws IOException { + @BeforeAll + static void registerTestEventsAndSchemas() { SchemaParameters schemaParameters = new SchemaParameters(); schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); ParameterService.register(schemaParameters, true); @@ -201,8 +199,8 @@ public class YamlEventProtocolTest { /** * Unregister test events and schemas. */ - @AfterClass - public static void unregisterTestEventsAndSchemas() { + @AfterAll + static void unregisterTestEventsAndSchemas() { ModelService.clear(); ParameterService.clear(); } @@ -214,7 +212,7 @@ public class YamlEventProtocolTest { * @throws IOException Signals that an I/O exception has occurred. */ @Test - public void testYamlProcessing() throws ApexEventException, IOException { + void testYamlProcessing() throws ApexEventException, IOException { assertThatThrownBy(() -> testYamlDecodeEncode("TestEvent0", 1, 0, "Empty0")) .hasMessage("event processing failed, event is null"); testYamlDecodeEncode("TestEvent0", 1, 0, "Empty1"); @@ -252,7 +250,7 @@ public class YamlEventProtocolTest { converter.init(parameters); String filePath = "src/test/resources/yaml_in/" + fileName + ".yaml"; - FileInputStream fileInputStream = new FileInputStream(new File(filePath)); + FileInputStream fileInputStream = new FileInputStream(filePath); HeaderDelimitedTextBlockReader reader = new HeaderDelimitedTextBlockReader(parameters); reader.init(fileInputStream); diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java index fdab1d8c1..7332f341e 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2023 Nordix Foundation + * Modifications Copyright (C) 2020, 2023-2024 Nordix Foundation * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ @@ -24,14 +24,15 @@ package org.onap.policy.apex.plugins.event.protocol.yaml; 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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.IOException; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -50,16 +51,14 @@ import org.onap.policy.common.parameters.ParameterService; /** * The Class TestYamlPluginStability. */ -public class YamlPluginStabilityTest { +class YamlPluginStabilityTest { static AxEvent testEvent; /** * Register test events and schemas. - * - * @throws IOException Signals that an I/O exception has occurred. */ - @BeforeClass - public static void registerTestEventsAndSchemas() throws IOException { + @BeforeAll + static void registerTestEventsAndSchemas() { SchemaParameters schemaParameters = new SchemaParameters(); schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); ParameterService.register(schemaParameters); @@ -67,15 +66,15 @@ public class YamlPluginStabilityTest { AxContextSchemas schemas = new AxContextSchemas(); AxContextSchema simpleIntSchema = new AxContextSchema(new AxArtifactKey("SimpleIntSchema", "0.0.1"), "JAVA", - "java.lang.Integer"); + "java.lang.Integer"); schemas.getSchemasMap().put(simpleIntSchema.getKey(), simpleIntSchema); AxContextSchema simpleDoubleSchema = new AxContextSchema(new AxArtifactKey("SimpleDoubleSchema", "0.0.1"), - "JAVA", "java.lang.Double"); + "JAVA", "java.lang.Double"); schemas.getSchemasMap().put(simpleDoubleSchema.getKey(), simpleDoubleSchema); AxContextSchema simpleStringSchema = new AxContextSchema(new AxArtifactKey("SimpleStringSchema", "0.0.1"), - "JAVA", "java.lang.String"); + "JAVA", "java.lang.String"); schemas.getSchemasMap().put(simpleStringSchema.getKey(), simpleStringSchema); ModelService.registerModel(AxContextSchemas.class, schemas); @@ -86,10 +85,10 @@ public class YamlPluginStabilityTest { AxField teField0 = new AxField(new AxReferenceKey(testEvent.getKey(), "intValue"), simpleIntSchema.getKey()); testEvent.getParameterMap().put("intValue", teField0); AxField teField1 = new AxField(new AxReferenceKey(testEvent.getKey(), "doubleValue"), - simpleDoubleSchema.getKey()); + simpleDoubleSchema.getKey()); testEvent.getParameterMap().put("doubleValue", teField1); AxField teField2 = new AxField(new AxReferenceKey(testEvent.getKey(), "stringValue"), - simpleStringSchema.getKey(), true); + simpleStringSchema.getKey(), true); testEvent.getParameterMap().put("stringValue", teField2); AxEvents events = new AxEvents(); @@ -101,8 +100,8 @@ public class YamlPluginStabilityTest { /** * Unregister test events and schemas. */ - @AfterClass - public static void unregisterTestEventsAndSchemas() { + @AfterAll + static void unregisterTestEventsAndSchemas() { ModelService.clear(); ParameterService.clear(); } @@ -112,9 +111,8 @@ public class YamlPluginStabilityTest { * * @throws ApexEventException the apex event exception */ - @SuppressWarnings("deprecation") @Test - public void testStability() throws ApexEventException { + void testStability() throws ApexEventException { Apex2YamlEventConverter converter = new Apex2YamlEventConverter(); assertThatThrownBy(() -> converter.init(null)) @@ -122,20 +120,20 @@ public class YamlPluginStabilityTest { YamlEventProtocolParameters pars = new YamlEventProtocolParameters(); converter.init(pars); - assertThatThrownBy(() -> converter.toApexEvent("NonExistantEvent", "")) + assertThatThrownBy(() -> converter.toApexEvent("NonExistentEvent", "")) .hasMessageContaining("Failed to unmarshal YAML event") - .getCause().hasMessageStartingWith("an event definition for an event named \"NonExistantEvent\""); + .cause().hasMessageStartingWith("an event definition for an event named \"NonExistentEvent\""); assertThatThrownBy(() -> converter.toApexEvent("TestEvent", null)) .hasMessage("event processing failed, event is null"); assertThatThrownBy(() -> converter.toApexEvent("TestEvent", 1)) .hasMessage("error converting event \"1\" to a string"); assertThatThrownBy(() -> converter.toApexEvent("TestEvent", "")) - .getCause().hasMessageContaining("Field \"doubleValue\" is missing"); + .cause().hasMessageContaining("Field \"doubleValue\" is missing"); assertThatThrownBy(() -> converter.fromApexEvent(null)) .hasMessage("event processing failed, Apex event is null"); ApexEvent apexEvent = new ApexEvent(testEvent.getKey().getName(), testEvent.getKey().getVersion(), - testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget(), - testEvent.getToscaPolicyState()); + testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget(), + testEvent.getToscaPolicyState()); apexEvent.put("doubleValue", 123.45); apexEvent.put("intValue", 123); apexEvent.put("stringValue", "123.45"); @@ -149,15 +147,15 @@ public class YamlPluginStabilityTest { .hasMessageContaining("error parsing TestEvent:0.0.1 event to Json. Field \"intValue\" is missing"); assertThatThrownBy(() -> converter.toApexEvent(null, "")) .hasMessageStartingWith("Failed to unmarshal YAML event") - .getCause().hasMessageStartingWith("event received without mandatory parameter \"name\""); + .cause().hasMessageStartingWith("event received without mandatory parameter \"name\""); pars.setNameAlias("TheNameField"); assertThatThrownBy(() -> converter.toApexEvent(null, "")) .hasMessageStartingWith("Failed to unmarshal YAML event") - .getCause().hasMessageStartingWith("event received without mandatory parameter \"name\""); + .cause().hasMessageStartingWith("event received without mandatory parameter \"name\""); apexEvent.put("intValue", 123); apexEvent.remove("stringValue"); - yamlString = (String) converter.fromApexEvent(apexEvent); + assertNotNull(converter.fromApexEvent(apexEvent)); apexEvent.put("stringValue", "123.45"); String yamlInputString = "doubleValue: 123.45\n" + "intValue: 123"; @@ -165,60 +163,71 @@ public class YamlPluginStabilityTest { List<ApexEvent> eventList = converter.toApexEvent("TestEvent", yamlInputString); assertEquals(123.45, eventList.get(0).get("doubleValue")); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: null"; + yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: null"; eventList = converter.toApexEvent("TestEvent", yamlInputString); - assertEquals(null, eventList.get(0).get("stringValue")); + assertNull(eventList.get(0).get("stringValue")); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: TestEvent"; + yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: TestEvent"; pars.setNameAlias("stringValue"); eventList = converter.toApexEvent(null, yamlInputString); assertEquals("TestEvent", eventList.get(0).get("stringValue")); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: SomeOtherEvent"; + yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: SomeOtherEvent"; eventList = converter.toApexEvent("TestEvent", yamlInputString); assertEquals("SomeOtherEvent", eventList.get(0).get("stringValue")); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: 0.0.1"; + yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: 0.0.1"; pars.setNameAlias(null); pars.setVersionAlias("stringValue"); eventList = converter.toApexEvent("TestEvent", yamlInputString); assertEquals("0.0.1", eventList.get(0).get("stringValue")); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: org.some.other.namespace"; + yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: org.some.other.namespace"; pars.setVersionAlias(null); pars.setNameSpaceAlias("stringValue"); final String yamlInputStringCopy = yamlInputString; assertThatThrownBy(() -> converter.toApexEvent("TestEvent", yamlInputStringCopy)) .hasMessageStartingWith("Failed to unmarshal YAML event") - .getCause().hasMessageStartingWith("namespace \"org.some.other.namespace\" on event"); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" - + "stringValue: org.onap.policy.apex.plugins.event.protocol.yaml"; + .cause().hasMessageStartingWith("namespace \"org.some.other.namespace\" on event"); + + yamlInputString = """ + doubleValue: 123.45 + intValue: 123 + stringValue: \ + org.onap.policy.apex.plugins.event.protocol.yaml"""; eventList = converter.toApexEvent("TestEvent", yamlInputString); assertEquals("org.onap.policy.apex.plugins.event.protocol.yaml", eventList.get(0).getNameSpace()); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MySource"; + yamlInputString = """ + doubleValue: 123.45 + intValue: 123 + stringValue: MySource"""; pars.setNameSpaceAlias(null); pars.setSourceAlias("stringValue"); eventList = converter.toApexEvent("TestEvent", yamlInputString); assertEquals("MySource", eventList.get(0).getSource()); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MyTarget"; + yamlInputString = """ + doubleValue: 123.45 + intValue: 123 + stringValue: MyTarget"""; pars.setSourceAlias(null); pars.setTargetAlias("stringValue"); eventList = converter.toApexEvent("TestEvent", yamlInputString); assertEquals("MyTarget", eventList.get(0).getTarget()); pars.setTargetAlias(null); - yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MyString"; pars.setSourceAlias(null); pars.setTargetAlias("intValue"); assertThatThrownBy(() -> converter.toApexEvent("TestEvent", yamlInputStringCopy)) .hasMessageStartingWith("Failed to unmarshal YAML event") - .getCause().hasMessageStartingWith("field \"target\" with type \"java.lang.Integer\""); + .cause().hasMessageStartingWith("field \"target\" with type \"java.lang.Integer\""); pars.setTargetAlias(null); - assertThatThrownBy(() -> converter.toApexEvent("TestEvent", "doubleValue: 123.45\n" + "intValue: ~\n" - + "stringValue: MyString")).getCause().hasMessageStartingWith("mandatory field \"intValue\" is missing"); + assertThatThrownBy(() -> converter.toApexEvent("TestEvent", """ + doubleValue: 123.45 + intValue: ~ + stringValue: MyString""")).cause().hasMessageStartingWith("mandatory field \"intValue\" is missing"); } } |