aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event
diff options
context:
space:
mode:
Diffstat (limited to 'policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event')
-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
28 files changed, 722 insertions, 422 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('\'', '"'));