diff options
author | waynedunican <wayne.dunican@est.tech> | 2024-06-13 09:19:14 +0100 |
---|---|---|
committer | waynedunican <wayne.dunican@est.tech> | 2024-06-20 12:24:23 +0100 |
commit | 9e8684c88435734cb2e142208436cec647cde887 (patch) | |
tree | b06334cdf8309d36ceba948797ff071d14a2e82d /models-interactions/model-actors/actorServiceProvider | |
parent | 8236c8bab1a27bd721586550f8ba879abcba3239 (diff) |
Convert models to JUnit 5
Review for models-actors
Issue-ID: POLICY-5042
Change-Id: Ica07b9fbda1eca24a8a432d57a2d9af52c84625d
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider')
39 files changed, 794 insertions, 729 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/pom.xml b/models-interactions/model-actors/actorServiceProvider/pom.xml index efebac6fe..cb5a38167 100644 --- a/models-interactions/model-actors/actorServiceProvider/pom.xml +++ b/models-interactions/model-actors/actorServiceProvider/pom.xml @@ -60,5 +60,10 @@ <artifactId>mockito-core</artifactId> <scope>compile</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-junit-jupiter</artifactId> + <scope>compile</scope> + </dependency> </dependencies> </project> diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java index 97f6bbacf..e59c2fd89 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,11 +22,11 @@ package org.onap.policy.controlloop.actorserviceprovider; 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.assertNotNull; -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.assertNotNull; +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.Mockito.doThrow; import static org.mockito.Mockito.never; @@ -42,8 +43,8 @@ import java.util.Map; import java.util.TreeMap; import java.util.function.Consumer; import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.controlloop.actorserviceprovider.impl.ActorImpl; @@ -51,32 +52,32 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; -public class ActorServiceTest { - private static final String EXPECTED_EXCEPTION = "expected exception"; - private static final String ACTOR1 = "actor A"; - private static final String ACTOR2 = "actor B"; - private static final String ACTOR3 = "actor C"; - private static final String ACTOR4 = "actor D"; +class ActorServiceTest { + static final String EXPECTED_EXCEPTION = "expected exception"; + static final String ACTOR1 = "actor A"; + static final String ACTOR2 = "actor B"; + static final String ACTOR3 = "actor C"; + static final String ACTOR4 = "actor D"; - private Actor actor1; - private Actor actor2; - private Actor actor3; - private Actor actor4; + Actor actor1; + Actor actor2; + Actor actor3; + Actor actor4; - private Map<String, Object> sub1; - private Map<String, Object> sub2; - private Map<String, Object> sub3; - private Map<String, Object> sub4; - private Map<String, Object> params; + Map<String, Object> sub1; + Map<String, Object> sub2; + Map<String, Object> sub3; + Map<String, Object> sub4; + Map<String, Object> params; - private ActorService service; + ActorService service; /** * Initializes the fields, including a fully populated {@link #service}. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { actor1 = spy(new ActorImpl(ACTOR1)); actor2 = spy(new ActorImpl(ACTOR2)); actor3 = spy(new ActorImpl(ACTOR3)); @@ -93,7 +94,7 @@ public class ActorServiceTest { } @Test - public void testActorService_testBuildList() { + void testActorService_testBuildList() { /* * make a service where actors two and four have names that are duplicates of the * others @@ -122,7 +123,7 @@ public class ActorServiceTest { } @Test - public void testDoStart() { + void testDoStart() { service.configure(params); setUpOp("testDoStart", actor -> when(actor.isConfigured()).thenReturn(false), Actor::start); @@ -148,7 +149,7 @@ public class ActorServiceTest { } @Test - public void testDoStop() { + void testDoStop() { service.configure(params); service.start(); @@ -175,7 +176,7 @@ public class ActorServiceTest { } @Test - public void testDoShutdown() { + void testDoShutdown() { service.configure(params); service.start(); @@ -211,7 +212,7 @@ public class ActorServiceTest { */ private void setUpOp(String testName, Consumer<Actor> oper2, Consumer<Actor> oper3) { Collection<Actor> actors = service.getActors(); - assertEquals(testName, 4, actors.size()); + assertEquals(4, actors.size(), testName); Iterator<Actor> iter = actors.iterator(); @@ -229,7 +230,7 @@ public class ActorServiceTest { } @Test - public void testGetActor() { + void testGetActor() { assertSame(actor1, service.getActor(ACTOR1)); assertSame(actor3, service.getActor(ACTOR3)); @@ -237,7 +238,7 @@ public class ActorServiceTest { } @Test - public void testGetActors() { + void testGetActors() { // @formatter:off assertEquals("[actor A, actor B, actor C, actor D]", service.getActors().stream() @@ -249,7 +250,7 @@ public class ActorServiceTest { } @Test - public void testGetActorNames() { + void testGetActorNames() { // @formatter:off assertEquals("[actor A, actor B, actor C, actor D]", service.getActorNames().stream() @@ -260,7 +261,7 @@ public class ActorServiceTest { } @Test - public void testDoConfigure() { + void testDoConfigure() { service.configure(params); assertTrue(service.isConfigured()); @@ -279,7 +280,7 @@ public class ActorServiceTest { * Tests doConfigure() where actors throw parameter validation and runtime exceptions. */ @Test - public void testDoConfigureExceptions() { + void testDoConfigureExceptions() { makeValidException(actor1); makeRuntimeException(actor2); makeValidException(actor3); @@ -297,7 +298,7 @@ public class ActorServiceTest { * </ul> */ @Test - public void testDoConfigureConfigure() { + void testDoConfigureConfigure() { // need mutable parameters params = new TreeMap<>(params); @@ -365,7 +366,7 @@ public class ActorServiceTest { } @Test - public void testLoadActors() { + void testLoadActors() { ActorService service = new ActorService(); assertFalse(service.getActors().isEmpty()); assertNotNull(service.getActor(DummyActor.class.getSimpleName())); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/CallbackManagerTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/CallbackManagerTest.java index 44606cb14..722be718c 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/CallbackManagerTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/CallbackManagerTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -20,27 +21,27 @@ package org.onap.policy.controlloop.actorserviceprovider; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Instant; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class CallbackManagerTest { +class CallbackManagerTest { private CallbackManager mgr; - @Before - public void setUp() { + @BeforeEach + void setUp() { mgr = new CallbackManager(); } @Test - public void testCanStart_testGetStartTime() { + void testCanStart_testGetStartTime() { // null until canXxx() is called assertNull(mgr.getStartTime()); @@ -58,7 +59,7 @@ public class CallbackManagerTest { } @Test - public void testCanEnd_testGetEndTime() { + void testCanEnd_testGetEndTime() { // null until canXxx() is called assertNull(mgr.getEndTime()); assertNull(mgr.getEndTime()); @@ -77,7 +78,7 @@ public class CallbackManagerTest { } @Test - public void testRun() { + void testRun() { mgr.run(); assertNotNull(mgr.getStartTime()); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DelayedIdentStringTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DelayedIdentStringTest.java index 5b9856f41..a63202024 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DelayedIdentStringTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DelayedIdentStringTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,14 +22,14 @@ package org.onap.policy.controlloop.actorserviceprovider; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class DelayedIdentStringTest { +class DelayedIdentStringTest { private int countToStringCalls; private Object object; @@ -37,8 +38,8 @@ public class DelayedIdentStringTest { /** * Initializes fields, including {@link #delay}. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { countToStringCalls = 0; object = new Object() { @@ -53,7 +54,7 @@ public class DelayedIdentStringTest { } @Test - public void testToString() { + void testToString() { String delayed = delay.toString(); assertEquals(1, countToStringCalls); @@ -86,7 +87,7 @@ public class DelayedIdentStringTest { } @Test - public void testDelayedIdentString() { + void testDelayedIdentString() { // should not have called the object's toString() method yet assertEquals(0, countToStringCalls); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DummyActor.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DummyActor.java index f10694de6..497e4ae52 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DummyActor.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DummyActor.java @@ -3,7 +3,7 @@ * TestActorServiceProvider * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 2024 Nordix Foundation. * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java index 6f667bb76..61fb6a31e 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,17 +22,17 @@ package org.onap.policy.controlloop.actorserviceprovider; 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.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.time.Instant; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.controlloop.ControlLoopOperation; -public class OperationOutcomeTest { +class OperationOutcomeTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-operation"; private static final String TARGET = "my-target"; @@ -47,13 +48,13 @@ public class OperationOutcomeTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { outcome = new OperationOutcome(); } @Test - public void testOperationOutcomeOperationOutcome() { + void testOperationOutcomeOperationOutcome() { setAll(); OperationOutcome outcome2 = new OperationOutcome(outcome); @@ -70,7 +71,7 @@ public class OperationOutcomeTest { } @Test - public void testToControlLoopOperation() { + void testToControlLoopOperation() { setAll(); ControlLoopOperation outcome2 = outcome.toControlLoopOperation(); @@ -89,7 +90,7 @@ public class OperationOutcomeTest { * Tests both isFor() methods, as one invokes the other. */ @Test - public void testIsFor() { + void testIsFor() { setAll(); // null case @@ -122,7 +123,7 @@ public class OperationOutcomeTest { } @Test - public void testSetResult() { + void testSetResult() { outcome.setResult(OperationResult.FAILURE_EXCEPTION); assertEquals(OperationResult.FAILURE_EXCEPTION, outcome.getResult()); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/UtilTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/UtilTest.java index 0a2a5a90e..068a72365 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/UtilTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/UtilTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -22,10 +23,10 @@ package org.onap.policy.controlloop.actorserviceprovider; 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.assertNotEquals; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import ch.qos.logback.classic.Logger; import java.util.LinkedHashMap; @@ -35,14 +36,14 @@ import java.util.TreeMap; import java.util.concurrent.atomic.AtomicInteger; import lombok.Builder; import lombok.Data; -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.utils.test.log.logback.ExtractAppender; import org.slf4j.LoggerFactory; -public class UtilTest { +class UtilTest { protected static final String EXPECTED_EXCEPTION = "expected exception"; /** @@ -54,26 +55,26 @@ public class UtilTest { /** * Initializes statics. */ - @BeforeClass - public static void setUpBeforeClass() { + @BeforeAll + static void setUpBeforeClass() { appender.setContext(logger.getLoggerContext()); appender.start(); logger.addAppender(appender); } - @AfterClass - public static void tearDownAfterClass() { + @AfterAll + static void tearDownAfterClass() { appender.stop(); } - @Before - public void setUp() { + @BeforeEach + void setUp() { appender.clearExtractions(); } @Test - public void testIdent() { + void testIdent() { Object object = new Object(); String result = Util.ident(object).toString(); @@ -83,7 +84,7 @@ public class UtilTest { } @Test - public void testRunFunction() { + void testRunFunction() { // no exception, no log AtomicInteger count = new AtomicInteger(); Util.runFunction(() -> count.incrementAndGet(), "no error"); @@ -110,7 +111,7 @@ public class UtilTest { } @Test - public void testTranslate() { + void testTranslate() { // Abc => Abc final Abc abc = Abc.builder().intValue(1).strValue("hello").anotherString("another").build(); Abc abc2 = Util.translate("abc to abc", abc, Abc.class); @@ -137,7 +138,7 @@ public class UtilTest { } @Test - public void testTranslateToMap() { + void testTranslateToMap() { assertNull(Util.translateToMap("map: null", null)); // Abc => Map @@ -155,7 +156,7 @@ public class UtilTest { @Data @Builder - public static class Abc { + static class Abc { private int intValue; private String strValue; private String anotherString; @@ -164,17 +165,17 @@ public class UtilTest { // this shares some fields with Abc so the data should transfer @Data @Builder - public static class Similar { + static class Similar { private int intValue; private String strValue; } // throws an exception when getXxx() is used - public static class DataWithException { + static class DataWithException { @SuppressWarnings("unused") private int intValue; - public int getIntValue() { + int getIntValue() { throw new IllegalStateException(); } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImplTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImplTest.java index cf07d3b2b..1635c16ce 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImplTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImplTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -22,10 +23,10 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; 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 static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; @@ -37,8 +38,8 @@ import static org.mockito.Mockito.when; import java.util.Iterator; import java.util.Map; import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.controlloop.actorserviceprovider.Operation; @@ -47,7 +48,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; -public class ActorImplTest { +class ActorImplTest { private static final String EXPECTED_EXCEPTION = "expected exception"; private static final String ACTOR_NAME = "my-actor"; private static final String OPER1 = "add"; @@ -72,8 +73,8 @@ public class ActorImplTest { /** * Initializes the fields, including a fully populated {@link #actor}. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { oper1 = spy(new MyOper(OPER1)); oper2 = spy(new MyOper(OPER2)); oper3 = spy(new MyOper(OPER3)); @@ -90,14 +91,14 @@ public class ActorImplTest { } @Test - public void testActorImpl_testGetName() { + void testActorImpl_testGetName() { assertEquals(ACTOR_NAME, actor.getName()); assertEquals(4, actor.getOperationNames().size()); assertEquals(0, actor.getSequenceNumber()); } @Test - public void testDoStart() { + void testDoStart() { actor.configure(params); assertEquals(4, actor.getOperationNames().size()); @@ -130,7 +131,7 @@ public class ActorImplTest { } @Test - public void testDoStop() { + void testDoStop() { actor.configure(params); actor.start(); assertEquals(4, actor.getOperationNames().size()); @@ -162,7 +163,7 @@ public class ActorImplTest { } @Test - public void testDoShutdown() { + void testDoShutdown() { actor.configure(params); actor.start(); assertEquals(4, actor.getOperationNames().size()); @@ -194,7 +195,7 @@ public class ActorImplTest { } @Test - public void testAddOperator() { + void testAddOperator() { // cannot add operators if already configured actor.configure(params); assertThatIllegalStateException().isThrownBy(() -> actor.addOperator(oper1)); @@ -215,7 +216,7 @@ public class ActorImplTest { } @Test - public void testGetOperator() { + void testGetOperator() { assertSame(oper1, actor.getOperator(OPER1)); assertSame(oper3, actor.getOperator(OPER3)); @@ -223,7 +224,7 @@ public class ActorImplTest { } @Test - public void testGetOperators() { + void testGetOperators() { // @formatter:off assertEquals("[add, divide, multiply, subtract]", actor.getOperators().stream() @@ -235,7 +236,7 @@ public class ActorImplTest { } @Test - public void testGetOperationNames() { + void testGetOperationNames() { // @formatter:off assertEquals("[add, divide, multiply, subtract]", actor.getOperationNames().stream() @@ -246,7 +247,7 @@ public class ActorImplTest { } @Test - public void testDoConfigure() { + void testDoConfigure() { actor.configure(params); assertTrue(actor.isConfigured()); @@ -266,7 +267,7 @@ public class ActorImplTest { * exceptions. */ @Test - public void testDoConfigureExceptions() { + void testDoConfigureExceptions() { makeValidException(oper1); makeRuntimeException(oper2); makeValidException(oper3); @@ -284,7 +285,7 @@ public class ActorImplTest { * </ul> */ @Test - public void testDoConfigureConfigure() { + void testDoConfigureConfigure() { // configure one operator oper1.configure(sub1); @@ -349,7 +350,7 @@ public class ActorImplTest { } @Test - public void testMakeOperatorParameters() { + void testMakeOperatorParameters() { actor.configure(params); // each operator should have received its own parameters diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java index 64d530d77..5ecebd668 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +23,11 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 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.assertNull; -import static org.junit.Assert.assertSame; +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.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -34,13 +35,13 @@ import java.util.Map; import java.util.Properties; import java.util.TreeMap; import java.util.function.Function; -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.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.event.comm.client.BidirectionalTopicClientException; import org.onap.policy.controlloop.actorserviceprovider.Util; @@ -48,8 +49,8 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.Bidirectional import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; -@RunWith(MockitoJUnitRunner.class) -public class BidirectionalTopicActorTest { +@ExtendWith(MockitoExtension.class) +class BidirectionalTopicActorTest { private static final String ACTOR = "my-actor"; private static final String UNKNOWN = "unknown"; @@ -69,8 +70,8 @@ public class BidirectionalTopicActorTest { /** * Configures the endpoints. */ - @BeforeClass - public static void setUpBeforeClass() { + @BeforeAll + static void setUpBeforeClass() { Properties props = new Properties(); props.setProperty("noop.sink.topics", MY_SINK); props.setProperty("noop.source.topics", MY_SOURCE1 + "," + MY_SOURCE2); @@ -81,8 +82,8 @@ public class BidirectionalTopicActorTest { TopicEndpointManager.getManager().addTopicSources(props); } - @AfterClass - public static void tearDownAfterClass() { + @AfterAll + static void tearDownAfterClass() { // clear all topics after the tests TopicEndpointManager.getManager().shutdown(); } @@ -90,14 +91,14 @@ public class BidirectionalTopicActorTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { actor = new MyActor(); actor.configure(Util.translateToMap(ACTOR, makeParams())); } @Test - public void testDoStart() throws BidirectionalTopicClientException { + void testDoStart() throws BidirectionalTopicClientException { // allocate some handlers actor.getTopicHandler(MY_SINK, MY_SOURCE1); actor.getTopicHandler(MY_SINK, MY_SOURCE2); @@ -116,7 +117,7 @@ public class BidirectionalTopicActorTest { } @Test - public void testDoStop() throws BidirectionalTopicClientException { + void testDoStop() throws BidirectionalTopicClientException { // allocate some handlers actor.getTopicHandler(MY_SINK, MY_SOURCE1); actor.getTopicHandler(MY_SINK, MY_SOURCE2); @@ -135,7 +136,8 @@ public class BidirectionalTopicActorTest { } @Test - public void testDoShutdown() { + void testDoShutdown() throws BidirectionalTopicClientException { + // allocate some handlers actor.getTopicHandler(MY_SINK, MY_SOURCE1); actor.getTopicHandler(MY_SINK, MY_SOURCE2); @@ -154,38 +156,38 @@ public class BidirectionalTopicActorTest { } @Test - public void testMakeOperatorParameters() { + void testMakeOperatorParameters() { BidirectionalTopicActorParams params = makeParams(); final BidirectionalTopicActor<BidirectionalTopicActorParams> prov = - new BidirectionalTopicActor<>(ACTOR, BidirectionalTopicActorParams.class); + new BidirectionalTopicActor<>(ACTOR, BidirectionalTopicActorParams.class); Function<String, Map<String, Object>> maker = - prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params)); + prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params)); assertNull(maker.apply(UNKNOWN)); // use a TreeMap to ensure the properties are sorted assertEquals("{sinkTopic=my-sink, sourceTopic=my-source-A, timeoutSec=10}", - new TreeMap<>(maker.apply("operA")).toString()); + new TreeMap<>(maker.apply("operA")).toString()); assertEquals("{sinkTopic=my-sink, sourceTopic=topicB, timeoutSec=10}", - new TreeMap<>(maker.apply("operB")).toString()); + new TreeMap<>(maker.apply("operB")).toString()); // with invalid actor parameters params.setOperations(null); Map<String, Object> map = Util.translateToMap(prov.getName(), params); assertThatThrownBy(() -> prov.makeOperatorParameters(map)) - .isInstanceOf(ParameterValidationRuntimeException.class); + .isInstanceOf(ParameterValidationRuntimeException.class); } @Test - public void testBidirectionalTopicActor() { + void testBidirectionalTopicActor() { assertEquals(ACTOR, actor.getName()); assertEquals(ACTOR, actor.getFullName()); } @Test - public void testGetTopicHandler() { + void testGetTopicHandler() throws BidirectionalTopicClientException { assertSame(handler1, actor.getTopicHandler(MY_SINK, MY_SOURCE1)); assertSame(handler2, actor.getTopicHandler(MY_SINK, MY_SOURCE2)); @@ -193,7 +195,7 @@ public class BidirectionalTopicActorTest { } @Test - public void testMakeTopicHandler() { + void testMakeTopicHandler() throws BidirectionalTopicClientException { // use a real actor actor = new BidirectionalTopicActor<>(ACTOR, BidirectionalTopicActorParams.class); @@ -214,21 +216,21 @@ public class BidirectionalTopicActorTest { // @formatter:off params.setOperations(Map.of( - "operA", Map.of(), - "operB", Map.of("sourceTopic", "topicB"))); + "operA", Map.of(), + "operB", Map.of("sourceTopic", "topicB"))); // @formatter:on return params; } private class MyActor extends BidirectionalTopicActor<BidirectionalTopicActorParams> { - public MyActor() { + MyActor() { super(ACTOR, BidirectionalTopicActorParams.class); } @Override protected BidirectionalTopicHandler makeTopicHandler(String sinkTopic, String sourceTopic) - throws BidirectionalTopicClientException { + throws BidirectionalTopicClientException { if (MY_SINK.equals(sinkTopic)) { if (MY_SOURCE1.equals(sourceTopic)) { diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java index 662f864c7..1fc8cc18e 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * 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. @@ -23,11 +24,11 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; 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.assertNotNull; -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.assertNotNull; +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.eq; import static org.mockito.Mockito.never; @@ -42,13 +43,14 @@ import java.util.function.BiConsumer; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; 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; @@ -62,8 +64,8 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; -@RunWith(MockitoJUnitRunner.class) -public class BidirectionalTopicOperationTest { +@ExtendWith(MockitoExtension.class) +class BidirectionalTopicOperationTest { private static final CommInfrastructure SINK_INFRA = CommInfrastructure.NOOP; private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception"); private static final String ACTOR = "my-actor"; @@ -98,14 +100,14 @@ public class BidirectionalTopicOperationTest { /** * Sets up. */ - @Before - public void setUp() throws CoderException { - when(config.getTopicHandler()).thenReturn(handler); - when(config.getForwarder()).thenReturn(forwarder); - when(config.getTimeoutMs()).thenReturn(TIMEOUT_MS); + @BeforeEach + void setUp() throws CoderException { + Mockito.lenient().when(config.getTopicHandler()).thenReturn(handler); + Mockito.lenient().when(config.getForwarder()).thenReturn(forwarder); + Mockito.lenient().when(config.getTimeoutMs()).thenReturn(TIMEOUT_MS); - when(handler.send(any())).thenReturn(true); - when(handler.getSinkTopicCommInfrastructure()).thenReturn(SINK_INFRA); + Mockito.lenient().when(handler.send(any())).thenReturn(true); + Mockito.lenient().when(handler.getSinkTopicCommInfrastructure()).thenReturn(SINK_INFRA); executor = new PseudoExecutor(); @@ -119,11 +121,11 @@ public class BidirectionalTopicOperationTest { ntimes = 1; - oper = new MyOperation(); + oper = new MyOperation(params, config); } @Test - public void testConstructor_testGetTopicHandler_testGetForwarder_testGetTopicParams() { + void testConstructor_testGetTopicHandler_testGetForwarder_testGetTopicParams() { assertEquals(ACTOR, oper.getActorName()); assertEquals(OPERATION, oper.getName()); assertSame(handler, oper.getTopicHandler()); @@ -133,8 +135,7 @@ public class BidirectionalTopicOperationTest { } @Test - public void testStartOperationAsync() throws Exception { - + void testStartOperationAsync() throws Exception { // tell it to expect three responses ntimes = 3; @@ -173,11 +174,11 @@ public class BidirectionalTopicOperationTest { * Tests startOperationAsync() when processResponse() throws an exception. */ @Test - public void testStartOperationAsyncProcException() throws Exception { - oper = new MyOperation() { + void testStartOperationAsyncProcException() throws Exception { + oper = new MyOperation(params, config) { @Override protected OperationOutcome processResponse(OperationOutcome outcome, String rawResponse, - StandardCoderObject scoResponse) { + StandardCoderObject scoResponse) { throw EXPECTED_EXCEPTION; } }; @@ -201,7 +202,7 @@ public class BidirectionalTopicOperationTest { * Tests startOperationAsync() when the publisher throws an exception. */ @Test - public void testStartOperationAsyncPubException() throws Exception { + void testStartOperationAsyncPubException() throws Exception { // indicate that nothing was published when(handler.send(any())).thenReturn(false); @@ -214,7 +215,7 @@ public class BidirectionalTopicOperationTest { } @Test - public void testGetTimeoutMsInteger() { + void testGetTimeoutMsInteger() { // use default assertEquals(TIMEOUT_MS, oper.getTimeoutMs(null)); assertEquals(TIMEOUT_MS, oper.getTimeoutMs(0)); @@ -224,7 +225,7 @@ public class BidirectionalTopicOperationTest { } @Test - public void testPublishRequest() { + void testPublishRequest() { assertThatCode(() -> oper.publishRequest(new MyRequest())).doesNotThrowAnyException(); } @@ -232,7 +233,7 @@ public class BidirectionalTopicOperationTest { * Tests publishRequest() when nothing is published. */ @Test - public void testPublishRequestUnpublished() { + void testPublishRequestUnpublished() { when(handler.send(any())).thenReturn(false); assertThatIllegalStateException().isThrownBy(() -> oper.publishRequest(new MyRequest())); } @@ -241,8 +242,8 @@ public class BidirectionalTopicOperationTest { * Tests publishRequest() when the request type is a String. */ @Test - public void testPublishRequestString() { - MyStringOperation oper2 = new MyStringOperation(); + void testPublishRequestString() { + MyStringOperation oper2 = new MyStringOperation(params, config); assertThatCode(() -> oper2.publishRequest(TEXT)).doesNotThrowAnyException(); } @@ -250,7 +251,7 @@ public class BidirectionalTopicOperationTest { * Tests publishRequest() when the coder throws an exception. */ @Test - public void testPublishRequestException() { + void testPublishRequestException() { setOperCoderException(); assertThatIllegalArgumentException().isThrownBy(() -> oper.publishRequest(new MyRequest())); } @@ -259,8 +260,8 @@ public class BidirectionalTopicOperationTest { * Tests processResponse() when it's a success and the response type is a String. */ @Test - public void testProcessResponseSuccessString() { - MyStringOperation oper2 = new MyStringOperation(); + void testProcessResponseSuccessString() { + MyStringOperation oper2 = new MyStringOperation(params, config); assertSame(outcome, oper2.processResponse(outcome, TEXT, null)); assertEquals(OperationResult.SUCCESS, outcome.getResult()); @@ -272,8 +273,8 @@ public class BidirectionalTopicOperationTest { * StandardCoderObject. */ @Test - public void testProcessResponseSuccessSco() { - MyScoOperation oper2 = new MyScoOperation(); + void testProcessResponseSuccessSco() { + MyScoOperation oper2 = new MyScoOperation(params, config); assertSame(outcome, oper2.processResponse(outcome, responseText, stdResponse)); assertEquals(OperationResult.SUCCESS, outcome.getResult()); @@ -284,7 +285,7 @@ public class BidirectionalTopicOperationTest { * Tests processResponse() when it's a failure. */ @Test - public void testProcessResponseFailure() throws CoderException { + void testProcessResponseFailure() throws CoderException { // indicate error in the response MyResponse resp = new MyResponse(); resp.setOutput("error"); @@ -301,7 +302,7 @@ public class BidirectionalTopicOperationTest { * Tests processResponse() when the decoder succeeds. */ @Test - public void testProcessResponseDecodeOk() throws CoderException { + void testProcessResponseDecodeOk() throws CoderException { assertSame(outcome, oper.processResponse(outcome, responseText, stdResponse)); assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(response, outcome.getResponse()); @@ -311,20 +312,18 @@ public class BidirectionalTopicOperationTest { * Tests processResponse() when the decoder throws an exception. */ @Test - public void testProcessResponseDecodeExcept() throws CoderException { - // @formatter:off + void testProcessResponseDecodeExcept() throws CoderException { assertThatIllegalArgumentException().isThrownBy( () -> oper.processResponse(outcome, "{invalid json", stdResponse)); - // @formatter:on } @Test - public void testPostProcessResponse() { + void testPostProcessResponse() { assertThatCode(() -> oper.postProcessResponse(outcome, null, null)).doesNotThrowAnyException(); } @Test - public void testGetCoder() { + void testGetCoder() { assertNotNull(oper.getCoder()); } @@ -332,7 +331,7 @@ public class BidirectionalTopicOperationTest { * Creates a new {@link #oper} whose coder will throw an exception. */ private void setOperCoderException() { - oper = new MyOperation() { + oper = new MyOperation(params, config) { @Override protected Coder getCoder() { return new StandardCoder() { @@ -347,7 +346,7 @@ public class BidirectionalTopicOperationTest { @Getter @Setter - public static class MyRequest { + static class MyRequest { private String theRequestId = REQ_ID; private String input; } @@ -355,7 +354,7 @@ public class BidirectionalTopicOperationTest { @Getter @Setter @EqualsAndHashCode - public static class MyResponse { + static class MyResponse { private String requestId; private String output; } @@ -363,8 +362,8 @@ public class BidirectionalTopicOperationTest { private class MyStringOperation extends BidirectionalTopicOperation<String, String> { - public MyStringOperation() { - super(BidirectionalTopicOperationTest.this.params, config, String.class, Collections.emptyList()); + MyStringOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) { + super(params, config, String.class, Collections.emptyList()); } @Override @@ -385,9 +384,8 @@ public class BidirectionalTopicOperationTest { private class MyScoOperation extends BidirectionalTopicOperation<MyRequest, StandardCoderObject> { - public MyScoOperation() { - super(BidirectionalTopicOperationTest.this.params, config, StandardCoderObject.class, - Collections.emptyList()); + MyScoOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) { + super(params, config, StandardCoderObject.class, Collections.emptyList()); } @Override @@ -408,8 +406,8 @@ public class BidirectionalTopicOperationTest { private class MyOperation extends BidirectionalTopicOperation<MyRequest, MyResponse> { - public MyOperation() { - super(BidirectionalTopicOperationTest.this.params, config, MyResponse.class, Collections.emptyList()); + MyOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) { + super(params, config, MyResponse.class, Collections.emptyList()); } @Override diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java index 4d19782c2..38e8a29bb 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,20 +23,21 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; 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.assertSame; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams; @@ -46,8 +48,9 @@ import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopic import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey; -@RunWith(MockitoJUnitRunner.class) -public class BidirectionalTopicOperatorTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class BidirectionalTopicOperatorTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-operation"; private static final String MY_SOURCE = "my-source"; @@ -70,12 +73,12 @@ public class BidirectionalTopicOperatorTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { keys = List.of(new SelectorKey("")); - when(mgr.getTopicHandler(MY_SINK, MY_SOURCE)).thenReturn(handler); - when(handler.addForwarder(keys)).thenReturn(forwarder); + Mockito.lenient().when(mgr.getTopicHandler(MY_SINK, MY_SOURCE)).thenReturn(handler); + Mockito.lenient().when(handler.addForwarder(keys)).thenReturn(forwarder); oper = new MyOperator(keys); @@ -86,14 +89,14 @@ public class BidirectionalTopicOperatorTest { } @Test - public void testConstructor_testGetParams_testGetTopicHandler_testGetForwarder() { + void testConstructor_testGetParams_testGetTopicHandler_testGetForwarder() { assertEquals(ACTOR, oper.getActorName()); assertEquals(OPERATION, oper.getName()); assertNotNull(oper.getCurrentConfig()); } @Test - public void testDoConfigure() { + void testDoConfigure() { oper.stop(); // invalid parameters @@ -104,7 +107,7 @@ public class BidirectionalTopicOperatorTest { } @Test - public void testBuildOperator() { + void testBuildOperator() { AtomicReference<ControlLoopOperationParams> paramsRef = new AtomicReference<>(); AtomicReference<BidirectionalTopicConfig> configRef = new AtomicReference<>(); @@ -147,7 +150,7 @@ public class BidirectionalTopicOperatorTest { private class MyOperator extends BidirectionalTopicOperator { - public MyOperator(List<SelectorKey> selectorKeys) { + MyOperator(List<SelectorKey> selectorKeys) { super(ACTOR, OPERATION, mgr, selectorKeys); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java index 5407f1fee..56a4c94cc 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,19 +22,19 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.Map; import java.util.TreeMap; import java.util.function.Function; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; -public class HttpActorTest { +class HttpActorTest { private static final String ACTOR = "my-actor"; private static final String UNKNOWN = "unknown"; @@ -42,13 +43,13 @@ public class HttpActorTest { private HttpActor<HttpActorParams> actor; - @Before - public void setUp() { + @BeforeEach + void setUp() { actor = new HttpActor<>(ACTOR, HttpActorParams.class); } @Test - public void testMakeOperatorParameters() { + void testMakeOperatorParameters() { HttpActorParams params = new HttpActorParams(); params.setClientName(CLIENT); params.setTimeoutSec(TIMEOUT); @@ -80,7 +81,7 @@ public class HttpActorTest { } @Test - public void testHttpActor() { + void testHttpActor() { assertEquals(ACTOR, actor.getName()); assertEquals(ACTOR, actor.getFullName()); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java index 7a99a54ba..9813d1b7a 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-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. @@ -25,11 +25,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 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.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.assertNotNull; +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.Mockito.when; @@ -59,13 +59,15 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; import lombok.Getter; import lombok.Setter; -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.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder; @@ -85,8 +87,9 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; -@RunWith(MockitoJUnitRunner.class) -public class HttpOperationTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class HttpOperationTest { private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception"); private static final String ACTOR = "my-actor"; @@ -129,8 +132,8 @@ public class HttpOperationTest { /** * Starts the simulator. */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + void setUpBeforeClass() throws Exception { // allocate a port int port = NetworkUtil.allocPort(); @@ -160,26 +163,26 @@ public class HttpOperationTest { /** * Destroys the Http factories and stops the appender. */ - @AfterClass - public static void tearDownAfterClass() { + @AfterAll + static void tearDownAfterClass() { HttpClientFactoryInstance.getClientFactory().destroy(); HttpServletServerFactoryInstance.getServerFactory().destroy(); } /** - * Initializes fields, including {@link #oper}, and resets the static fields used by + * Initializes fields, including {@link #oper}, and resets thestatic fields used by * the REST server. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { rejectRequest = false; nget = 0; npost = 0; nput = 0; ndelete = 0; - when(response.readEntity(String.class)).thenReturn(TEXT); - when(response.getStatus()).thenReturn(200); + Mockito.lenient().when(response.readEntity(String.class)).thenReturn(TEXT); + Mockito.lenient().when(response.getStatus()).thenReturn(200); params = ControlLoopOperationParams.builder().actor(ACTOR).operation(OPERATION).requestId(REQ_ID).build(); @@ -188,7 +191,7 @@ public class HttpOperationTest { callback = new AtomicReference<>(); future = new CompletableFuture<>(); - when(clientFactory.get(any())).thenReturn(client); + Mockito.lenient().when(clientFactory.get(any())).thenReturn(client); initConfig(HTTP_CLIENT); @@ -196,24 +199,24 @@ public class HttpOperationTest { } @Test - public void testHttpOperator() { + void testHttpOperator() { assertEquals(ACTOR, oper.getActorName()); assertEquals(OPERATION, oper.getName()); assertEquals(ACTOR + "." + OPERATION, oper.getFullName()); } @Test - public void testMakeHeaders() { + void testMakeHeaders() { assertEquals(Collections.emptyMap(), oper.makeHeaders()); } @Test - public void testGetPath() { + void testGetPath() { assertEquals(PATH, oper.getPath()); } @Test - public void testMakeUrl() { + void testMakeUrl() { // use a real client initRealConfig(HTTP_CLIENT); @@ -223,7 +226,7 @@ public class HttpOperationTest { } @Test - public void testDoConfigureMapOfStringObject_testGetClient_testGetPath_testGetTimeoutMs() { + void testDoConfigureMapOfStringObject_testGetClient_testGetPath_testGetTimeoutMs() { // use value from operator assertEquals(1000L, oper.getTimeoutMs(null)); @@ -237,7 +240,7 @@ public class HttpOperationTest { * Tests handleResponse() when it completes. */ @Test - public void testHandleResponseComplete() throws Exception { + void testHandleResponseComplete() throws Exception { CompletableFuture<OperationOutcome> future2 = oper.handleResponse(outcome, PATH, cb -> { callback.set(cb); return future; @@ -257,7 +260,7 @@ public class HttpOperationTest { * Tests handleResponse() when it fails. */ @Test - public void testHandleResponseFailed() throws Exception { + void testHandleResponseFailed() throws Exception { CompletableFuture<OperationOutcome> future2 = oper.handleResponse(outcome, PATH, cb -> { callback.set(cb); return future; @@ -278,7 +281,7 @@ public class HttpOperationTest { * Tests processResponse() when it's a success and the response type is a String. */ @Test - public void testProcessResponseSuccessString() throws Exception { + void testProcessResponseSuccessString() throws Exception { CompletableFuture<OperationOutcome> result = oper.processResponse(outcome, PATH, response); assertTrue(result.isDone()); assertSame(outcome, result.get()); @@ -290,7 +293,7 @@ public class HttpOperationTest { * Tests processResponse() when it's a failure. */ @Test - public void testProcessResponseFailure() throws Exception { + void testProcessResponseFailure() throws Exception { when(response.getStatus()).thenReturn(555); CompletableFuture<OperationOutcome> result = oper.processResponse(outcome, PATH, response); assertTrue(result.isDone()); @@ -303,7 +306,7 @@ public class HttpOperationTest { * Tests processResponse() when the decoder succeeds. */ @Test - public void testProcessResponseDecodeOk() throws Exception { + void testProcessResponseDecodeOk() throws Exception { when(response.readEntity(String.class)).thenReturn("10"); MyGetOperation<Integer> oper2 = new MyGetOperation<>(Integer.class); @@ -319,19 +322,19 @@ public class HttpOperationTest { * Tests processResponse() when the decoder throws an exception. */ @Test - public void testProcessResponseDecodeExcept() throws CoderException { + void testProcessResponseDecodeExcept() throws CoderException { MyGetOperation<Integer> oper2 = new MyGetOperation<>(Integer.class); assertThatIllegalArgumentException().isThrownBy(() -> oper2.processResponse(outcome, PATH, response)); } @Test - public void testPostProcessResponse() { + void testPostProcessResponse() { assertThatCode(() -> oper.postProcessResponse(outcome, PATH, null, null)).doesNotThrowAnyException(); } @Test - public void testIsSuccess() { + void testIsSuccess() { when(response.getStatus()).thenReturn(200); assertTrue(oper.isSuccess(response, null)); @@ -343,7 +346,7 @@ public class HttpOperationTest { * Tests a GET. */ @Test - public void testGet() throws Exception { + void testGet() throws Exception { // use a real client initRealConfig(HTTP_CLIENT); @@ -360,7 +363,7 @@ public class HttpOperationTest { * Tests a DELETE. */ @Test - public void testDelete() throws Exception { + void testDelete() throws Exception { // use a real client initRealConfig(HTTP_CLIENT); @@ -377,7 +380,7 @@ public class HttpOperationTest { * Tests a POST. */ @Test - public void testPost() throws Exception { + void testPost() throws Exception { // use a real client initRealConfig(HTTP_CLIENT); MyPostOperation oper2 = new MyPostOperation(); @@ -393,7 +396,7 @@ public class HttpOperationTest { * Tests a PUT. */ @Test - public void testPut() throws Exception { + void testPut() throws Exception { // use a real client initRealConfig(HTTP_CLIENT); @@ -407,7 +410,7 @@ public class HttpOperationTest { } @Test - public void testMakeDecoder() { + void testMakeDecoder() { assertNotNull(oper.getCoder()); } @@ -480,18 +483,18 @@ public class HttpOperationTest { @Getter @Setter - public static class MyRequest { + static class MyRequest { private String input = "some input"; } @Getter @Setter - public static class MyResponse { + static class MyResponse { private String output = "some output"; } private class MyGetOperation<T> extends HttpOperation<T> { - public MyGetOperation(Class<T> responseClass) { + MyGetOperation(Class<T> responseClass) { super(HttpOperationTest.this.params, HttpOperationTest.this.config, responseClass, Collections.emptyList()); } @@ -512,7 +515,7 @@ public class HttpOperationTest { } private class MyPostOperation extends HttpOperation<MyResponse> { - public MyPostOperation() { + MyPostOperation() { super(HttpOperationTest.this.params, HttpOperationTest.this.config, MyResponse.class, Collections.emptyList()); } @@ -540,7 +543,7 @@ public class HttpOperationTest { } private class MyPutOperation extends HttpOperation<MyResponse> { - public MyPutOperation() { + MyPutOperation() { super(HttpOperationTest.this.params, HttpOperationTest.this.config, MyResponse.class, Collections.emptyList()); } @@ -568,7 +571,7 @@ public class HttpOperationTest { } private class MyDeleteOperation extends HttpOperation<String> { - public MyDeleteOperation() { + MyDeleteOperation() { super(HttpOperationTest.this.params, HttpOperationTest.this.config, String.class, Collections.emptyList()); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java index 35cf08227..b070a6136 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,21 +23,22 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; 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.assertNull; +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.assertNull; import static org.mockito.Mockito.when; import java.util.Collections; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.controlloop.actorserviceprovider.Operation; @@ -47,8 +49,9 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; -@RunWith(MockitoJUnitRunner.class) -public class HttpOperatorTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class HttpOperatorTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-name"; @@ -68,8 +71,8 @@ public class HttpOperatorTest { * Initializes fields, including {@link #oper}, and resets the static fields used by * the REST server. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { when(factory.get(HTTP_CLIENT)).thenReturn(client); oper = new MyOperator(); @@ -80,14 +83,14 @@ public class HttpOperatorTest { } @Test - public void testHttpOperator() { + void testHttpOperator() { assertEquals(ACTOR, oper.getActorName()); assertEquals(OPERATION, oper.getName()); assertEquals(ACTOR + "." + OPERATION, oper.getFullName()); } @Test - public void testDoConfigureMapOfStringObject_testGetConfig() { + void testDoConfigureMapOfStringObject_testGetConfig() { // start with an UNCONFIGURED operator oper.shutdown(); oper = new MyOperator(); @@ -106,7 +109,7 @@ public class HttpOperatorTest { } @Test - public void testBuildOperation() { + void testBuildOperation() { HttpOperator oper2 = new MyOperator(); assertNotNull(oper2); assertNotNull(oper2.getClientFactory()); @@ -137,13 +140,13 @@ public class HttpOperatorTest { } @Test - public void testGetClientFactory() { + void testGetClientFactory() { HttpOperator oper2 = new HttpOperator(ACTOR, OPERATION); assertNotNull(oper2.getClientFactory()); } private class MyOperator extends HttpOperator { - public MyOperator() { + MyOperator() { super(ACTOR, OPERATION, MyOperation::new); } @@ -154,7 +157,7 @@ public class HttpOperatorTest { } private class MyOperation extends HttpOperation<String> { - public MyOperation(ControlLoopOperationParams params, HttpConfig config) { + MyOperation(ControlLoopOperationParams params, HttpConfig config) { super(params, config, String.class, Collections.emptyList()); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java index 2f7976ce5..0850bb358 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-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. @@ -23,11 +23,11 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; 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.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.assertNotNull; +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 static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -38,11 +38,13 @@ import java.util.Collections; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -54,8 +56,9 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingCo /** * Tests HttpOperation when polling is enabled. */ -@RunWith(MockitoJUnitRunner.class) -public class HttpPollingOperationTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class HttpPollingOperationTest { private static final String BASE_URI = "http://my-host:6969/base-uri/"; private static final String MY_PATH = "my-path"; private static final String FULL_PATH = BASE_URI + MY_PATH; @@ -85,19 +88,19 @@ public class HttpPollingOperationTest { /** * Sets up. */ - @Before - public void setUp() throws Exception { - when(client.getBaseUrl()).thenReturn(BASE_URI); + @BeforeEach + void setUp() throws Exception { + Mockito.lenient().when(client.getBaseUrl()).thenReturn(BASE_URI); - when(config.getClient()).thenReturn(client); - when(config.getMaxPolls()).thenReturn(MAX_POLLS); - when(config.getPollPath()).thenReturn(POLL_PATH); - when(config.getPollWaitSec()).thenReturn(POLL_WAIT_SEC); + Mockito.lenient().when(config.getClient()).thenReturn(client); + Mockito.lenient().when(config.getMaxPolls()).thenReturn(MAX_POLLS); + Mockito.lenient().when(config.getPollPath()).thenReturn(POLL_PATH); + Mockito.lenient().when(config.getPollWaitSec()).thenReturn(POLL_WAIT_SEC); response = MY_RESPONSE; - when(rawResponse.getStatus()).thenReturn(RESPONSE_SUCCESS); - when(rawResponse.readEntity(String.class)).thenReturn(response); + Mockito.lenient().when(rawResponse.getStatus()).thenReturn(RESPONSE_SUCCESS); + Mockito.lenient().when(rawResponse.readEntity(String.class)).thenReturn(response); params = ControlLoopOperationParams.builder().actor(MY_ACTOR).operation(MY_OPERATION).build(); outcome = params.makeOutcome(); @@ -106,7 +109,7 @@ public class HttpPollingOperationTest { } @Test - public void testConstructor_testGetWaitMsGet() { + void testConstructor_testGetWaitMsGet() { assertEquals(MY_ACTOR, oper.getActorName()); assertEquals(MY_OPERATION, oper.getName()); assertSame(config, oper.getConfig()); @@ -114,7 +117,7 @@ public class HttpPollingOperationTest { } @Test - public void testSetUsePollExceptions() { + void testSetUsePollExceptions() { // should be no exception oper.setUsePolling(); @@ -125,7 +128,7 @@ public class HttpPollingOperationTest { } @Test - public void testPostProcess() throws Exception { + void testPostProcess() throws Exception { // completed oper.generateSubRequestId(2); CompletableFuture<OperationOutcome> future2 = @@ -151,7 +154,7 @@ public class HttpPollingOperationTest { * Tests postProcess() when the poll is repeated a couple of times. */ @Test - public void testPostProcessRepeated_testResetGetCount() throws Exception { + void testPostProcessRepeated_testResetGetCount() throws Exception { /* * Two accepts and then a success - should result in two polls. */ @@ -193,7 +196,7 @@ public class HttpPollingOperationTest { } @Test - public void testDetmStatus() { + void testDetmStatus() { // make an operation that does NOT override detmStatus() oper = new HttpOperation<String>(params, config, String.class, Collections.emptyList()) {}; @@ -228,7 +231,7 @@ public class HttpPollingOperationTest { private static class MyOper extends HttpOperation<String> { - public MyOper(ControlLoopOperationParams params, HttpConfig config) { + MyOper(ControlLoopOperationParams params, HttpConfig config) { super(params, config, String.class, Collections.emptyList()); setUsePolling(); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java index f340f1972..ca81e2eb3 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,18 +22,20 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; 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.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.Mockito.when; import java.util.Collections; import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.controlloop.actorserviceprovider.Util; @@ -42,8 +45,9 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingCo import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; -@RunWith(MockitoJUnitRunner.class) -public class HttpPollingOperatorTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class HttpPollingOperatorTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-name"; private static final String CLIENT = "my-client"; @@ -64,8 +68,8 @@ public class HttpPollingOperatorTest { * Initializes fields, including {@link #oper}, and resets the static fields used by * the REST server. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { when(factory.get(CLIENT)).thenReturn(client); oper = new MyOperator(); @@ -77,14 +81,14 @@ public class HttpPollingOperatorTest { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(ACTOR, oper.getActorName()); assertEquals(OPERATION, oper.getName()); assertEquals(ACTOR + "." + OPERATION, oper.getFullName()); } @Test - public void testDoConfigure_testGetters() { + void testDoConfigure_testGetters() { assertTrue(oper.getCurrentConfig() instanceof HttpPollingConfig); // test invalid parameters @@ -93,7 +97,7 @@ public class HttpPollingOperatorTest { } @Test - public void testGetClientFactory() { + void testGetClientFactory() { HttpPollingOperator oper2 = new HttpPollingOperator(ACTOR, OPERATION); assertNotNull(oper2.getClientFactory()); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java index ae07f1f19..57dbfb141 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java @@ -23,12 +23,12 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import static org.assertj.core.api.Assertions.assertThat; 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.assertNotNull; -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.assertNotNull; +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 ch.qos.logback.classic.Logger; import java.time.Instant; @@ -53,13 +53,15 @@ import java.util.function.Consumer; import java.util.function.Supplier; import lombok.Getter; import lombok.Setter; -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.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; 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.utils.NetLoggerUtil.EventType; import org.onap.policy.common.utils.coder.Coder; @@ -79,8 +81,8 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfi import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.slf4j.LoggerFactory; -@RunWith(MockitoJUnitRunner.class) -public class OperationPartialTest { +@ExtendWith(MockitoExtension.class) +class OperationPartialTest { private static final CommInfrastructure SINK_INFRA = CommInfrastructure.NOOP; private static final CommInfrastructure SOURCE_INFRA = CommInfrastructure.NOOP; private static final int MAX_REQUESTS = 100; @@ -136,8 +138,8 @@ public class OperationPartialTest { /** * Attaches the appender to the logger. */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + static void setUpBeforeClass() throws Exception { /* * Attach appender to the logger. */ @@ -150,16 +152,16 @@ public class OperationPartialTest { /** * Stops the appender. */ - @AfterClass - public static void tearDownAfterClass() { + @AfterAll + static void tearDownAfterClass() { appender.stop(); } /** * Initializes the fields, including {@link #oper}. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { executor = new PseudoExecutor(); params = ControlLoopOperationParams.builder().completeCallback(this::completer).requestId(REQ_ID) @@ -180,14 +182,14 @@ public class OperationPartialTest { } @Test - public void testOperatorPartial_testGetActorName_testGetName() { + void testOperatorPartial_testGetActorName_testGetName() { assertEquals(ACTOR, oper.getActorName()); assertEquals(OPERATION, oper.getName()); assertEquals(ACTOR + "." + OPERATION, oper.getFullName()); } @Test - public void testGetBlockingThread() throws Exception { + void testGetBlockingThread() throws Exception { CompletableFuture<Void> future = new CompletableFuture<>(); // use the real executor @@ -204,12 +206,12 @@ public class OperationPartialTest { } @Test - public void testGetPropertyNames() { + void testGetPropertyNames() { assertThat(oper.getPropertyNames()).isEqualTo(PROP_NAMES); } @Test - public void testGetProperty_testSetProperty_testGetRequiredProperty() { + void testGetProperty_testSetProperty_testGetRequiredProperty() { oper.setProperty("propertyA", "valueA"); oper.setProperty("propertyB", "valueB"); oper.setProperty("propertyC", 20); @@ -226,7 +228,7 @@ public class OperationPartialTest { } @Test - public void testStart() { + void testStart() { verifyRun("testStart", 1, 1, OperationResult.SUCCESS); } @@ -234,7 +236,7 @@ public class OperationPartialTest { * Tests start() with multiple running requests. */ @Test - public void testStartMultiple() { + void testStartMultiple() { for (int count = 0; count < MAX_PARALLEL; ++count) { oper.start(); } @@ -251,7 +253,7 @@ public class OperationPartialTest { } @Test - public void testStartOperationAsync() { + void testStartOperationAsync() { oper.start(); assertTrue(executor.runAll(MAX_REQUESTS)); @@ -259,7 +261,7 @@ public class OperationPartialTest { } @Test - public void testIsSuccess() { + void testIsSuccess() { assertFalse(oper.isSuccess(null)); OperationOutcome outcome = new OperationOutcome(); @@ -269,12 +271,12 @@ public class OperationPartialTest { for (OperationResult failure : FAILURE_RESULTS) { outcome.setResult(failure); - assertFalse("testIsSuccess-" + failure, oper.isSuccess(outcome)); + assertFalse(oper.isSuccess(outcome), "testIsSuccess-" + failure); } } @Test - public void testIsActorFailed() { + void testIsActorFailed() { assertFalse(oper.isActorFailed(null)); OperationOutcome outcome = params.makeOutcome(); @@ -308,7 +310,7 @@ public class OperationPartialTest { } @Test - public void testDoOperation() { + void testDoOperation() { /* * Use an operation that doesn't override doOperation(). */ @@ -322,7 +324,7 @@ public class OperationPartialTest { } @Test - public void testTimeout() throws Exception { + void testTimeout() throws Exception { // use a real executor params = params.toBuilder().executor(ForkJoinPool.commonPool()).build(); @@ -360,7 +362,7 @@ public class OperationPartialTest { * Tests retry functions, when the count is set to zero and retries are exhausted. */ @Test - public void testSetRetryFlag_testRetryOnFailure_ZeroRetries_testStartOperationAttempt() { + void testSetRetryFlag_testRetryOnFailure_ZeroRetries_testStartOperationAttempt() { params = params.toBuilder().retry(0).build(); // new params, thus need a new operation @@ -375,7 +377,7 @@ public class OperationPartialTest { * Tests retry functions, when the count is null and retries are exhausted. */ @Test - public void testSetRetryFlag_testRetryOnFailure_NullRetries() { + void testSetRetryFlag_testRetryOnFailure_NullRetries() { params = params.toBuilder().retry(null).build(); // new params, thus need a new operation @@ -390,7 +392,7 @@ public class OperationPartialTest { * Tests retry functions, when retries are exhausted. */ @Test - public void testSetRetryFlag_testRetryOnFailure_RetriesExhausted() { + void testSetRetryFlag_testRetryOnFailure_RetriesExhausted() { final int maxRetries = 3; params = params.toBuilder().retry(maxRetries).build(); @@ -407,7 +409,7 @@ public class OperationPartialTest { * Tests retry functions, when a success follows some retries. */ @Test - public void testSetRetryFlag_testRetryOnFailure_SuccessAfterRetries() { + void testSetRetryFlag_testRetryOnFailure_SuccessAfterRetries() { params = params.toBuilder().retry(10).build(); // new params, thus need a new operation @@ -424,7 +426,7 @@ public class OperationPartialTest { * Tests retry functions, when the outcome is {@code null}. */ @Test - public void testSetRetryFlag_testRetryOnFailure_NullOutcome() { + void testSetRetryFlag_testRetryOnFailure_NullOutcome() { // arrange to return null from doOperation() oper = new MyOper() { @@ -441,7 +443,7 @@ public class OperationPartialTest { } @Test - public void testSleep() throws Exception { + void testSleep() throws Exception { CompletableFuture<Void> future = oper.sleep(-1, TimeUnit.SECONDS); assertTrue(future.isDone()); assertNull(future.get()); @@ -471,7 +473,7 @@ public class OperationPartialTest { } @Test - public void testIsSameOperation() { + void testIsSameOperation() { assertFalse(oper.isSameOperation(null)); OperationOutcome outcome = params.makeOutcome(); @@ -494,7 +496,7 @@ public class OperationPartialTest { } @Test - public void testFromException() { + void testFromException() { // arrange to generate an exception when operation runs oper.setGenException(true); @@ -505,7 +507,7 @@ public class OperationPartialTest { * Tests fromException() when there is no exception. */ @Test - public void testFromExceptionNoExcept() { + void testFromExceptionNoExcept() { verifyRun("testFromExceptionNoExcept", 1, 1, OperationResult.SUCCESS); } @@ -513,7 +515,7 @@ public class OperationPartialTest { * Tests both flavors of anyOf(), because one invokes the other. */ @Test - public void testAnyOf() throws Exception { + void testAnyOf() throws Exception { // first task completes, others do not List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); @@ -565,7 +567,7 @@ public class OperationPartialTest { */ @Test @SuppressWarnings("unchecked") - public void testAnyOfEdge() throws Exception { + void testAnyOfEdge() throws Exception { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); // zero items: check both using a list and using an array @@ -581,7 +583,7 @@ public class OperationPartialTest { } @Test - public void testAllOfArray() throws Exception { + void testAllOfArray() throws Exception { final OperationOutcome outcome = params.makeOutcome(); CompletableFuture<OperationOutcome> future1 = new CompletableFuture<>(); @@ -612,7 +614,7 @@ public class OperationPartialTest { } @Test - public void testAllOfList() throws Exception { + void testAllOfList() throws Exception { final OperationOutcome outcome = params.makeOutcome(); CompletableFuture<OperationOutcome> future1 = new CompletableFuture<>(); @@ -651,7 +653,7 @@ public class OperationPartialTest { */ @Test @SuppressWarnings("unchecked") - public void testAllOfEdge() throws Exception { + void testAllOfEdge() throws Exception { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); // zero items: check both using a list and using an array @@ -667,7 +669,7 @@ public class OperationPartialTest { } @Test - public void testAttachFutures() throws Exception { + void testAttachFutures() throws Exception { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); // third task throws an exception during construction @@ -690,7 +692,7 @@ public class OperationPartialTest { } @Test - public void testCombineOutcomes() throws Exception { + void testCombineOutcomes() throws Exception { // only one outcome verifyOutcomes(0, OperationResult.SUCCESS); verifyOutcomes(0, OperationResult.FAILURE_EXCEPTION); @@ -729,7 +731,7 @@ public class OperationPartialTest { * Tests both flavors of sequence(), because one invokes the other. */ @Test - public void testSequence() throws Exception { + void testSequence() throws Exception { final OperationOutcome outcome = params.makeOutcome(); List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); @@ -770,7 +772,7 @@ public class OperationPartialTest { */ @Test @SuppressWarnings("unchecked") - public void testSequenceEdge() throws Exception { + void testSequenceEdge() throws Exception { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); // zero items: check both using a list and using an array @@ -808,7 +810,7 @@ public class OperationPartialTest { } @Test - public void testDetmPriority() throws CoderException { + void testDetmPriority() throws CoderException { assertEquals(1, oper.detmPriority(null)); OperationOutcome outcome = params.makeOutcome(); @@ -819,7 +821,7 @@ public class OperationPartialTest { for (Entry<OperationResult, Integer> ent : map.entrySet()) { outcome.setResult(ent.getKey()); - assertEquals(ent.getKey().toString(), ent.getValue().intValue(), oper.detmPriority(outcome)); + assertEquals(ent.getValue().intValue(), oper.detmPriority(outcome), ent.getKey().toString()); } /* @@ -834,7 +836,7 @@ public class OperationPartialTest { * Tests callbackStarted() when the pipeline has already been stopped. */ @Test - public void testCallbackStartedNotRunning() { + void testCallbackStartedNotRunning() { AtomicReference<Future<OperationOutcome>> future = new AtomicReference<>(); /* @@ -860,7 +862,7 @@ public class OperationPartialTest { * Tests callbackCompleted() when the pipeline has already been stopped. */ @Test - public void testCallbackCompletedNotRunning() { + void testCallbackCompletedNotRunning() { AtomicReference<Future<OperationOutcome>> future = new AtomicReference<>(); // arrange to stop the controller when the start-callback is invoked @@ -880,7 +882,7 @@ public class OperationPartialTest { } @Test - public void testSetOutcomeControlLoopOperationOutcomeThrowable() { + void testSetOutcomeControlLoopOperationOutcomeThrowable() { final CompletionException timex = new CompletionException(new TimeoutException(EXPECTED_EXCEPTION)); OperationOutcome outcome; @@ -897,7 +899,7 @@ public class OperationPartialTest { } @Test - public void testSetOutcomeControlLoopOperationOutcomePolicyResult() { + void testSetOutcomeControlLoopOperationOutcomePolicyResult() { OperationOutcome outcome; outcome = new OperationOutcome(); @@ -912,19 +914,19 @@ public class OperationPartialTest { for (OperationResult result : FAILURE_RESULTS) { outcome = new OperationOutcome(); oper.setOutcome(outcome, result); - assertEquals(result.toString(), ControlLoopOperation.FAILED_MSG, outcome.getMessage()); - assertEquals(result.toString(), result, outcome.getResult()); + assertEquals(ControlLoopOperation.FAILED_MSG, outcome.getMessage(), result.toString()); + assertEquals(result, outcome.getResult(), result.toString()); } } @Test - public void testMakeOutcome() { + void testMakeOutcome() { oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, MY_TARGET_ENTITY); assertEquals(MY_TARGET_ENTITY, oper.makeOutcome().getTarget()); } @Test - public void testIsTimeout() { + void testIsTimeout() { final TimeoutException timex = new TimeoutException(EXPECTED_EXCEPTION); assertFalse(oper.isTimeout(new IllegalStateException(EXPECTED_EXCEPTION))); @@ -938,7 +940,7 @@ public class OperationPartialTest { } @Test - public void testLogMessage() { + void testLogMessage() { final String infraStr = SINK_INFRA.toString(); // log structured data @@ -994,20 +996,20 @@ public class OperationPartialTest { } @Test - public void testGetRetry() { + void testGetRetry() { assertEquals(0, oper.getRetry(null)); assertEquals(10, oper.getRetry(10)); } @Test - public void testGetRetryWait() { + void testGetRetryWait() { // need an operator that doesn't override the retry time OperationPartial oper2 = new OperationPartial(params, config, Collections.emptyList()) {}; assertEquals(OperationPartial.DEFAULT_RETRY_WAIT_MS, oper2.getRetryWaitMs()); } @Test - public void testGetTimeOutMs() { + void testGetTimeOutMs() { assertEquals(TIMEOUT * 1000, oper.getTimeoutMs(params.getTimeoutSec())); params = params.toBuilder().timeoutSec(null).build(); @@ -1080,30 +1082,30 @@ public class OperationPartialTest { manipulator.accept(future); - assertTrue(testName, executor.runAll(MAX_REQUESTS)); + assertTrue(executor.runAll(MAX_REQUESTS), testName); - assertEquals(testName, expectedCallbacks, numStart); - assertEquals(testName, expectedCallbacks, numEnd); + assertEquals(expectedCallbacks, numStart, testName); + assertEquals(expectedCallbacks, numEnd, testName); if (expectedCallbacks > 0) { - assertNotNull(testName, opstart); - assertNotNull(testName, opend); - assertEquals(testName, expectedResult, opend.getResult()); + assertNotNull(opstart, testName); + assertNotNull(opend, testName); + assertEquals(expectedResult, opend.getResult(), testName); - assertSame(testName, tstart, opstart.getStart()); - assertSame(testName, tstart, opend.getStart()); + assertSame(tstart, opstart.getStart(), testName); + assertSame(tstart, opend.getStart(), testName); try { assertTrue(future.isDone()); - assertEquals(testName, opend, future.get()); + assertEquals(opend, future.get(), testName); // "start" is never final for (OperationOutcome outcome : starts) { - assertFalse(testName, outcome.isFinalOutcome()); + assertFalse(outcome.isFinalOutcome(), testName); } // only the last "complete" is final - assertTrue(testName, ends.removeLast().isFinalOutcome()); + assertTrue(ends.removeLast().isFinalOutcome(), testName); for (OperationOutcome outcome : ends) { assertFalse(outcome.isFinalOutcome()); @@ -1115,12 +1117,12 @@ public class OperationPartialTest { if (expectedOperations > 0) { assertNotNull(testName, oper.getSubRequestId()); - assertEquals(testName + " op start", oper.getSubRequestId(), opstart.getSubRequestId()); - assertEquals(testName + " op end", oper.getSubRequestId(), opend.getSubRequestId()); + assertEquals(oper.getSubRequestId(), opstart.getSubRequestId(), testName + " op start"); + assertEquals(oper.getSubRequestId(), opend.getSubRequestId(), testName + " op end"); } } - assertEquals(testName, expectedOperations, oper.getCount()); + assertEquals(expectedOperations, oper.getCount(), testName); } /** @@ -1142,7 +1144,7 @@ public class OperationPartialTest { @Getter - public static class MyData { + static class MyData { private String text = TEXT; } @@ -1159,7 +1161,7 @@ public class OperationPartialTest { private CompletableFuture<OperationOutcome> preProc; - public MyOper() { + MyOper() { super(OperationPartialTest.this.params, config, PROP_NAMES); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartialTest.java index 370426fd4..20fe209fa 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartialTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -20,19 +21,19 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import java.util.Map; import java.util.TreeMap; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.controlloop.actorserviceprovider.Operation; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; -public class OperatorPartialTest { +class OperatorPartialTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-name"; @@ -41,8 +42,8 @@ public class OperatorPartialTest { /** * Initializes {@link #operator}. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { operator = new OperatorPartial(ACTOR, OPERATION) { @Override public Operation buildOperation(ControlLoopOperationParams params) { @@ -52,14 +53,14 @@ public class OperatorPartialTest { } @Test - public void testOperatorPartial_testGetActorName_testGetName() { + void testOperatorPartial_testGetActorName_testGetName() { assertEquals(ACTOR, operator.getActorName()); assertEquals(OPERATION, operator.getName()); assertEquals(ACTOR + "." + OPERATION, operator.getFullName()); } @Test - public void testDoStart() { + void testDoStart() { operator.configure(null); operator = spy(operator); @@ -69,7 +70,7 @@ public class OperatorPartialTest { } @Test - public void testDoStop() { + void testDoStop() { operator.configure(null); operator.start(); @@ -80,7 +81,7 @@ public class OperatorPartialTest { } @Test - public void testDoShutdown() { + void testDoShutdown() { operator.configure(null); operator.start(); @@ -91,7 +92,7 @@ public class OperatorPartialTest { } @Test - public void testDoConfigureMapOfStringObject() { + void testDoConfigureMapOfStringObject() { operator = spy(operator); Map<String, Object> params = new TreeMap<>(); @@ -101,7 +102,7 @@ public class OperatorPartialTest { } @Test - public void testGetBlockingExecutor() { + void testGetBlockingExecutor() { assertNotNull(operator.getBlockingExecutor()); } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/StartConfigPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/StartConfigPartialTest.java index 7a822c1d9..209cb495f 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/StartConfigPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/StartConfigPartialTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -22,18 +23,18 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; 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.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.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class StartConfigPartialTest { +class StartConfigPartialTest { private static final IllegalArgumentException EXPECTED_EXCEPTION = new IllegalArgumentException("expected exception"); private static final String MY_NAME = "my-name"; @@ -46,8 +47,8 @@ public class StartConfigPartialTest { /** * Creates a config whose doXxx() methods do nothing. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { config = new StartConfigPartial<>(MY_NAME) { @Override protected void doConfigure(String parameters) { @@ -74,17 +75,17 @@ public class StartConfigPartialTest { } @Test - public void testConfigImpl_testGetFullName() { + void testConfigImpl_testGetFullName() { assertEquals(MY_NAME, config.getFullName()); } @Test - public void testIsAlive() { + void testIsAlive() { assertFalse(config.isAlive()); } @Test - public void testIsConfigured_testConfigure() { + void testIsConfigured_testConfigure() { // throw an exception during doConfigure(), but should remain unconfigured assertFalse(config.isConfigured()); doThrow(EXPECTED_EXCEPTION).when(config).doConfigure(PARAMSX); @@ -114,7 +115,7 @@ public class StartConfigPartialTest { } @Test - public void testStart() { + void testStart() { assertFalse(config.isAlive()); // can't start if not configured yet @@ -147,7 +148,7 @@ public class StartConfigPartialTest { } @Test - public void testStop() { + void testStop() { config.configure(PARAMS); // ok to stop if not running, but shouldn't invoke doStop() @@ -179,7 +180,7 @@ public class StartConfigPartialTest { } @Test - public void testShutdown() { + void testShutdown() { config.configure(PARAMS); // ok to shutdown if not running, but shouldn't invoke doShutdown() diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ActorParamsTest.java index 0304ef3be..3999ecf74 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ActorParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ActorParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -23,23 +24,23 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Map; import java.util.TreeMap; import java.util.function.Consumer; import java.util.function.Function; import lombok.Setter; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Util; -public class ActorParamsTest { +class ActorParamsTest { private static final String CONTAINER = "my-container"; @@ -58,8 +59,8 @@ public class ActorParamsTest { * Initializes {@link #operations} with two items and {@link params} with a fully * populated object. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { operations = new TreeMap<>(); operations.put(PATH1, Map.of("path", URI1)); operations.put(PATH2, Map.of("path", URI2, "text2", TEXT2B)); @@ -68,7 +69,7 @@ public class ActorParamsTest { } @Test - public void testMakeOperationParameters() { + void testMakeOperationParameters() { Function<String, Map<String, Object>> maker = params.makeOperationParameters(CONTAINER); assertNull(maker.apply("unknown-operation")); @@ -82,7 +83,7 @@ public class ActorParamsTest { } @Test - public void testDoValidation() { + void testDoValidation() { assertThatCode(() -> params.doValidation(CONTAINER)).doesNotThrowAnyException(); // invalid param @@ -92,7 +93,7 @@ public class ActorParamsTest { } @Test - public void testValidate() { + void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); // only a few fields are required @@ -108,13 +109,13 @@ public class ActorParamsTest { // original params should be valid ValidationResult result = params.validate(CONTAINER); - assertTrue(fieldName, result.isValid()); + assertTrue(result.isValid(), fieldName); // make invalid params ActorParams params2 = makeActorParams(); makeInvalid.accept(params2); result = params2.validate(CONTAINER); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid(), fieldName); assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected); } @@ -128,7 +129,7 @@ public class ActorParamsTest { } @Setter - public static class MyParams extends ActorParams { + static class MyParams extends ActorParams { @SuppressWarnings("unused") private String text1; diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java index 769e0fca5..5c8b659fa 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,18 +22,18 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; import static org.assertj.core.api.Assertions.assertThat; -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 java.util.Collections; import java.util.Map; import java.util.function.Consumer; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Util; -public class BidirectionalTopicActorParamsTest { +class BidirectionalTopicActorParamsTest { private static final String CONTAINER = "my-container"; private static final String DFLT_SOURCE = "default-source"; @@ -58,8 +59,8 @@ public class BidirectionalTopicActorParamsTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { BidirectionalTopicParams oper1 = BidirectionalTopicParams.builder().sourceTopic(OPER1_SOURCE) .sinkTopic(OPER1_SINK).timeoutSec(OPER1_TIMEOUT).build(); @@ -72,7 +73,7 @@ public class BidirectionalTopicActorParamsTest { } @Test - public void testValidate() { + void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); // only a few fields are required @@ -97,13 +98,13 @@ public class BidirectionalTopicActorParamsTest { // original params should be valid ValidationResult result = params.validate(CONTAINER); - assertTrue(fieldName, result.isValid()); + assertTrue(result.isValid(), fieldName); // make invalid params BidirectionalTopicActorParams params2 = makeBidirectionalTopicActorParams(); makeInvalid.accept(params2); result = params2.validate(CONTAINER); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid(), fieldName); assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java index 7b44333f9..8f833b700 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,25 +21,27 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.List; import java.util.concurrent.Executor; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager; import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey; -@RunWith(MockitoJUnitRunner.class) -public class BidirectionalTopicConfigTest { +@ExtendWith(MockitoExtension.class) +class BidirectionalTopicConfigTest { private static final String MY_SINK = "my-sink"; private static final String MY_SOURCE = "my-source"; private static final int TIMEOUT_SEC = 10; @@ -57,8 +60,8 @@ public class BidirectionalTopicConfigTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { List<SelectorKey> keys = Arrays.asList(new SelectorKey("")); when(topicManager.getTopicHandler(MY_SINK, MY_SOURCE)).thenReturn(topicHandler); @@ -70,7 +73,7 @@ public class BidirectionalTopicConfigTest { } @Test - public void test() { + void test() { assertSame(executor, config.getBlockingExecutor()); assertSame(topicHandler, config.getTopicHandler()); assertSame(forwarder, config.getForwarder()); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicParamsTest.java index 0ec0bb57c..99915ac1a 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,17 +22,17 @@ package org.onap.policy.controlloop.actorserviceprovider.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.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.function.Function; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams.BidirectionalTopicParamsBuilder; -public class BidirectionalTopicParamsTest { +class BidirectionalTopicParamsTest { private static final String CONTAINER = "my-container"; private static final String SINK = "my-sink"; @@ -40,13 +41,13 @@ public class BidirectionalTopicParamsTest { private BidirectionalTopicParams params; - @Before - public void setUp() { + @BeforeEach + void setUp() { params = BidirectionalTopicParams.builder().sinkTopic(SINK).sourceTopic(SOURCE).timeoutSec(TIMEOUT).build(); } @Test - public void testValidate() { + void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); testValidateField("sink", "null", bldr -> bldr.sinkTopic(null)); @@ -59,7 +60,7 @@ public class BidirectionalTopicParamsTest { } @Test - public void testBuilder_testToBuilder() { + void testBuilder_testToBuilder() { assertEquals(SINK, params.getSinkTopic()); assertEquals(SOURCE, params.getSourceTopic()); assertEquals(TIMEOUT, params.getTimeoutSec()); @@ -75,11 +76,11 @@ public class BidirectionalTopicParamsTest { // original params should be valid ValidationResult result = params.validate(CONTAINER); - assertTrue(fieldName, result.isValid()); + assertTrue(result.isValid(), fieldName); // make invalid params result = makeInvalid.apply(params.toBuilder()).build().validate(CONTAINER); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid(), fieldName); assertThat(result.getResult()).contains(fieldName).contains(expected); } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java index bdf6b307a..55597611f 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,18 +23,17 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; 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.assertFalse; -import static org.junit.Assert.assertNotNull; -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.assertNotNull; +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 static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.util.Map; import java.util.TreeMap; @@ -44,11 +44,13 @@ import java.util.concurrent.ForkJoinPool; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.function.Function; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.controlloop.actorserviceprovider.ActorService; import org.onap.policy.controlloop.actorserviceprovider.Operation; @@ -57,8 +59,9 @@ import org.onap.policy.controlloop.actorserviceprovider.Operator; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams.ControlLoopOperationParamsBuilder; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; -@RunWith(MockitoJUnitRunner.class) -public class ControlLoopOperationParamsTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class ControlLoopOperationParamsTest { private static final String NULL_MSG = "null"; private static final String EXPECTED_EXCEPTION = "expected exception"; private static final String ACTOR = "my-actor"; @@ -100,12 +103,12 @@ public class ControlLoopOperationParamsTest { /** * Initializes mocks and sets {@link #params} to a fully-loaded set of parameters. */ - @Before - public void setUp() { - when(actorService.getActor(ACTOR)).thenReturn(actor); - when(actor.getOperator(OPERATION)).thenReturn(operator); - when(operator.buildOperation(any())).thenReturn(operation); - when(operation.start()).thenReturn(operFuture); + @BeforeEach + void setUp() { + Mockito.lenient().when(actorService.getActor(ACTOR)).thenReturn(actor); + Mockito.lenient().when(actor.getOperator(OPERATION)).thenReturn(operator); + Mockito.lenient().when(operator.buildOperation(any())).thenReturn(operation); + Mockito.lenient().when(operation.start()).thenReturn(operFuture); payload = new TreeMap<>(); @@ -118,26 +121,26 @@ public class ControlLoopOperationParamsTest { } @Test - public void testStart() { + void testStart() { assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().requestId(null).build().start()); assertSame(operFuture, params.start()); } @Test - public void testBuild() { + void testBuild() { assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().requestId(null).build().build()); assertSame(operation, params.build()); } @Test - public void testGetRequestId() { + void testGetRequestId() { assertSame(REQ_ID, params.getRequestId()); } @Test - public void testMakeOutcome() { + void testMakeOutcome() { assertEquals(ACTOR, outcome.getActor()); assertEquals(OPERATION, outcome.getOperation()); assertNull(outcome.getStart()); @@ -148,7 +151,7 @@ public class ControlLoopOperationParamsTest { } @Test - public void testCallbackStarted() { + void testCallbackStarted() { params.callbackStarted(outcome); verify(starter).accept(outcome); @@ -173,7 +176,7 @@ public class ControlLoopOperationParamsTest { } @Test - public void testCallbackCompleted() { + void testCallbackCompleted() { params.callbackCompleted(outcome); verify(completer).accept(outcome); @@ -198,7 +201,7 @@ public class ControlLoopOperationParamsTest { } @Test - public void testValidateFields() { + void testValidateFields() { testValidate("actor", NULL_MSG, bldr -> bldr.actor(null)); testValidate("actorService", NULL_MSG, bldr -> bldr.actorService(null)); testValidate("executor", NULL_MSG, bldr -> bldr.executor(null)); @@ -226,31 +229,31 @@ public class ControlLoopOperationParamsTest { // original params should be valid BeanValidationResult result = params.validate(); - assertTrue(fieldName, result.isValid()); + assertTrue(result.isValid(), fieldName); // make invalid params result = makeInvalid.apply(params.toBuilder()).build().validate(); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid(), fieldName); assertThat(result.getResult()).contains(fieldName).contains(expected); } @Test - public void testBuilder_testToBuilder() { + void testBuilder_testToBuilder() { assertEquals(params, params.toBuilder().build()); } @Test - public void testGetActor() { + void testGetActor() { assertSame(ACTOR, params.getActor()); } @Test - public void testGetActorService() { + void testGetActorService() { assertSame(actorService, params.getActorService()); } @Test - public void testGetExecutor() { + void testGetExecutor() { assertSame(executor, params.getExecutor()); // should use default when unspecified @@ -258,12 +261,12 @@ public class ControlLoopOperationParamsTest { } @Test - public void testGetOperation() { + void testGetOperation() { assertSame(OPERATION, params.getOperation()); } @Test - public void testGetPayload() { + void testGetPayload() { assertSame(payload, params.getPayload()); // should be null when unspecified @@ -271,7 +274,7 @@ public class ControlLoopOperationParamsTest { } @Test - public void testGetRetry() { + void testGetRetry() { assertSame(RETRY, params.getRetry()); // should be null when unspecified @@ -279,7 +282,7 @@ public class ControlLoopOperationParamsTest { } @Test - public void testGetTimeoutSec() { + void testGetTimeoutSec() { assertSame(TIMEOUT, params.getTimeoutSec()); // should be 300 when unspecified @@ -290,12 +293,12 @@ public class ControlLoopOperationParamsTest { } @Test - public void testGetStartCallback() { + void testGetStartCallback() { assertSame(starter, params.getStartCallback()); } @Test - public void testGetCompleteCallback() { + void testGetCompleteCallback() { assertSame(completer, params.getCompleteCallback()); } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java index 5812b0437..3e460bac3 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,18 +22,18 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; import static org.assertj.core.api.Assertions.assertThat; -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 java.util.Map; import java.util.TreeMap; import java.util.function.Consumer; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Util; -public class HttpActorParamsTest { +class HttpActorParamsTest { private static final String CONTAINER = "my-container"; private static final String CLIENT = "my-client"; @@ -50,8 +51,8 @@ public class HttpActorParamsTest { * Initializes {@link #operations} with two items and {@link params} with a fully * populated object. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { operations = new TreeMap<>(); operations.put(PATH1, Map.of("path", URI1)); operations.put(PATH2, Map.of("path", URI2)); @@ -60,7 +61,7 @@ public class HttpActorParamsTest { } @Test - public void testValidate() { + void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); // only a few fields are required @@ -83,13 +84,13 @@ public class HttpActorParamsTest { // original params should be valid ValidationResult result = params.validate(CONTAINER); - assertTrue(fieldName, result.isValid()); + assertTrue(result.isValid(), fieldName); // make invalid params HttpActorParams params2 = makeHttpActorParams(); makeInvalid.accept(params2); result = params2.validate(CONTAINER); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid(), fieldName); assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java index 181e0ba67..e43cd8c62 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,21 +21,21 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.when; import java.util.concurrent.Executor; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; -@RunWith(MockitoJUnitRunner.class) -public class HttpConfigTest { +@ExtendWith(MockitoExtension.class) +class HttpConfigTest { private static final String MY_CLIENT = "my-client"; private static final String MY_PATH = "my-path"; private static final int TIMEOUT_SEC = 10; @@ -51,8 +52,8 @@ public class HttpConfigTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { when(factory.get(MY_CLIENT)).thenReturn(client); HttpParams params = HttpParams.builder().clientName(MY_CLIENT).path(MY_PATH).timeoutSec(TIMEOUT_SEC).build(); @@ -60,7 +61,7 @@ public class HttpConfigTest { } @Test - public void test() { + void test() { assertSame(executor, config.getBlockingExecutor()); assertSame(client, config.getClient()); assertEquals(MY_PATH, config.getPath()); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java index f4c6a2089..f0611a79b 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,17 +22,17 @@ package org.onap.policy.controlloop.actorserviceprovider.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.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.function.Function; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams.HttpParamsBuilder; -public class HttpParamsTest { +class HttpParamsTest { private static final String CONTAINER = "my-container"; private static final String CLIENT = "my-client"; @@ -40,13 +41,13 @@ public class HttpParamsTest { private HttpParams params; - @Before - public void setUp() { + @BeforeEach + void setUp() { params = HttpParams.builder().clientName(CLIENT).path(PATH).timeoutSec(TIMEOUT).build(); } @Test - public void testValidate() { + void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); testValidateField("clientName", "null", bldr -> bldr.clientName(null)); @@ -63,7 +64,7 @@ public class HttpParamsTest { } @Test - public void testBuilder_testToBuilder() { + void testBuilder_testToBuilder() { assertEquals(CLIENT, params.getClientName()); assertEquals(PATH, params.getPath()); assertEquals(TIMEOUT, params.getTimeoutSec()); @@ -76,11 +77,11 @@ public class HttpParamsTest { // original params should be valid ValidationResult result = params.validate(CONTAINER); - assertTrue(fieldName, result.isValid()); + assertTrue(result.isValid(), fieldName); // make invalid params result = makeInvalid.apply(params.toBuilder()).build().validate(CONTAINER); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid(), fieldName); assertThat(result.getResult()).contains(fieldName).contains(expected); } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingActorParamsTest.java index 3202c2e54..f59887b91 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingActorParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingActorParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,19 +22,19 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; import static org.assertj.core.api.Assertions.assertThat; -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 java.util.Map; import java.util.TreeMap; import java.util.function.Consumer; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Util; -public class HttpPollingActorParamsTest { +class HttpPollingActorParamsTest { private static final String CONTAINER = "my-container"; private static final String CLIENT = "my-client"; private static final String POLL_PATH = "my-poll-path"; @@ -53,8 +54,8 @@ public class HttpPollingActorParamsTest { * Initializes {@link #operations} with two items and {@link params} with a fully * populated object. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { operations = new TreeMap<>(); operations.put(PATH1, Map.of("path", URI1)); operations.put(PATH2, Map.of("path", URI2)); @@ -63,7 +64,7 @@ public class HttpPollingActorParamsTest { } @Test - public void testValidate() { + void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); // only a few fields are required @@ -92,13 +93,13 @@ public class HttpPollingActorParamsTest { // original params should be valid ValidationResult result = params.validate(CONTAINER); - assertTrue(fieldName, result.isValid()); + assertTrue(result.isValid(), fieldName); // make invalid params HttpPollingActorParams params2 = makeHttpPollingActorParams(); makeInvalid.accept(params2); result = params2.validate(CONTAINER); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid(), fieldName); assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfigTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfigTest.java index 65fd308fe..0fcf39ed4 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfigTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfigTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,21 +21,21 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.when; import java.util.concurrent.Executor; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; -@RunWith(MockitoJUnitRunner.class) -public class HttpPollingConfigTest { +@ExtendWith(MockitoExtension.class) +class HttpPollingConfigTest { private static final String MY_CLIENT = "my-client"; private static final String MY_PATH = "my-path"; private static final String POLL_PATH = "poll-path"; @@ -55,8 +56,8 @@ public class HttpPollingConfigTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { when(factory.get(MY_CLIENT)).thenReturn(client); params = HttpPollingParams.builder().maxPolls(MAX_POLLS).pollPath(POLL_PATH).pollWaitSec(WAIT_SEC) @@ -65,7 +66,7 @@ public class HttpPollingConfigTest { } @Test - public void test() { + void test() { assertEquals(POLL_PATH + "/", config.getPollPath()); assertEquals(MAX_POLLS, config.getMaxPolls()); assertEquals(WAIT_SEC, config.getPollWaitSec()); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingParamsTest.java index 42a8717bd..6131dea04 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -21,17 +22,17 @@ package org.onap.policy.controlloop.actorserviceprovider.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.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.function.Function; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams.HttpPollingParamsBuilder; -public class HttpPollingParamsTest { +class HttpPollingParamsTest { private static final String CONTAINER = "my-container"; private static final String CLIENT = "my-client"; private static final String PATH = "my-path"; @@ -42,14 +43,14 @@ public class HttpPollingParamsTest { private HttpPollingParams params; - @Before - public void setUp() { + @BeforeEach + void setUp() { params = HttpPollingParams.builder().pollPath(POLL_PATH).maxPolls(MAX_POLLS).pollWaitSec(POLL_WAIT_SEC) .clientName(CLIENT).path(PATH).timeoutSec(TIMEOUT).build(); } @Test - public void testValidate() { + void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); testValidateField("pollPath", "null", bldr -> bldr.pollPath(null)); @@ -66,7 +67,7 @@ public class HttpPollingParamsTest { } @Test - public void testBuilder_testToBuilder() { + void testBuilder_testToBuilder() { assertEquals(CLIENT, params.getClientName()); assertEquals(POLL_PATH, params.getPollPath()); @@ -81,11 +82,11 @@ public class HttpPollingParamsTest { // original params should be valid ValidationResult result = params.validate(CONTAINER); - assertTrue(fieldName, result.isValid()); + assertTrue(result.isValid(), fieldName); // make invalid params result = makeInvalid.apply(params.toBuilder()).build().validate(CONTAINER); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid(), fieldName); assertThat(result.getResult()).contains(fieldName).contains(expected); } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ParameterValidationRuntimeExceptionTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ParameterValidationRuntimeExceptionTest.java index 328e4facb..dca27fb15 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ParameterValidationRuntimeExceptionTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ParameterValidationRuntimeExceptionTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -20,44 +21,44 @@ package org.onap.policy.controlloop.actorserviceprovider.parameters; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.parameters.ValidationStatus; -public class ParameterValidationRuntimeExceptionTest { +class ParameterValidationRuntimeExceptionTest { private static final String THE_MESSAGE = "the message"; private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception"); private ValidationResult result; - @Before - public void setUp() { + @BeforeEach + void setUp() { result = new ObjectValidationResult("param", null, ValidationStatus.INVALID, "null"); } @Test - public void testParameterValidationExceptionValidationResult() { + void testParameterValidationExceptionValidationResult() { ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(result); assertSame(result, ex.getResult()); assertNull(ex.getMessage()); } @Test - public void testParameterValidationExceptionValidationResultString() { + void testParameterValidationExceptionValidationResultString() { ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(THE_MESSAGE, result); assertSame(result, ex.getResult()); assertEquals(THE_MESSAGE, ex.getMessage()); } @Test - public void testParameterValidationExceptionValidationResultThrowable() { + void testParameterValidationExceptionValidationResultThrowable() { ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(EXPECTED_EXCEPTION, result); assertSame(result, ex.getResult()); assertEquals(EXPECTED_EXCEPTION.toString(), ex.getMessage()); @@ -65,7 +66,7 @@ public class ParameterValidationRuntimeExceptionTest { } @Test - public void testParameterValidationExceptionValidationResultStringThrowable() { + void testParameterValidationExceptionValidationResultStringThrowable() { ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(THE_MESSAGE, EXPECTED_EXCEPTION, result); assertSame(result, ex.getResult()); @@ -74,7 +75,7 @@ public class ParameterValidationRuntimeExceptionTest { } @Test - public void testGetResult() { + void testGetResult() { ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(result); assertSame(result, ex.getResult()); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/FutureManagerTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/FutureManagerTest.java index eff3dbb18..f97ff9ac1 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/FutureManagerTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/FutureManagerTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,22 +21,24 @@ package org.onap.policy.controlloop.actorserviceprovider.pipeline; -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.anyBoolean; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.concurrent.Future; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) -public class FutureManagerTest { +@ExtendWith(MockitoExtension.class) +class FutureManagerTest { private static final String EXPECTED_EXCEPTION = "expected exception"; @@ -53,13 +56,13 @@ public class FutureManagerTest { /** * Initializes fields, including {@link #mgr}. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { mgr = new FutureManager(); } @Test - public void testStop() { + void testStop() { mgr.add(future1); mgr.add(future2); mgr.add(future3); @@ -96,7 +99,7 @@ public class FutureManagerTest { } @Test - public void testAdd() { + void testAdd() { // still running - this should not be invoked mgr.add(future1); verify(future1, never()).cancel(anyBoolean()); @@ -119,7 +122,7 @@ public class FutureManagerTest { } @Test - public void testRemove() { + void testRemove() { mgr.add(future1); mgr.add(future2); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/ListenerManagerTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/ListenerManagerTest.java index bbd82cbd1..882a8b0f8 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/ListenerManagerTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/ListenerManagerTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,20 +21,20 @@ package org.onap.policy.controlloop.actorserviceprovider.pipeline; -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.never; import static org.mockito.Mockito.verify; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) -public class ListenerManagerTest { +@ExtendWith(MockitoExtension.class) +class ListenerManagerTest { private static final String EXPECTED_EXCEPTION = "expected exception"; @@ -51,13 +52,13 @@ public class ListenerManagerTest { /** * Initializes fields, including {@link #mgr}. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { mgr = new ListenerManager(); } @Test - public void testStop_testIsRunning() { + void testStop_testIsRunning() { mgr.add(runnable1); mgr.add(runnable2); mgr.add(runnable3); @@ -92,7 +93,7 @@ public class ListenerManagerTest { } @Test - public void testAdd() { + void testAdd() { // still running - this should not be invoked mgr.add(runnable1); verify(runnable1, never()).run(); @@ -111,7 +112,7 @@ public class ListenerManagerTest { } @Test - public void testRemove() { + void testRemove() { mgr.add(runnable1); mgr.add(runnable2); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java index 44c9e20af..c0d3a0df8 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +22,12 @@ package org.onap.policy.controlloop.actorserviceprovider.pipeline; 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.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -41,15 +42,15 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import java.util.function.Function; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) -public class PipelineControllerFutureTest { +@ExtendWith(MockitoExtension.class) +class PipelineControllerFutureTest { private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception"); private static final String TEXT = "some text"; @@ -77,8 +78,8 @@ public class PipelineControllerFutureTest { * Initializes fields, including {@link #controller}. Adds all runners and futures to * the controller. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { compFuture = spy(new CompletableFuture<>()); controller = new PipelineControllerFuture<>(); @@ -90,7 +91,7 @@ public class PipelineControllerFutureTest { } @Test - public void testCancel_testAddFutureOfFBoolean_testAddRunnable__testIsRunning() { + void testCancel_testAddFutureOfFBoolean_testAddRunnable__testIsRunning() { assertTrue(controller.isRunning()); assertTrue(controller.cancel(false)); @@ -110,7 +111,7 @@ public class PipelineControllerFutureTest { } @Test - public void testCompleteT() throws Exception { + void testCompleteT() throws Exception { assertTrue(controller.complete(TEXT)); assertEquals(TEXT, controller.get()); @@ -121,7 +122,7 @@ public class PipelineControllerFutureTest { } @Test - public void testCompleteExceptionallyThrowable() { + void testCompleteExceptionallyThrowable() { assertTrue(controller.completeExceptionally(EXPECTED_EXCEPTION)); assertThatThrownBy(() -> controller.get()).hasCause(EXPECTED_EXCEPTION); @@ -132,7 +133,7 @@ public class PipelineControllerFutureTest { } @Test - public void testCompleteAsyncSupplierOfQextendsTExecutor() throws Exception { + void testCompleteAsyncSupplierOfQextendsTExecutor() throws Exception { CompletableFuture<String> future = controller.completeAsync(() -> TEXT, executor); // haven't stopped anything yet @@ -156,7 +157,7 @@ public class PipelineControllerFutureTest { * Tests completeAsync(executor) when canceled before execution. */ @Test - public void testCompleteAsyncSupplierOfQextendsTExecutorCanceled() throws Exception { + void testCompleteAsyncSupplierOfQextendsTExecutorCanceled() throws Exception { CompletableFuture<String> future = controller.completeAsync(() -> TEXT, executor); assertTrue(future.cancel(false)); @@ -169,7 +170,7 @@ public class PipelineControllerFutureTest { } @Test - public void testCompleteAsyncSupplierOfQextendsT() throws Exception { + void testCompleteAsyncSupplierOfQextendsT() throws Exception { CompletableFuture<String> future = controller.completeAsync(() -> TEXT); assertEquals(TEXT, future.get()); @@ -180,7 +181,7 @@ public class PipelineControllerFutureTest { * Tests completeAsync() when canceled. */ @Test - public void testCompleteAsyncSupplierOfQextendsTCanceled() throws Exception { + void testCompleteAsyncSupplierOfQextendsTCanceled() throws Exception { CountDownLatch canceled = new CountDownLatch(1); // run async, but await until canceled @@ -207,7 +208,7 @@ public class PipelineControllerFutureTest { } @Test - public void testCompleteOnTimeoutTLongTimeUnit() throws Exception { + void testCompleteOnTimeoutTLongTimeUnit() throws Exception { CountDownLatch stopped = new CountDownLatch(1); controller.add(() -> stopped.countDown()); @@ -226,7 +227,7 @@ public class PipelineControllerFutureTest { * Tests completeOnTimeout() when completed before the timeout. */ @Test - public void testCompleteOnTimeoutTLongTimeUnitNoTimeout() throws Exception { + void testCompleteOnTimeoutTLongTimeUnitNoTimeout() throws Exception { CompletableFuture<String> future = controller.completeOnTimeout("timed out", 5, TimeUnit.SECONDS); controller.complete(TEXT); @@ -239,7 +240,7 @@ public class PipelineControllerFutureTest { * Tests completeOnTimeout() when canceled before the timeout. */ @Test - public void testCompleteOnTimeoutTLongTimeUnitCanceled() { + void testCompleteOnTimeoutTLongTimeUnitCanceled() { CompletableFuture<String> future = controller.completeOnTimeout(TEXT, 5, TimeUnit.SECONDS); assertTrue(future.cancel(true)); @@ -249,7 +250,7 @@ public class PipelineControllerFutureTest { } @Test - public void testNewIncompleteFuture() { + void testNewIncompleteFuture() { PipelineControllerFuture<String> future = controller.newIncompleteFuture(); assertNotNull(future); assertTrue(future instanceof PipelineControllerFuture); @@ -258,7 +259,7 @@ public class PipelineControllerFutureTest { } @Test - public void testDelayedComplete() throws Exception { + void testDelayedComplete() throws Exception { controller.add(runnable1); BiConsumer<String, Throwable> stopper = controller.delayedComplete(); @@ -287,7 +288,7 @@ public class PipelineControllerFutureTest { * Tests delayedComplete() when an exception is generated. */ @Test - public void testDelayedCompleteWithException() throws Exception { + void testDelayedCompleteWithException() throws Exception { controller.add(runnable1); BiConsumer<String, Throwable> stopper = controller.delayedComplete(); @@ -313,7 +314,7 @@ public class PipelineControllerFutureTest { } @Test - public void testDelayedRemoveFutureOfF() throws Exception { + void testDelayedRemoveFutureOfF() throws Exception { BiConsumer<String, Throwable> remover = controller.delayedRemove(future1); remover.accept(TEXT, EXPECTED_EXCEPTION); @@ -330,7 +331,7 @@ public class PipelineControllerFutureTest { } @Test - public void testDelayedRemoveRunnable() throws Exception { + void testDelayedRemoveRunnable() throws Exception { BiConsumer<String, Throwable> remover = controller.delayedRemove(runnable1); remover.accept(TEXT, EXPECTED_EXCEPTION); @@ -347,7 +348,7 @@ public class PipelineControllerFutureTest { } @Test - public void testRemoveFutureOfF_testRemoveRunnable() { + void testRemoveFutureOfF_testRemoveRunnable() { controller.remove(runnable2); controller.remove(future1); @@ -363,7 +364,7 @@ public class PipelineControllerFutureTest { * Tests both wrap() methods. */ @Test - public void testWrap() throws Exception { + void testWrap() throws Exception { controller = spy(controller); CompletableFuture<String> future = controller.wrap(compFuture); @@ -379,7 +380,7 @@ public class PipelineControllerFutureTest { * Tests wrap(), when the controller is not running. */ @Test - public void testWrapNotRunning() throws Exception { + void testWrapNotRunning() throws Exception { controller.cancel(false); controller = spy(controller); @@ -394,7 +395,7 @@ public class PipelineControllerFutureTest { * Tests wrap(), when the future throws an exception. */ @Test - public void testWrapException() throws Exception { + void testWrapException() throws Exception { controller = spy(controller); CompletableFuture<String> future = controller.wrap(compFuture); @@ -407,7 +408,7 @@ public class PipelineControllerFutureTest { } @Test - public void testWrapFunction() throws Exception { + void testWrapFunction() throws Exception { Function<String, CompletableFuture<String>> func = controller.wrap(input -> { compFuture.complete(input); @@ -427,7 +428,7 @@ public class PipelineControllerFutureTest { * Tests wrap(Function) when the controller is canceled after the future is added. */ @Test - public void testWrapFunctionCancel() throws Exception { + void testWrapFunctionCancel() throws Exception { Function<String, CompletableFuture<String>> func = controller.wrap(input -> compFuture); CompletableFuture<String> future = func.apply(TEXT); @@ -445,7 +446,7 @@ public class PipelineControllerFutureTest { * Tests wrap(Function) when the controller is not running. */ @Test - public void testWrapFunctionNotRunning() { + void testWrapFunctionNotRunning() { AtomicReference<String> value = new AtomicReference<>(); Function<String, CompletableFuture<String>> func = controller.wrap(input -> { diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtilTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtilTest.java index fbcacbf30..aef170ba7 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtilTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtilTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -22,13 +23,13 @@ package org.onap.policy.controlloop.actorserviceprovider.pipeline; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; -public class PipelineUtilTest { +class PipelineUtilTest { @Test - public void testPipelineUtil() { + void testPipelineUtil() { ControlLoopOperationParams params = ControlLoopOperationParams.builder().build(); PipelineUtil util = new PipelineUtil(params); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/BidirectionalTopicHandlerTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/BidirectionalTopicHandlerTest.java index f96fc0fdc..862e6c49d 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/BidirectionalTopicHandlerTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/BidirectionalTopicHandlerTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,28 +22,30 @@ package org.onap.policy.controlloop.actorserviceprovider.topic; 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.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.endpoints.event.comm.client.BidirectionalTopicClientException; -@RunWith(MockitoJUnitRunner.class) -public class BidirectionalTopicHandlerTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class BidirectionalTopicHandlerTest { private static final String UNKNOWN = "unknown"; private static final String MY_SOURCE = "my-source"; private static final String MY_SINK = "my-sink"; @@ -64,8 +67,8 @@ public class BidirectionalTopicHandlerTest { /** * Sets up. */ - @Before - public void setUp() throws BidirectionalTopicClientException { + @BeforeEach + void setUp() throws BidirectionalTopicClientException { when(mgr.getTopicSinks(MY_SINK)).thenReturn(Arrays.asList(publisher)); when(mgr.getTopicSources(Arrays.asList(MY_SOURCE))).thenReturn(Arrays.asList(subscriber)); @@ -77,7 +80,7 @@ public class BidirectionalTopicHandlerTest { } @Test - public void testBidirectionalTopicHandler_testGetSource_testGetTarget() { + void testBidirectionalTopicHandler_testGetSource_testGetTarget() { assertEquals(MY_SOURCE, handler.getSourceTopic()); assertEquals(MY_SINK, handler.getSinkTopic()); @@ -96,24 +99,24 @@ public class BidirectionalTopicHandlerTest { } @Test - public void testShutdown() { + void testShutdown() { handler.shutdown(); verify(subscriber).unregister(any()); } @Test - public void testStart() { + void testStart() { verify(subscriber).register(any()); } @Test - public void testStop() { + void testStop() { handler.stop(); verify(subscriber).unregister(any()); } @Test - public void testAddForwarder() { + void testAddForwarder() { // array form Forwarder forwarder = handler.addForwarder(new SelectorKey(KEY1), new SelectorKey(KEY2)); assertNotNull(forwarder); @@ -123,7 +126,7 @@ public class BidirectionalTopicHandlerTest { } @Test - public void testGetTopicEndpointManager() { + void testGetTopicEndpointManager() { // setting "mgr" to null should cause it to use the superclass' method mgr = null; assertNotNull(handler.getTopicEndpointManager()); @@ -131,7 +134,7 @@ public class BidirectionalTopicHandlerTest { private class MyTopicHandler extends BidirectionalTopicHandler { - public MyTopicHandler(String sinkTopic, String sourceTopic) throws BidirectionalTopicClientException { + MyTopicHandler(String sinkTopic, String sourceTopic) throws BidirectionalTopicClientException { super(sinkTopic, sourceTopic); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java index 3b368e225..e050416f5 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-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. @@ -30,16 +31,19 @@ import static org.mockito.Mockito.verify; import java.util.Arrays; import java.util.Map; import java.util.function.BiConsumer; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.Util; -@RunWith(MockitoJUnitRunner.class) -public class ForwarderTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class ForwarderTest { private static final String TEXT = "some text"; private static final String KEY1 = "requestId"; @@ -75,8 +79,8 @@ public class ForwarderTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { forwarder = new Forwarder(Arrays.asList(new SelectorKey(KEY1), new SelectorKey(KEY2, SUBKEY))); forwarder.register(Arrays.asList(VALUEA_REQID, VALUEA_SUBREQID), listener1); @@ -86,7 +90,7 @@ public class ForwarderTest { } @Test - public void testRegister() { + void testRegister() { // key size mismatches assertThatIllegalArgumentException().isThrownBy(() -> forwarder.register(Arrays.asList(), listener1)) .withMessage("key/value mismatch"); @@ -96,7 +100,7 @@ public class ForwarderTest { } @Test - public void testUnregister() { + void testUnregister() { // remove listener1b forwarder.unregister(Arrays.asList(VALUEA_REQID, VALUEA_SUBREQID), listener1b); @@ -121,7 +125,7 @@ public class ForwarderTest { } @Test - public void testOnMessage() { + void testOnMessage() { StandardCoderObject sco = makeMessage(Map.of(KEY1, VALUEA_REQID, KEY2, Map.of(SUBKEY, VALUEA_SUBREQID))); forwarder.onMessage(TEXT, sco); @@ -166,7 +170,7 @@ public class ForwarderTest { * Tests onMessage() when listener1 throws an exception. */ @Test - public void testOnMessageListenerException1() { + void testOnMessageListenerException1() { doThrow(new IllegalStateException("expected exception")).when(listener1).accept(any(), any()); StandardCoderObject sco = makeMessage(Map.of(KEY1, VALUEA_REQID, KEY2, Map.of(SUBKEY, VALUEA_SUBREQID))); @@ -179,7 +183,7 @@ public class ForwarderTest { * Tests onMessage() when listener1b throws an exception. */ @Test - public void testOnMessageListenerException1b() { + void testOnMessageListenerException1b() { doThrow(new IllegalStateException("expected exception")).when(listener1b).accept(any(), any()); StandardCoderObject sco = makeMessage(Map.of(KEY1, VALUEA_REQID, KEY2, Map.of(SUBKEY, VALUEA_SUBREQID))); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/SelectorKeyTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/SelectorKeyTest.java index 5ffcbf7dc..dd39a03c6 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/SelectorKeyTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/SelectorKeyTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * 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. @@ -20,34 +21,34 @@ package org.onap.policy.controlloop.actorserviceprovider.topic; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.Map; import lombok.Builder; import lombok.Getter; import lombok.Setter; -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.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.Util; -public class SelectorKeyTest { +class SelectorKeyTest { private static final String FIELD1 = "map"; private static final String FIELD2 = "abc"; private static final String FIELDX = "abd"; private SelectorKey key; - @Before - public void setUp() { + @BeforeEach + void setUp() { key = new SelectorKey(FIELD1, FIELD2); } @Test - public void testHashCode_testEquals() { + void testHashCode_testEquals() { SelectorKey key2 = new SelectorKey(FIELD1, FIELD2); assertEquals(key, key2); assertEquals(key.hashCode(), key2.hashCode()); @@ -64,7 +65,7 @@ public class SelectorKeyTest { } @Test - public void testExtractField() { + void testExtractField() { Map<String, Object> map = Map.of("hello", "world", FIELD1, Map.of("another", "", FIELD2, "value B")); StandardCoderObject sco = Util.translate("", map, StandardCoderObject.class); @@ -84,7 +85,7 @@ public class SelectorKeyTest { } @Test - public void testToString() { + void testToString() { assertEquals("[map, abc]", key.toString()); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/TopicListenerImplTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/TopicListenerImplTest.java index 9e3b476e9..3044a1e44 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/TopicListenerImplTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/TopicListenerImplTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +21,9 @@ package org.onap.policy.controlloop.actorserviceprovider.topic; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +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.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; @@ -31,18 +32,20 @@ import static org.mockito.Mockito.verify; import java.util.Arrays; import java.util.Map; import java.util.function.BiConsumer; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; -@RunWith(MockitoJUnitRunner.class) -public class TopicListenerImplTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) +class TopicListenerImplTest { private static final StandardCoder coder = new StandardCoder(); private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; private static final String MY_TOPIC = "my-topic"; @@ -72,8 +75,8 @@ public class TopicListenerImplTest { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { topic = new TopicListenerImpl(); forwarder1 = topic.addForwarder(new SelectorKey(KEY1)); @@ -89,7 +92,7 @@ public class TopicListenerImplTest { } @Test - public void testShutdown() { + void testShutdown() { // shut it down, which should clear all forwarders topic.shutdown(); @@ -103,13 +106,13 @@ public class TopicListenerImplTest { } @Test - public void testAddForwarder() { + void testAddForwarder() { assertSame(forwarder1, topic.addForwarder(new SelectorKey(KEY1))); assertSame(forwarder2, topic.addForwarder(new SelectorKey(KEY1), new SelectorKey(KEY2, SUBKEY))); } @Test - public void testOnTopicEvent() { + void testOnTopicEvent() { /* * send a message that should go to listener1 on forwarder1 and listener2 on * forwarder2 |