</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
+ <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
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.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.NoopTopicFactories;
import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicPropertyBuilder;
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";
/**
* Destroys all managed topics.
*/
- @After
+ @AfterEach
public void tearDown() {
NoopTopicFactories.getSinkFactory().destroy();
NoopTopicFactories.getSourceFactory().destroy();
}
@Test
- public void testSerialize() {
+ void testSerialize() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
}
@Test
- public void testAddTopicSourcesListOfTopicParameters() {
+ void testAddTopicSourcesListOfTopicParameters() {
TopicEndpoint manager = new TopicEndpointProxy();
List<TopicSource> sources = manager.addTopicSources(group.getTopicSources());
}
@Test
- public void testAddTopicSourcesProperties() {
+ void testAddTopicSourcesProperties() {
TopicEndpoint manager = new TopicEndpointProxy();
List<TopicSource> sources = manager.addTopicSources(configuration);
}
@Test
- public void testAddTopicSinksListOfTopicParameters() {
+ void testAddTopicSinksListOfTopicParameters() {
TopicEndpoint manager = new TopicEndpointProxy();
List<TopicSink> sinks = manager.addTopicSinks(group.getTopicSinks());
}
@Test
- public void testAddTopicSinksProperties() {
+ void testAddTopicSinksProperties() {
TopicEndpoint manager = new TopicEndpointProxy();
List<TopicSink> sinks = manager.addTopicSinks(configuration);
}
@Test
- public void testAddTopicsProperties() {
+ void testAddTopicsProperties() {
TopicEndpoint manager = new TopicEndpointProxy();
List<Topic> topics = manager.addTopics(configuration);
}
@Test
- public void testAddTopicsTopicParameterGroup() {
+ void testAddTopicsTopicParameterGroup() {
TopicEndpoint manager = new TopicEndpointProxy();
List<Topic> topics = manager.addTopics(group);
}
@Test
- public void testAddTopicsTopicParameterGroupNull() {
+ void testAddTopicsTopicParameterGroupNull() {
TopicEndpoint manager = new TopicEndpointProxy();
List<Topic> topics = manager.addTopics(new TopicParameterGroup());
}
@Test
- public void testLockSinks_lockSources_locked() {
+ void testLockSinks_lockSources_locked() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.lock();
for (Topic topic : manager.addTopics(group)) {
}
@Test
- public void testLockSinks_lockSources_unlocked() {
+ void testLockSinks_lockSources_unlocked() {
TopicEndpoint manager = new TopicEndpointProxy();
for (Topic topic : manager.addTopics(group)) {
assertFalse(topic.isLocked());
}
@Test
- public void testGetTopicSources() {
+ void testGetTopicSources() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
}
@Test
- public void testGetTopicSinks() {
+ void testGetTopicSinks() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
}
@Test
- public void testGetNoopTopicSources() {
+ void testGetNoopTopicSources() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
}
@Test
- public void testGetNoopTopicSinks() {
+ void testGetNoopTopicSinks() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSinks(configuration);
}
@Test
- public void testLifecycle() {
+ void testLifecycle() {
TopicEndpoint manager = new TopicEndpointProxy();
assertTrue(manager.start());
}
@Test
- public void testLock() {
+ void testLock() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.lock();
}
@Test
- public void testGetTopicSource() {
+ void testGetTopicSource() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
}
@Test
- public void testGetTopicSink() {
+ void testGetTopicSink() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSinks(configuration);
}
@Test
- public void testGetNoopTopicSource() {
+ void testGetNoopTopicSource() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSources(configuration);
}
@Test
- public void testGetNoopTopicSink() {
+ void testGetNoopTopicSink() {
TopicEndpoint manager = new TopicEndpointProxy();
manager.addTopicSinks(configuration);
* 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.
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;
/**
* Tests building a topic using BusTopicParams.
*/
- public void testBuildBusTopicParams() {
+ void testBuildBusTopicParams() {
initFactory();
// two unmanaged topics
/**
* 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()));
/**
* Tests building a topic using a list of servers and a topic.
*/
- public void testBuildListOfStringString() {
+ void testBuildListOfStringString() {
initFactory();
T item1 = buildTopic(servers, MY_TOPIC);
* 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());
}
@Override
- public void testBuildProperties_Variations() {
+ void testBuildProperties_Variations() {
super.testBuildProperties_Variations();
// check boolean properties that default to true
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);
}
}
* ============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.
public abstract class KafkaTopicFactoryTestBase<T extends Topic> extends BusTopicFactoryTestBase<T> {
@Override
- public void testBuildBusTopicParams_Ex() {
+ void testBuildBusTopicParams_Ex() {
super.testBuildBusTopicParams_Ex();
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_SINK_TOPICS;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
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";
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
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
@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());
@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 ["));
}
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());
}
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;
/**
* Creates the object to be tested.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
factory = new SourceFactory();
}
- @After
+ @AfterEach
public void tearDown() {
factory.destroy();
}
@Test
@Override
- public void testBuildProperties() {
+ void testBuildProperties() {
initFactory();
@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 ["));
}
* ============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.
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());
}
* 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.
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;
protected abstract boolean io(String message);
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
}
@Test
- public void testIo() {
+ void testIo() {
TopicListener listener = mock(TopicListener.class);
this.endpoint.register(listener);
this.endpoint.start();
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());
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);
}
}
* 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.
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;
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;
/**
* 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));
}
@Test
- public void testBuildListOfStringStringBoolean() {
+ void testBuildListOfStringStringBoolean() {
initFactory();
T item1 = buildTopic(servers, MY_TOPIC, true);
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());
@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();
}
* 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.
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() {
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(new NoopTopicSinkFactory().toString().startsWith("NoopTopicSinkFactory ["));
}
}
* 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.
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());
}
@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) {
* 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.
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() {
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(new NoopTopicSourceFactory().toString().startsWith("NoopTopicSourceFactory ["));
}
}
* 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.
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());
}
@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) {
* 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.
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;
/**
* Tests building a topic using varied Properties.
*/
- public void testBuildProperties_Variations() {
+ void testBuildProperties_Variations() {
initFactory();
// null topic list
/**
* 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
/**
* 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());
/**
* Tests exception cases with destroy(topic).
*/
- public void testDestroyString_Ex() {
+ void testDestroyString_Ex() {
// null topic
assertThatIllegalArgumentException().as("null topic").isThrownBy(() -> destroyTopic(null));
/**
* Tests the destroy() method.
*/
- public void testDestroy() {
+ void testDestroy() {
initFactory();
List<T> lst = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).build());
/**
* Tests exception cases with get(topic).
*/
- public void testGet_Ex() {
+ void testGet_Ex() {
// null topic
assertThatIllegalArgumentException().as("null topic").isThrownBy(() -> getTopic(null));
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;
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;
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;
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);
}
@Test
- public void testFetchingBusConsumerSleepAfterFetchFailure() throws InterruptedException {
+ void testFetchingBusConsumerSleepAfterFetchFailure() throws InterruptedException {
var cons = new FetchingBusConsumerImpl(makeBuilder().fetchTimeout(SHORT_TIMEOUT_MILLIS).build()) {
}
@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();
}
@Test
- public void testFetchNoMessages() throws IOException {
+ void testFetchNoMessages() {
KafkaConsumerWrapper kafkaConsumerWrapper = new KafkaConsumerWrapper(makeKafkaBuilder().build());
kafkaConsumerWrapper.consumer = mockedKafkaConsumer;
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);
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);
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());
}
* 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.
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();
}
@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"));
}
@Test
- public void testAllNullOrEmpty() {
+ void testAllNullOrEmpty() {
assertTrue(base.allNullOrEmpty());
assertTrue(base.allNullOrEmpty(""));
assertTrue(base.allNullOrEmpty(null, ""));
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());
}
@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);
}
@Test
- public void testValidators() {
+ void testValidators() {
BusTopicParams params = makeBuilder().build();
// test validity methods
}
@Test
- public void testInvertedValidators() {
+ void testInvertedValidators() {
assertFalse(makeBuilder().additionalProps(null).build().isAdditionalPropsValid());
assertTrue(makeBuilder().aftEnvironment("").build().isAftEnvironmentInvalid());
assertFalse(makeBuilder().apiKey("").build().isApiKeyValid());
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;
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();
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());
}
@Test
- public void testStart() {
+ void testStart() {
assertTrue(sink.start());
assertEquals(1, sink.initCount);
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;
}
@Test
- public void testSend() {
+ void testSend() {
sink.start();
BusPublisher pub = mock(BusPublisher.class);
sink.publisher = pub;
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");
}
@Test
- public void testShutdown() {
+ void testShutdown() {
BusPublisher pub = mock(BusPublisher.class);
sink.publisher = pub;
}
@Test
- public void testAnyNullOrEmpty() {
+ void testAnyNullOrEmpty() {
assertFalse(sink.anyNullOrEmpty());
assertFalse(sink.anyNullOrEmpty("any-none-null", "any-none-null-B"));
}
@Test
- public void testAllNullOrEmpty() {
+ void testAllNullOrEmpty() {
assertTrue(sink.allNullOrEmpty());
assertTrue(sink.allNullOrEmpty(""));
assertTrue(sink.allNullOrEmpty(null, ""));
}
@Test
- public void testToString() {
+ void testToString() {
assertTrue(sink.toString().startsWith("InlineBusTopicSink ["));
}
* ============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.
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();
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();
}
@Test
- public void testGetTopicCommInfrastructure() {
+ void testGetTopicCommInfrastructure() {
assertEquals(CommInfrastructure.KAFKA, sink.getTopicCommInfrastructure());
}
* 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.
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;
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;
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;
/**
* Creates the object to be tested, as well as various mocks.
*/
- @Before
+ @BeforeEach
@Override
public void setUp() {
super.setUp();
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);
}
@Test
- public void testUnregister() {
+ void testUnregister() {
TopicListener listener2 = mock(TopicListener.class);
source.register(listener);
source.register(listener2);
}
@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() {
}
@Test
- public void testSingleThreadedBusTopicSource() {
+ void testSingleThreadedBusTopicSource() {
// Note: if the value contains "-", it's probably a UUID
// verify that different wrappers can be built
}
@Test
- public void testStart() {
+ void testStart() {
source.start();
assertTrue(source.isAlive());
assertEquals(1, source.initCount);
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();
}
@Test
- public void testRun() throws Exception {
+ void testRun() throws Exception {
source.register(listener);
/*
}
@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();
}
@Test
- public void testGetFetchTimeout() {
+ void testGetFetchTimeout() {
assertEquals(MY_FETCH_TIMEOUT, source.getFetchTimeout());
}
@Test
- public void testGetFetchLimit() {
+ void testGetFetchLimit() {
assertEquals(MY_FETCH_LIMIT, source.getFetchLimit());
}
* 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.
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();
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());
}
* 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.
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;
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();
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());
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);
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);
}
@Test
- public void testLock_testUnlock() {
+ void testLock_testUnlock() {
assertFalse(base.isLocked());
assertTrue(base.lock());
assertEquals(0, base.startCount);
* 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;
* 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;
}
@Test
- public void testIsLocked() {
+ void testIsLocked() {
assertFalse(base.isLocked());
base.lock();
assertTrue(base.isLocked());
}
@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());
}
@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");
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(base.toString());
}
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;
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;
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;
/**
* Configures the endpoints.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
Properties props = new Properties();
props.setProperty("noop.sink.topics", SINK_TOPIC);
TopicEndpointManager.getManager().addTopicSources(props);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
// clear all topics after the tests
TopicEndpointManager.getManager().shutdown();
/**
* 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);
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());
* 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");
* Tests the "delegate" methods.
*/
@Test
- public void testDelegates() {
+ void testDelegates() {
assertTrue(client.send("hello"));
verify(sink).send("hello");
}
@Test
- public void testGetTopicEndpointManager() throws BidirectionalTopicClientException {
+ void testGetTopicEndpointManager() throws BidirectionalTopicClientException {
// use a real manager
client = new BidirectionalTopicClient(SINK_TOPIC, SOURCE_TOPIC);
assertNotNull(client.getTopicEndpointManager());
}
@Test
- public void testAwaitReceipt() throws Exception {
+ void testAwaitReceipt() throws Exception {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
}
@Test
- public void testAwaitReceipt_AlreadyDone() throws Exception {
+ void testAwaitReceipt_AlreadyDone() throws Exception {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
}
@Test
- public void testAwaitReceipt_MessageDoesNotMatch() throws Exception {
+ void testAwaitReceipt_MessageDoesNotMatch() throws Exception {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
}
@Test
- public void testAwaitReceipt_DecodeFails() throws Exception {
+ void testAwaitReceipt_DecodeFails() throws Exception {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
}
@Test
- public void testAwaitReceipt_Interrupted() throws InterruptedException {
+ void testAwaitReceipt_Interrupted() throws InterruptedException {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
}
@Test
- public void testAwaitReceipt_MultipleLoops() throws Exception {
+ void testAwaitReceipt_MultipleLoops() throws Exception {
context.start(theMessage);
// wait for multiple "send" calls
}
@Test
- public void testStop() throws InterruptedException {
+ void testStop() throws InterruptedException {
context.start(theMessage);
assertThat(context.awaitSend(1)).isTrue();
* 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.
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));
}
* 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.
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;
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;
*
* @throws Exception if an error occurs
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
sink = mock(TopicSink.class);
when(sink.send(anyString())).thenReturn(true);
TopicEndpointManager.getManager().addTopicSinks(props);
}
- @AfterClass
+ @AfterAll
public static void tearDown() {
// clear all topics after the tests
TopicEndpointManager.getManager().shutdown();
* Uses a real NO-OP topic sink.
*/
@Test
- public void testGetTopicSinks() throws Exception {
+ void testGetTopicSinks() throws Exception {
sink = TopicEndpointManager.getManager().getNoopTopicSink(TOPIC);
assertNotNull(sink);
}
@Test
- public void testTopicSinkClient() {
+ void testTopicSinkClient() {
// unknown topic -> should throw exception
sinks = new LinkedList<>();
assertThatThrownBy(() -> new TopicSinkClient2(TOPIC)).isInstanceOf(TopicSinkClientException.class)
}
@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());
}
@Test
- public void testSend() {
+ void testSend() {
client.send(Arrays.asList("abc", "def"));
verify(sink).send("['abc','def']".replace('\'', '"'));
package org.onap.policy.common.endpoints.http.server.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import io.prometheus.client.servlet.jakarta.exporter.MetricsServlet;
import jakarta.ws.rs.client.Entity;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.network.NetworkUtil;
-public class HttpClientTest {
+class HttpClientTest {
private static final String TEST_HTTP_NO_AUTH_CLIENT = "testHttpNoAuthClient";
private static final String TEST_HTTP_AUTH_CLIENT = "testHttpAuthClient";
private static final String LOCALHOST = "localhost";
*
* @throws InterruptedException can be interrupted
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws InterruptedException {
/* echo server - http + no auth */
/**
* Clear https clients and reset providers.
*/
- @Before
+ @BeforeEach
public void setUp() {
HttpClientFactoryInstance.getClientFactory().destroy();
/**
* After the class is created method.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
HttpServletServerFactoryInstance.getServerFactory().destroy();
HttpClientFactoryInstance.getClientFactory().destroy();
}
@Test
- public void testHttpGetNoAuthClient() throws Exception {
+ void testHttpGetNoAuthClient() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
final Response response = client.get(HELLO);
}
@Test
- public void testHttpGetNoAuthClientAsync() throws Exception {
+ void testHttpGetNoAuthClientAsync() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
MyCallback callback = new MyCallback();
private void verifyCallback(String testName, MyCallback callback, final Response response)
throws InterruptedException {
- assertTrue(testName, callback.await());
- assertNull(testName, callback.getThrowable());
- assertSame(testName, response, callback.getResponse());
+ assertTrue(callback.await(), testName);
+ assertNull(callback.getThrowable(), testName);
+ assertSame(response, callback.getResponse(), testName);
}
@Test
- public void testHttpPutNoAuthClient() throws Exception {
+ void testHttpPutNoAuthClient() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666);
Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
}
@Test
- public void testHttpPutNoAuthClientAsync() throws Exception {
+ void testHttpPutNoAuthClientAsync() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666);
Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
}
@Test
- public void testHttpPostNoAuthClient() throws Exception {
+ void testHttpPostNoAuthClient() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
}
@Test
- public void testHttpPostNoAuthClientAsync() throws Exception {
+ void testHttpPostNoAuthClientAsync() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
}
@Test
- public void testHttpDeletetNoAuthClient() throws Exception {
+ void testHttpDeletetNoAuthClient() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
}
@Test
- public void testHttpDeletetNoAuthClientAsync() throws Exception {
+ void testHttpDeletetNoAuthClientAsync() throws Exception {
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
* @throws Exception if an error occurs
*/
@Test
- public void testHttpAsyncAuthClient() throws Exception {
+ void testHttpAsyncAuthClient() throws Exception {
final HttpClient client = getAuthHttpClient();
MyCallback callback = new MyCallback();
}
@Test
- public void testHttpGetAuthClient() throws Exception {
+ void testHttpGetAuthClient() throws Exception {
final HttpClient client = getAuthHttpClient();
final Response response = client.get(HELLO);
}
@Test
- public void testHttpPutAuthClient() throws Exception {
+ void testHttpPutAuthClient() throws Exception {
final HttpClient client = getAuthHttpClient();
Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
}
@Test
- public void testHttpPutAuthClient_GsonProvider() throws Exception {
+ void testHttpPutAuthClient_GsonProvider() throws Exception {
final HttpClient client = HttpClientFactoryInstance.getClientFactory()
.build(BusTopicParams.builder().clientName(TEST_HTTP_AUTH_CLIENT).useHttps(true)
.allowSelfSignedCerts(true).hostname(LOCALHOST).port(6667).basePath(JUNIT_ECHO)
}
@Test
- public void testHttpAuthClient401() throws Exception {
+ void testHttpAuthClient401() throws Exception {
final HttpClient client = getNoAuthHttpClient("testHttpAuthClient401", true,
6667);
final Response response = client.get(HELLO);
}
@Test
- public void testHttpAuthClientProps() throws Exception {
+ void testHttpAuthClientProps() throws Exception {
final Properties httpProperties = new Properties();
/* PAP and PDP services */
* 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.
package org.onap.policy.common.endpoints.http.server.test;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class HttpExceptionsTest extends ExceptionsTester {
+class HttpExceptionsTest extends ExceptionsTester {
@Test
- public void testHttpClientConfigException() {
+ void testHttpClientConfigException() {
test(HttpClientConfigException.class);
}
}
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchThrowable;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import io.prometheus.client.servlet.jakarta.exporter.MetricsServlet;
import java.util.Objects;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
/**
* HttpServletServer JUNIT tests.
*/
-public class HttpServerTest {
+class HttpServerTest {
private static final String JVM_MEMORY_BYTES_USED = "jvm_memory_bytes_used";
private static final String METRICS_URI = "/metrics";
private static final String PROMETHEUS = "prometheus";
/**
* Increments the port number, clears the servers, and resets the providers.
*/
- @Before
+ @BeforeEach
public void setUp() {
incrementPort();
portUrl = LOCALHOST_PREFIX + port;
/**
* To delete temporary properties cadi_longitude,and cadi_latitude.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
HttpServletServerFactoryInstance.getServerFactory().destroy();
System.clearProperty("cadi_longitude");
}
@Test
- public void testDefaultPackageServer() throws Exception {
+ void testDefaultPackageServer() throws Exception {
logger.info("-- testDefaultPackageServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testGsonPackageServer() throws Exception {
+ void testGsonPackageServer() throws Exception {
logger.info("-- testGsonPackageServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testYamlPackageServer() throws Exception {
+ void testYamlPackageServer() throws Exception {
logger.info("-- testYamlPackageServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testDefaultClassServer() throws Exception {
+ void testDefaultClassServer() throws Exception {
logger.info("-- testDefaultClassServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
* This test checks a server from a plain java servlet (note it uses prometheus as the sample server).
*/
@Test
- public void testStdServletServer() throws Exception {
+ void testStdServletServer() throws Exception {
logger.info("-- testStdServletServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
* This test explicitly creates a prometheus server.
*/
@Test
- public void testExplicitPrometheusServer() throws Exception {
+ void testExplicitPrometheusServer() throws Exception {
logger.info("-- testPrometheusServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
* This test is an all-in-one for a single server: prometheus, jax-rs, servlet, swagger, and filters.
*/
@Test
- public void testPrometheusJaxRsFilterSwaggerServer() throws Exception {
+ void testPrometheusJaxRsFilterSwaggerServer() throws Exception {
logger.info("-- testPrometheusServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testJacksonClassServer() throws Exception {
+ void testJacksonClassServer() throws Exception {
logger.info("-- testJacksonClassServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testGsonClassServer() throws Exception {
+ void testGsonClassServer() throws Exception {
logger.info("-- testGsonClassServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testYamlClassServer() throws Exception {
+ void testYamlClassServer() throws Exception {
logger.info("-- testYamlClassServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testSerialize() {
+ void testSerialize() {
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
.build("echo", LOCALHOST, port, "/", false, true);
server.addServletPackage("/*", this.getClass().getPackage().getName());
}
@Test
- public void testSingleServer() throws Exception {
+ void testSingleServer() throws Exception {
logger.info("-- testSingleServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testMultipleServers() throws Exception {
+ void testMultipleServers() throws Exception {
logger.info("-- testMultipleServers() --");
HttpServletServer server1 = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testMultiServicePackage() throws Exception {
+ void testMultiServicePackage() throws Exception {
logger.info("-- testMultiServicePackage() --");
String randomName = UUID.randomUUID().toString();
}
@Test
- public void testServiceClass() throws Exception {
+ void testServiceClass() throws Exception {
logger.info("-- testServiceClass() --");
String randomName = UUID.randomUUID().toString();
}
@Test
- public void testMultiServiceClass() throws Exception {
+ void testMultiServiceClass() throws Exception {
logger.info("-- testMultiServiceClass() --");
String randomName = UUID.randomUUID().toString();
}
@Test
- public void testSingleStaticResourceServer() throws Exception {
+ void testSingleStaticResourceServer() throws Exception {
logger.info("-- testSingleStaticResourceServer() --");
HttpServletServer staticServer = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testMultiStaticResourceServer() throws Exception {
+ void testMultiStaticResourceServer() throws Exception {
logger.info("-- testMultiStaticResourceServer() --");
HttpServletServer staticResourceServer = HttpServletServerFactoryInstance.getServerFactory()
}
@Test
- public void testMultiTypesServer() throws Exception {
+ void testMultiTypesServer() throws Exception {
logger.info("-- testMultiTypesServer() --");
HttpServletServer staticResourceServer = HttpServletServerFactoryInstance.getServerFactory()
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.common.endpoints.http.server.test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.JsonSyntaxException;
import jakarta.ws.rs.core.Response;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.server.JsonExceptionMapper;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-public class JsonExceptionMapperTest {
+class JsonExceptionMapperTest {
private JsonExceptionMapper mapper;
- @Before
+ @BeforeEach
public void setUp() {
mapper = new JsonExceptionMapper();
}
@Test
- public void testToResponse() throws CoderException {
+ void testToResponse() throws CoderException {
JsonSyntaxException ex = new JsonSyntaxException("expected exception");
Response resp = mapper.toResponse(ex);
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Properties;
import lombok.Getter;
import org.apache.commons.io.IOUtils;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactory;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.springframework.test.util.ReflectionTestUtils;
-public class RestServerTest {
+class RestServerTest {
private static final String METRICS_URI = "/metrics";
private static final String SERVER1 = "my-server-A";
private static final String SERVER2 = "my-server-B";
* Starts the REST server.
* @throws Exception if an error occurs
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
saveFactory = (Factory) ReflectionTestUtils.getField(RestServer.class, FACTORY_FIELD);
/**
* Restores the factory and stops the REST server.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
ReflectionTestUtils.setField(RestServer.class, FACTORY_FIELD, saveFactory);
/**
* Initializes mocks.
*/
- @Before
+ @BeforeEach
public void setUp() {
server1 = mock(HttpServletServer.class);
server2 = mock(HttpServletServer.class);
}
@Test
- public void testRestServer() {
+ void testRestServer() {
rest = new RestServer(params, Filter2.class, Provider1.class, Provider2.class);
rest.start();
}
@Test
- public void testRestServerListList() {
+ void testRestServerListList() {
rest = new RestServer(params, List.of(Filter2.class), List.of(Provider1.class, Provider2.class));
rest.start();
}
@Test
- public void testRestServer_MissingProviders() {
+ void testRestServer_MissingProviders() {
assertThatIllegalArgumentException().isThrownBy(() -> new RestServer(params, List.of(Filter2.class), null));
}
@Test
- public void testGetServerProperties_testGetProviderNames() {
+ void testGetServerProperties_testGetProviderNames() {
rest = new RestServer(params, Provider1.class, Provider2.class);
ArgumentCaptor<Properties> cap = ArgumentCaptor.forClass(Properties.class);
}
@Test
- public void testExplicitPrometheusAddedToProperty() {
+ void testExplicitPrometheusAddedToProperty() {
when(params.isPrometheus()).thenReturn(true);
rest = new RestServer(params, Filter2.class, Provider1.class, Provider2.class);
ArgumentCaptor<Properties> cap = ArgumentCaptor.forClass(Properties.class);
}
@Test
- public void testStandardServletAddedToProperty() {
+ void testStandardServletAddedToProperty() {
when(params.getServletUriPath()).thenReturn("/metrics");
when(params.getServletClass()).thenReturn(MetricsServlet.class.getName());
rest = new RestServer(params, Filter2.class, Provider1.class, Provider2.class);
}
@Test
- public void testInvalidJson() throws Exception {
+ void testInvalidJson() throws Exception {
initRealParams();
assertEquals(200, roundTrip(new StandardCoder().encode(new MyRequest())));
}
@Test
- public void testInvalidYaml() throws Exception {
+ void testInvalidYaml() throws Exception {
initRealParams();
assertEquals(200, roundTrip(new StandardCoder().encode(new MyRequest()),
}
@Test
- public void testToString() {
+ void testToString() {
rest = new RestServer(params, Filter2.class, Provider1.class, Provider2.class);
assertNotNull(rest.toString());
}
@Test
- public void testFactory() {
+ void testFactory() {
assertNotNull(saveFactory);
assertNotNull(saveFactory.getServerFactory());
}
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.common.endpoints.http.server.test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.core.Response;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.server.YamlExceptionMapper;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.yaml.snakeyaml.error.YAMLException;
-public class YamlExceptionMapperTest {
+class YamlExceptionMapperTest {
private YamlExceptionMapper mapper;
- @Before
+ @BeforeEach
public void setUp() {
mapper = new YamlExceptionMapper();
}
@Test
- public void testToResponse() throws CoderException {
+ void testToResponse() throws CoderException {
YAMLException ex = new YAMLException("expected exception");
Response resp = mapper.toResponse(ex);
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.common.endpoints.http.server.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.JsonObject;
import jakarta.ws.rs.core.MediaType;
import java.util.Map;
import java.util.TreeMap;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.server.YamlJacksonHandler;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
-public class YamlJacksonHandlerTest {
+class YamlJacksonHandlerTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
YamlJacksonHandler hdlr = new YamlJacksonHandler();
assertTrue(hdlr.isReadable(null, null, null, MediaType.valueOf(YamlMessageBodyHandler.APPLICATION_YAML)));
}
@Test
- public void testMapDouble() throws Exception {
+ void testMapDouble() throws Exception {
MyMap map = new MyMap();
map.props = new HashMap<>();
map.props.put("plainString", "def");
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.common.endpoints.http.server.test;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import jakarta.ws.rs.core.MediaType;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Map;
import lombok.ToString;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
import org.yaml.snakeyaml.error.YAMLException;
-public class YamlMessageBodyHandlerTest {
+class YamlMessageBodyHandlerTest {
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String GEN_TYPE = "some-type";
private YamlMessageBodyHandler hdlr;
- @Before
+ @BeforeEach
public void setUp() {
hdlr = new YamlMessageBodyHandler();
}
@Test
- public void testIsWriteable() {
+ void testIsWriteable() {
for (String subtype : subtypes) {
- assertTrue("writeable " + subtype, hdlr.isWriteable(null, null, null, new MediaType(GEN_TYPE, subtype)));
+ assertTrue(hdlr.isWriteable(null, null, null, new MediaType(GEN_TYPE, subtype)), "writeable " + subtype);
}
}
@Test
- public void testGetSize() {
+ void testGetSize() {
assertEquals(-1, hdlr.getSize(null, null, null, null, null));
}
@Test
- public void testWriteTo_testReadFrom() throws Exception {
+ void testWriteTo_testReadFrom() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
MyObject obj1 = new MyObject(10);
hdlr.writeTo(obj1, obj1.getClass(), CLASS_OBJ, null, null, null, outstr);
}
@Test
- public void testWriteTo_DifferentTypes() throws Exception {
+ void testWriteTo_DifferentTypes() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
// use a derived type, but specify the base type when writing
}
@Test
- public void testWriteTo_Ex() throws Exception {
+ void testWriteTo_Ex() throws Exception {
OutputStream outstr = new OutputStream() {
@Override
public void write(int value) throws IOException {
}
@Test
- public void testIsReadable() {
+ void testIsReadable() {
for (String subtype : subtypes) {
- assertTrue("readable " + subtype, hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, subtype)));
+ assertTrue(hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, subtype)), "readable " + subtype);
}
}
@Test
- public void testReadFrom_DifferentTypes() throws Exception {
+ void testReadFrom_DifferentTypes() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
MyObject obj1 = new MyObject(10);
hdlr.writeTo(obj1, obj1.getClass(), CLASS_OBJ, null, null, null, outstr);
}
@Test
- public void testReadFrom_Ex() throws Exception {
+ void testReadFrom_Ex() throws Exception {
InputStream inpstr = new InputStream() {
@Override
public int read() throws IOException {
}
@Test
- public void testReadFrom_Invalid() throws Exception {
+ void testReadFrom_Invalid() throws Exception {
InputStream inpstr = new ByteArrayInputStream("plain text".getBytes());
assertThatThrownBy(() -> hdlr.readFrom(CLASS_OBJ, CLASS_OBJ, null, null, null, inpstr))
}
@Test
- public void testMapDouble() throws Exception {
+ void testMapDouble() throws Exception {
MyMap map = new MyMap();
map.props = new HashMap<>();
map.props.put("plainString", "def");
* 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.
package org.onap.policy.common.endpoints.listeners;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
-public class JsonListenerTest {
+class JsonListenerTest {
/**
* Used to attach an appender to the class' logger.
/**
* Initializes statics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveLevel = logger.getLevel();
logger.setLevel(Level.INFO);
appender.start();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
logger.setLevel(saveLevel);
appender.stop();
/**
* Initializes mocks and a listener.
*/
- @Before
+ @BeforeEach
public void setUp() {
appender.clearExtractions();
};
}
- @After
+ @AfterEach
public void tearDown() {
logger.detachAppender(appender);
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
logger.addAppender(appender);
primary = spy(primary);
* 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.
package org.onap.policy.common.endpoints.listeners;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
-public class MessageTypeDispatcherTest {
+class MessageTypeDispatcherTest {
/**
* Used to attach an appender to the class' logger.
/**
* Initializes statics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveLevel = logger.getLevel();
logger.setLevel(Level.INFO);
appender.start();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
logger.setLevel(saveLevel);
appender.stop();
/**
* Initializes mocks and a listener.
*/
- @Before
+ @BeforeEach
@SuppressWarnings("unchecked")
public void setUp() {
appender.clearExtractions();
primary = new MessageTypeDispatcher(TYPE_FIELD);
}
- @After
+ @AfterEach
public void tearDown() {
logger.detachAppender(appender);
}
@Test
- public void testRegister_testUnregister() {
+ void testRegister_testUnregister() {
primary.register(TYPE1, secondary1);
primary.register(TYPE2, secondary2);
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
primary.register(TYPE1, secondary1);
logger.addAppender(appender);
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.common.endpoints.listeners;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
-public class RequestIdDispatcherTest {
+class RequestIdDispatcherTest {
/**
* Used to attach an appender to the class' logger.
/**
* Initializes statics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveLevel = logger.getLevel();
logger.setLevel(Level.INFO);
appender.start();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
logger.setLevel(saveLevel);
appender.stop();
* Create various mocks and primary listener.
*/
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() {
appender.clearExtractions();
primary = new RequestIdDispatcher<>(MyMessage.class, REQID_FIELD);
}
- @After
+ @AfterEach
public void tearDown() {
logger.detachAppender(appender);
}
@Test
- public void testRegisterMessageListener() {
+ void testRegisterMessageListener() {
primary.register(secondary1);
// should process message that does not have a request id
}
@Test
- public void testRegisterStringMessageListener() {
+ void testRegisterStringMessageListener() {
primary.register(REQID1, secondary1);
// should NOT process message that does not have a request id
}
@Test
- public void testUnregisterMessageListener() {
+ void testUnregisterMessageListener() {
primary.register(secondary1);
primary.register(secondary2);
}
@Test
- public void testUnregisterString() {
+ void testUnregisterString() {
primary.register(REQID1, secondary1);
primary.register(REQID2, secondary2);
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
primary.register(REQID1, secondary1);
primary.register(REQID2, secondary2);
primary.register(secondary3);
}
@Test
- public void testOfferToListener() {
+ void testOfferToListener() {
logger.addAppender(appender);
// no listener for this
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.common.endpoints.listeners;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
-public class ScoListenerTest {
+class ScoListenerTest {
/**
* Used to attach an appender to the class' logger.
/**
* Initializes statics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveLevel = logger.getLevel();
logger.setLevel(Level.INFO);
appender.start();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
logger.setLevel(saveLevel);
appender.stop();
/**
* Create various mocks and primary handler.
*/
- @Before
+ @BeforeEach
public void setUp() {
appender.clearExtractions();
};
}
- @After
+ @AfterEach
public void tearDown() {
logger.detachAppender(appender);
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
primary = spy(primary);
status = new MyMessage(NAME);
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2024 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.common.endpoints.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class RestServerParametersTest {
+class RestServerParametersTest {
private static CommonTestData testData = new CommonTestData();
private static final Coder coder = new StandardCoder();
@Test
- public void test() {
+ void test() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
final ValidationResult validationResult = restServerParameters.validate();
}
@Test
- public void testValidate() {
+ void testValidate() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
final ValidationResult result = restServerParameters.validate();
}
@Test
- public void test_valid() throws Exception {
+ void test_valid() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json");
RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
}
@Test
- public void test_invalid() throws Exception {
+ void test_invalid() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json");
RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2024 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.common.endpoints.parameters;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TopicParameterGroupTest {
+class TopicParameterGroupTest {
private static CommonTestData testData = new CommonTestData();
private static final Coder coder = new StandardCoder();
@Test
- public void test() throws CoderException {
+ void test() throws CoderException {
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
final ValidationResult validationResult = topicParameterGroup.validate();
}
@Test
- public void testValidate() {
+ void testValidate() {
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
final ValidationResult result = topicParameterGroup.validate();
}
@Test
- public void test_valid() throws Exception {
+ void test_valid() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
}
@Test
- public void test_invalid() throws Exception {
+ void test_invalid() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
}
@Test
- public void test_missing_mandatory_params() throws Exception {
+ void test_missing_mandatory_params() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_missing_mandatory.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
}
@Test
- public void test_allparams() throws Exception {
+ void test_allparams() throws Exception {
String json = testData.getParameterGroupAsString(
"src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_all_params.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.openpojo.validation.rule.impl.SetterMustExistRule;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ToStringTester;
/**
*
* @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
*/
-public class TestHealthCheckReport {
+class TestHealthCheckReport {
@Test
- public void testHealthCheckReport() {
+ void testHealthCheckReport() {
final Validator validator =
ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
.with(new GetterTester()).with(new SetterTester()).with(new ToStringTester()).build();
* 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.
package org.onap.policy.common.endpoints.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.features.NetLoggerFeatureApi;
import org.onap.policy.common.endpoints.features.NetLoggerFeatureProviders;
/**
* Test class for network log utilities such as logging and feature invocation.
*/
-public class NetLoggerUtilTest {
+class NetLoggerUtilTest {
private static final String TEST_TOPIC = "test-topic";
private static final String MESSAGE = "hello world!";
/**
* Obtains the test implementation of NetLoggerFeatureApi.
*/
- @BeforeClass
+ @BeforeAll
public static void setUp() {
netLoggerFeature = (NetLoggerFeature) NetLoggerFeatureProviders.getProviders().getList().get(0);
}
/**
* Clears events list and resets return/exceptions flags before invoking every unit test.
*/
- @Before
+ @BeforeEach
public void reset() {
TestAppender.clear();
netLoggerFeature.setReturnValue(false, false);
* Tests obtaining the network logger instance.
*/
@Test
- public void getNetworkLoggerTest() {
+ void getNetworkLoggerTest() {
assertEquals("network", NetLoggerUtil.getNetworkLogger().getName());
}
* Tests logging a message to the network logger and invoking features before/after logging.
*/
@Test
- public void logTest() {
+ void logTest() {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
}
* Tests that the network logger is used to log messages if a logger is not passed in.
*/
@Test
- public void logDefaultTest() {
+ void logDefaultTest() {
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
assertEquals("network", TestAppender.events.get(0).getLoggerName());
* Tests a NetLoggerFeature that replaces base implementation before logging.
*/
@Test
- public void beforeLogReturnTrueTest() {
+ void beforeLogReturnTrueTest() {
netLoggerFeature.setReturnValue(true, false);
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(1, TestAppender.events.size());
* Tests a NetLoggerFeature that post processes a logged message.
*/
@Test
- public void afterLogReturnTrueTest() {
+ void afterLogReturnTrueTest() {
netLoggerFeature.setReturnValue(false, true);
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
* Tests throwing an exception in the before hook.
*/
@Test
- public void beforeLogExceptionTest() {
+ void beforeLogExceptionTest() {
netLoggerFeature.setExceptions(true, false);
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(2, TestAppender.events.size());
* Tests throwing an exception in the after hook.
*/
@Test
- public void afterLogExceptionTest() {
+ void afterLogExceptionTest() {
netLoggerFeature.setExceptions(false, true);
NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(2, TestAppender.events.size());
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.common.endpoints.utils;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Properties;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class PropertyUtilsTest {
+class PropertyUtilsTest {
private static final String DFLT_STRING = "my-default";
private static final int DLFT_INT = 1000;
/**
* Initializes {@link #utils}.
*/
- @Before
+ @BeforeEach
public void setUp() {
Properties properties = new Properties();
properties.put("myPrefix.my-string", "some text");
}
@Test
- public void testGetString() {
+ void testGetString() {
assertEquals("some text", utils.getString(".my-string", DFLT_STRING));
assertEquals(DFLT_STRING, utils.getString(".empty-string", DFLT_STRING));
assertEquals(DFLT_STRING, utils.getString(".missing-string", DFLT_STRING));
}
@Test
- public void testGetBoolean() {
+ void testGetBoolean() {
assertTrue(utils.getBoolean(".my-bool", false));
assertFalse(utils.getBoolean(".my-bool2", true));
assertTrue(utils.getBoolean(".empty-bool", true));
}
@Test
- public void testGetInteger() {
+ void testGetInteger() {
assertEquals(100, utils.getInteger(".my-int", DLFT_INT));
assertEquals(200, utils.getInteger(".my-int2", DLFT_INT));
assertEquals(DLFT_INT, utils.getInteger(".empty-int", DLFT_INT));