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/actor.so/src/test/java | |
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/actor.so/src/test/java')
8 files changed, 197 insertions, 195 deletions
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java index 1e38861e2..286ed3ce4 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 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. @@ -47,20 +47,20 @@ import org.onap.policy.so.SoResponse; /** * Superclass for various operator tests. */ -public abstract class BasicSoOperation extends BasicHttpOperation { +abstract class BasicSoOperation extends BasicHttpOperation { protected static final String[] IGNORE_FIELDS = {"RequestID", "subRequestID", "seconds", "nanos"}; - public static final String MODEL_CUSTOM_ID = "my-model-customization-id"; - public static final String MODEL_INVAR_ID = "my-model-invariant-id"; - public static final String MODEL_NAME = "my-model-name"; - public static final String MODEL_VERSION = "my-model-version"; - public static final String MODEL_VERS_ID = "my-model-version-id"; - public static final String SUBSCRIPTION_SVC_TYPE = "my-subscription-service-type"; - public static final String MY_PATH = "my-path"; - public static final String POLL_PATH = "my-poll-path/"; - public static final int MAX_POLLS = 3; - public static final int POLL_WAIT_SEC = 20; - public static final Integer VF_COUNT = 10; + static final String MODEL_CUSTOM_ID = "my-model-customization-id"; + static final String MODEL_INVAR_ID = "my-model-invariant-id"; + static final String MODEL_NAME = "my-model-name"; + static final String MODEL_VERSION = "my-model-version"; + static final String MODEL_VERS_ID = "my-model-version-id"; + static final String SUBSCRIPTION_SVC_TYPE = "my-subscription-service-type"; + static final String MY_PATH = "my-path"; + static final String POLL_PATH = "my-poll-path/"; + static final int MAX_POLLS = 3; + static final int POLL_WAIT_SEC = 20; + static final Integer VF_COUNT = 10; @Mock protected HttpPollingConfig config; @@ -72,7 +72,7 @@ public abstract class BasicSoOperation extends BasicHttpOperation { /** * Constructs the object using a default actor and operation name. */ - public BasicSoOperation() { + BasicSoOperation() { super(); } @@ -82,7 +82,7 @@ public abstract class BasicSoOperation extends BasicHttpOperation { * @param actor actor name * @param operation operation name */ - public BasicSoOperation(String actor, String operation) { + BasicSoOperation(String actor, String operation) { super(actor, operation); } @@ -93,8 +93,8 @@ public abstract class BasicSoOperation extends BasicHttpOperation { org.onap.policy.simulators.Util.buildSoSim(); BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("").hostname("localhost") - .managed(true).port(org.onap.policy.simulators.Util.SOSIM_SERVER_PORT) - .build(); + .managed(true).port(org.onap.policy.simulators.Util.SOSIM_SERVER_PORT) + .build(); HttpClientFactoryInstance.getClientFactory().build(clientParams); SoSimulatorJaxRs.setRequirePolling(true); @@ -109,7 +109,7 @@ public abstract class BasicSoOperation extends BasicHttpOperation { /** * Initializes mocks and sets up. */ - public void setUp() throws Exception { + void setUp() throws Exception { super.setUpBasic(); response = new SoResponse(); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java index f7a59201d..ff1a93b85 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2022 CTC, Inc. and others. 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. @@ -24,17 +24,17 @@ package org.onap.policy.controlloop.actor.so; import static org.assertj.core.api.Assertions.assertThat; 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 java.util.List; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +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.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; @@ -43,35 +43,35 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingCo import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; import org.onap.policy.so.SoResponse; -@RunWith(MockitoJUnitRunner.class) -public class ModifyCllTest extends BasicSoOperation { +@ExtendWith(MockitoExtension.class) +class ModifyCllTest extends BasicSoOperation { private ModifyCll oper; - public ModifyCllTest() { + ModifyCllTest() { super(DEFAULT_ACTOR, ModifyCll.NAME); } - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + static void setUpBeforeClass() throws Exception { initBeforeClass(); } - @AfterClass - public static void tearDownAfterClass() { + @AfterAll + static void tearDownAfterClass() { destroyAfterClass(); } @Override - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { super.setUp(); oper = new ModifyCll(params, config); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT) .path("infra/serviceIntent/v1/modify") .pollPath("orchestrationRequests/v5/").maxPolls(2).build(); @@ -87,7 +87,7 @@ public class ModifyCllTest extends BasicSoOperation { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(ModifyCll.NAME, oper.getName()); assertFalse(oper.isUsePolling()); @@ -98,7 +98,7 @@ public class ModifyCllTest extends BasicSoOperation { } @Test - public void testGetPropertyNames() { + void testGetPropertyNames() { assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.EVENT_PAYLOAD)); } @@ -110,7 +110,7 @@ public class ModifyCllTest extends BasicSoOperation { * Tests makeRequest() when a property is missing. */ @Test - public void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() throws Exception { oper = new ModifyCll(params, config); assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest()) diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java index 8a31f2c93..c5c183275 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2020 Wipro Limited. * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020,2023 Nordix Foundation. + * Modifications Copyright (C) 2020,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,17 +25,17 @@ package org.onap.policy.controlloop.actor.so; import static org.assertj.core.api.Assertions.assertThat; 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.assertInstanceOf; import java.util.List; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +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.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; @@ -44,35 +44,35 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingCo import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; import org.onap.policy.so.SoResponse; -@RunWith(MockitoJUnitRunner.class) -public class ModifyNssiTest extends BasicSoOperation { +@ExtendWith(MockitoExtension.class) +class ModifyNssiTest extends BasicSoOperation { private ModifyNssi oper; - public ModifyNssiTest() { + ModifyNssiTest() { super(DEFAULT_ACTOR, ModifyNssi.NAME); } - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + static void setUpBeforeClass() throws Exception { initBeforeClass(); } - @AfterClass - public static void tearDownAfterClass() { + @AfterAll + static void tearDownAfterClass() { destroyAfterClass(); } @Override - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { super.setUp(); oper = new ModifyNssi(params, config); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("3gppservices/v7/modify") .pollPath("orchestrationRequests/v5/").maxPolls(2).build(); config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); @@ -83,11 +83,11 @@ public class ModifyNssiTest extends BasicSoOperation { outcome = oper.start().get(); assertEquals(OperationResult.SUCCESS, outcome.getResult()); - assertTrue(outcome.getResponse() instanceof SoResponse); + assertInstanceOf(SoResponse.class, outcome.getResponse()); } @Test - public void testConstructor() { + void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(ModifyNssi.NAME, oper.getName()); assertFalse(oper.isUsePolling()); @@ -98,7 +98,7 @@ public class ModifyNssiTest extends BasicSoOperation { } @Test - public void testGetPropertyNames() { + void testGetPropertyNames() { assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.EVENT_PAYLOAD)); } @@ -110,7 +110,7 @@ public class ModifyNssiTest extends BasicSoOperation { * Tests makeRequest() when a property is missing. */ @Test - public void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() throws Exception { oper = new ModifyNssi(params, config); assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest()) diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/RestManagerResponseTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/RestManagerResponseTest.java index 2055adbc8..8b5a050b6 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/RestManagerResponseTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/RestManagerResponseTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 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. @@ -24,16 +24,16 @@ package org.onap.policy.controlloop.actor.so; 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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import jakarta.ws.rs.core.GenericType; -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.Coder; import org.onap.policy.common.utils.coder.StandardCoder; -public class RestManagerResponseTest { +class RestManagerResponseTest { private static final Coder coder = new StandardCoder(); private static final int MY_STATUS = 200; @@ -41,23 +41,23 @@ public class RestManagerResponseTest { private RestManagerResponse resp; - @Before - public void setUp() { + @BeforeEach + void setUp() { resp = new RestManagerResponse(MY_STATUS, MY_TEXT, coder); } @Test - public void testGetStatus() { + void testGetStatus() { assertEquals(MY_STATUS, resp.getStatus()); } @Test - public void testClose() { + void testClose() { assertThatCode(() -> resp.close()).doesNotThrowAnyException(); } @Test - public void testReadEntityClassOfT() { + void testReadEntityClassOfT() { // try with JSON MyObject obj = resp.readEntity(MyObject.class); assertNotNull(obj); @@ -75,7 +75,7 @@ public class RestManagerResponseTest { @Test @SuppressWarnings("unchecked") - public void testUnsupported() { + void testUnsupported() { GenericType<String> generic = GenericType.forInstance(String.class); assertThatThrownBy(() -> resp.hasEntity()).isInstanceOf(UnsupportedOperationException.class); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java index a06c91817..9cd1bea7a 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2018-2020 AT&T. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 2024 Nordix Foundation. * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,29 +23,29 @@ package org.onap.policy.controlloop.actor.so; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.stream.Collectors; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.controlloop.actor.test.BasicActor; -public class SoActorTest extends BasicActor { +class SoActorTest extends BasicActor { @Test - public void testConstructor() { + void testConstructor() { SoActor prov = new SoActor(); // verify that it has the operators we expect var expected = Arrays.asList(VfModuleCreate.NAME, VfModuleDelete.NAME, ModifyNssi.NAME, ModifyCll.NAME).stream() - .sorted().collect(Collectors.toList()); + .sorted().collect(Collectors.toList()); var actual = prov.getOperationNames().stream().sorted().collect(Collectors.toList()); assertEquals(expected.toString(), actual.toString()); } @Test - public void testActorService() { + void testActorService() { // verify that it all plugs into the ActorService verifyActorService(SoActor.NAME, "service.yaml"); } diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java index a2d392510..fe88a2371 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Wipro Limited. - * 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. @@ -24,11 +24,11 @@ package org.onap.policy.controlloop.actor.so; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.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.Mockito.lenient; import java.time.LocalDateTime; @@ -36,10 +36,10 @@ import java.time.Month; import java.util.Collections; import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.Tenant; import org.onap.policy.common.utils.coder.Coder; @@ -53,8 +53,8 @@ import org.onap.policy.so.SoRequestInfo; import org.onap.policy.so.SoRequestStatus; import org.onap.policy.so.SoResponse; -@RunWith(MockitoJUnitRunner.class) -public class SoOperationTest extends BasicSoOperation { +@ExtendWith(MockitoExtension.class) + class SoOperationTest extends BasicSoOperation { private static final List<String> PROP_NAMES = Collections.emptyList(); @@ -64,8 +64,8 @@ public class SoOperationTest extends BasicSoOperation { * Sets up. */ @Override - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { super.setUp(); initConfig(); @@ -74,7 +74,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(DEFAULT_OPERATION, oper.getName()); assertSame(config, oper.getConfig()); @@ -86,7 +86,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testValidateTarget() { + void testValidateTarget() { // check when various fields are null verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_CUSTOMIZATION_ID, targetEntities); verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_INVARIANT_ID, targetEntities); @@ -108,7 +108,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testGetRequestState() { + void testGetRequestState() { SoResponse resp = new SoResponse(); assertNull(oper.getRequestState(resp)); @@ -125,7 +125,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testIsSuccess() { + void testIsSuccess() { // always true assertTrue(oper.isSuccess(rawResponse, response)); @@ -135,7 +135,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testSetOutcome() { + void testSetOutcome() { // success case lenient().when(rawResponse.getStatus()).thenReturn(200); assertSame(outcome, oper.setOutcome(outcome, OperationResult.SUCCESS, rawResponse, response)); @@ -154,7 +154,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testPrepareSoModelInfo() throws CoderException { + void testPrepareSoModelInfo() throws CoderException { // valid data SoModelInfo info = oper.prepareSoModelInfo(); verifyRequest("model.json", info); @@ -166,13 +166,13 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testConstructRequestInfo() throws CoderException { + void testConstructRequestInfo() throws CoderException { SoRequestInfo info = oper.constructRequestInfo(); verifyRequest("reqinfo.json", info); } @Test - public void testBuildRequestParameters() throws CoderException { + void testBuildRequestParameters() throws CoderException { // valid data verifyRequest("reqparams.json", oper.buildRequestParameters().get()); @@ -192,7 +192,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testBuildConfigurationParameters() { + void testBuildConfigurationParameters() { // valid data assertEquals(List.of(Collections.emptyMap()), oper.buildConfigurationParameters().get()); @@ -212,7 +212,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testConstructCloudConfiguration() throws Exception { + void testConstructCloudConfiguration() throws Exception { Tenant tenantItem = new Tenant(); tenantItem.setTenantId("my-tenant-id"); @@ -235,7 +235,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testGetRequiredText() throws Exception { + void testGetRequiredText() throws Exception { assertThatCode(() -> oper.getRequiredText("some value", "my value")).doesNotThrowAnyException(); @@ -244,7 +244,7 @@ public class SoOperationTest extends BasicSoOperation { } @Test - public void testGetCoder() throws CoderException { + void testGetCoder() throws CoderException { Coder opcoder = oper.getCoder(); // ensure we can decode an SO timestamp diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java index ad242c0dc..721cb6a6d 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Wipro Limited. - * 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. @@ -24,9 +24,10 @@ package org.onap.policy.controlloop.actor.so; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -35,12 +36,12 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.tuple.Pair; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +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.junit.jupiter.MockitoExtension; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ModelVer; @@ -56,8 +57,8 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingPa import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoResponse; -@RunWith(MockitoJUnitRunner.class) -public class VfModuleCreateTest extends BasicSoOperation { +@ExtendWith(MockitoExtension.class) +class VfModuleCreateTest extends BasicSoOperation { private static final String MODEL_NAME2 = "my-model-name-B"; @@ -67,26 +68,26 @@ public class VfModuleCreateTest extends BasicSoOperation { private VfModuleCreate oper; - public VfModuleCreateTest() { + VfModuleCreateTest() { super(DEFAULT_ACTOR, VfModuleCreate.NAME); } - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + static void setUpBeforeClass() throws Exception { initBeforeClass(); } - @AfterClass - public static void tearDownAfterClass() { + @AfterAll + static void tearDownAfterClass() { destroyAfterClass(); } /** * Sets up. */ - @Before + @BeforeEach @Override - public void setUp() throws Exception { + void setUp() throws Exception { super.setUp(); oper = new VfModuleCreate(params, config); loadProperties(); @@ -96,10 +97,10 @@ public class VfModuleCreateTest extends BasicSoOperation { * Tests "success" case with simulator. */ @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT) - .path("serviceInstantiation/v7/serviceInstances").pollPath("orchestrationRequests/v5/") - .maxPolls(2).build(); + .path("serviceInstantiation/v7/serviceInstances").pollPath("orchestrationRequests/v5/") + .maxPolls(2).build(); config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); @@ -111,14 +112,14 @@ public class VfModuleCreateTest extends BasicSoOperation { // run the operation outcome = oper.start().get(); assertEquals(OperationResult.SUCCESS, outcome.getResult()); - assertTrue(outcome.getResponse() instanceof SoResponse); + assertInstanceOf(SoResponse.class, outcome.getResponse()); int count = oper.getProperty(OperationProperties.DATA_VF_COUNT); assertEquals(VF_COUNT + 1, count); } @Test - public void testConstructor() { + void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(VfModuleCreate.NAME, oper.getName()); assertTrue(oper.isUsePolling()); @@ -126,26 +127,26 @@ public class VfModuleCreateTest extends BasicSoOperation { // verify that target validation is done params = params.toBuilder().targetType(null).build(); assertThatIllegalArgumentException().isThrownBy(() -> new VfModuleCreate(params, config)) - .withMessageContaining("Target information"); + .withMessageContaining("Target information"); } @Test - public void testGetPropertyNames() { + void testGetPropertyNames() { // @formatter:off assertThat(oper.getPropertyNames()).isEqualTo( - List.of( - OperationProperties.AAI_SERVICE, - OperationProperties.AAI_SERVICE_MODEL, - OperationProperties.AAI_VNF, - OperationProperties.AAI_VNF_MODEL, - OperationProperties.AAI_DEFAULT_CLOUD_REGION, - OperationProperties.AAI_DEFAULT_TENANT, - OperationProperties.DATA_VF_COUNT)); + List.of( + OperationProperties.AAI_SERVICE, + OperationProperties.AAI_SERVICE_MODEL, + OperationProperties.AAI_VNF, + OperationProperties.AAI_VNF_MODEL, + OperationProperties.AAI_DEFAULT_CLOUD_REGION, + OperationProperties.AAI_DEFAULT_TENANT, + OperationProperties.DATA_VF_COUNT)); // @formatter:on } @Test - public void testStartOperationAsync_testSuccessfulCompletion() throws Exception { + void testStartOperationAsync_testSuccessfulCompletion() throws Exception { when(client.post(any(), any(), any(), any())).thenAnswer(provideResponse(rawResponse)); // use a real executor @@ -179,7 +180,7 @@ public class VfModuleCreateTest extends BasicSoOperation { * Tests startOperationAsync() when polling is required. */ @Test - public void testStartOperationAsyncWithPolling() throws Exception { + void testStartOperationAsyncWithPolling() throws Exception { when(rawResponse.getStatus()).thenReturn(500, 500, 500, 500, 200, 200); when(client.post(any(), any(), any(), any())).thenAnswer(provideResponse(rawResponse)); @@ -204,7 +205,7 @@ public class VfModuleCreateTest extends BasicSoOperation { } @Test - public void testMakeRequest() throws CoderException { + void testMakeRequest() throws CoderException { Pair<String, SoRequest> pair = oper.makeRequest(); // @formatter:off @@ -220,14 +221,14 @@ public class VfModuleCreateTest extends BasicSoOperation { * Tests makeRequest() when a property is missing. */ @Test - public void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() throws Exception { loadProperties(); ServiceInstance instance = new ServiceInstance(); oper.setProperty(OperationProperties.AAI_SERVICE, instance); assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest()) - .withMessageContaining("missing service instance ID"); + .withMessageContaining("missing service instance ID"); } private void loadProperties() { diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java index 10f3f2bed..5ece1968d 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Wipro Limited. - * 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. @@ -24,10 +24,11 @@ package org.onap.policy.controlloop.actor.so; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +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.lenient; import static org.mockito.Mockito.mock; @@ -50,14 +51,14 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.tuple.Pair; -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.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ServiceInstance; @@ -73,8 +74,8 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingPa import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoResponse; -@RunWith(MockitoJUnitRunner.class) -public class VfModuleDeleteTest extends BasicSoOperation { +@ExtendWith(MockitoExtension.class) +class VfModuleDeleteTest extends BasicSoOperation { private static final String EXPECTED_EXCEPTION = "expected exception"; private static final String SVC_INSTANCE_ID = "my-service-instance-id"; private static final String VNF_ID = "my-vnf-id"; @@ -89,17 +90,17 @@ public class VfModuleDeleteTest extends BasicSoOperation { private CompletableFuture<HttpResponse<String>> javaFuture; private VfModuleDelete oper; - public VfModuleDeleteTest() { + VfModuleDeleteTest() { super(DEFAULT_ACTOR, VfModuleDelete.NAME); } - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + static void setUpBeforeClass() throws Exception { initBeforeClass(); } - @AfterClass - public static void tearDownAfterClass() { + @AfterAll + static void tearDownAfterClass() { destroyAfterClass(); } @@ -107,8 +108,8 @@ public class VfModuleDeleteTest extends BasicSoOperation { * Sets up. */ @Override - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { super.setUp(); initHostPort(); @@ -124,9 +125,9 @@ public class VfModuleDeleteTest extends BasicSoOperation { * Tests "success" case with simulator. */ @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("serviceInstances/v7") - .pollPath("orchestrationRequests/v5/").maxPolls(2).build(); + .pollPath("orchestrationRequests/v5/").maxPolls(2).build(); config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); @@ -138,14 +139,14 @@ public class VfModuleDeleteTest extends BasicSoOperation { // run the operation outcome = oper.start().get(); assertEquals(OperationResult.SUCCESS, outcome.getResult()); - assertTrue(outcome.getResponse() instanceof SoResponse); + assertInstanceOf(SoResponse.class, outcome.getResponse()); int count = oper.getProperty(OperationProperties.DATA_VF_COUNT); assertEquals(VF_COUNT - 1, count); } @Test - public void testConstructor() { + void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(VfModuleDelete.NAME, oper.getName()); assertTrue(oper.isUsePolling()); @@ -153,24 +154,24 @@ public class VfModuleDeleteTest extends BasicSoOperation { // verify that target validation is done params = params.toBuilder().targetType(null).build(); assertThatIllegalArgumentException().isThrownBy(() -> new MyOperation(params, config)) - .withMessageContaining("Target information"); + .withMessageContaining("Target information"); } @Test - public void testGetPropertyNames() { + void testGetPropertyNames() { // @formatter:off assertThat(oper.getPropertyNames()).isEqualTo( - List.of( - OperationProperties.AAI_SERVICE, - OperationProperties.AAI_VNF, - OperationProperties.AAI_DEFAULT_CLOUD_REGION, - OperationProperties.AAI_DEFAULT_TENANT, - OperationProperties.DATA_VF_COUNT)); + List.of( + OperationProperties.AAI_SERVICE, + OperationProperties.AAI_VNF, + OperationProperties.AAI_DEFAULT_CLOUD_REGION, + OperationProperties.AAI_DEFAULT_TENANT, + OperationProperties.DATA_VF_COUNT)); // @formatter:on } @Test - public void testStartOperationAsync_testSuccessfulCompletion() throws Exception { + void testStartOperationAsync_testSuccessfulCompletion() throws Exception { // use a real executor params = params.toBuilder().executor(ForkJoinPool.commonPool()).build(); @@ -202,7 +203,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { * Tests startOperationAsync() when polling is required. */ @Test - public void testStartOperationAsyncWithPolling() throws Exception { + void testStartOperationAsyncWithPolling() throws Exception { // indicate that the response was incomplete configureResponse(coder.encode(response).replace("COMPLETE", "incomplete")); @@ -229,7 +230,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { } @Test - public void testMakeRequest() throws CoderException { + void testMakeRequest() throws CoderException { Pair<String, SoRequest> pair = oper.makeRequest(); assertEquals("/my-service-instance-id/vnfs/my-vnf-id/vfModules/null", pair.getLeft()); @@ -238,7 +239,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { } @Test - public void testDelete() throws Exception { + void testDelete() throws Exception { SoRequest req = new SoRequest(); req.setRequestId(REQ_ID); @@ -247,7 +248,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { String reqText = oper.prettyPrint(req); final CompletableFuture<Response> delFuture = - oper.delete("my-uri", headers, MediaType.APPLICATION_JSON, reqText, callback); + oper.delete("my-uri", headers, MediaType.APPLICATION_JSON, reqText, callback); ArgumentCaptor<HttpRequest> reqCaptor = ArgumentCaptor.forClass(HttpRequest.class); verify(javaClient).sendAsync(reqCaptor.capture(), any()); @@ -276,7 +277,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { */ @Test @SuppressWarnings("unchecked") - public void testDeleteException() throws Exception { + void testDeleteException() throws Exception { Throwable thrown = new IllegalStateException(EXPECTED_EXCEPTION); // need a new future, with an exception @@ -289,7 +290,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { String reqText = oper.prettyPrint(req); CompletableFuture<Response> delFuture = - oper.delete("/my-uri", Map.of(), MediaType.APPLICATION_JSON, reqText, callback); + oper.delete("/my-uri", Map.of(), MediaType.APPLICATION_JSON, reqText, callback); assertTrue(delFuture.isCompletedExceptionally()); @@ -302,7 +303,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { * Tests addAuthHeader() when there is a username, but no password. */ @Test - public void testAddAuthHeader() { + void testAddAuthHeader() { Builder builder = mock(Builder.class); lenient().when(client.getUserName()).thenReturn("the-user"); lenient().when(client.getPassword()).thenReturn("the-password"); @@ -323,7 +324,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { * Tests addAuthHeader() when there is no username. */ @Test - public void testAddAuthHeaderNoUser() { + void testAddAuthHeaderNoUser() { Builder builder = mock(Builder.class); lenient().when(client.getPassword()).thenReturn("world"); oper.addAuthHeader(builder); @@ -339,7 +340,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { * Tests addAuthHeader() when there is a username, but no password. */ @Test - public void testAddAuthHeaderUserOnly() { + void testAddAuthHeaderUserOnly() { Builder builder = mock(Builder.class); lenient().when(client.getUserName()).thenReturn("my-user"); oper.addAuthHeader(builder); @@ -359,18 +360,18 @@ public class VfModuleDeleteTest extends BasicSoOperation { * Tests makeRequest() when a property is missing. */ @Test - public void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() throws Exception { loadProperties(); ServiceInstance instance = new ServiceInstance(); oper.setProperty(OperationProperties.AAI_SERVICE, instance); assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest()) - .withMessageContaining("missing service instance ID"); + .withMessageContaining("missing service instance ID"); } @Test - public void testMakeHttpClient() { + void testMakeHttpClient() { // must use a real operation to invoke this method assertNotNull(new MyOperation(params, config).makeHttpClient()); } @@ -391,7 +392,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { private class MyOperation extends VfModuleDelete { - public MyOperation(ControlLoopOperationParams params, HttpPollingConfig config) { + MyOperation(ControlLoopOperationParams params, HttpPollingConfig config) { super(params, config); } |