aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'policy-endpoints/src/test/java')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java130
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java29
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/IndexedKafkaTopicSourceFactoryTest.java74
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicFactoryTestBase.java4
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicPropertyBuilder.java28
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkFactoryTest.java41
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkTest.java8
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceFactoryTest.java29
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceTest.java10
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java46
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java48
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkFactoryTest.java9
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkTest.java11
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactoryTest.java9
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceTest.java13
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicFactoryTestBase.java23
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java77
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java47
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java22
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java66
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineKafkaTopicSinkTest.java24
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/KafkaPublisherWrapperTest.java97
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java73
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedKafkaTopicSourceTest.java23
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java90
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/BidirectionalTopicClientTest.java75
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicClientExceptionTest.java10
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java28
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/features/NetLoggerFeatureApiTest.java86
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/AuthorizationFilterTest.java84
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java60
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpExceptionsTest.java7
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java58
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/JsonExceptionMapperTest.java14
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestServerTest.java43
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java14
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlJacksonHandlerTest.java16
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java40
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java27
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/MessageTypeDispatcherTest.java29
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/RequestIdDispatcherTest.java37
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java27
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestClientParametersTest.java116
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java22
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java26
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java7
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/KafkaPropertyUtilsTest.java55
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java29
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java24
49 files changed, 1306 insertions, 659 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java
index b6777db7..a30904dd 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java
@@ -24,17 +24,20 @@ package org.onap.policy.common.endpoints.event.comm;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicFactories;
+import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicPropertyBuilder;
import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicPropertyBuilder;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
@@ -42,11 +45,14 @@ import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.gson.GsonTestUtils;
-public class TopicEndpointProxyTest {
+class TopicEndpointProxyTest {
private static final String NOOP_SOURCE_TOPIC = "noop-source";
private static final String NOOP_SINK_TOPIC = "noop-sink";
+ private static final String KAFKA_SOURCE_TOPIC = "kafka-source";
+ private static final String KAFKA_SINK_TOPIC = "kafka-sink";
+
private final Properties configuration = new Properties();
private final TopicParameterGroup group = new TopicParameterGroup();
@@ -100,14 +106,16 @@ public class TopicEndpointProxyTest {
/**
* Destroys all managed topics.
*/
- @After
+ @AfterEach
public void tearDown() {
NoopTopicFactories.getSinkFactory().destroy();
NoopTopicFactories.getSourceFactory().destroy();
+ KafkaTopicFactories.getSinkFactory().destroy();
+ KafkaTopicFactories.getSourceFactory().destroy();
}
@Test
- public void testSerialize() {
+ void testSerialize() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
@@ -118,7 +126,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testAddTopicSourcesListOfTopicParameters() {
+ void testAddTopicSourcesListOfTopicParameters() {
TopicEndpoint manager = new TopicEndpointProxy();
List<TopicSource> sources = manager.addTopicSources(group.getTopicSources());
@@ -126,10 +134,33 @@ public class TopicEndpointProxyTest {
assertTrue(allSources(sources));
assertFalse(anySink(sources));
+
+ sources = manager.addTopicSources(group.getTopicSources());
+ assertSame(1, sources.size());
+ assertTrue(allSources(sources));
}
@Test
- public void testAddTopicSourcesProperties() {
+ void testAddTopicSourcesKafka() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ KafkaTopicPropertyBuilder kafkaTopicPropertyBuilder =
+ new KafkaTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_KAFKA_SOURCE_TOPICS)
+ .makeTopic(KAFKA_SOURCE_TOPIC);
+
+ configuration.putAll(kafkaTopicPropertyBuilder.build());
+ group.getTopicSources().add(kafkaTopicPropertyBuilder.getParams());
+ List<TopicSource> sources = manager.addTopicSources(group.getTopicSources());
+ assertSame(2, sources.size());
+
+ configuration.remove(KAFKA_SOURCE_TOPIC);
+ group.setTopicSources(new LinkedList<>());
+ sources = manager.addTopicSources(group.getTopicSources());
+ assertSame(0, sources.size());
+ }
+
+ @Test
+ void testAddTopicSourcesProperties() {
TopicEndpoint manager = new TopicEndpointProxy();
List<TopicSource> sources = manager.addTopicSources(configuration);
@@ -140,7 +171,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testAddTopicSinksListOfTopicParameters() {
+ void testAddTopicSinksListOfTopicParameters() {
TopicEndpoint manager = new TopicEndpointProxy();
List<TopicSink> sinks = manager.addTopicSinks(group.getTopicSinks());
@@ -151,7 +182,29 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testAddTopicSinksProperties() {
+ void testAddTopicSinksListOfTopicParametersKafka() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ List<TopicSink> sinks = manager.addTopicSinks(group.getTopicSinks());
+ assertSame(1, sinks.size());
+
+ KafkaTopicPropertyBuilder kafkaTopicPropertyBuilder =
+ new KafkaTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_KAFKA_SINK_TOPICS)
+ .makeTopic(KAFKA_SINK_TOPIC);
+
+ configuration.putAll(kafkaTopicPropertyBuilder.build());
+ group.getTopicSources().add(kafkaTopicPropertyBuilder.getParams());
+ sinks = manager.addTopicSinks(group.getTopicSources());
+ assertSame(2, sinks.size());
+
+ configuration.remove(KAFKA_SOURCE_TOPIC);
+ group.setTopicSources(new LinkedList<>());
+ sinks = manager.addTopicSinks(group.getTopicSources());
+ assertSame(0, sinks.size());
+ }
+
+ @Test
+ void testAddTopicSinksProperties() {
TopicEndpoint manager = new TopicEndpointProxy();
List<TopicSink> sinks = manager.addTopicSinks(configuration);
@@ -162,7 +215,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testAddTopicsProperties() {
+ void testAddTopicsProperties() {
TopicEndpoint manager = new TopicEndpointProxy();
List<Topic> topics = manager.addTopics(configuration);
@@ -173,7 +226,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testAddTopicsTopicParameterGroup() {
+ void testAddTopicsTopicParameterGroup() {
TopicEndpoint manager = new TopicEndpointProxy();
List<Topic> topics = manager.addTopics(group);
@@ -184,7 +237,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testAddTopicsTopicParameterGroupNull() {
+ void testAddTopicsTopicParameterGroupNull() {
TopicEndpoint manager = new TopicEndpointProxy();
List<Topic> topics = manager.addTopics(new TopicParameterGroup());
@@ -192,7 +245,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testLockSinks_lockSources_locked() {
+ void testLockSinks_lockSources_locked() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.lock();
for (Topic topic : manager.addTopics(group)) {
@@ -201,7 +254,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testLockSinks_lockSources_unlocked() {
+ void testLockSinks_lockSources_unlocked() {
TopicEndpoint manager = new TopicEndpointProxy();
for (Topic topic : manager.addTopics(group)) {
assertFalse(topic.isLocked());
@@ -209,7 +262,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testGetTopicSources() {
+ void testGetTopicSources() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
@@ -220,10 +273,17 @@ public class TopicEndpointProxyTest {
assertTrue(allSources(sources));
assertFalse(anySink(sources));
+
+ assertThatThrownBy(() -> manager.getKafkaTopicSource("testTopic"))
+ .hasMessageContaining("KafkaTopiceSource for testTopic not found");
+
+ List<String> topicName = null;
+ assertThatThrownBy(() -> manager.getTopicSources(topicName))
+ .hasMessageContaining("must provide a list of topics");
}
@Test
- public void testGetTopicSinks() {
+ void testGetTopicSinks() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
@@ -234,10 +294,24 @@ public class TopicEndpointProxyTest {
assertFalse(anySource(sinks));
assertTrue(allSinks(sinks));
+
+ final List<String> sinks2 = null;
+ assertThatThrownBy(() -> manager.getTopicSinks(sinks2)).hasMessageContaining("must provide a list of topics");
+
+ List<String> sinks3 = List.of(NOOP_SINK_TOPIC);
+ assertThatCode(() -> manager.getTopicSinks(sinks3)).doesNotThrowAnyException();
+
+ String sinkTest = null;
+ assertThatThrownBy(() -> manager.getTopicSinks(sinkTest))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("Invalid parameter");
+
+ assertThatThrownBy(() -> manager.getKafkaTopicSink("testTopic"))
+ .hasMessageContaining("KafkaTopicSink for testTopic not found");
}
@Test
- public void testGetNoopTopicSources() {
+ void testGetNoopTopicSources() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
@@ -245,7 +319,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testGetNoopTopicSinks() {
+ void testGetNoopTopicSinks() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSinks(configuration);
@@ -253,7 +327,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testLifecycle() {
+ void testLifecycle() {
TopicEndpoint manager = new TopicEndpointProxy();
assertTrue(manager.start());
@@ -270,7 +344,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testLock() {
+ void testLock() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.lock();
@@ -281,7 +355,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testGetTopicSource() {
+ void testGetTopicSource() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
@@ -292,7 +366,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testGetTopicSink() {
+ void testGetTopicSink() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSinks(configuration);
@@ -303,7 +377,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testGetNoopTopicSource() {
+ void testGetNoopTopicSource() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
@@ -314,7 +388,7 @@ public class TopicEndpointProxyTest {
}
@Test
- public void testGetNoopTopicSink() {
+ void testGetNoopTopicSink() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSinks(configuration);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java
index 7a819e0d..b2a35408 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. 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.
@@ -21,13 +22,13 @@
package org.onap.policy.common.endpoints.event.comm.bus;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-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.assertNotSame;
-import static org.junit.Assert.assertSame;
-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.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX;
@@ -74,7 +75,7 @@ public abstract class BusTopicFactoryTestBase<T extends Topic> extends TopicFact
/**
* Tests building a topic using BusTopicParams.
*/
- public void testBuildBusTopicParams() {
+ void testBuildBusTopicParams() {
initFactory();
// two unmanaged topics
@@ -111,7 +112,7 @@ public abstract class BusTopicFactoryTestBase<T extends Topic> extends TopicFact
/**
* Tests exception cases when building a topic using BusTopicParams.
*/
- public void testBuildBusTopicParams_Ex() {
+ void testBuildBusTopicParams_Ex() {
// null topic
assertThatIllegalArgumentException().isThrownBy(() -> buildTopic(makeBuilder().topic(null).build()));
@@ -122,7 +123,7 @@ public abstract class BusTopicFactoryTestBase<T extends Topic> extends TopicFact
/**
* Tests building a topic using a list of servers and a topic.
*/
- public void testBuildListOfStringString() {
+ void testBuildListOfStringString() {
initFactory();
T item1 = buildTopic(servers, MY_TOPIC);
@@ -148,7 +149,7 @@ public abstract class BusTopicFactoryTestBase<T extends Topic> extends TopicFact
* Tests building a topic using Properties. Verifies parameters specific to Bus
* topics.
*/
- public void testBuildProperties() {
+ void testBuildProperties() {
initFactory();
List<T> topics = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build());
@@ -174,7 +175,7 @@ public abstract class BusTopicFactoryTestBase<T extends Topic> extends TopicFact
}
@Override
- public void testBuildProperties_Variations() {
+ void testBuildProperties_Variations() {
super.testBuildProperties_Variations();
// check boolean properties that default to true
@@ -210,8 +211,8 @@ public abstract class BusTopicFactoryTestBase<T extends Topic> extends TopicFact
builder.setTopicProperty(builderName, value.toString());
}
- assertEquals("size for default " + value, 1, buildTopics(builder.build()).size());
- assertTrue("default for " + value, validate.test(getLastParams()));
+ assertEquals(1, buildTopics(builder.build()).size(), "size for default " + value);
+ assertTrue(validate.test(getLastParams()), "default for " + value);
}
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/IndexedKafkaTopicSourceFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/IndexedKafkaTopicSourceFactoryTest.java
new file mode 100644
index 00000000..80229419
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/IndexedKafkaTopicSourceFactoryTest.java
@@ -0,0 +1,74 @@
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.event.comm.bus;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.List;
+import org.apache.kafka.clients.ClientUtils;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+
+class IndexedKafkaTopicSourceFactoryTest {
+
+ private IndexedKafkaTopicSourceFactory factory;
+
+ @Mock
+ ClientUtils mockClientUtils;
+
+ @Test
+ void testBuild() {
+ factory = new IndexedKafkaTopicSourceFactory();
+ BusTopicParams params = new BusTopicParams();
+
+ // set servers to null
+ params.setServers(null);
+ assertThatThrownBy(() -> factory.build(params))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("KAFKA Server(s) must be provided");
+
+ // set servers to empty
+ params.setServers(List.of());
+ assertThatThrownBy(() -> factory.build(params))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("KAFKA Server(s) must be provided");
+
+ List<String> servers = List.of("kafka:9092", "kafka:29092");
+ params.setServers(servers);
+
+ // set topic to null
+ params.setTopic(null);
+ assertThatThrownBy(() -> factory.build(params))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("A topic must be provided");
+
+ // set topic to empty
+ params.setTopic("");
+ assertThatThrownBy(() -> factory.build(params))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("A topic must be provided");
+
+ params.setTopic("topic01");
+
+ assertThatThrownBy(() -> factory.build(servers, "topic1"))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("cannot create topic");
+ }
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicFactoryTestBase.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicFactoryTestBase.java
index 3dfd96dd..084e0404 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicFactoryTestBase.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicFactoryTestBase.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-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.
@@ -33,7 +33,7 @@ import org.onap.policy.common.endpoints.event.comm.Topic;
public abstract class KafkaTopicFactoryTestBase<T extends Topic> extends BusTopicFactoryTestBase<T> {
@Override
- public void testBuildBusTopicParams_Ex() {
+ void testBuildBusTopicParams_Ex() {
super.testBuildBusTopicParams_Ex();
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicPropertyBuilder.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicPropertyBuilder.java
index a00879c1..b49f58e2 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicPropertyBuilder.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicPropertyBuilder.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022, 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.
@@ -26,17 +26,25 @@ import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperti
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX;
-import java.util.Arrays;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import lombok.Getter;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
+@Getter
public class KafkaTopicPropertyBuilder extends TopicPropertyBuilder {
public static final String SERVER = "localhost:9092";
public static final String TOPIC2 = "my-topic-2";
+ public static final String ADDITIONAL_PROPS = "{\"security.protocol\": \"SASL_PLAINTEXT\","
+ + "\"sasl.mechanism\": \"SCRAM-SHA-512\",\"sasl.jaas.config\": "
+ + "\"org.apache.kafka.common.security.plain.PlainLoginModule "
+ + "required username=abc password=abc serviceName=kafka;\"}";
- @Getter
- private TopicParameters params = new TopicParameters();
+ private final TopicParameters params = new TopicParameters();
/**
* Constructs the object.
@@ -61,6 +69,7 @@ public class KafkaTopicPropertyBuilder extends TopicPropertyBuilder {
setTopicProperty(PROPERTY_HTTP_HTTPS_SUFFIX, "true");
setTopicProperty(PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX, MY_PARTITION);
setTopicProperty(PROPERTY_TOPIC_SERVERS_SUFFIX, SERVER);
+ setTopicProperty(".additionalProps", ADDITIONAL_PROPS);
params.setTopicCommInfrastructure("kafka");
params.setTopic(topic);
@@ -68,8 +77,17 @@ public class KafkaTopicPropertyBuilder extends TopicPropertyBuilder {
params.setManaged(true);
params.setUseHttps(true);
params.setPartitionId(MY_PARTITION);
- params.setServers(Arrays.asList(SERVER));
+ params.setServers(List.of(SERVER));
+ params.setAdditionalProps(getAdditionalProps());
return this;
}
+
+ private Map<String, String> getAdditionalProps() {
+ try {
+ return new ObjectMapper().readValue(ADDITIONAL_PROPS, Map.class);
+ } catch (JsonProcessingException e) {
+ return Collections.emptyMap();
+ }
+ }
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkFactoryTest.java
index 52868c44..5ff6782f 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkFactoryTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkFactoryTest.java
@@ -20,9 +20,10 @@
package org.onap.policy.common.endpoints.event.comm.bus;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_KAFKA_SINK_TOPICS;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
@@ -30,12 +31,12 @@ import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
-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.common.endpoints.event.comm.bus.internal.BusTopicParams;
-public class KafkaTopicSinkFactoryTest extends KafkaTopicFactoryTestBase<KafkaTopicSink> {
+class KafkaTopicSinkFactoryTest extends KafkaTopicFactoryTestBase<KafkaTopicSink> {
private SinkFactory factory;
public static final String KAFKA_SERVER = "localhost:9092";
@@ -43,7 +44,7 @@ public class KafkaTopicSinkFactoryTest extends KafkaTopicFactoryTestBase<KafkaTo
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -51,21 +52,21 @@ public class KafkaTopicSinkFactoryTest extends KafkaTopicFactoryTestBase<KafkaTo
factory = new SinkFactory();
}
- @After
+ @AfterEach
public void tearDown() {
factory.destroy();
}
@Test
@Override
- public void testBuildBusTopicParams() {
+ void testBuildBusTopicParams() {
super.testBuildBusTopicParams();
super.testBuildBusTopicParams_Ex();
}
@Test
@Override
- public void testBuildListOfStringString() {
+ void testBuildListOfStringString() {
super.testBuildListOfStringString();
// check parameters that were used
@@ -75,7 +76,7 @@ public class KafkaTopicSinkFactoryTest extends KafkaTopicFactoryTestBase<KafkaTo
@Test
@Override
- public void testBuildProperties() {
+ void testBuildProperties() {
List<KafkaTopicSink> topics = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build());
assertEquals(1, topics.size());
assertEquals(MY_TOPIC, topics.get(0).getTopic());
@@ -88,6 +89,7 @@ public class KafkaTopicSinkFactoryTest extends KafkaTopicFactoryTestBase<KafkaTo
assertEquals(MY_TOPIC, params.getTopic());
assertEquals(MY_EFFECTIVE_TOPIC, params.getEffectiveTopic());
assertEquals(MY_PARTITION, params.getPartitionId());
+ assertNotNull(params.getAdditionalProps());
List<KafkaTopicSink> topics2 = buildTopics(makePropBuilder().makeTopic(TOPIC3)
.removeTopicProperty(PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX).build());
@@ -101,25 +103,32 @@ public class KafkaTopicSinkFactoryTest extends KafkaTopicFactoryTestBase<KafkaTo
}
@Test
+ void testBuildFromProperties() {
+ Properties props = makePropBuilder().makeTopic(MY_TOPIC).build();
+ var listTopic = factory.build(props);
+ assertNotNull(listTopic);
+ }
+
+ @Test
@Override
- public void testDestroyString_testGet_testInventory() {
+ void testDestroyString_testGet_testInventory() {
super.testDestroyString_testGet_testInventory();
super.testDestroyString_Ex();
}
@Test
@Override
- public void testDestroy() {
+ void testDestroy() {
super.testDestroy();
}
@Test
- public void testGet() {
+ void testGet() {
super.testGet_Ex();
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(factory.toString().startsWith("IndexedKafkaTopicSinkFactory ["));
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkTest.java
index 483e4e99..a34dac74 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSinkTest.java
@@ -20,14 +20,14 @@
package org.onap.policy.common.endpoints.event.comm.bus;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class KafkaTopicSinkTest {
+class KafkaTopicSinkTest {
@Test
- public void test() {
+ void test() {
assertNotNull(KafkaTopicFactories.getSinkFactory());
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceFactoryTest.java
index 392cefe9..3e4ffda5 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceFactoryTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceFactoryTest.java
@@ -20,22 +20,21 @@
package org.onap.policy.common.endpoints.event.comm.bus;
-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.assertTrue;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_KAFKA_SOURCE_TOPICS;
-import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
-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.common.endpoints.event.comm.bus.internal.BusTopicParams;
-public class KafkaTopicSourceFactoryTest extends KafkaTopicFactoryTestBase<KafkaTopicSource> {
+class KafkaTopicSourceFactoryTest extends KafkaTopicFactoryTestBase<KafkaTopicSource> {
private SourceFactory factory;
@@ -44,7 +43,7 @@ public class KafkaTopicSourceFactoryTest extends KafkaTopicFactoryTestBase<Kafka
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -52,14 +51,14 @@ public class KafkaTopicSourceFactoryTest extends KafkaTopicFactoryTestBase<Kafka
factory = new SourceFactory();
}
- @After
+ @AfterEach
public void tearDown() {
factory.destroy();
}
@Test
@Override
- public void testBuildProperties() {
+ void testBuildProperties() {
initFactory();
@@ -78,24 +77,24 @@ public class KafkaTopicSourceFactoryTest extends KafkaTopicFactoryTestBase<Kafka
@Test
@Override
- public void testDestroyString_testGet_testInventory() {
+ void testDestroyString_testGet_testInventory() {
super.testDestroyString_testGet_testInventory();
super.testDestroyString_Ex();
}
@Test
@Override
- public void testDestroy() {
+ void testDestroy() {
super.testDestroy();
}
@Test
- public void testGet() {
+ void testGet() {
super.testGet_Ex();
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(factory.toString().startsWith("IndexedKafkaTopicSourceFactory ["));
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceTest.java
index 5079e601..6afe5576 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/KafkaTopicSourceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-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,14 +20,14 @@
package org.onap.policy.common.endpoints.event.comm.bus;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class KafkaTopicSourceTest {
+class KafkaTopicSourceTest {
@Test
- public void verifyKafkaTopicFactoriesNotNull() {
+ void verifyKafkaTopicFactoriesNotNull() {
assertNotNull(KafkaTopicFactories.getSourceFactory());
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java
index 6cdb628a..fd8f3a96 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. 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,17 +21,18 @@
package org.onap.policy.common.endpoints.event.comm.bus;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.util.Arrays;
import java.util.Collections;
-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.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicListener;
@@ -46,7 +48,7 @@ public abstract class NoopTopicEndpointTest<F extends NoopTopicFactory<T>, T ext
protected abstract boolean io(String message);
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -54,7 +56,7 @@ public abstract class NoopTopicEndpointTest<F extends NoopTopicFactory<T>, T ext
}
@Test
- public void testIo() {
+ void testIo() {
TopicListener listener = mock(TopicListener.class);
this.endpoint.register(listener);
this.endpoint.start();
@@ -67,28 +69,28 @@ public abstract class NoopTopicEndpointTest<F extends NoopTopicFactory<T>, T ext
this.endpoint.unregister(listener);
}
- @Test(expected = IllegalArgumentException.class)
- public void testIoNullMessage() {
- io(null);
+ @Test
+ void testIoNullMessage() {
+ assertThatThrownBy(() -> io(null)).isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testIoEmptyMessage() {
- io("");
+ @Test
+ void testIoEmptyMessage() {
+ assertThatThrownBy(() -> io("")).isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalStateException.class)
- public void testOfferNotStarted() {
- io(MY_MESSAGE);
+ @Test
+ void testOfferNotStarted() {
+ assertThatThrownBy(() -> io(MY_MESSAGE)).isInstanceOf(IllegalStateException.class);
}
@Test
- public void testGetTopicCommInfrastructure() {
+ void testGetTopicCommInfrastructure() {
assertEquals(CommInfrastructure.NOOP, this.endpoint.getTopicCommInfrastructure());
}
@Test
- public void testStart_testStop_testShutdown() {
+ void testStart_testStop_testShutdown() {
this.endpoint.start();
assertTrue(this.endpoint.isAlive());
@@ -109,10 +111,10 @@ public abstract class NoopTopicEndpointTest<F extends NoopTopicFactory<T>, T ext
assertFalse(this.endpoint.isAlive());
}
- @Test(expected = IllegalStateException.class)
- public void testStart_Locked() {
+ @Test
+ void testStart_Locked() {
this.endpoint.lock();
- this.endpoint.start();
+ assertThatThrownBy(() -> this.endpoint.start()).isInstanceOf(IllegalStateException.class);
}
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java
index af7a4b29..3a0ec95f 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. 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.
@@ -21,11 +22,12 @@
package org.onap.policy.common.endpoints.event.comm.bus;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
@@ -35,9 +37,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Properties;
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.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
@@ -52,20 +54,20 @@ public abstract class NoopTopicFactoryTest<F extends NoopTopicFactory<T>, T exte
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
initFactory();
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
factory.destroy();
}
@Test
- public void testBuildBusTopicParams() {
+ void testBuildBusTopicParams() {
initFactory();
T item1 = buildTopic(makeParams(servers, MY_TOPIC, true));
@@ -76,7 +78,7 @@ public abstract class NoopTopicFactoryTest<F extends NoopTopicFactory<T>, T exte
}
@Test
- public void testBuildListOfStringStringBoolean() {
+ void testBuildListOfStringStringBoolean() {
initFactory();
T item1 = buildTopic(servers, MY_TOPIC, true);
@@ -115,18 +117,18 @@ public abstract class NoopTopicFactoryTest<F extends NoopTopicFactory<T>, T exte
assertNotSame(item1, buildTopic(servers, MY_TOPIC, false));
}
- @Test(expected = IllegalArgumentException.class)
- public void testBuildListOfStringStringBoolean_NullTopic() {
- buildTopic(servers, null, true);
+ @Test
+ void testBuildListOfStringStringBoolean_NullTopic() {
+ assertThatThrownBy(() -> buildTopic(servers, null, true)).isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testBuildListOfStringStringBoolean_EmptyTopic() {
- buildTopic(servers, "", true);
+ @Test
+ void testBuildListOfStringStringBoolean_EmptyTopic() {
+ assertThatThrownBy(() -> buildTopic(servers, "", true)).isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testBuildProperties() {
+ void testBuildProperties() {
// managed topic
initFactory();
assertEquals(1, buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build()).size());
@@ -178,19 +180,19 @@ public abstract class NoopTopicFactoryTest<F extends NoopTopicFactory<T>, T exte
@Test
@Override
- public void testDestroyString_testGet_testInventory() {
+ void testDestroyString_testGet_testInventory() {
super.testDestroyString_testGet_testInventory();
super.testDestroyString_Ex();
}
@Test
@Override
- public void testDestroy() {
+ void testDestroy() {
super.testDestroy();
}
@Test
- public void testGet() {
+ void testGet() {
super.testGet_Ex();
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkFactoryTest.java
index b4ab54fa..872fabf9 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkFactoryTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkFactoryTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018-2019 AT&T Intellectual Property. 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,11 +21,11 @@
package org.onap.policy.common.endpoints.event.comm.bus;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class NoopTopicSinkFactoryTest extends NoopTopicFactoryTest<NoopTopicSinkFactory, NoopTopicSink> {
+class NoopTopicSinkFactoryTest extends NoopTopicFactoryTest<NoopTopicSinkFactory, NoopTopicSink> {
@Override
protected NoopTopicSinkFactory buildFactory() {
@@ -32,7 +33,7 @@ public class NoopTopicSinkFactoryTest extends NoopTopicFactoryTest<NoopTopicSink
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(new NoopTopicSinkFactory().toString().startsWith("NoopTopicSinkFactory ["));
}
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkTest.java
index 02478367..26de1647 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSinkTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -21,11 +22,11 @@
package org.onap.policy.common.endpoints.event.comm.bus;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertFalse;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class NoopTopicSinkTest extends NoopTopicEndpointTest<NoopTopicSinkFactory, NoopTopicSink> {
+class NoopTopicSinkTest extends NoopTopicEndpointTest<NoopTopicSinkFactory, NoopTopicSink> {
public NoopTopicSinkTest() {
super(new NoopTopicSinkFactory());
@@ -37,12 +38,12 @@ public class NoopTopicSinkTest extends NoopTopicEndpointTest<NoopTopicSinkFactor
}
@Test
- public void testToString() {
+ void testToString() {
assertThat(endpoint.toString()).startsWith("NoopTopicSink");
}
@Test
- public void testSend() {
+ void testSend() {
NoopTopicSink sink = new NoopTopicSink(servers, MY_TOPIC) {
@Override
protected boolean broadcast(String message) {
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactoryTest.java
index e16174fd..fe5343f5 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactoryTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactoryTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. 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,11 +21,11 @@
package org.onap.policy.common.endpoints.event.comm.bus;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class NoopTopicSourceFactoryTest extends NoopTopicFactoryTest<NoopTopicSourceFactory, NoopTopicSource> {
+class NoopTopicSourceFactoryTest extends NoopTopicFactoryTest<NoopTopicSourceFactory, NoopTopicSource> {
@Override
protected NoopTopicSourceFactory buildFactory() {
@@ -32,7 +33,7 @@ public class NoopTopicSourceFactoryTest extends NoopTopicFactoryTest<NoopTopicSo
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(new NoopTopicSourceFactory().toString().startsWith("NoopTopicSourceFactory ["));
}
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceTest.java
index 22ccb9a8..a28a619e 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceTest.java
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. 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,12 +21,12 @@
package org.onap.policy.common.endpoints.event.comm.bus;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class NoopTopicSourceTest extends NoopTopicEndpointTest<NoopTopicSourceFactory, NoopTopicSource> {
+class NoopTopicSourceTest extends NoopTopicEndpointTest<NoopTopicSourceFactory, NoopTopicSource> {
public NoopTopicSourceTest() {
super(new NoopTopicSourceFactory());
@@ -37,12 +38,12 @@ public class NoopTopicSourceTest extends NoopTopicEndpointTest<NoopTopicSourceFa
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(this.endpoint.toString().startsWith("NoopTopicSource"));
}
@Test
- public void testOffer() {
+ void testOffer() {
NoopTopicSource source = new NoopTopicSource(servers, MY_TOPIC) {
@Override
protected boolean broadcast(String message) {
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicFactoryTestBase.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicFactoryTestBase.java
index 9795fd30..0efbf3c2 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicFactoryTestBase.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicFactoryTestBase.java
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. 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.
@@ -22,11 +23,11 @@ package org.onap.policy.common.endpoints.event.comm.bus;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-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.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
import java.util.List;
@@ -95,7 +96,7 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
/**
* Tests building a topic using varied Properties.
*/
- public void testBuildProperties_Variations() {
+ void testBuildProperties_Variations() {
initFactory();
// null topic list
@@ -116,7 +117,7 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
/**
* Tests building multiple topics using Properties.
*/
- public void testBuildProperties_Multiple() {
+ void testBuildProperties_Multiple() {
initFactory();
// make two fully-defined topics, and add two duplicate topic names to the list
@@ -136,7 +137,7 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
/**
* Tests destroy(topic), get(topic), and inventory() methods.
*/
- public void testDestroyString_testGet_testInventory() {
+ void testDestroyString_testGet_testInventory() {
initFactory();
List<T> lst = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).build());
@@ -177,7 +178,7 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
/**
* Tests exception cases with destroy(topic).
*/
- public void testDestroyString_Ex() {
+ void testDestroyString_Ex() {
// null topic
assertThatIllegalArgumentException().as("null topic").isThrownBy(() -> destroyTopic(null));
@@ -188,7 +189,7 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
/**
* Tests the destroy() method.
*/
- public void testDestroy() {
+ void testDestroy() {
initFactory();
List<T> lst = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).build());
@@ -210,7 +211,7 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
/**
* Tests exception cases with get(topic).
*/
- public void testGet_Ex() {
+ void testGet_Ex() {
// null topic
assertThatIllegalArgumentException().as("null topic").isThrownBy(() -> getTopic(null));
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java
index 2c33a257..36efff90 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java
@@ -23,14 +23,17 @@ package org.onap.policy.common.endpoints.event.comm.bus.internal;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
@@ -43,9 +46,9 @@ import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.TopicPartition;
-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.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
@@ -53,7 +56,7 @@ import org.onap.policy.common.endpoints.event.comm.bus.internal.BusConsumer.Fetc
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusConsumer.KafkaConsumerWrapper;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-public class BusConsumerTest extends TopicTestBase {
+class BusConsumerTest extends TopicTestBase {
private static final int SHORT_TIMEOUT_MILLIS = 10;
private static final int LONG_TIMEOUT_MILLIS = 3000;
@@ -63,21 +66,21 @@ public class BusConsumerTest extends TopicTestBase {
AutoCloseable closeable;
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
closeable = MockitoAnnotations.openMocks(this);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
closeable.close();
}
@Test
- public void testFetchingBusConsumer() {
+ void testFetchingBusConsumer() {
// should not be negative
var cons = new FetchingBusConsumerImpl(makeBuilder().fetchTimeout(-1).build());
assertThat(cons.getSleepTime()).isEqualTo(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH);
@@ -97,7 +100,7 @@ public class BusConsumerTest extends TopicTestBase {
}
@Test
- public void testFetchingBusConsumerSleepAfterFetchFailure() throws InterruptedException {
+ void testFetchingBusConsumerSleepAfterFetchFailure() throws InterruptedException {
var cons = new FetchingBusConsumerImpl(makeBuilder().fetchTimeout(SHORT_TIMEOUT_MILLIS).build()) {
@@ -139,18 +142,20 @@ public class BusConsumerTest extends TopicTestBase {
}
@Test
- public void testKafkaConsumerWrapper() {
+ void testKafkaConsumerWrapper() {
// verify that different wrappers can be built
assertThatCode(() -> new KafkaConsumerWrapper(makeKafkaBuilder().build())).doesNotThrowAnyException();
}
- @Test(expected = IllegalArgumentException.class)
- public void testKafkaConsumerWrapper_InvalidTopic() {
- new KafkaConsumerWrapper(makeBuilder().topic(null).build());
+ @Test
+ void testKafkaConsumerWrapper_InvalidTopic() {
+ BusTopicParams params = makeBuilder().topic(null).build();
+ assertThatThrownBy(() -> new KafkaConsumerWrapper(params))
+ .isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testKafkaConsumerWrapperFetch() {
+ void testKafkaConsumerWrapperFetch() {
//Setup Properties for consumer
Properties kafkaProps = new Properties();
@@ -174,7 +179,7 @@ public class BusConsumerTest extends TopicTestBase {
}
@Test
- public void testFetchNoMessages() throws IOException {
+ void testFetchNoMessages() {
KafkaConsumerWrapper kafkaConsumerWrapper = new KafkaConsumerWrapper(makeKafkaBuilder().build());
kafkaConsumerWrapper.consumer = mockedKafkaConsumer;
@@ -182,24 +187,25 @@ public class BusConsumerTest extends TopicTestBase {
Iterable<String> result = kafkaConsumerWrapper.fetch();
- verify(mockedKafkaConsumer, times(1)).poll(any());
+ verify(mockedKafkaConsumer).poll(any());
- assertThat(result != null);
+ assertNotNull(result);
- assertThat(!result.iterator().hasNext());
+ assertFalse(result.iterator().hasNext());
mockedKafkaConsumer.close();
}
@Test
- public void testFetchWithMessages() {
+ void testFetchWithMessages() {
// Setup
KafkaConsumerWrapper kafkaConsumerWrapper = new KafkaConsumerWrapper(makeKafkaBuilder().build());
kafkaConsumerWrapper.consumer = mockedKafkaConsumer;
- ConsumerRecord<String, String> record = new ConsumerRecord<>("my-effective-topic", 0, 0, "key", "value");
+ ConsumerRecord<String, String> customerRecord =
+ new ConsumerRecord<>("my-effective-topic", 0, 0, "key", "value");
Map<TopicPartition, List<ConsumerRecord<String, String>>> recordsMap = new HashMap<>();
- recordsMap.put(new TopicPartition("my-effective-topic", 0), Collections.singletonList(record));
+ recordsMap.put(new TopicPartition("my-effective-topic", 0), Collections.singletonList(customerRecord));
ConsumerRecords<String, String> consumerRecords = new ConsumerRecords<>(recordsMap);
when(mockedKafkaConsumer.poll(any())).thenReturn(consumerRecords);
@@ -210,29 +216,30 @@ public class BusConsumerTest extends TopicTestBase {
verify(mockedKafkaConsumer, times(1)).commitSync(any(Map.class));
- assertThat(result != null);
+ assertNotNull(result);
- assertThat(result.iterator().hasNext());
+ assertTrue(result.iterator().hasNext());
- assertThat(result.iterator().next().equals("value"));
+ assertEquals("value", result.iterator().next());
mockedKafkaConsumer.close();
}
@Test
- public void testFetchWithMessagesAndTraceparent() {
+ void testFetchWithMessagesAndTraceparent() {
// Setup
KafkaConsumerWrapper kafkaConsumerWrapper = new KafkaConsumerWrapper(makeKafkaBuilder().build());
kafkaConsumerWrapper.consumer = mockedKafkaConsumer;
- ConsumerRecord<String, String> record = new ConsumerRecord<>("my-effective-topic", 0, 0, "key", "value");
- record.headers().add(
+ ConsumerRecord<String, String> customerRecord =
+ new ConsumerRecord<>("my-effective-topic", 0, 0, "key", "value");
+ customerRecord.headers().add(
"traceparent",
"00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01".getBytes(StandardCharsets.UTF_8)
);
Map<TopicPartition, List<ConsumerRecord<String, String>>> recordsMap = new HashMap<>();
- recordsMap.put(new TopicPartition("my-effective-topic", 0), Collections.singletonList(record));
+ recordsMap.put(new TopicPartition("my-effective-topic", 0), Collections.singletonList(customerRecord));
ConsumerRecords<String, String> consumerRecords = new ConsumerRecords<>(recordsMap);
when(mockedKafkaConsumer.poll(any())).thenReturn(consumerRecords);
@@ -243,23 +250,23 @@ public class BusConsumerTest extends TopicTestBase {
verify(mockedKafkaConsumer, times(1)).commitSync(any(Map.class));
- assertThat(result != null);
+ assertNotNull(result);
- assertThat(result.iterator().hasNext());
+ assertTrue(result.iterator().hasNext());
- assertThat(result.iterator().next().equals("value"));
+ assertEquals("value", result.iterator().next());
mockedKafkaConsumer.close();
}
@Test
- public void testKafkaConsumerWrapperClose() {
+ void testKafkaConsumerWrapperClose() {
assertThatCode(() -> new KafkaConsumerWrapper(makeKafkaBuilder().build()).close()).doesNotThrowAnyException();
}
@Test
- public void testKafkaConsumerWrapperToString() {
+ void testKafkaConsumerWrapperToString() {
assertNotNull(new KafkaConsumerWrapper(makeKafkaBuilder().build()) {}.toString());
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
index 0a2a5d34..f24f7e2e 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. 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.
@@ -21,25 +22,25 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
import static org.assertj.core.api.Assertions.assertThatCode;
-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.assertTrue;
-
-import org.junit.Before;
-import org.junit.Test;
+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.assertTrue;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
import org.onap.policy.common.utils.gson.GsonTestUtils;
-public class BusTopicBaseTest extends TopicTestBase {
+class BusTopicBaseTest extends TopicTestBase {
private BusTopicBaseImpl base;
/**
* Initializes the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -48,46 +49,46 @@ public class BusTopicBaseTest extends TopicTestBase {
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(base.toString());
}
@Test
- public void testSerialize() {
+ void testSerialize() {
assertThatCode(() -> new GsonTestUtils().compareGson(base, BusTopicBaseTest.class)).doesNotThrowAnyException();
}
@Test
- public void testGetApiKey() {
+ void testGetApiKey() {
assertEquals(MY_API_KEY, base.getApiKey());
}
@Test
- public void testGetApiSecret() {
+ void testGetApiSecret() {
assertEquals(MY_API_SECRET, base.getApiSecret());
}
@Test
- public void testIsUseHttps() {
- assertEquals(true, base.isUseHttps());
- assertEquals(false, new BusTopicBaseImpl(builder.useHttps(false).build()).isUseHttps());
+ void testIsUseHttps() {
+ assertTrue(base.isUseHttps());
+ assertFalse(new BusTopicBaseImpl(builder.useHttps(false).build()).isUseHttps());
}
@Test
- public void testIsAllowSelfSignedCerts() {
- assertEquals(true, base.isAllowSelfSignedCerts());
- assertEquals(false, new BusTopicBaseImpl(builder.allowSelfSignedCerts(false).build()).isAllowSelfSignedCerts());
+ void testIsAllowSelfSignedCerts() {
+ assertTrue(base.isAllowSelfSignedCerts());
+ assertFalse(new BusTopicBaseImpl(builder.allowSelfSignedCerts(false).build()).isAllowSelfSignedCerts());
}
@Test
- public void testTopic() {
+ void testTopic() {
assertEquals(MY_TOPIC, base.getTopic());
assertEquals(MY_EFFECTIVE_TOPIC, base.getEffectiveTopic());
assertNotEquals(base.getTopic(), base.getEffectiveTopic());
}
@Test
- public void testAnyNullOrEmpty() {
+ void testAnyNullOrEmpty() {
assertFalse(base.anyNullOrEmpty());
assertFalse(base.anyNullOrEmpty("any-none-null", "any-none-null-B"));
@@ -98,7 +99,7 @@ public class BusTopicBaseTest extends TopicTestBase {
}
@Test
- public void testAllNullOrEmpty() {
+ void testAllNullOrEmpty() {
assertTrue(base.allNullOrEmpty());
assertTrue(base.allNullOrEmpty(""));
assertTrue(base.allNullOrEmpty(null, ""));
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java
index 3abb8b10..e016ca2b 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java
@@ -21,28 +21,28 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
-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.assertTrue;
import java.util.LinkedList;
import java.util.List;
import java.util.function.BiConsumer;
-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.endpoints.event.comm.bus.TopicTestBase;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder;
-public class BusTopicParamsTest extends TopicTestBase {
+class BusTopicParamsTest extends TopicTestBase {
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
}
@Test
- public void testGetters() {
+ void testGetters() {
BusTopicParams params = makeBuilder().build();
assertEquals(addProps, params.getAdditionalProps());
@@ -73,7 +73,7 @@ public class BusTopicParamsTest extends TopicTestBase {
}
@Test
- public void testBooleanGetters() {
+ void testBooleanGetters() {
// ensure that booleans are independent of each other
testBoolean("true:false:false", TopicParamsBuilder::allowSelfSignedCerts);
testBoolean("false:true:false", TopicParamsBuilder::managed);
@@ -81,7 +81,7 @@ public class BusTopicParamsTest extends TopicTestBase {
}
@Test
- public void testValidators() {
+ void testValidators() {
BusTopicParams params = makeBuilder().build();
// test validity methods
@@ -106,7 +106,7 @@ public class BusTopicParamsTest extends TopicTestBase {
}
@Test
- public void testInvertedValidators() {
+ void testInvertedValidators() {
assertFalse(makeBuilder().additionalProps(null).build().isAdditionalPropsValid());
assertTrue(makeBuilder().aftEnvironment("").build().isAftEnvironmentInvalid());
assertFalse(makeBuilder().apiKey("").build().isApiKeyValid());
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
index 7aa70b2a..ce363269 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
@@ -22,10 +22,11 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
import static org.assertj.core.api.Assertions.assertThatCode;
-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.assertj.core.api.Assertions.assertThatThrownBy;
+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.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@@ -34,22 +35,22 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
-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.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicListener;
import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
import org.onap.policy.common.utils.gson.GsonTestUtils;
-public class InlineBusTopicSinkTest extends TopicTestBase {
+class InlineBusTopicSinkTest extends TopicTestBase {
private InlineBusTopicSinkImpl sink;
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -57,19 +58,19 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
sink = new InlineBusTopicSinkImpl(makeBuilder().build());
}
- @After
+ @AfterEach
public void tearDown() {
sink.shutdown();
}
@Test
- public void testSerialize() {
+ void testSerialize() {
assertThatCode(() -> new GsonTestUtils().compareGson(sink, InlineBusTopicSinkTest.class))
.doesNotThrowAnyException();
}
@Test
- public void testInlineBusTopicSinkImpl() {
+ void testInlineBusTopicSinkImpl() {
// verify that different wrappers can be built
sink = new InlineBusTopicSinkImpl(makeBuilder().build());
assertEquals(MY_PARTITION, sink.getPartitionKey());
@@ -79,7 +80,7 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
}
@Test
- public void testStart() {
+ void testStart() {
assertTrue(sink.start());
assertEquals(1, sink.initCount);
@@ -88,14 +89,14 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
assertEquals(1, sink.initCount);
}
- @Test(expected = IllegalStateException.class)
- public void testStart_Locked() {
+ @Test
+ void testStart_Locked() {
sink.lock();
- sink.start();
+ assertThatThrownBy(() -> sink.start()).isInstanceOf(IllegalStateException.class);
}
@Test
- public void testStop() {
+ void testStop() {
BusPublisher pub = mock(BusPublisher.class);
sink.publisher = pub;
@@ -114,7 +115,7 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
}
@Test
- public void testSend() {
+ void testSend() {
sink.start();
BusPublisher pub = mock(BusPublisher.class);
sink.publisher = pub;
@@ -137,31 +138,30 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE);
}
- @Test(expected = IllegalArgumentException.class)
- public void testSend_NullMessage() {
+ @Test
+ void testSend_NullMessage() {
sink.start();
sink.publisher = mock(BusPublisher.class);
- sink.send(null);
+ assertThatThrownBy(() -> sink.send(null)).isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testSend_EmptyMessage() {
+ @Test
+ void testSend_EmptyMessage() {
sink.start();
sink.publisher = mock(BusPublisher.class);
- sink.send("");
+ assertThatThrownBy(() -> sink.send("")).isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalStateException.class)
- public void testSend_NotStarted() {
+ @Test
+ void testSend_NotStarted() {
sink.publisher = mock(BusPublisher.class);
-
- sink.send(MY_MESSAGE);
+ assertThatThrownBy(() -> sink.send(MY_MESSAGE)).isInstanceOf(IllegalStateException.class);
}
@Test
- public void testSetPartitionKey_getPartitionKey() {
+ void testSetPartitionKey_getPartitionKey() {
assertEquals(MY_PARTITION, sink.getPartitionKey());
sink.setPartitionKey("part-B");
@@ -169,7 +169,7 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
}
@Test
- public void testShutdown() {
+ void testShutdown() {
BusPublisher pub = mock(BusPublisher.class);
sink.publisher = pub;
@@ -178,7 +178,7 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
}
@Test
- public void testAnyNullOrEmpty() {
+ void testAnyNullOrEmpty() {
assertFalse(sink.anyNullOrEmpty());
assertFalse(sink.anyNullOrEmpty("any-none-null", "any-none-null-B"));
@@ -189,7 +189,7 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
}
@Test
- public void testAllNullOrEmpty() {
+ void testAllNullOrEmpty() {
assertTrue(sink.allNullOrEmpty());
assertTrue(sink.allNullOrEmpty(""));
assertTrue(sink.allNullOrEmpty(null, ""));
@@ -202,7 +202,7 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(sink.toString().startsWith("InlineBusTopicSink ["));
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineKafkaTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineKafkaTopicSinkTest.java
index 643025c2..91412ff6 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineKafkaTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineKafkaTopicSinkTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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,22 +21,22 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
import static org.assertj.core.api.Assertions.assertThatCode;
-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.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.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
-public class InlineKafkaTopicSinkTest extends TopicTestBase {
+class InlineKafkaTopicSinkTest extends TopicTestBase {
private InlineKafkaTopicSink sink;
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -44,18 +44,18 @@ public class InlineKafkaTopicSinkTest extends TopicTestBase {
sink = new InlineKafkaTopicSink(makeKafkaBuilder().build());
}
- @After
+ @AfterEach
public void tearDown() {
sink.shutdown();
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(sink.toString().startsWith("InlineKafkaTopicSink ["));
}
@Test
- public void testInit() {
+ void testInit() {
// nothing null
sink = new InlineKafkaTopicSink(makeKafkaBuilder().build());
sink.init();
@@ -63,7 +63,7 @@ public class InlineKafkaTopicSinkTest extends TopicTestBase {
}
@Test
- public void testGetTopicCommInfrastructure() {
+ void testGetTopicCommInfrastructure() {
assertEquals(CommInfrastructure.KAFKA, sink.getTopicCommInfrastructure());
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/KafkaPublisherWrapperTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/KafkaPublisherWrapperTest.java
new file mode 100644
index 00000000..1f7c2cf7
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/KafkaPublisherWrapperTest.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.event.comm.bus.internal;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.Properties;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentMatchers;
+
+class KafkaPublisherWrapperTest {
+
+ private BusPublisher.KafkaPublisherWrapper kafkaPublisherWrapper;
+ private Producer<String, String> mockProducer;
+ private BusTopicParams mockBusTopicParams;
+
+ @BeforeEach
+ void setUp() {
+ mockProducer = mock(KafkaProducer.class);
+ mockBusTopicParams = mock(BusTopicParams.class);
+
+ when(mockBusTopicParams.getTopic()).thenReturn("testTopic");
+ when(mockBusTopicParams.getServers()).thenReturn(Collections.singletonList("localhost:9092"));
+ when(mockBusTopicParams.isTopicInvalid()).thenReturn(false);
+ when(mockBusTopicParams.isAdditionalPropsValid()).thenReturn(false);
+ when(mockBusTopicParams.isAllowTracing()).thenReturn(false);
+
+ kafkaPublisherWrapper = new BusPublisher.KafkaPublisherWrapper(mockBusTopicParams) {
+ protected Producer<String, String> createProducer(Properties props) { // NOSONAR instance creation
+ return mockProducer;
+ }
+ };
+ }
+
+ @Test
+ void testConstructor() {
+ verify(mockBusTopicParams).getTopic();
+ verify(mockBusTopicParams).getServers();
+ verify(mockBusTopicParams).isTopicInvalid();
+ verify(mockBusTopicParams).isAdditionalPropsValid();
+ verify(mockBusTopicParams).isAllowTracing();
+ }
+
+ @Test
+ void testSendSuccess() {
+ when(mockProducer.send(ArgumentMatchers.any(ProducerRecord.class))).thenReturn(null);
+ assertTrue(kafkaPublisherWrapper.send("partitionId", "testMessage"));
+ }
+
+ @Test
+ void testSendNullMessage() {
+ IllegalArgumentException thrown = assertThrows(
+ IllegalArgumentException.class,
+ () -> kafkaPublisherWrapper.send("partitionId", null),
+ "Expected send() to throw, but it didn't"
+ );
+ assertEquals("No message provided", thrown.getMessage());
+ }
+
+ @Test
+ void testSendFailure() {
+ when(mockProducer.send(ArgumentMatchers.any(ProducerRecord.class))).thenThrow(RuntimeException.class);
+ assertTrue(kafkaPublisherWrapper.send("partitionId", "testMessage"));
+ }
+
+ @Test
+ void testClose() {
+ assertThatCode(kafkaPublisherWrapper::close).doesNotThrowAnyException();
+ }
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
index dbdd8813..bc2d3779 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2018-2021 AT&T Intellectual Property. 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.
@@ -22,9 +23,10 @@ package org.onap.policy.common.endpoints.event.comm.bus.internal;
import static org.assertj.core.api.Assertions.assertThat;
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.assertTrue;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -36,9 +38,9 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.Collections;
-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.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -47,7 +49,7 @@ import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
import org.onap.policy.common.utils.gson.GsonTestUtils;
import org.onap.policy.common.utils.network.NetworkUtil;
-public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
+class SingleThreadedBusTopicSourceTest extends TopicTestBase {
private Thread thread;
private BusConsumer cons;
private TopicListener listener;
@@ -56,7 +58,7 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
/**
* Creates the object to be tested, as well as various mocks.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -67,19 +69,19 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
source = new SingleThreadedBusTopicSourceImpl(makeBuilder().build());
}
- @After
+ @AfterEach
public void tearDown() {
source.shutdown();
}
@Test
- public void testSerialize() {
+ void testSerialize() {
assertThatCode(() -> new GsonTestUtils().compareGson(source, SingleThreadedBusTopicSourceTest.class))
.doesNotThrowAnyException();
}
@Test
- public void testRegister() {
+ void testRegister() {
source.register(listener);
assertEquals(1, source.initCount);
source.offer(MY_MESSAGE);
@@ -112,7 +114,7 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
}
@Test
- public void testUnregister() {
+ void testUnregister() {
TopicListener listener2 = mock(TopicListener.class);
source.register(listener);
source.register(listener2);
@@ -139,12 +141,12 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(source.toString().startsWith("SingleThreadedBusTopicSource ["));
}
@Test
- public void testMakePollerThread() {
+ void testMakePollerThread() {
SingleThreadedBusTopicSource source2 = new SingleThreadedBusTopicSource(makeBuilder().build()) {
@Override
public CommInfrastructure getTopicCommInfrastructure() {
@@ -161,7 +163,7 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
}
@Test
- public void testSingleThreadedBusTopicSource() {
+ void testSingleThreadedBusTopicSource() {
// Note: if the value contains "-", it's probably a UUID
// verify that different wrappers can be built
@@ -189,7 +191,7 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
}
@Test
- public void testStart() {
+ void testStart() {
source.start();
assertTrue(source.isAlive());
assertEquals(1, source.initCount);
@@ -209,20 +211,23 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
verify(thread, times(2)).start();
}
- @Test(expected = IllegalStateException.class)
- public void testStart_Locked() {
+ @Test
+ void testStart_Locked() {
source.lock();
- source.start();
+ assertThatThrownBy(() -> source.start()).isInstanceOf(IllegalStateException.class);
}
- @Test(expected = IllegalStateException.class)
- public void testStart_InitEx() {
- source.initEx = true;
- source.start();
+ @Test
+ void testStart_InitEx() {
+ assertThatThrownBy(() -> {
+ source.initEx = true;
+
+ source.start();
+ }).isInstanceOf(IllegalStateException.class);
}
@Test
- public void testStop() {
+ void testStop() {
source.start();
source.stop();
verify(cons).close();
@@ -238,7 +243,7 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
}
@Test
- public void testRun() throws Exception {
+ void testRun() throws Exception {
source.register(listener);
/*
@@ -293,30 +298,30 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
}
@Test
- public void testOffer() {
+ void testOffer() {
source.register(listener);
source.offer(MY_MESSAGE);
verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE);
assertEquals(Arrays.asList(MY_MESSAGE), Arrays.asList(source.getRecentEvents()));
}
- @Test(expected = IllegalStateException.class)
- public void testOffer_NotStarted() {
- source.offer(MY_MESSAGE);
+ @Test
+ void testOffer_NotStarted() {
+ assertThatThrownBy(() -> source.offer(MY_MESSAGE)).isInstanceOf(IllegalStateException.class);
}
@Test
- public void testGetConsumerGroup() {
+ void testGetConsumerGroup() {
assertEquals(MY_CONS_GROUP, source.getConsumerGroup());
}
@Test
- public void testGetConsumerInstance() {
+ void testGetConsumerInstance() {
assertEquals(MY_CONS_INST, source.getConsumerInstance());
}
@Test
- public void testShutdown() {
+ void testShutdown() {
source.register(listener);
source.shutdown();
@@ -325,12 +330,12 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
}
@Test
- public void testGetFetchTimeout() {
+ void testGetFetchTimeout() {
assertEquals(MY_FETCH_TIMEOUT, source.getFetchTimeout());
}
@Test
- public void testGetFetchLimit() {
+ void testGetFetchLimit() {
assertEquals(MY_FETCH_LIMIT, source.getFetchLimit());
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedKafkaTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedKafkaTopicSourceTest.java
index 6b63c9f4..84df1228 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedKafkaTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedKafkaTopicSourceTest.java
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. 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.
@@ -21,23 +22,23 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
import static org.assertj.core.api.Assertions.assertThatCode;
-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.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.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
import org.onap.policy.common.utils.gson.GsonTestUtils;
-public class SingleThreadedKafkaTopicSourceTest extends TopicTestBase {
+class SingleThreadedKafkaTopicSourceTest extends TopicTestBase {
private SingleThreadedKafkaTopicSource source;
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -45,24 +46,24 @@ public class SingleThreadedKafkaTopicSourceTest extends TopicTestBase {
source = new SingleThreadedKafkaTopicSource(makeKafkaBuilder().build());
}
- @After
+ @AfterEach
public void tearDown() {
source.shutdown();
}
- public void testSerialize() {
+ void testSerialize() {
assertThatCode(() -> new GsonTestUtils().compareGson(source, SingleThreadedKafkaTopicSourceTest.class))
.doesNotThrowAnyException();
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(source.toString().startsWith("SingleThreadedKafkaTopicSource ["));
source.shutdown();
}
@Test
- public void testGetTopicCommInfrastructure() {
+ void testGetTopicCommInfrastructure() {
assertEquals(CommInfrastructure.KAFKA, source.getTopicCommInfrastructure());
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
index 0f09b12e..fe719848 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. 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.
@@ -21,10 +22,11 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
import static org.assertj.core.api.Assertions.assertThatCode;
-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.assertj.core.api.Assertions.assertThatThrownBy;
+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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@@ -33,21 +35,21 @@ import static org.mockito.Mockito.verify;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-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.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicListener;
import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
import org.onap.policy.common.utils.gson.GsonTestUtils;
-public class TopicBaseTest extends TopicTestBase {
+class TopicBaseTest extends TopicTestBase {
private TopicBaseImpl base;
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
@@ -55,54 +57,56 @@ public class TopicBaseTest extends TopicTestBase {
base = new TopicBaseImpl(servers, MY_TOPIC);
}
- @Test(expected = IllegalArgumentException.class)
- public void testTopicBase_NullServers() {
- new TopicBaseImpl(null, MY_TOPIC);
+ @Test
+ void testTopicBase_NullServers() {
+ assertThatThrownBy(() -> new TopicBaseImpl(null, MY_TOPIC)).isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testTopicBase_EmptyServers() {
- new TopicBaseImpl(Collections.emptyList(), MY_TOPIC);
+ @Test
+ void testTopicBase_EmptyServers() {
+ List<String> testList = Collections.emptyList();
+ assertThatThrownBy(() -> new TopicBaseImpl(testList, MY_TOPIC))
+ .isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testTopicBase_NullTopic() {
- new TopicBaseImpl(servers, null);
+ @Test
+ void testTopicBase_NullTopic() {
+ assertThatThrownBy(() -> new TopicBaseImpl(servers, null)).isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testTopicBase_EmptyTopic() {
- new TopicBaseImpl(servers, "");
+ @Test
+ void testTopicBase_EmptyTopic() {
+ assertThatThrownBy(() -> new TopicBaseImpl(servers, "")).isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testTopicBase_EffectiveTopic() {
+ void testTopicBase_EffectiveTopic() {
TopicBase baseEf = new TopicBaseImpl(servers, MY_TOPIC, MY_EFFECTIVE_TOPIC);
assertEquals(MY_TOPIC, baseEf.getTopic());
assertEquals(MY_EFFECTIVE_TOPIC, baseEf.getEffectiveTopic());
}
@Test
- public void testTopicBase_NullEffectiveTopic() {
+ void testTopicBase_NullEffectiveTopic() {
TopicBase baseEf = new TopicBaseImpl(servers, MY_TOPIC, null);
assertEquals(MY_TOPIC, baseEf.getTopic());
assertEquals(MY_TOPIC, baseEf.getEffectiveTopic());
}
@Test
- public void testTopicBase_EmptyEffectiveTopic() {
+ void testTopicBase_EmptyEffectiveTopic() {
TopicBase baseEf = new TopicBaseImpl(servers, MY_TOPIC, "");
assertEquals(MY_TOPIC, baseEf.getTopic());
assertEquals(MY_TOPIC, baseEf.getEffectiveTopic());
}
@Test
- public void testSerialize() {
+ void testSerialize() {
assertThatCode(() -> new GsonTestUtils().compareGson(base, TopicBaseTest.class)).doesNotThrowAnyException();
}
@Test
- public void testRegister() {
+ void testRegister() {
TopicListener listener = mock(TopicListener.class);
base.register(listener);
assertEquals(Arrays.asList(listener), base.snapshotTopicListeners());
@@ -117,13 +121,13 @@ public class TopicBaseTest extends TopicTestBase {
assertEquals(Arrays.asList(listener, listener2), base.snapshotTopicListeners());
}
- @Test(expected = IllegalArgumentException.class)
- public void testRegister_NullListener() {
- base.register(null);
+ @Test
+ void testRegister_NullListener() {
+ assertThatThrownBy(() -> base.register(null)).isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testUnregister() {
+ void testUnregister() {
// register two listeners
TopicListener listener = mock(TopicListener.class);
TopicListener listener2 = mock(TopicListener.class);
@@ -143,14 +147,14 @@ public class TopicBaseTest extends TopicTestBase {
assertTrue(base.snapshotTopicListeners().isEmpty());
}
- @Test(expected = IllegalArgumentException.class)
- public void testUnregister_NullListener() {
+ @Test
+ void testUnregister_NullListener() {
base.register(mock(TopicListener.class));
- base.unregister(null);
+ assertThatThrownBy(() -> base.unregister(null)).isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testBroadcast() {
+ void testBroadcast() {
// register two listeners
TopicListener listener = mock(TopicListener.class);
TopicListener listener2 = mock(TopicListener.class);
@@ -172,7 +176,7 @@ public class TopicBaseTest extends TopicTestBase {
}
@Test
- public void testLock_testUnlock() {
+ void testLock_testUnlock() {
assertFalse(base.isLocked());
assertTrue(base.lock());
assertEquals(0, base.startCount);
@@ -200,7 +204,7 @@ public class TopicBaseTest extends TopicTestBase {
* Tests lock/unlock when the stop/start methods return false.
*/
@Test
- public void testLock_testUnlock_FalseReturns() {
+ void testLock_testUnlock_FalseReturns() {
// lock, but stop returns false
base.stopReturn = false;
@@ -219,7 +223,7 @@ public class TopicBaseTest extends TopicTestBase {
* Tests lock/unlock when the start method throws an exception.
*/
@Test
- public void testLock_testUnlock_Exception() {
+ void testLock_testUnlock_Exception() {
// lock & re-lock, but start throws an exception
base.startEx = true;
@@ -230,7 +234,7 @@ public class TopicBaseTest extends TopicTestBase {
}
@Test
- public void testIsLocked() {
+ void testIsLocked() {
assertFalse(base.isLocked());
base.lock();
assertTrue(base.isLocked());
@@ -239,18 +243,18 @@ public class TopicBaseTest extends TopicTestBase {
}
@Test
- public void testGetTopic() {
+ void testGetTopic() {
assertEquals(MY_TOPIC, base.getTopic());
}
@Test
- public void testGetEffectiveTopic() {
+ void testGetEffectiveTopic() {
assertEquals(MY_TOPIC, base.getTopic());
assertEquals(MY_TOPIC, base.getEffectiveTopic());
}
@Test
- public void testIsAlive() {
+ void testIsAlive() {
assertFalse(base.isAlive());
base.start();
assertTrue(base.isAlive());
@@ -259,12 +263,12 @@ public class TopicBaseTest extends TopicTestBase {
}
@Test
- public void testGetServers() {
+ void testGetServers() {
assertEquals(servers, base.getServers());
}
@Test
- public void testGetRecentEvents() {
+ void testGetRecentEvents() {
assertEquals(0, base.getRecentEvents().length);
base.addEvent("recent-A");
@@ -277,7 +281,7 @@ public class TopicBaseTest extends TopicTestBase {
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(base.toString());
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/BidirectionalTopicClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/BidirectionalTopicClientTest.java
index 704b2cb0..890fa720 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/BidirectionalTopicClientTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/BidirectionalTopicClientTest.java
@@ -23,14 +23,15 @@ package org.onap.policy.common.endpoints.event.comm.client;
import static org.assertj.core.api.Assertions.assertThat;
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.assertNotSame;
-import static org.junit.Assert.assertSame;
-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.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -41,15 +42,15 @@ import java.util.concurrent.TimeUnit;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
@@ -60,8 +61,8 @@ import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-@RunWith(MockitoJUnitRunner.class)
-public class BidirectionalTopicClientTest {
+@ExtendWith(MockitoExtension.class)
+class BidirectionalTopicClientTest {
private static final Coder coder = new StandardCoder();
private static final long MAX_WAIT_MS = 5000;
private static final long SHORT_WAIT_MS = 1;
@@ -89,7 +90,7 @@ public class BidirectionalTopicClientTest {
/**
* Configures the endpoints.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
Properties props = new Properties();
props.setProperty("noop.sink.topics", SINK_TOPIC);
@@ -101,7 +102,7 @@ public class BidirectionalTopicClientTest {
TopicEndpointManager.getManager().addTopicSources(props);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
// clear all topics after the tests
TopicEndpointManager.getManager().shutdown();
@@ -110,19 +111,19 @@ public class BidirectionalTopicClientTest {
/**
* Creates mocks and an initial client object.
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
- when(sink.send(anyString())).thenReturn(true);
- when(sink.getTopicCommInfrastructure()).thenReturn(SINK_INFRA);
+ lenient().when(sink.send(anyString())).thenReturn(true);
+ lenient().when(sink.getTopicCommInfrastructure()).thenReturn(SINK_INFRA);
- when(source.offer(anyString())).thenReturn(true);
- when(source.getTopicCommInfrastructure()).thenReturn(SOURCE_INFRA);
+ lenient().when(source.offer(anyString())).thenReturn(true);
+ lenient().when(source.getTopicCommInfrastructure()).thenReturn(SOURCE_INFRA);
- when(endpoint.getTopicSinks(anyString())).thenReturn(Arrays.asList());
- when(endpoint.getTopicSinks(SINK_TOPIC)).thenReturn(Arrays.asList(sink));
+ lenient().when(endpoint.getTopicSinks(anyString())).thenReturn(Arrays.asList());
+ lenient().when(endpoint.getTopicSinks(SINK_TOPIC)).thenReturn(Arrays.asList(sink));
- when(endpoint.getTopicSources(any())).thenReturn(Arrays.asList());
- when(endpoint.getTopicSources(Arrays.asList(SOURCE_TOPIC))).thenReturn(Arrays.asList(source));
+ lenient().when(endpoint.getTopicSources(any())).thenReturn(Arrays.asList());
+ lenient().when(endpoint.getTopicSources(Arrays.asList(SOURCE_TOPIC))).thenReturn(Arrays.asList(source));
theMessage = new MyMessage(MY_TEXT);
@@ -131,13 +132,13 @@ public class BidirectionalTopicClientTest {
context = new Context();
}
- @After
+ @AfterEach
public void tearDown() {
context.stop();
}
@Test
- public void testBidirectionalTopicClient_testGetters() {
+ void testBidirectionalTopicClient_testGetters() {
assertSame(sink, client.getSink());
assertSame(source, client.getSource());
assertEquals(SINK_TOPIC, client.getSinkTopic());
@@ -150,7 +151,7 @@ public class BidirectionalTopicClientTest {
* Tests the constructor when the sink or source cannot be found.
*/
@Test
- public void testBidirectionalTopicClientExceptions() {
+ void testBidirectionalTopicClientExceptions() {
assertThatThrownBy(() -> new BidirectionalTopicClient2("unknown-sink", SOURCE_TOPIC))
.isInstanceOf(BidirectionalTopicClientException.class)
.hasMessage("no sinks for topic: unknown-sink");
@@ -171,7 +172,7 @@ public class BidirectionalTopicClientTest {
* Tests the "delegate" methods.
*/
@Test
- public void testDelegates() {
+ void testDelegates() {
assertTrue(client.send("hello"));
verify(sink).send("hello");
@@ -186,7 +187,7 @@ public class BidirectionalTopicClientTest {
}
@Test
- public void testGetTopicEndpointManager() throws BidirectionalTopicClientException {
+ void testGetTopicEndpointManager() throws BidirectionalTopicClientException {
// use a real manager
client = new BidirectionalTopicClient(SINK_TOPIC, SOURCE_TOPIC);
assertNotNull(client.getTopicEndpointManager());
@@ -199,7 +200,7 @@ public class BidirectionalTopicClientTest {
}
@Test
- public void testAwaitReceipt() throws Exception {
+ void testAwaitReceipt() throws Exception {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
@@ -213,7 +214,7 @@ public class BidirectionalTopicClientTest {
}
@Test
- public void testAwaitReceipt_AlreadyDone() throws Exception {
+ void testAwaitReceipt_AlreadyDone() throws Exception {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
@@ -227,7 +228,7 @@ public class BidirectionalTopicClientTest {
}
@Test
- public void testAwaitReceipt_MessageDoesNotMatch() throws Exception {
+ void testAwaitReceipt_MessageDoesNotMatch() throws Exception {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
@@ -242,7 +243,7 @@ public class BidirectionalTopicClientTest {
}
@Test
- public void testAwaitReceipt_DecodeFails() throws Exception {
+ void testAwaitReceipt_DecodeFails() throws Exception {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
@@ -260,7 +261,7 @@ public class BidirectionalTopicClientTest {
}
@Test
- public void testAwaitReceipt_Interrupted() throws InterruptedException {
+ void testAwaitReceipt_Interrupted() throws InterruptedException {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
@@ -270,7 +271,7 @@ public class BidirectionalTopicClientTest {
}
@Test
- public void testAwaitReceipt_MultipleLoops() throws Exception {
+ void testAwaitReceipt_MultipleLoops() throws Exception {
context.start(theMessage);
// wait for multiple "send" calls
@@ -282,7 +283,7 @@ public class BidirectionalTopicClientTest {
}
@Test
- public void testStop() throws InterruptedException {
+ void testStop() throws InterruptedException {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicClientExceptionTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicClientExceptionTest.java
index 7b64a20f..ba935822 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicClientExceptionTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicClientExceptionTest.java
@@ -3,7 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 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,15 @@
package org.onap.policy.common.endpoints.event.comm.client;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class TopicClientExceptionTest {
+class TopicClientExceptionTest {
@Test
- public void test() {
+ void test() {
assertEquals(5, new ExceptionsTester().test(TopicSinkClientException.class));
assertEquals(5, new ExceptionsTester().test(BidirectionalTopicClientException.class));
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java
index 48c86c98..81621195 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java
@@ -3,7 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 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.common.endpoints.event.comm.client;
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.assertNotNull;
+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.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -35,13 +35,13 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
-public class TopicSinkClientTest {
+class TopicSinkClientTest {
private static final String TOPIC = "my-topic";
private TopicSinkClient client;
@@ -53,7 +53,7 @@ public class TopicSinkClientTest {
*
* @throws Exception if an error occurs
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
sink = mock(TopicSink.class);
when(sink.send(anyString())).thenReturn(true);
@@ -70,7 +70,7 @@ public class TopicSinkClientTest {
TopicEndpointManager.getManager().addTopicSinks(props);
}
- @AfterClass
+ @AfterAll
public static void tearDown() {
// clear all topics after the tests
TopicEndpointManager.getManager().shutdown();
@@ -80,7 +80,7 @@ public class TopicSinkClientTest {
* Uses a real NO-OP topic sink.
*/
@Test
- public void testGetTopicSinks() throws Exception {
+ void testGetTopicSinks() throws Exception {
sink = TopicEndpointManager.getManager().getNoopTopicSink(TOPIC);
assertNotNull(sink);
@@ -97,7 +97,7 @@ public class TopicSinkClientTest {
}
@Test
- public void testTopicSinkClient() {
+ void testTopicSinkClient() {
// unknown topic -> should throw exception
sinks = new LinkedList<>();
assertThatThrownBy(() -> new TopicSinkClient2(TOPIC)).isInstanceOf(TopicSinkClientException.class)
@@ -105,7 +105,7 @@ public class TopicSinkClientTest {
}
@Test
- public void testTopicSinkClient_GetTopic() throws TopicSinkClientException {
+ void testTopicSinkClient_GetTopic() throws TopicSinkClientException {
assertEquals(TOPIC, new TopicSinkClient(TopicEndpointManager.getManager().getNoopTopicSink(TOPIC)).getTopic());
assertEquals(TOPIC, new TopicSinkClient(TOPIC).getTopic());
@@ -115,7 +115,7 @@ public class TopicSinkClientTest {
}
@Test
- public void testSend() {
+ void testSend() {
client.send(Arrays.asList("abc", "def"));
verify(sink).send("['abc','def']".replace('\'', '"'));
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/features/NetLoggerFeatureApiTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/features/NetLoggerFeatureApiTest.java
new file mode 100644
index 00000000..2ea64239
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/features/NetLoggerFeatureApiTest.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.features;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+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.jupiter.MockitoExtension;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.slf4j.Logger;
+
+@ExtendWith(MockitoExtension.class)
+class NetLoggerFeatureApiTest {
+
+ @Mock
+ private Logger mockLogger;
+
+ @Mock
+ private EventType mockEventType;
+
+ @Mock
+ private CommInfrastructure mockCommInfrastructure;
+
+ private NetLoggerFeatureApi featureApi;
+
+ @BeforeEach
+ public void setUp() {
+ featureApi = new NetLoggerFeatureApi() {
+ @Override
+ public boolean beforeLog(Logger eventLogger, EventType type, CommInfrastructure protocol, String topic,
+ String message) {
+ return NetLoggerFeatureApi.super.beforeLog(eventLogger, type, protocol, topic, message);
+ }
+
+ @Override
+ public boolean afterLog(Logger eventLogger, EventType type, CommInfrastructure protocol, String topic,
+ String message) {
+ return NetLoggerFeatureApi.super.afterLog(eventLogger, type, protocol, topic, message);
+ }
+
+ @Override
+ public int getSequenceNumber() {
+ return 0;
+ }
+
+ @Override
+ public String getName() {
+ return NetLoggerFeatureApi.super.getName();
+ }
+ };
+ }
+
+ @Test
+ void testBeforeLogDefaultBehavior() {
+ boolean result = featureApi.beforeLog(mockLogger, mockEventType, mockCommInfrastructure,
+ "testTopic", "testMessage");
+ assertFalse(result, "Expected beforeLog to return false by default");
+ }
+
+ @Test
+ void testAfterLogDefaultBehavior() {
+ boolean result = featureApi.afterLog(mockLogger, mockEventType, mockCommInfrastructure,
+ "testTopic", "testMessage");
+ assertFalse(result, "Expected afterLog to return false by default");
+ }
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/AuthorizationFilterTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/AuthorizationFilterTest.java
new file mode 100644
index 00000000..2ab3071f
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/AuthorizationFilterTest.java
@@ -0,0 +1,84 @@
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.http.server.test;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.ServletRequest;
+import jakarta.servlet.ServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.common.endpoints.http.server.AuthorizationFilter;
+
+class AuthorizationFilterTest {
+
+ AuthorizationFilter filter;
+
+ @Mock
+ ServletRequest request;
+
+ @Mock
+ HttpServletRequest httpRequest;
+
+ @Mock
+ HttpServletResponse httpResponse;
+
+ @Mock
+ ServletResponse response;
+
+ @Mock
+ FilterChain chain;
+
+ @BeforeEach
+ void setUp() {
+ request = mock(ServletRequest.class);
+ response = mock(ServletResponse.class);
+ chain = mock(FilterChain.class);
+ httpRequest = mock(HttpServletRequest.class);
+ httpResponse = mock(HttpServletResponse.class);
+
+ filter = new AuthorizationFilter() {
+ @Override
+ protected String getRole(HttpServletRequest request) {
+ return "testRole";
+ }
+ };
+ }
+
+ @Test
+ void testAuthorizationFilter() {
+ assertThatThrownBy(() -> filter.doFilter(request, response, chain))
+ .isInstanceOf(ServletException.class)
+ .hasMessageContaining("Not an HttpServletRequest instance");
+
+ assertThatThrownBy(() -> filter.doFilter(httpRequest, response, chain))
+ .isInstanceOf(ServletException.class)
+ .hasMessageContaining("Not an HttpServletResponse instance");
+
+ assertThatCode(() -> filter.doFilter(httpRequest, httpResponse, chain))
+ .doesNotThrowAnyException();
+ }
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
index 11067974..3d80aa81 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
@@ -22,11 +22,11 @@
package org.onap.policy.common.endpoints.http.server.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import io.prometheus.client.servlet.jakarta.exporter.MetricsServlet;
import jakarta.ws.rs.client.Entity;
@@ -41,10 +41,10 @@ import java.util.TreeMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
-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.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
@@ -55,7 +55,7 @@ import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.network.NetworkUtil;
-public class HttpClientTest {
+class HttpClientTest {
private static final String TEST_HTTP_NO_AUTH_CLIENT = "testHttpNoAuthClient";
private static final String TEST_HTTP_AUTH_CLIENT = "testHttpAuthClient";
private static final String LOCALHOST = "localhost";
@@ -75,7 +75,7 @@ public class HttpClientTest {
*
* @throws InterruptedException can be interrupted
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws InterruptedException {
/* echo server - http + no auth */
@@ -136,7 +136,7 @@ public class HttpClientTest {
/**
* Clear https clients and reset providers.
*/
- @Before
+ @BeforeEach
public void setUp() {
HttpClientFactoryInstance.getClientFactory().destroy();
@@ -146,7 +146,7 @@ public class HttpClientTest {
/**
* After the class is created method.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
HttpServletServerFactoryInstance.getServerFactory().destroy();
HttpClientFactoryInstance.getClientFactory().destroy();
@@ -187,7 +187,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpGetNoAuthClient() throws Exception {
+ void testHttpGetNoAuthClient() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
final Response response = client.get(HELLO);
@@ -198,7 +198,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpGetNoAuthClientAsync() throws Exception {
+ void testHttpGetNoAuthClientAsync() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
MyCallback callback = new MyCallback();
@@ -214,13 +214,13 @@ public class HttpClientTest {
private void verifyCallback(String testName, MyCallback callback, final Response response)
throws InterruptedException {
- assertTrue(testName, callback.await());
- assertNull(testName, callback.getThrowable());
- assertSame(testName, response, callback.getResponse());
+ assertTrue(callback.await(), testName);
+ assertNull(callback.getThrowable(), testName);
+ assertSame(response, callback.getResponse(), testName);
}
@Test
- public void testHttpPutNoAuthClient() throws Exception {
+ void testHttpPutNoAuthClient() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666);
Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
@@ -232,7 +232,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpPutNoAuthClientAsync() throws Exception {
+ void testHttpPutNoAuthClientAsync() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666);
Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
@@ -248,7 +248,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpPostNoAuthClient() throws Exception {
+ void testHttpPostNoAuthClient() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
@@ -261,7 +261,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpPostNoAuthClientAsync() throws Exception {
+ void testHttpPostNoAuthClientAsync() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
@@ -278,7 +278,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpDeletetNoAuthClient() throws Exception {
+ void testHttpDeletetNoAuthClient() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
@@ -290,7 +290,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpDeletetNoAuthClientAsync() throws Exception {
+ void testHttpDeletetNoAuthClientAsync() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
@@ -310,7 +310,7 @@ public class HttpClientTest {
* @throws Exception if an error occurs
*/
@Test
- public void testHttpAsyncAuthClient() throws Exception {
+ void testHttpAsyncAuthClient() throws Exception {
final HttpClient client = getAuthHttpClient();
MyCallback callback = new MyCallback();
@@ -325,7 +325,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpGetAuthClient() throws Exception {
+ void testHttpGetAuthClient() throws Exception {
final HttpClient client = getAuthHttpClient();
final Response response = client.get(HELLO);
@@ -336,7 +336,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpPutAuthClient() throws Exception {
+ void testHttpPutAuthClient() throws Exception {
final HttpClient client = getAuthHttpClient();
Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
@@ -348,7 +348,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpPutAuthClient_GsonProvider() throws Exception {
+ void testHttpPutAuthClient_GsonProvider() throws Exception {
final HttpClient client = HttpClientFactoryInstance.getClientFactory()
.build(BusTopicParams.builder().clientName(TEST_HTTP_AUTH_CLIENT).useHttps(true)
.allowSelfSignedCerts(true).hostname(LOCALHOST).port(6667).basePath(JUNIT_ECHO)
@@ -366,7 +366,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpAuthClient401() throws Exception {
+ void testHttpAuthClient401() throws Exception {
final HttpClient client = getNoAuthHttpClient("testHttpAuthClient401", true,
6667);
final Response response = client.get(HELLO);
@@ -374,7 +374,7 @@ public class HttpClientTest {
}
@Test
- public void testHttpAuthClientProps() throws Exception {
+ void testHttpAuthClientProps() throws Exception {
final Properties httpProperties = new Properties();
/* PAP and PDP services */
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpExceptionsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpExceptionsTest.java
index 85135759..aaa9c489 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpExceptionsTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpExceptionsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. 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,14 +21,14 @@
package org.onap.policy.common.endpoints.http.server.test;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class HttpExceptionsTest extends ExceptionsTester {
+class HttpExceptionsTest extends ExceptionsTester {
@Test
- public void testHttpClientConfigException() {
+ void testHttpClientConfigException() {
test(HttpClientConfigException.class);
}
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
index 8a2574e1..818851ff 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
@@ -26,10 +26,10 @@ 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.assertj.core.api.Assertions.catchThrowable;
-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.assertTrue;
import com.google.gson.Gson;
import io.prometheus.client.servlet.jakarta.exporter.MetricsServlet;
@@ -43,9 +43,9 @@ import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
@@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
/**
* HttpServletServer JUNIT tests.
*/
-public class HttpServerTest {
+class HttpServerTest {
private static final String JVM_MEMORY_BYTES_USED = "jvm_memory_bytes_used";
private static final String METRICS_URI = "/metrics";
private static final String PROMETHEUS = "prometheus";
@@ -90,7 +90,7 @@ public class HttpServerTest {
/**
* Increments the port number, clears the servers, and resets the providers.
*/
- @Before
+ @BeforeEach
public void setUp() {
incrementPort();
portUrl = LOCALHOST_PREFIX + port;
@@ -108,7 +108,7 @@ public class HttpServerTest {
/**
* To delete temporary properties cadi_longitude,and cadi_latitude.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
HttpServletServerFactoryInstance.getServerFactory().destroy();
System.clearProperty("cadi_longitude");
@@ -116,7 +116,7 @@ public class HttpServerTest {
}
@Test
- public void testDefaultPackageServer() throws Exception {
+ void testDefaultPackageServer() throws Exception {
logger.info("-- testDefaultPackageServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -137,7 +137,7 @@ public class HttpServerTest {
}
@Test
- public void testGsonPackageServer() throws Exception {
+ void testGsonPackageServer() throws Exception {
logger.info("-- testGsonPackageServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -166,7 +166,7 @@ public class HttpServerTest {
}
@Test
- public void testYamlPackageServer() throws Exception {
+ void testYamlPackageServer() throws Exception {
logger.info("-- testYamlPackageServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -197,7 +197,7 @@ public class HttpServerTest {
}
@Test
- public void testDefaultClassServer() throws Exception {
+ void testDefaultClassServer() throws Exception {
logger.info("-- testDefaultClassServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -221,7 +221,7 @@ public class HttpServerTest {
* This test checks a server from a plain java servlet (note it uses prometheus as the sample server).
*/
@Test
- public void testStdServletServer() throws Exception {
+ void testStdServletServer() throws Exception {
logger.info("-- testStdServletServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -241,7 +241,7 @@ public class HttpServerTest {
* This test explicitly creates a prometheus server.
*/
@Test
- public void testExplicitPrometheusServer() throws Exception {
+ void testExplicitPrometheusServer() throws Exception {
logger.info("-- testPrometheusServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -260,7 +260,7 @@ public class HttpServerTest {
* This test is an all-in-one for a single server: prometheus, jax-rs, servlet, swagger, and filters.
*/
@Test
- public void testPrometheusJaxRsFilterSwaggerServer() throws Exception {
+ void testPrometheusJaxRsFilterSwaggerServer() throws Exception {
logger.info("-- testPrometheusServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -291,7 +291,7 @@ public class HttpServerTest {
}
@Test
- public void testJacksonClassServer() throws Exception {
+ void testJacksonClassServer() throws Exception {
logger.info("-- testJacksonClassServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -318,7 +318,7 @@ public class HttpServerTest {
}
@Test
- public void testGsonClassServer() throws Exception {
+ void testGsonClassServer() throws Exception {
logger.info("-- testGsonClassServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -346,7 +346,7 @@ public class HttpServerTest {
}
@Test
- public void testYamlClassServer() throws Exception {
+ void testYamlClassServer() throws Exception {
logger.info("-- testYamlClassServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -376,7 +376,7 @@ public class HttpServerTest {
}
@Test
- public void testSerialize() {
+ void testSerialize() {
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
.build("echo", LOCALHOST, port, "/", false, true);
server.addServletPackage("/*", this.getClass().getPackage().getName());
@@ -388,7 +388,7 @@ public class HttpServerTest {
}
@Test
- public void testSingleServer() throws Exception {
+ void testSingleServer() throws Exception {
logger.info("-- testSingleServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
@@ -415,7 +415,7 @@ public class HttpServerTest {
}
@Test
- public void testMultipleServers() throws Exception {
+ void testMultipleServers() throws Exception {
logger.info("-- testMultipleServers() --");
HttpServletServer server1 = HttpServletServerFactoryInstance.getServerFactory()
@@ -449,7 +449,7 @@ public class HttpServerTest {
}
@Test
- public void testMultiServicePackage() throws Exception {
+ void testMultiServicePackage() throws Exception {
logger.info("-- testMultiServicePackage() --");
String randomName = UUID.randomUUID().toString();
@@ -472,7 +472,7 @@ public class HttpServerTest {
}
@Test
- public void testServiceClass() throws Exception {
+ void testServiceClass() throws Exception {
logger.info("-- testServiceClass() --");
String randomName = UUID.randomUUID().toString();
@@ -491,7 +491,7 @@ public class HttpServerTest {
}
@Test
- public void testMultiServiceClass() throws Exception {
+ void testMultiServiceClass() throws Exception {
logger.info("-- testMultiServiceClass() --");
String randomName = UUID.randomUUID().toString();
@@ -515,7 +515,7 @@ public class HttpServerTest {
}
@Test
- public void testSingleStaticResourceServer() throws Exception {
+ void testSingleStaticResourceServer() throws Exception {
logger.info("-- testSingleStaticResourceServer() --");
HttpServletServer staticServer = HttpServletServerFactoryInstance.getServerFactory()
@@ -553,7 +553,7 @@ public class HttpServerTest {
}
@Test
- public void testMultiStaticResourceServer() throws Exception {
+ void testMultiStaticResourceServer() throws Exception {
logger.info("-- testMultiStaticResourceServer() --");
HttpServletServer staticResourceServer = HttpServletServerFactoryInstance.getServerFactory()
@@ -580,7 +580,7 @@ public class HttpServerTest {
}
@Test
- public void testMultiTypesServer() throws Exception {
+ void testMultiTypesServer() throws Exception {
logger.info("-- testMultiTypesServer() --");
HttpServletServer staticResourceServer = HttpServletServerFactoryInstance.getServerFactory()
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/JsonExceptionMapperTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/JsonExceptionMapperTest.java
index 27e98670..e1441908 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/JsonExceptionMapperTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/JsonExceptionMapperTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 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,26 +21,26 @@
package org.onap.policy.common.endpoints.http.server.test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.JsonSyntaxException;
import jakarta.ws.rs.core.Response;
-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.endpoints.http.server.JsonExceptionMapper;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-public class JsonExceptionMapperTest {
+class JsonExceptionMapperTest {
private JsonExceptionMapper mapper;
- @Before
+ @BeforeEach
public void setUp() {
mapper = new JsonExceptionMapper();
}
@Test
- public void testToResponse() throws CoderException {
+ void testToResponse() throws CoderException {
JsonSyntaxException ex = new JsonSyntaxException("expected exception");
Response resp = mapper.toResponse(ex);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestServerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestServerTest.java
index a789a66f..18030409 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestServerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestServerTest.java
@@ -24,12 +24,11 @@ package org.onap.policy.common.endpoints.http.server.test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -54,10 +53,10 @@ import java.util.List;
import java.util.Properties;
import lombok.Getter;
import org.apache.commons.io.IOUtils;
-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.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactory;
@@ -73,7 +72,7 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.springframework.test.util.ReflectionTestUtils;
-public class RestServerTest {
+class RestServerTest {
private static final String METRICS_URI = "/metrics";
private static final String SERVER1 = "my-server-A";
private static final String SERVER2 = "my-server-B";
@@ -100,7 +99,7 @@ public class RestServerTest {
* Starts the REST server.
* @throws Exception if an error occurs
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
saveFactory = (Factory) ReflectionTestUtils.getField(RestServer.class, FACTORY_FIELD);
@@ -128,7 +127,7 @@ public class RestServerTest {
/**
* Restores the factory and stops the REST server.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
ReflectionTestUtils.setField(RestServer.class, FACTORY_FIELD, saveFactory);
@@ -138,7 +137,7 @@ public class RestServerTest {
/**
* Initializes mocks.
*/
- @Before
+ @BeforeEach
public void setUp() {
server1 = mock(HttpServletServer.class);
server2 = mock(HttpServletServer.class);
@@ -157,7 +156,7 @@ public class RestServerTest {
}
@Test
- public void testRestServer() {
+ void testRestServer() {
rest = new RestServer(params, Filter2.class, Provider1.class, Provider2.class);
rest.start();
@@ -170,7 +169,7 @@ public class RestServerTest {
}
@Test
- public void testRestServerListList() {
+ void testRestServerListList() {
rest = new RestServer(params, List.of(Filter2.class), List.of(Provider1.class, Provider2.class));
rest.start();
@@ -183,12 +182,12 @@ public class RestServerTest {
}
@Test
- public void testRestServer_MissingProviders() {
+ void testRestServer_MissingProviders() {
assertThatIllegalArgumentException().isThrownBy(() -> new RestServer(params, List.of(Filter2.class), null));
}
@Test
- public void testGetServerProperties_testGetProviderNames() {
+ void testGetServerProperties_testGetProviderNames() {
rest = new RestServer(params, Provider1.class, Provider2.class);
ArgumentCaptor<Properties> cap = ArgumentCaptor.forClass(Properties.class);
@@ -214,7 +213,7 @@ public class RestServerTest {
}
@Test
- public void testExplicitPrometheusAddedToProperty() {
+ void testExplicitPrometheusAddedToProperty() {
when(params.isPrometheus()).thenReturn(true);
rest = new RestServer(params, Filter2.class, Provider1.class, Provider2.class);
ArgumentCaptor<Properties> cap = ArgumentCaptor.forClass(Properties.class);
@@ -229,7 +228,7 @@ public class RestServerTest {
}
@Test
- public void testStandardServletAddedToProperty() {
+ void testStandardServletAddedToProperty() {
when(params.getServletUriPath()).thenReturn("/metrics");
when(params.getServletClass()).thenReturn(MetricsServlet.class.getName());
rest = new RestServer(params, Filter2.class, Provider1.class, Provider2.class);
@@ -247,7 +246,7 @@ public class RestServerTest {
}
@Test
- public void testInvalidJson() throws Exception {
+ void testInvalidJson() throws Exception {
initRealParams();
assertEquals(200, roundTrip(new StandardCoder().encode(new MyRequest())));
@@ -256,7 +255,7 @@ public class RestServerTest {
}
@Test
- public void testInvalidYaml() throws Exception {
+ void testInvalidYaml() throws Exception {
initRealParams();
assertEquals(200, roundTrip(new StandardCoder().encode(new MyRequest()),
@@ -297,13 +296,13 @@ public class RestServerTest {
}
@Test
- public void testToString() {
+ void testToString() {
rest = new RestServer(params, Filter2.class, Provider1.class, Provider2.class);
assertNotNull(rest.toString());
}
@Test
- public void testFactory() {
+ void testFactory() {
assertNotNull(saveFactory);
assertNotNull(saveFactory.getServerFactory());
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java
index 5317eadb..b5dcb182 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 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,26 +21,26 @@
package org.onap.policy.common.endpoints.http.server.test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.core.Response;
-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.endpoints.http.server.YamlExceptionMapper;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.yaml.snakeyaml.error.YAMLException;
-public class YamlExceptionMapperTest {
+class YamlExceptionMapperTest {
private YamlExceptionMapper mapper;
- @Before
+ @BeforeEach
public void setUp() {
mapper = new YamlExceptionMapper();
}
@Test
- public void testToResponse() throws CoderException {
+ void testToResponse() throws CoderException {
YAMLException ex = new YAMLException("expected exception");
Response resp = mapper.toResponse(ex);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlJacksonHandlerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlJacksonHandlerTest.java
index b2b81c26..01e9fdc5 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlJacksonHandlerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlJacksonHandlerTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 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,9 +21,9 @@
package org.onap.policy.common.endpoints.http.server.test;
-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.assertTrue;
import com.google.gson.JsonObject;
import jakarta.ws.rs.core.MediaType;
@@ -34,16 +34,16 @@ import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.server.YamlJacksonHandler;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
-public class YamlJacksonHandlerTest {
+class YamlJacksonHandlerTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
YamlJacksonHandler hdlr = new YamlJacksonHandler();
assertTrue(hdlr.isReadable(null, null, null, MediaType.valueOf(YamlMessageBodyHandler.APPLICATION_YAML)));
@@ -83,7 +83,7 @@ public class YamlJacksonHandlerTest {
}
@Test
- public void testMapDouble() throws Exception {
+ void testMapDouble() throws Exception {
MyMap map = new MyMap();
map.props = new HashMap<>();
map.props.put("plainString", "def");
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
index 962c09db..1c7f5245 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 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.common.endpoints.http.server.test;
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.assertTrue;
import jakarta.ws.rs.core.MediaType;
import java.io.ByteArrayInputStream;
@@ -35,12 +35,12 @@ import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import lombok.ToString;
-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.endpoints.http.server.YamlMessageBodyHandler;
import org.yaml.snakeyaml.error.YAMLException;
-public class YamlMessageBodyHandlerTest {
+class YamlMessageBodyHandlerTest {
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String GEN_TYPE = "some-type";
@@ -54,15 +54,15 @@ public class YamlMessageBodyHandlerTest {
private YamlMessageBodyHandler hdlr;
- @Before
+ @BeforeEach
public void setUp() {
hdlr = new YamlMessageBodyHandler();
}
@Test
- public void testIsWriteable() {
+ void testIsWriteable() {
for (String subtype : subtypes) {
- assertTrue("writeable " + subtype, hdlr.isWriteable(null, null, null, new MediaType(GEN_TYPE, subtype)));
+ assertTrue(hdlr.isWriteable(null, null, null, new MediaType(GEN_TYPE, subtype)), "writeable " + subtype);
}
@@ -79,12 +79,12 @@ public class YamlMessageBodyHandlerTest {
}
@Test
- public void testGetSize() {
+ void testGetSize() {
assertEquals(-1, hdlr.getSize(null, null, null, null, null));
}
@Test
- public void testWriteTo_testReadFrom() throws Exception {
+ void testWriteTo_testReadFrom() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
MyObject obj1 = new MyObject(10);
hdlr.writeTo(obj1, obj1.getClass(), CLASS_OBJ, null, null, null, outstr);
@@ -95,7 +95,7 @@ public class YamlMessageBodyHandlerTest {
}
@Test
- public void testWriteTo_DifferentTypes() throws Exception {
+ void testWriteTo_DifferentTypes() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
// use a derived type, but specify the base type when writing
@@ -108,7 +108,7 @@ public class YamlMessageBodyHandlerTest {
}
@Test
- public void testWriteTo_Ex() throws Exception {
+ void testWriteTo_Ex() throws Exception {
OutputStream outstr = new OutputStream() {
@Override
public void write(int value) throws IOException {
@@ -124,9 +124,9 @@ public class YamlMessageBodyHandlerTest {
}
@Test
- public void testIsReadable() {
+ void testIsReadable() {
for (String subtype : subtypes) {
- assertTrue("readable " + subtype, hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, subtype)));
+ assertTrue(hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, subtype)), "readable " + subtype);
}
@@ -143,7 +143,7 @@ public class YamlMessageBodyHandlerTest {
}
@Test
- public void testReadFrom_DifferentTypes() throws Exception {
+ void testReadFrom_DifferentTypes() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
MyObject obj1 = new MyObject(10);
hdlr.writeTo(obj1, obj1.getClass(), CLASS_OBJ, null, null, null, outstr);
@@ -161,7 +161,7 @@ public class YamlMessageBodyHandlerTest {
}
@Test
- public void testReadFrom_Ex() throws Exception {
+ void testReadFrom_Ex() throws Exception {
InputStream inpstr = new InputStream() {
@Override
public int read() throws IOException {
@@ -176,7 +176,7 @@ public class YamlMessageBodyHandlerTest {
}
@Test
- public void testReadFrom_Invalid() throws Exception {
+ void testReadFrom_Invalid() throws Exception {
InputStream inpstr = new ByteArrayInputStream("plain text".getBytes());
assertThatThrownBy(() -> hdlr.readFrom(CLASS_OBJ, CLASS_OBJ, null, null, null, inpstr))
@@ -186,7 +186,7 @@ public class YamlMessageBodyHandlerTest {
}
@Test
- public void testMapDouble() throws Exception {
+ void testMapDouble() throws Exception {
MyMap map = new MyMap();
map.props = new HashMap<>();
map.props.put("plainString", "def");
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java
index 54f49077..11cd3c56 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. 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,8 +21,8 @@
package org.onap.policy.common.endpoints.listeners;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
@@ -30,17 +31,17 @@ import static org.mockito.Mockito.verify;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-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.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
-public class JsonListenerTest {
+class JsonListenerTest {
/**
* Used to attach an appender to the class' logger.
@@ -62,7 +63,7 @@ public class JsonListenerTest {
/**
* Initializes statics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveLevel = logger.getLevel();
logger.setLevel(Level.INFO);
@@ -71,7 +72,7 @@ public class JsonListenerTest {
appender.start();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
logger.setLevel(saveLevel);
appender.stop();
@@ -80,7 +81,7 @@ public class JsonListenerTest {
/**
* Initializes mocks and a listener.
*/
- @Before
+ @BeforeEach
public void setUp() {
appender.clearExtractions();
@@ -92,13 +93,13 @@ public class JsonListenerTest {
};
}
- @After
+ @AfterEach
public void tearDown() {
logger.detachAppender(appender);
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
logger.addAppender(appender);
primary = spy(primary);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/MessageTypeDispatcherTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/MessageTypeDispatcherTest.java
index e4c84f3a..95dd9f53 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/MessageTypeDispatcherTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/MessageTypeDispatcherTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. 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,8 +21,8 @@
package org.onap.policy.common.endpoints.listeners;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@@ -31,17 +32,17 @@ import static org.mockito.Mockito.verify;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-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.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
-public class MessageTypeDispatcherTest {
+class MessageTypeDispatcherTest {
/**
* Used to attach an appender to the class' logger.
@@ -68,7 +69,7 @@ public class MessageTypeDispatcherTest {
/**
* Initializes statics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveLevel = logger.getLevel();
logger.setLevel(Level.INFO);
@@ -77,7 +78,7 @@ public class MessageTypeDispatcherTest {
appender.start();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
logger.setLevel(saveLevel);
appender.stop();
@@ -86,7 +87,7 @@ public class MessageTypeDispatcherTest {
/**
* Initializes mocks and a listener.
*/
- @Before
+ @BeforeEach
@SuppressWarnings("unchecked")
public void setUp() {
appender.clearExtractions();
@@ -97,13 +98,13 @@ public class MessageTypeDispatcherTest {
primary = new MessageTypeDispatcher(TYPE_FIELD);
}
- @After
+ @AfterEach
public void tearDown() {
logger.detachAppender(appender);
}
@Test
- public void testRegister_testUnregister() {
+ void testRegister_testUnregister() {
primary.register(TYPE1, secondary1);
primary.register(TYPE2, secondary2);
@@ -136,7 +137,7 @@ public class MessageTypeDispatcherTest {
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
primary.register(TYPE1, secondary1);
logger.addAppender(appender);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/RequestIdDispatcherTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/RequestIdDispatcherTest.java
index d71d413e..1158a4c9 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/RequestIdDispatcherTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/RequestIdDispatcherTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. 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.
@@ -21,8 +22,8 @@
package org.onap.policy.common.endpoints.listeners;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -31,11 +32,11 @@ import static org.mockito.Mockito.verify;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-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.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -44,7 +45,7 @@ import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
-public class RequestIdDispatcherTest {
+class RequestIdDispatcherTest {
/**
* Used to attach an appender to the class' logger.
@@ -75,7 +76,7 @@ public class RequestIdDispatcherTest {
/**
* Initializes statics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveLevel = logger.getLevel();
logger.setLevel(Level.INFO);
@@ -84,7 +85,7 @@ public class RequestIdDispatcherTest {
appender.start();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
logger.setLevel(saveLevel);
appender.stop();
@@ -94,7 +95,7 @@ public class RequestIdDispatcherTest {
* Create various mocks and primary listener.
*/
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() {
appender.clearExtractions();
@@ -106,13 +107,13 @@ public class RequestIdDispatcherTest {
primary = new RequestIdDispatcher<>(MyMessage.class, REQID_FIELD);
}
- @After
+ @AfterEach
public void tearDown() {
logger.detachAppender(appender);
}
@Test
- public void testRegisterMessageListener() {
+ void testRegisterMessageListener() {
primary.register(secondary1);
// should process message that does not have a request id
@@ -131,7 +132,7 @@ public class RequestIdDispatcherTest {
}
@Test
- public void testRegisterStringMessageListener() {
+ void testRegisterStringMessageListener() {
primary.register(REQID1, secondary1);
// should NOT process message that does not have a request id
@@ -161,7 +162,7 @@ public class RequestIdDispatcherTest {
}
@Test
- public void testUnregisterMessageListener() {
+ void testUnregisterMessageListener() {
primary.register(secondary1);
primary.register(secondary2);
@@ -182,7 +183,7 @@ public class RequestIdDispatcherTest {
}
@Test
- public void testUnregisterString() {
+ void testUnregisterString() {
primary.register(REQID1, secondary1);
primary.register(REQID2, secondary2);
@@ -204,7 +205,7 @@ public class RequestIdDispatcherTest {
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
primary.register(REQID1, secondary1);
primary.register(REQID2, secondary2);
primary.register(secondary3);
@@ -228,7 +229,7 @@ public class RequestIdDispatcherTest {
}
@Test
- public void testOfferToListener() {
+ void testOfferToListener() {
logger.addAppender(appender);
// no listener for this
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java
index a782e4b2..4236a77c 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. 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,19 @@
package org.onap.policy.common.endpoints.listeners;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-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.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -41,7 +42,7 @@ import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
-public class ScoListenerTest {
+class ScoListenerTest {
/**
* Used to attach an appender to the class' logger.
@@ -67,7 +68,7 @@ public class ScoListenerTest {
/**
* Initializes statics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveLevel = logger.getLevel();
logger.setLevel(Level.INFO);
@@ -76,7 +77,7 @@ public class ScoListenerTest {
appender.start();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
logger.setLevel(saveLevel);
appender.stop();
@@ -85,7 +86,7 @@ public class ScoListenerTest {
/**
* Create various mocks and primary handler.
*/
- @Before
+ @BeforeEach
public void setUp() {
appender.clearExtractions();
@@ -98,13 +99,13 @@ public class ScoListenerTest {
};
}
- @After
+ @AfterEach
public void tearDown() {
logger.detachAppender(appender);
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
primary = spy(primary);
status = new MyMessage(NAME);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestClientParametersTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestClientParametersTest.java
new file mode 100644
index 00000000..6013ff2d
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestClientParametersTest.java
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.parameters;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
+
+class RestClientParametersTest {
+
+ private RestClientParameters params;
+
+ @BeforeEach
+ void setUp() {
+ params = new RestClientParameters();
+ }
+
+ @Test
+ void testValidate_ValidParameters() {
+ params.setHostname("localhost");
+ params.setClientName("testClient");
+ params.setPort(8080);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.CLEAN, result.getStatus(), "Expected the parameters to be valid");
+ assertNull(result.getResult(), "Expected no validation errors");
+ }
+
+ @Test
+ void testValidate_InvalidHostname() {
+ params.setHostname("");
+ params.setClientName("testClient");
+ params.setPort(8080);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
+ assertTrue(result.getResult().contains("hostname") && result.getResult().contains("is blank"),
+ "Expected invalid hostname error message");
+ }
+
+ @Test
+ void testValidate_InvalidClientName() {
+ params.setHostname("localhost");
+ params.setClientName("");
+ params.setPort(8080);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
+ assertTrue(result.getResult().contains("clientName") && result.getResult().contains("is blank"),
+ "Expected invalid clientName error message");
+ }
+
+ @Test
+ void testValidate_InvalidPort() {
+ params.setHostname("localhost");
+ params.setClientName("testClient");
+ params.setPort(-1);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
+ assertTrue(result.getResult().contains("port") && result.getResult().contains("is not valid"),
+ "Expected invalid port error message");
+ }
+
+ @Test
+ void testValidate_MultipleInvalidParameters() {
+ params.setHostname("");
+ params.setClientName("");
+ params.setPort(-1);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
+
+ assertTrue(result.getResult().contains("hostname") && result.getResult().contains("is blank"),
+ "Expected invalid hostname error message");
+
+ assertTrue(result.getResult().contains("clientName") && result.getResult().contains("is blank"),
+ "Expected invalid clientName error message");
+
+ assertTrue(result.getResult().contains("port") && result.getResult().contains("is not valid"),
+ "Expected invalid port error message");
+ }
+
+ @Test
+ void testGetAndSetName() {
+ String name = "testClient";
+ params.setName(name);
+ assertEquals(name, params.getName(), "Expected the client name to be set and retrieved correctly");
+ }
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java
index 9f03150e..6492b900 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2024 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,12 +22,12 @@
package org.onap.policy.common.endpoints.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -37,13 +37,13 @@ import org.onap.policy.common.utils.coder.StandardCoder;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class RestServerParametersTest {
+class RestServerParametersTest {
private static CommonTestData testData = new CommonTestData();
private static final Coder coder = new StandardCoder();
@Test
- public void test() {
+ void test() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
final ValidationResult validationResult = restServerParameters.validate();
@@ -57,7 +57,7 @@ public class RestServerParametersTest {
}
@Test
- public void testValidate() {
+ void testValidate() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
final ValidationResult result = restServerParameters.validate();
@@ -66,7 +66,7 @@ public class RestServerParametersTest {
}
@Test
- public void test_valid() throws Exception {
+ void test_valid() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json");
RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
@@ -76,7 +76,7 @@ public class RestServerParametersTest {
}
@Test
- public void test_invalid() throws Exception {
+ void test_invalid() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json");
RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java
index 62f86d41..a81263a9 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2024 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,17 +21,17 @@
package org.onap.policy.common.endpoints.parameters;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
@@ -43,12 +43,12 @@ import org.onap.policy.common.utils.coder.StandardCoder;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TopicParameterGroupTest {
+class TopicParameterGroupTest {
private static CommonTestData testData = new CommonTestData();
private static final Coder coder = new StandardCoder();
@Test
- public void test() throws CoderException {
+ void test() throws CoderException {
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
final ValidationResult validationResult = topicParameterGroup.validate();
@@ -65,7 +65,7 @@ public class TopicParameterGroupTest {
}
@Test
- public void testValidate() {
+ void testValidate() {
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
final ValidationResult result = topicParameterGroup.validate();
@@ -74,7 +74,7 @@ public class TopicParameterGroupTest {
}
@Test
- public void test_valid() throws Exception {
+ void test_valid() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
@@ -84,7 +84,7 @@ public class TopicParameterGroupTest {
}
@Test
- public void test_invalid() throws Exception {
+ void test_invalid() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
@@ -94,7 +94,7 @@ public class TopicParameterGroupTest {
}
@Test
- public void test_missing_mandatory_params() throws Exception {
+ void test_missing_mandatory_params() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_missing_mandatory.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
@@ -104,7 +104,7 @@ public class TopicParameterGroupTest {
}
@Test
- public void test_allparams() throws Exception {
+ void test_allparams() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_all_params.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java
index 36970d74..62db30b2 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. 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.
@@ -28,7 +29,7 @@ import com.openpojo.validation.rule.impl.GetterMustExistRule;
import com.openpojo.validation.rule.impl.SetterMustExistRule;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ToStringTester;
/**
@@ -36,10 +37,10 @@ import org.onap.policy.common.utils.test.ToStringTester;
*
* @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
*/
-public class TestHealthCheckReport {
+class TestHealthCheckReport {
@Test
- public void testHealthCheckReport() {
+ void testHealthCheckReport() {
final Validator validator =
ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
.with(new GetterTester()).with(new SetterTester()).with(new ToStringTester()).build();
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/KafkaPropertyUtilsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/KafkaPropertyUtilsTest.java
new file mode 100644
index 00000000..52caa470
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/KafkaPropertyUtilsTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-endpoints
+ * ================================================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.utils;
+
+import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_ADDITIONAL_PROPS_SUFFIX;
+
+import java.util.Properties;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class KafkaPropertyUtilsTest {
+
+ @Test
+ void test() {
+ var properties = new Properties();
+ properties.setProperty("mytopic" + PROPERTY_ADDITIONAL_PROPS_SUFFIX, "{444-");
+ PropertyUtils props = new PropertyUtils(properties, "mytopic", null);
+
+ var build = KafkaPropertyUtils.makeBuilder(props, "mytopic", "servers").build();
+ Assertions.assertTrue(build.getAdditionalProps().isEmpty());
+
+ properties.setProperty("mytopic" + PROPERTY_ADDITIONAL_PROPS_SUFFIX,
+ "{\"security.protocol\": \"SASL_PLAINTEXT\"}");
+ build = KafkaPropertyUtils.makeBuilder(props, "mytopic", "servers").build();
+ Assertions.assertTrue(build.getAdditionalProps().containsKey("security.protocol"));
+
+ properties.setProperty("mytopic" + PROPERTY_ADDITIONAL_PROPS_SUFFIX,
+ "{\"security.protocol\": false }");
+ build = KafkaPropertyUtils.makeBuilder(props, "mytopic", "servers").build();
+ Assertions.assertTrue(build.getAdditionalProps().isEmpty());
+
+ properties.setProperty("mytopic" + PROPERTY_ADDITIONAL_PROPS_SUFFIX, "");
+ build = KafkaPropertyUtils.makeBuilder(props, "mytopic", "servers").build();
+ Assertions.assertTrue(build.getAdditionalProps().isEmpty());
+ }
+
+} \ No newline at end of file
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java
index 1e8c0316..123d1a77 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. 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,15 +21,15 @@
package org.onap.policy.common.endpoints.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.features.NetLoggerFeatureApi;
import org.onap.policy.common.endpoints.features.NetLoggerFeatureProviders;
@@ -38,7 +39,7 @@ import org.slf4j.Logger;
/**
* Test class for network log utilities such as logging and feature invocation.
*/
-public class NetLoggerUtilTest {
+class NetLoggerUtilTest {
private static final String TEST_TOPIC = "test-topic";
private static final String MESSAGE = "hello world!";
@@ -50,7 +51,7 @@ public class NetLoggerUtilTest {
/**
* Obtains the test implementation of NetLoggerFeatureApi.
*/
- @BeforeClass
+ @BeforeAll
public static void setUp() {
netLoggerFeature = (NetLoggerFeature) NetLoggerFeatureProviders.getProviders().getList().get(0);
}
@@ -58,7 +59,7 @@ public class NetLoggerUtilTest {
/**
* Clears events list and resets return/exceptions flags before invoking every unit test.
*/
- @Before
+ @BeforeEach
public void reset() {
TestAppender.clear();
netLoggerFeature.setReturnValue(false, false);
@@ -69,7 +70,7 @@ public class NetLoggerUtilTest {
* Tests obtaining the network logger instance.
*/
@Test
- public void getNetworkLoggerTest() {
+ void getNetworkLoggerTest() {
assertEquals("network", NetLoggerUtil.getNetworkLogger().getName());
}
@@ -77,7 +78,7 @@ public class NetLoggerUtilTest {
* Tests logging a message to the network logger and invoking features before/after logging.
*/
@Test
- public void logTest() {
+ void logTest() {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
}
@@ -86,7 +87,7 @@ public class NetLoggerUtilTest {
* Tests that the network logger is used to log messages if a logger is not passed in.
*/
@Test
- public void logDefaultTest() {
+ void logDefaultTest() {
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
assertEquals("network", TestAppender.events.get(0).getLoggerName());
@@ -96,7 +97,7 @@ public class NetLoggerUtilTest {
* Tests a NetLoggerFeature that replaces base implementation before logging.
*/
@Test
- public void beforeLogReturnTrueTest() {
+ void beforeLogReturnTrueTest() {
netLoggerFeature.setReturnValue(true, false);
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(1, TestAppender.events.size());
@@ -106,7 +107,7 @@ public class NetLoggerUtilTest {
* Tests a NetLoggerFeature that post processes a logged message.
*/
@Test
- public void afterLogReturnTrueTest() {
+ void afterLogReturnTrueTest() {
netLoggerFeature.setReturnValue(false, true);
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
@@ -116,7 +117,7 @@ public class NetLoggerUtilTest {
* Tests throwing an exception in the before hook.
*/
@Test
- public void beforeLogExceptionTest() {
+ void beforeLogExceptionTest() {
netLoggerFeature.setExceptions(true, false);
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(2, TestAppender.events.size());
@@ -126,7 +127,7 @@ public class NetLoggerUtilTest {
* Tests throwing an exception in the after hook.
*/
@Test
- public void afterLogExceptionTest() {
+ void afterLogExceptionTest() {
netLoggerFeature.setExceptions(false, true);
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(2, TestAppender.events.size());
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java
index f8665a90..a639382f 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 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,16 +21,16 @@
package org.onap.policy.common.endpoints.utils;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Properties;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class PropertyUtilsTest {
+class PropertyUtilsTest {
private static final String DFLT_STRING = "my-default";
private static final int DLFT_INT = 1000;
@@ -42,7 +42,7 @@ public class PropertyUtilsTest {
/**
* Initializes {@link #utils}.
*/
- @Before
+ @BeforeEach
public void setUp() {
Properties properties = new Properties();
properties.put("myPrefix.my-string", "some text");
@@ -66,7 +66,7 @@ public class PropertyUtilsTest {
}
@Test
- public void testGetString() {
+ void testGetString() {
assertEquals("some text", utils.getString(".my-string", DFLT_STRING));
assertEquals(DFLT_STRING, utils.getString(".empty-string", DFLT_STRING));
assertEquals(DFLT_STRING, utils.getString(".missing-string", DFLT_STRING));
@@ -77,7 +77,7 @@ public class PropertyUtilsTest {
}
@Test
- public void testGetBoolean() {
+ void testGetBoolean() {
assertTrue(utils.getBoolean(".my-bool", false));
assertFalse(utils.getBoolean(".my-bool2", true));
assertTrue(utils.getBoolean(".empty-bool", true));
@@ -90,7 +90,7 @@ public class PropertyUtilsTest {
}
@Test
- public void testGetInteger() {
+ void testGetInteger() {
assertEquals(100, utils.getInteger(".my-int", DLFT_INT));
assertEquals(200, utils.getInteger(".my-int2", DLFT_INT));
assertEquals(DLFT_INT, utils.getInteger(".empty-int", DLFT_INT));