diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-08-22 14:47:22 +0100 |
---|---|---|
committer | Liam Fallon <liam.fallon@est.tech> | 2023-08-24 14:30:09 +0000 |
commit | a354531009fcfe529d08183249601adb6d0adc6e (patch) | |
tree | c6386f6056c62c20e1730ddc535fff40aeb1e27f /plugins/forwarding-plugins | |
parent | 960773d01db3072b4a57dbd69e911df1af2df47c (diff) |
Upgrade policy-distribution to JUnit 5java-17
Issue-ID: POLICY-4805
Change-Id: I47aaed48f3f05c2f1c5814882386e114dbad0443
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'plugins/forwarding-plugins')
6 files changed, 90 insertions, 96 deletions
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java index d8ebb4ec..f160d1ba 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java @@ -22,20 +22,20 @@ package org.onap.policy.distribution.forwarding.file; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationStatus; /** * Class to perform unit test of {@link FilePolicyForwarderParameterGroup}. */ -public class FilePolicyForwarderParameterGroupTest { +class FilePolicyForwarderParameterGroupTest { @Test - public void testBuilderAndGetters() { - final FilePolicyForwarderParameterGroup configurationParameters = new FilePolicyForwarderParameterGroup(); + void testBuilderAndGetters() { + final var configurationParameters = new FilePolicyForwarderParameterGroup(); configurationParameters.setPath("/tmp"); configurationParameters.setVerbose(true); configurationParameters.setName("myConfiguration"); @@ -47,8 +47,8 @@ public class FilePolicyForwarderParameterGroupTest { } @Test - public void testInvalidPath() { - final FilePolicyForwarderParameterGroup configurationParameters = new FilePolicyForwarderParameterGroup(); + void testInvalidPath() { + final var configurationParameters = new FilePolicyForwarderParameterGroup(); configurationParameters.setPath(""); configurationParameters.setVerbose(false); configurationParameters.setName("myConfiguration"); diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java index fb00dae1..dbc5804b 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java @@ -23,7 +23,7 @@ package org.onap.policy.distribution.forwarding.file; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.file.Files; @@ -31,14 +31,11 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.forwarding.PolicyForwardingException; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @@ -49,10 +46,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; * Class to perform unit test of {@link FilePolicyForwarder}. * */ -@RunWith(MockitoJUnitRunner.class) -public class FilePolicyForwarderTest { - @ClassRule - public static TemporaryFolder tempFolder = new TemporaryFolder(); +class FilePolicyForwarderTest { + + private static Path tempFolder; private static final boolean VERBOSE = true; private static final String GROUP_NAME = "fileConfiguration"; @@ -60,10 +56,11 @@ public class FilePolicyForwarderTest { /** * Set up. */ - @BeforeClass - public static void setUp() { + @BeforeAll + static void setUp(@TempDir Path tempDir) { + tempFolder = tempDir; final FilePolicyForwarderParameterGroup configurationParameters = new FilePolicyForwarderParameterGroup(); - configurationParameters.setPath(tempFolder.getRoot().getAbsolutePath().toString()); + configurationParameters.setPath(tempFolder.toFile().getAbsolutePath()); configurationParameters.setVerbose(VERBOSE); configurationParameters.setName(GROUP_NAME); ParameterService.register(configurationParameters); @@ -72,36 +69,36 @@ public class FilePolicyForwarderTest { /** * Tear down. */ - @AfterClass - public static void tearDown() { + @AfterAll + static void tearDown() { ParameterService.deregister(GROUP_NAME); } @Test - public void testForwardPolicy() throws PolicyForwardingException { + void testForwardPolicy() throws PolicyForwardingException { final Collection<ToscaEntity> policies = new ArrayList<>(); - final ToscaPolicy policy = createPolicy(policies, "test", "test"); + final var policy = createPolicy(policies); - final FilePolicyForwarder forwarder = new FilePolicyForwarder(); + final var forwarder = new FilePolicyForwarder(); forwarder.configure(GROUP_NAME); forwarder.forward(policies); - final Path path = Paths.get(tempFolder.getRoot().getAbsolutePath().toString(), policy.getName()); + final var path = Paths.get(tempFolder.toFile().getAbsolutePath(), policy.getName()); assertTrue(Files.exists(path)); } @Test - public void testForwardPolicyError() { + void testForwardPolicyError() { final Collection<ToscaEntity> policies = new ArrayList<>(); - final ToscaPolicy policy = createPolicy(policies, "test", "test"); + final var policy = createPolicy(policies); - final ToscaPolicy spy = Mockito.spy(policy); + final var spy = Mockito.spy(policy); Mockito.when(spy.toString()).thenAnswer(invocation -> { throw new IOException(); }); policies.add(spy); - final FilePolicyForwarder forwarder = new FilePolicyForwarder(); + final var forwarder = new FilePolicyForwarder(); forwarder.configure(GROUP_NAME); assertThatThrownBy(() -> forwarder.forward(policies)).isInstanceOf(PolicyForwardingException.class) @@ -109,19 +106,19 @@ public class FilePolicyForwarderTest { } @Test - public void testForwardUnsupportedPolicy() { + void testForwardUnsupportedPolicy() { final Collection<ToscaEntity> policies = new ArrayList<>(); - final FilePolicyForwarder forwarder = new FilePolicyForwarder(); + final var forwarder = new FilePolicyForwarder(); forwarder.configure(GROUP_NAME); - final ToscaEntity policy = new UnsupportedPolicy(); + final var policy = new UnsupportedPolicy(); policies.add(policy); assertThatThrownBy(() -> forwarder.forward(policies)).isInstanceOf(PolicyForwardingException.class) .hasMessageContaining("Cannot forward policy"); } - class UnsupportedPolicy extends ToscaEntity { + static class UnsupportedPolicy extends ToscaEntity { @Override public String getName() { @@ -129,8 +126,7 @@ public class FilePolicyForwarderTest { } } - private ToscaPolicy createPolicy(final Collection<ToscaEntity> policies, final String name, - final String description) { + private ToscaPolicy createPolicy(final Collection<ToscaEntity> policies) { final ToscaPolicy policy = new ToscaPolicy(); policy.setName("test"); policy.setDescription("test"); diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiAutomationCompositionForwarderParametersTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiAutomationCompositionForwarderParametersTest.java index 1904edc7..091b245c 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiAutomationCompositionForwarderParametersTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiAutomationCompositionForwarderParametersTest.java @@ -22,10 +22,10 @@ package org.onap.policy.distribution.forwarding.lifecycle.api; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.distribution.forwarding.testclasses.CommonTestData; @@ -34,7 +34,7 @@ import org.onap.policy.distribution.forwarding.testclasses.CommonTestData; * * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech) */ -public class LifecycleApiAutomationCompositionForwarderParametersTest { +class LifecycleApiAutomationCompositionForwarderParametersTest { private static final String AUTOMATION_COMPOSITION_RUNTIME_HOST_NAME = "localhost"; private static final int AUTOMATION_COMPOSITION_RUNTIME_PORT = 6969; @@ -43,8 +43,8 @@ public class LifecycleApiAutomationCompositionForwarderParametersTest { @Test - public void testValidParameters() { - final LifecycleApiAutomationCompositionForwarderParameters configurationParameters = + void testValidParameters() { + final var configurationParameters = CommonTestData.getPolicyForwarderParameters( "src/test/resources/parameters/LifecycleApiAutomationCompositionForwarderParameters.json", LifecycleApiAutomationCompositionForwarderParameters.class); @@ -67,8 +67,8 @@ public class LifecycleApiAutomationCompositionForwarderParametersTest { } @Test - public void testInvalidParameters() { - final LifecycleApiForwarderParameters configurationParameters = + void testInvalidParameters() { + final var configurationParameters = CommonTestData.getPolicyForwarderParameters( "src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json", LifecycleApiForwarderParameters.class); @@ -77,8 +77,8 @@ public class LifecycleApiAutomationCompositionForwarderParametersTest { } @Test - public void testEmptyParameters() { - final LifecycleApiForwarderParameters configurationParameters = + void testEmptyParameters() { + final var configurationParameters = CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json", LifecycleApiForwarderParameters.class); diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiAutomationCompositionForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiAutomationCompositionForwarderTest.java index 0c9a8f6e..f28b52e5 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiAutomationCompositionForwarderTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiAutomationCompositionForwarderTest.java @@ -25,10 +25,9 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.ArrayList; import java.util.Collection; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.policy.common.parameters.ParameterGroup; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -45,7 +44,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; * * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech) */ -public class LifecycleApiAutomationCompositionForwarderTest { +class LifecycleApiAutomationCompositionForwarderTest { private static final String AUTOMATION_COMPOSITION = "src/test/resources/parameters/sample_automation_composition.json"; @@ -60,9 +59,9 @@ public class LifecycleApiAutomationCompositionForwarderTest { * @throws PolicyForwardingException if any error occurs * @throws InterruptedException if any error occurs */ - @BeforeClass - public static void setUp() throws PolicyForwardingException, CoderException, InterruptedException { - final ParameterGroup parameterGroup = CommonTestData.getPolicyForwarderParameters( + @BeforeAll + static void setUp() throws PolicyForwardingException, CoderException, InterruptedException { + final var parameterGroup = CommonTestData.getPolicyForwarderParameters( "src/test/resources/parameters/LifecycleApiAutomationCompositionForwarderParameters.json", LifecycleApiAutomationCompositionForwarderParameters.class); ParameterService.register(parameterGroup); @@ -75,19 +74,19 @@ public class LifecycleApiAutomationCompositionForwarderTest { /** * Tear down. */ - @AfterClass - public static void tearDown() { + @AfterAll + static void tearDown() { ParameterService.deregister(LifecycleApiAutomationCompositionForwarderParameters.class.getSimpleName()); simulator.stopLifecycycleApiSimulator(); } @Test - public void testForwardAutomationCompositionUsingSimulator() throws Exception { + void testForwardAutomationCompositionUsingSimulator() throws Exception { assertThatCode(() -> { - final ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( + final var toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION), ToscaServiceTemplate.class); - final LifecycleApiAutomationCompositionForwarder forwarder = + final var forwarder = new LifecycleApiAutomationCompositionForwarder(); forwarder.configure(LifecycleApiAutomationCompositionForwarderParameters.class.getSimpleName()); @@ -100,12 +99,12 @@ public class LifecycleApiAutomationCompositionForwarderTest { } @Test - public void testForwardAutomationCompositionFailureUsingSimulator() throws Exception { + void testForwardAutomationCompositionFailureUsingSimulator() throws Exception { - final ToscaEntity toscaEntity = new ToscaEntity(); + final var toscaEntity = new ToscaEntity(); toscaEntity.setName("FailureCase"); - final LifecycleApiAutomationCompositionForwarder forwarder = new LifecycleApiAutomationCompositionForwarder(); + final var forwarder = new LifecycleApiAutomationCompositionForwarder(); forwarder.configure(LifecycleApiAutomationCompositionForwarderParameters.class.getSimpleName()); final Collection<ToscaEntity> automationCompositionList = new ArrayList<>(); diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java index 42602cf7..2cee6e6c 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java @@ -22,11 +22,11 @@ package org.onap.policy.distribution.forwarding.lifecycle.api; 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 org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.distribution.forwarding.testclasses.CommonTestData; @@ -35,7 +35,7 @@ import org.onap.policy.distribution.forwarding.testclasses.CommonTestData; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -public class LifecycleApiForwarderParametersTest { +class LifecycleApiForwarderParametersTest { private static final String POLICY_API_HOST_NAME = "localhost"; private static final int POLICY_API_PORT = 6969; @@ -48,8 +48,8 @@ public class LifecycleApiForwarderParametersTest { @Test - public void testValidParameters() { - final LifecycleApiForwarderParameters configurationParameters = + void testValidParameters() { + final var configurationParameters = CommonTestData.getPolicyForwarderParameters( "src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json", LifecycleApiForwarderParameters.class); @@ -73,8 +73,8 @@ public class LifecycleApiForwarderParametersTest { } @Test - public void testInvalidParameters() { - final LifecycleApiForwarderParameters configurationParameters = + void testInvalidParameters() { + final var configurationParameters = CommonTestData.getPolicyForwarderParameters( "src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json", LifecycleApiForwarderParameters.class); @@ -83,8 +83,8 @@ public class LifecycleApiForwarderParametersTest { } @Test - public void testEmptyParameters() { - final LifecycleApiForwarderParameters configurationParameters = + void testEmptyParameters() { + final var configurationParameters = CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json", LifecycleApiForwarderParameters.class); diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java index 604445ed..ba85505d 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java @@ -26,10 +26,9 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.ArrayList; import java.util.Collection; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.policy.common.parameters.ParameterGroup; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -46,7 +45,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -public class LifecycleApiPolicyForwarderTest { +class LifecycleApiPolicyForwarderTest { private static final String POLICY = "src/test/resources/parameters/sample_policy.json"; private static final String POLICY_ERROR = "src/test/resources/parameters/sample_policy_failure.json"; @@ -61,9 +60,9 @@ public class LifecycleApiPolicyForwarderTest { * @throws PolicyForwardingException if any error occurs * @throws InterruptedException if any error occurs */ - @BeforeClass - public static void setUp() throws PolicyForwardingException, CoderException, InterruptedException { - final ParameterGroup parameterGroup = CommonTestData.getPolicyForwarderParameters( + @BeforeAll + static void setUp() throws PolicyForwardingException, CoderException, InterruptedException { + final var parameterGroup = CommonTestData.getPolicyForwarderParameters( "src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json", LifecycleApiForwarderParameters.class); ParameterService.register(parameterGroup); @@ -76,21 +75,21 @@ public class LifecycleApiPolicyForwarderTest { /** * Tear down. */ - @AfterClass - public static void tearDown() { + @AfterAll + static void tearDown() { ParameterService.deregister(LifecycleApiForwarderParameters.class.getSimpleName()); simulator.stopLifecycycleApiSimulator(); } @Test - public void testForwardPolicyUsingSimulator() throws Exception { + void testForwardPolicyUsingSimulator() throws Exception { assertThatCode(() -> { - final ToscaServiceTemplate toscaServiceTemplate1 = + final var toscaServiceTemplate1 = standardCoder.decode(ResourceUtils.getResourceAsString(POLICY_TYPE), ToscaServiceTemplate.class); - final ToscaServiceTemplate toscaServiceTemplate2 = + final var toscaServiceTemplate2 = standardCoder.decode(ResourceUtils.getResourceAsString(POLICY), ToscaServiceTemplate.class); - final LifecycleApiPolicyForwarder forwarder = new LifecycleApiPolicyForwarder(); + final var forwarder = new LifecycleApiPolicyForwarder(); forwarder.configure(LifecycleApiForwarderParameters.class.getSimpleName()); final Collection<ToscaEntity> policies = new ArrayList<>(); @@ -103,17 +102,17 @@ public class LifecycleApiPolicyForwarderTest { } @Test - public void testForwardPolicyFailureUsingSimulator() throws Exception { + void testForwardPolicyFailureUsingSimulator() throws Exception { - final ToscaServiceTemplate toscaServiceTemplate1 = + final var toscaServiceTemplate1 = standardCoder.decode(ResourceUtils.getResourceAsString(POLICY_TYPE), ToscaServiceTemplate.class); - final ToscaServiceTemplate toscaServiceTemplate2 = + final var toscaServiceTemplate2 = standardCoder.decode(ResourceUtils.getResourceAsString(POLICY), ToscaServiceTemplate.class); - final ToscaServiceTemplate toscaServiceTemplate3 = + final var toscaServiceTemplate3 = standardCoder.decode(ResourceUtils.getResourceAsString(POLICY_ERROR), ToscaServiceTemplate.class); - final ToscaEntity unsupportedPolicy = new UnsupportedPolicy(); + final var unsupportedPolicy = new UnsupportedPolicy(); - final LifecycleApiPolicyForwarder forwarder = new LifecycleApiPolicyForwarder(); + final var forwarder = new LifecycleApiPolicyForwarder(); forwarder.configure(LifecycleApiForwarderParameters.class.getSimpleName()); final Collection<ToscaEntity> policies = new ArrayList<>(); |