From 08ec52b6ed5ef7159087d708bddfa40d9ac03717 Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Mon, 21 Aug 2023 14:35:56 +0100 Subject: Upgrade Java 17 Issue-ID: POLICY-4803 Change-Id: Iad0d08ee6f8ab18eb177b458d8edbba4002bcc73 Signed-off-by: adheli.tavares --- plugins/reception-plugins/pom.xml | 5 +- ...ositionDecoderFileInCsarParameterGroupTest.java | 18 +-- ...AutomationCompositionDecoderFileInCsarTest.java | 45 +++--- ...ecoderFileInCsarToPolicyParameterGroupTest.java | 18 +-- .../file/PolicyDecoderFileInCsarToPolicyTest.java | 61 ++++---- .../file/TestFileSystemReceptionHandler.java | 56 ++++---- ...eceptionHandlerConfigurationParameterGroup.java | 50 +++---- .../sdc/TestComponentDoneStatusMessage.java | 18 +-- .../sdc/TestDistributionStatusMessage.java | 18 +-- .../handling/sdc/TestSdcReceptionHandler.java | 159 ++++++++++----------- ...eceptionHandlerConfigurationParameterGroup.java | 63 ++++---- .../handling/sdc/exceptions/TestExceptions.java | 6 +- 12 files changed, 242 insertions(+), 275 deletions(-) (limited to 'plugins/reception-plugins') diff --git a/plugins/reception-plugins/pom.xml b/plugins/reception-plugins/pom.xml index acb5d30c..09a6d259 100644 --- a/plugins/reception-plugins/pom.xml +++ b/plugins/reception-plugins/pom.xml @@ -19,12 +19,13 @@ SPDX-License-Identifier: Apache-2.0 ============LICENSE_END========================================================= --> - + 4.0.0 org.onap.policy.distribution distribution-plugins - 3.0.0-SNAPSHOT + 3.0.1-SNAPSHOT reception-plugins diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/AutomationCompositionDecoderFileInCsarParameterGroupTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/AutomationCompositionDecoderFileInCsarParameterGroupTest.java index ea844e4e..201133f2 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/AutomationCompositionDecoderFileInCsarParameterGroupTest.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/AutomationCompositionDecoderFileInCsarParameterGroupTest.java @@ -21,9 +21,9 @@ package org.onap.policy.distribution.reception.decoding.policy.file; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.distribution.reception.handling.sdc.CommonTestData; @@ -32,11 +32,11 @@ import org.onap.policy.distribution.reception.handling.sdc.CommonTestData; * * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech) */ -public class AutomationCompositionDecoderFileInCsarParameterGroupTest { +class AutomationCompositionDecoderFileInCsarParameterGroupTest { @Test - public void testValidParameters() { - final AutomationCompositionDecoderFileInCsarParameterGroup configurationParameters = CommonTestData + void testValidParameters() { + final var configurationParameters = CommonTestData .getPolicyDecoderParameters( "src/test/resources/parameters/FileInCsarAutomationCompositionDecoderParameters.json", AutomationCompositionDecoderFileInCsarParameterGroup.class); @@ -48,8 +48,8 @@ public class AutomationCompositionDecoderFileInCsarParameterGroupTest { } @Test - public void testInvalidParameters() { - final AutomationCompositionDecoderFileInCsarParameterGroup configurationParameters = + void testInvalidParameters() { + final var configurationParameters = CommonTestData.getPolicyDecoderParameters( "src/test/resources/parameters/FileInCsarAutomationCompositionDecoderParametersInvalid.json", AutomationCompositionDecoderFileInCsarParameterGroup.class); @@ -58,8 +58,8 @@ public class AutomationCompositionDecoderFileInCsarParameterGroupTest { } @Test - public void testEmptyParameters() { - final AutomationCompositionDecoderFileInCsarParameterGroup configurationParameters = + void testEmptyParameters() { + final var configurationParameters = CommonTestData.getPolicyDecoderParameters("src/test/resources/parameters/EmptyParameters.json", AutomationCompositionDecoderFileInCsarParameterGroup.class); diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/AutomationCompositionDecoderFileInCsarTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/AutomationCompositionDecoderFileInCsarTest.java index ac8a75df..eca893dc 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/AutomationCompositionDecoderFileInCsarTest.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/AutomationCompositionDecoderFileInCsarTest.java @@ -22,36 +22,31 @@ package org.onap.policy.distribution.reception.decoding.policy.file; import static org.assertj.core.api.Assertions.assertThatThrownBy; -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 java.io.File; -import java.util.Collection; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +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.distribution.model.Csar; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; import org.onap.policy.distribution.reception.handling.sdc.CommonTestData; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * Class to perform unit test of {@link AutomationCompositionDecoderFileInCsar}. * * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech) */ -@RunWith(MockitoJUnitRunner.class) -public class AutomationCompositionDecoderFileInCsarTest { +class AutomationCompositionDecoderFileInCsarTest { /** * Set up. */ - @BeforeClass - public static void setUp() { - final AutomationCompositionDecoderFileInCsarParameterGroup configurationParameters = CommonTestData + @BeforeAll + static void setUp() { + final var configurationParameters = CommonTestData .getPolicyDecoderParameters( "src/test/resources/parameters/FileInCsarAutomationCompositionDecoderParameters.json", AutomationCompositionDecoderFileInCsarParameterGroup.class); @@ -62,33 +57,33 @@ public class AutomationCompositionDecoderFileInCsarTest { /** * Tear down. */ - @AfterClass - public static void tearDown() { + @AfterAll + static void tearDown() { ParameterService.deregister(AutomationCompositionDecoderFileInCsarParameterGroup.class.getSimpleName()); } @Test - public void testDecodeAutomationComposition() throws PolicyDecodingException { + void testDecodeAutomationComposition() throws PolicyDecodingException { - final AutomationCompositionDecoderFileInCsar decoder = new AutomationCompositionDecoderFileInCsar(); + final var decoder = new AutomationCompositionDecoderFileInCsar(); decoder.configure(AutomationCompositionDecoderFileInCsarParameterGroup.class.getSimpleName()); - final File file = new File("src/test/resources/service-Sampleservice-acm.csar"); - final Csar csar = new Csar(file.getAbsolutePath()); + final var file = new File("src/test/resources/service-Sampleservice-acm.csar"); + final var csar = new Csar(file.getAbsolutePath()); assertTrue(decoder.canHandle(csar)); - final Collection automationCompositionHolders = decoder.decode(csar); + final var automationCompositionHolders = decoder.decode(csar); assertEquals(1, automationCompositionHolders.size()); } @Test - public void testDecodeAutomationCompositionZipError() { + void testDecodeAutomationCompositionZipError() { - final AutomationCompositionDecoderFileInCsar decoder = new AutomationCompositionDecoderFileInCsar(); + final var decoder = new AutomationCompositionDecoderFileInCsar(); decoder.configure(AutomationCompositionDecoderFileInCsarParameterGroup.class.getSimpleName()); - final File file = new File("unknown.csar"); - final Csar csar = new Csar(file.getAbsolutePath()); + final var file = new File("unknown.csar"); + final var csar = new Csar(file.getAbsolutePath()); assertTrue(decoder.canHandle(csar)); assertThatThrownBy(() -> decoder.decode(csar)).isInstanceOf(PolicyDecodingException.class) diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java index c3cf3f5b..0164fe57 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java @@ -21,9 +21,9 @@ package org.onap.policy.distribution.reception.decoding.policy.file; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.distribution.reception.handling.sdc.CommonTestData; @@ -32,11 +32,11 @@ import org.onap.policy.distribution.reception.handling.sdc.CommonTestData; * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ -public class PolicyDecoderFileInCsarToPolicyParameterGroupTest { +class PolicyDecoderFileInCsarToPolicyParameterGroupTest { @Test - public void testValidParameters() { - final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = CommonTestData + void testValidParameters() { + final var configurationParameters = CommonTestData .getPolicyDecoderParameters("src/test/resources/parameters/FileInCsarPolicyDecoderParameters.json", PolicyDecoderFileInCsarToPolicyParameterGroup.class); @@ -48,8 +48,8 @@ public class PolicyDecoderFileInCsarToPolicyParameterGroupTest { } @Test - public void testInvalidParameters() { - final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = + void testInvalidParameters() { + final var configurationParameters = CommonTestData.getPolicyDecoderParameters( "src/test/resources/parameters/FileInCsarPolicyDecoderParametersInvalid.json", PolicyDecoderFileInCsarToPolicyParameterGroup.class); @@ -58,8 +58,8 @@ public class PolicyDecoderFileInCsarToPolicyParameterGroupTest { } @Test - public void testEmptyParameters() { - final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = + void testEmptyParameters() { + final var configurationParameters = CommonTestData.getPolicyDecoderParameters("src/test/resources/parameters/EmptyParameters.json", PolicyDecoderFileInCsarToPolicyParameterGroup.class); diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java index 45dd167c..88b4c863 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java @@ -22,35 +22,30 @@ package org.onap.policy.distribution.reception.decoding.policy.file; import static org.assertj.core.api.Assertions.assertThatThrownBy; -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 java.io.File; -import java.util.Collection; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +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.distribution.model.Csar; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; import org.onap.policy.distribution.reception.handling.sdc.CommonTestData; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * Class to perform unit test of {@link PolicyDecoderFileInCsarToPolicy}. * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ -@RunWith(MockitoJUnitRunner.class) -public class PolicyDecoderFileInCsarToPolicyTest { +class PolicyDecoderFileInCsarToPolicyTest { /** * Set up. */ - @BeforeClass - public static void setUp() { + @BeforeAll + static void setUp() { final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = CommonTestData .getPolicyDecoderParameters("src/test/resources/parameters/FileInCsarPolicyDecoderParameters.json", PolicyDecoderFileInCsarToPolicyParameterGroup.class); @@ -61,47 +56,47 @@ public class PolicyDecoderFileInCsarToPolicyTest { /** * Tear down. */ - @AfterClass - public static void tearDown() { + @AfterAll + static void tearDown() { ParameterService.deregister(PolicyDecoderFileInCsarToPolicyParameterGroup.class.getSimpleName()); } @Test - public void testDecodePolicy() throws PolicyDecodingException { + void testDecodePolicy() throws PolicyDecodingException { - final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); + final var decoder = new PolicyDecoderFileInCsarToPolicy(); decoder.configure(PolicyDecoderFileInCsarToPolicyParameterGroup.class.getSimpleName()); - final File file = new File("src/test/resources/service-Sampleservice.csar"); - final Csar csar = new Csar(file.getAbsolutePath()); + final var file = new File("src/test/resources/service-Sampleservice.csar"); + final var csar = new Csar(file.getAbsolutePath()); assertTrue(decoder.canHandle(csar)); - final Collection policyHolders = decoder.decode(csar); + final var policyHolders = decoder.decode(csar); assertEquals(2, policyHolders.size()); } @Test - public void testDecodeYamlPolicy() throws PolicyDecodingException { + void testDecodeYamlPolicy() throws PolicyDecodingException { - final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); + final var decoder = new PolicyDecoderFileInCsarToPolicy(); decoder.configure(PolicyDecoderFileInCsarToPolicyParameterGroup.class.getSimpleName()); - final File file = new File("src/test/resources/service-Sampleservice-yaml.csar"); - final Csar csar = new Csar(file.getAbsolutePath()); + final var file = new File("src/test/resources/service-Sampleservice-yaml.csar"); + final var csar = new Csar(file.getAbsolutePath()); assertTrue(decoder.canHandle(csar)); - final Collection policyHolders = decoder.decode(csar); + final var policyHolders = decoder.decode(csar); assertEquals(2, policyHolders.size()); } @Test - public void testDecodePolicyZipError() { + void testDecodePolicyZipError() { - final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); + final var decoder = new PolicyDecoderFileInCsarToPolicy(); decoder.configure(PolicyDecoderFileInCsarToPolicyParameterGroup.class.getSimpleName()); - final File file = new File("unknown.csar"); - final Csar csar = new Csar(file.getAbsolutePath()); + final var file = new File("unknown.csar"); + final var csar = new Csar(file.getAbsolutePath()); assertTrue(decoder.canHandle(csar)); assertThatThrownBy(() -> decoder.decode(csar)).isInstanceOf(PolicyDecodingException.class) @@ -110,13 +105,13 @@ public class PolicyDecoderFileInCsarToPolicyTest { @Test - public void testDecodePolicyCoderError() { + void testDecodePolicyCoderError() { - final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); + final var decoder = new PolicyDecoderFileInCsarToPolicy(); decoder.configure(PolicyDecoderFileInCsarToPolicyParameterGroup.class.getSimpleName()); - final File file = new File("src/test/resources/service-Sampleservice-test.csar"); - final Csar csar = new Csar(file.getAbsolutePath()); + final var file = new File("src/test/resources/service-Sampleservice-test.csar"); + final var csar = new Csar(file.getAbsolutePath()); assertTrue(decoder.canHandle(csar)); assertThatThrownBy(() -> decoder.decode(csar)).isInstanceOf(PolicyDecodingException.class) diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java index 7308018d..c36cd363 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java @@ -22,8 +22,9 @@ package org.onap.policy.distribution.reception.handling.file; import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; -import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.io.File; import java.io.FileReader; @@ -31,14 +32,11 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager; @@ -48,13 +46,12 @@ import org.slf4j.LoggerFactory; /** * Class to perform unit test of {@link FileSystemReceptionHandler}. */ -@RunWith(MockitoJUnitRunner.class) -public class TestFileSystemReceptionHandler { +class TestFileSystemReceptionHandler { private static final Logger LOGGER = LoggerFactory.getLogger(TestFileSystemReceptionHandler.class); - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); + @TempDir + public File tempFolder; private FileSystemReceptionHandlerConfigurationParameterGroup pssdConfigParameters; private FileSystemReceptionHandler fileSystemHandler; @@ -67,25 +64,25 @@ public class TestFileSystemReceptionHandler { * @throws SecurityException if it occurs * @throws IllegalArgumentException if it occurs */ - @Before - public final void init() throws IOException, SecurityException, IllegalArgumentException { + @BeforeEach + final void init() throws IOException, SecurityException, IllegalArgumentException { DistributionStatisticsManager.resetAllStatistics(); - final Gson gson = new GsonBuilder().create(); + final var gson = new GsonBuilder().create(); pssdConfigParameters = gson.fromJson(new FileReader("src/test/resources/handling-filesystem.json"), FileSystemReceptionHandlerConfigurationParameterGroup.class); ParameterService.register(pssdConfigParameters); fileSystemHandler = new FileSystemReceptionHandler(); } - @After - public void teardown() { + @AfterEach + void teardown() { ParameterService.deregister(pssdConfigParameters); } @Test - public final void testInit() throws IOException { - FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler); + final void testInit() throws IOException { + var sypHandler = spy(fileSystemHandler); Mockito.doNothing().when(sypHandler).initFileWatcher(Mockito.isA(String.class), Mockito.anyInt()); assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName())) @@ -93,8 +90,8 @@ public class TestFileSystemReceptionHandler { } @Test - public final void testDestroy() throws IOException { - final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler); + final void testDestroy() throws IOException { + final var sypHandler = spy(fileSystemHandler); Mockito.doNothing().when(sypHandler).initFileWatcher(Mockito.isA(String.class), Mockito.anyInt()); assertThatCode(() -> { @@ -104,17 +101,17 @@ public class TestFileSystemReceptionHandler { } @Test - public void testMain() throws IOException { - final Object lock = new Object(); - final String watchPath = tempFolder.getRoot().getAbsolutePath(); + void testMain() throws IOException { + final var lock = new Object(); + final var watchPath = tempFolder.getAbsolutePath(); class Processed { public boolean processed = false; } - final Processed cond = new Processed(); + final var cond = new Processed(); - final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler); + final var sypHandler = Mockito.spy(fileSystemHandler); Mockito.doAnswer((Answer) invocation -> { synchronized (lock) { cond.processed = true; @@ -123,7 +120,7 @@ public class TestFileSystemReceptionHandler { return null; }).when(sypHandler).createPolicyInputAndCallHandler(Mockito.isA(String.class)); - final Thread th = new Thread(() -> { + final var th = new Thread(() -> { try { sypHandler.initFileWatcher(watchPath, 2); } catch (final IOException ex) { @@ -134,7 +131,7 @@ public class TestFileSystemReceptionHandler { th.start(); try { // wait until internal watch service started or counter reached - final AtomicInteger counter = new AtomicInteger(); + final var counter = new AtomicInteger(); counter.set(0); synchronized (lock) { while (!sypHandler.isRunning() && counter.getAndIncrement() < 10) { @@ -156,8 +153,7 @@ public class TestFileSystemReceptionHandler { } catch (final InterruptedException ex) { LOGGER.error("testMain failed", ex); } - Mockito.verify(sypHandler, Mockito.times(1)).createPolicyInputAndCallHandler(Mockito.isA(String.class)); + verify(sypHandler, Mockito.times(1)).createPolicyInputAndCallHandler(Mockito.isA(String.class)); } } - diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java index c8bcc7bd..46d7f27e 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java @@ -24,64 +24,58 @@ package org.onap.policy.distribution.reception.handling.file; 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 com.google.gson.Gson; import com.google.gson.GsonBuilder; +import java.io.File; import java.io.FileReader; import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.onap.policy.common.parameters.ValidationResult; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; /** * Class to perform unit test of {@link FileSystemReceptionHandlerConfigurationParameterGroup}. * */ -public class TestFileSystemReceptionHandlerConfigurationParameterGroup { - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); +class TestFileSystemReceptionHandlerConfigurationParameterGroup { - @Test - public void testFileSystemConfiguration() throws IOException { - FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null; - String validPath = null; + @TempDir + private File tempFolder; - validPath = tempFolder.getRoot().getAbsolutePath(); + @Test + void testFileSystemConfiguration() throws IOException { + String validPath = tempFolder.getPath(); - configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup(); + var configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup(); configParameters.setWatchPath(validPath); configParameters.setMaxThread(2); - final ValidationResult validationResult = configParameters.validate(); + final var validationResult = configParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(validPath, configParameters.getWatchPath()); assertEquals(2, configParameters.getMaxThread()); } @Test - public void testInvalidFileSystemConfiguration() throws IOException { - FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null; - final Gson gson = new GsonBuilder().create(); - configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"), + void testInvalidFileSystemConfiguration() throws IOException { + final var gson = new GsonBuilder().create(); + var configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"), FileSystemReceptionHandlerConfigurationParameterGroup.class); - final ValidationResult validationResult = configParameters.validate(); + final var validationResult = configParameters.validate(); assertFalse(validationResult.isValid()); } @Test - public void testFileSystemReceptionHandlerConfigurationParameterBuilderWithInvalidPath() throws IOException { - final String invalidPath = tempFolder.newFile("foobar").getAbsolutePath(); + void testFileSystemReceptionHandlerConfigurationParameterBuilderWithInvalidPath() throws IOException { + final var invalidPath = new File(tempFolder, "foobar").getAbsolutePath(); - final FileSystemReceptionHandlerConfigurationParameterGroup configParameters = - new FileSystemReceptionHandlerConfigurationParameterGroup(); + final var configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup(); configParameters.setWatchPath(invalidPath); - final ValidationResult validateResult = configParameters.validate(); + final var validateResult = configParameters.validate(); assertFalse(validateResult.isValid()); assertThat(validateResult.getResult()).contains("is not a valid directory"); } diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java index c5935822..d3f7ee00 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java @@ -21,20 +21,20 @@ package org.onap.policy.distribution.reception.handling.sdc; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.sdc.utils.DistributionStatusEnum; -public class TestComponentDoneStatusMessage { +class TestComponentDoneStatusMessage { private static final String CONSUMER_ID = "dummyId"; private static final String DISTRIBUTION_ID = "dummyDistribution"; @Test - public void testComponentDoneStatusMessage_Success() { - final long timestamp = System.currentTimeMillis(); - final ComponentDoneStatusMessage message = ComponentDoneStatusMessage.builder().consumerId(CONSUMER_ID) + void testComponentDoneStatusMessage_Success() { + final var timestamp = System.currentTimeMillis(); + final var message = ComponentDoneStatusMessage.builder().consumerId(CONSUMER_ID) .distributionId(DISTRIBUTION_ID).distributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK) .timestamp(timestamp).build(); assertEquals("POLICY", message.getComponentName()); @@ -45,9 +45,9 @@ public class TestComponentDoneStatusMessage { } @Test - public void testComponentDoneStatusMessage_Failure() { - final long timestamp = System.currentTimeMillis(); - final ComponentDoneStatusMessage message = ComponentDoneStatusMessage.builder().consumerId(CONSUMER_ID) + void testComponentDoneStatusMessage_Failure() { + final var timestamp = System.currentTimeMillis(); + final var message = ComponentDoneStatusMessage.builder().consumerId(CONSUMER_ID) .distributionId(DISTRIBUTION_ID).distributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR) .timestamp(timestamp).build(); assertEquals("POLICY", message.getComponentName()); diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java index 62cf0f3d..86d4bdeb 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java @@ -21,22 +21,22 @@ package org.onap.policy.distribution.reception.handling.sdc; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.sdc.utils.DistributionStatusEnum; -public class TestDistributionStatusMessage { +class TestDistributionStatusMessage { private static final String ARTIFACT_URL = "http://dummyurl"; private static final String CONSUMER_ID = "dummyId"; private static final String DISTRIBUTION_ID = "dummyDistribution"; @Test - public void testDistributionStatusMessage_Download() { - final long timestamp = System.currentTimeMillis(); + void testDistributionStatusMessage_Download() { + final var timestamp = System.currentTimeMillis(); - final DistributionStatusMessage message = DistributionStatusMessage.builder().artifactUrl(ARTIFACT_URL) + final var message = DistributionStatusMessage.builder().artifactUrl(ARTIFACT_URL) .consumerId(CONSUMER_ID).distributionId(DISTRIBUTION_ID) .distributionStatus(DistributionStatusEnum.DOWNLOAD_OK).timestamp(timestamp).build(); assertEquals(ARTIFACT_URL, message.getArtifactURL()); @@ -47,10 +47,10 @@ public class TestDistributionStatusMessage { } @Test - public void testDistributionStatusMessage_Deploy() { - final long timestamp = System.currentTimeMillis(); + void testDistributionStatusMessage_Deploy() { + final var timestamp = System.currentTimeMillis(); - final DistributionStatusMessage message = DistributionStatusMessage.builder().artifactUrl(ARTIFACT_URL) + final var message = DistributionStatusMessage.builder().artifactUrl(ARTIFACT_URL) .consumerId(CONSUMER_ID).distributionId(DISTRIBUTION_ID) .distributionStatus(DistributionStatusEnum.DEPLOY_OK).timestamp(timestamp).build(); assertEquals(ARTIFACT_URL, message.getArtifactURL()); diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java index 3e8f4a63..9a993c6c 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java @@ -23,28 +23,25 @@ package org.onap.policy.distribution.reception.handling.sdc; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; -import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.io.FileReader; import java.io.IOException; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.forwarding.PolicyForwarder; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; @@ -68,23 +65,17 @@ import org.onap.sdc.utils.DistributionActionResultEnum; * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ -@RunWith(MockitoJUnitRunner.class) -public class TestSdcReceptionHandler { +class TestSdcReceptionHandler { private static final String DUMMY_SERVICE_CSAR = "dummyService.csar"; - @Mock - private IDistributionClientResult successfulClientInitResult; - @Mock - private IDistributionClientResult failureClientInitResult; - @Mock - private IDistributionClient distributionClient; - @Mock - private IDistributionClientDownloadResult successfulClientDownloadResult; - @Mock - private INotificationData notificationData; - @Mock - private IArtifactInfo artifactInfo; + private final IDistributionClientResult successfulClientInitResult = mock(IDistributionClientResult.class); + private final IDistributionClientResult failureClientInitResult = mock(IDistributionClientResult.class); + private final IDistributionClient distributionClient = mock(IDistributionClient.class); + private final IDistributionClientDownloadResult successfulClientDownloadResult + = mock(IDistributionClientDownloadResult.class); + private final INotificationData notificationData = mock(INotificationData.class); + private final IArtifactInfo artifactInfo = mock(IArtifactInfo.class); private SdcReceptionHandlerConfigurationParameterGroup pssdConfigParameters; private SdcReceptionHandler sypHandler; @@ -97,70 +88,70 @@ public class TestSdcReceptionHandler { * @throws SecurityException if it occurs * @throws IllegalArgumentException if it occurs */ - @Before - public final void init() throws IOException, SecurityException, IllegalArgumentException { + @BeforeEach + final void init() throws IOException, SecurityException, IllegalArgumentException { DistributionStatisticsManager.resetAllStatistics(); - final Gson gson = new GsonBuilder().create(); + final var gson = new GsonBuilder().create(); pssdConfigParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"), SdcReceptionHandlerConfigurationParameterGroup.class); ParameterService.register(pssdConfigParameters); - final SdcReceptionHandler sdcHandler = new SdcReceptionHandler(); - sypHandler = Mockito.spy(sdcHandler); - - Mockito.when(sypHandler.createSdcDistributionClient()).thenReturn(distributionClient); - Mockito.when(distributionClient.init(any(), any())).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.start()).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.stop()).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.sendComponentDoneStatus(any())).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.sendComponentDoneStatus(any(), any())).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.sendDownloadStatus(any())).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.sendDownloadStatus(any(), any())).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.sendDeploymentStatus(any())).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.sendDeploymentStatus(any(), any())).thenReturn(successfulClientInitResult); - Mockito.when(distributionClient.download(any())).thenReturn(successfulClientDownloadResult); - Mockito.when(notificationData.getServiceArtifacts()).thenReturn(List.of(artifactInfo)); - Mockito.when(artifactInfo.getArtifactName()).thenReturn(DUMMY_SERVICE_CSAR); - Mockito.when(successfulClientDownloadResult.getArtifactPayload()).thenReturn(new byte[1]); - Mockito.when(successfulClientInitResult.getDistributionActionResult()) + final var sdcHandler = new SdcReceptionHandler(); + sypHandler = spy(sdcHandler); + + when(sypHandler.createSdcDistributionClient()).thenReturn(distributionClient); + when(distributionClient.init(any(), any())).thenReturn(successfulClientInitResult); + when(distributionClient.start()).thenReturn(successfulClientInitResult); + when(distributionClient.stop()).thenReturn(successfulClientInitResult); + when(distributionClient.sendComponentDoneStatus(any())).thenReturn(successfulClientInitResult); + when(distributionClient.sendComponentDoneStatus(any(), any())).thenReturn(successfulClientInitResult); + when(distributionClient.sendDownloadStatus(any())).thenReturn(successfulClientInitResult); + when(distributionClient.sendDownloadStatus(any(), any())).thenReturn(successfulClientInitResult); + when(distributionClient.sendDeploymentStatus(any())).thenReturn(successfulClientInitResult); + when(distributionClient.sendDeploymentStatus(any(), any())).thenReturn(successfulClientInitResult); + when(distributionClient.download(any())).thenReturn(successfulClientDownloadResult); + when(notificationData.getServiceArtifacts()).thenReturn(List.of(artifactInfo)); + when(artifactInfo.getArtifactName()).thenReturn(DUMMY_SERVICE_CSAR); + when(successfulClientDownloadResult.getArtifactPayload()).thenReturn(new byte[1]); + when(successfulClientInitResult.getDistributionActionResult()) .thenReturn(DistributionActionResultEnum.SUCCESS); - Mockito.when(successfulClientDownloadResult.getDistributionActionResult()) + when(successfulClientDownloadResult.getDistributionActionResult()) .thenReturn(DistributionActionResultEnum.SUCCESS); - Mockito.when(failureClientInitResult.getDistributionActionResult()) + when(failureClientInitResult.getDistributionActionResult()) .thenReturn(DistributionActionResultEnum.FAIL); } - @After - public void teardown() { + @AfterEach + void teardown() { ParameterService.deregister(pssdConfigParameters); } @Test - public final void testInitializeSdcClient() { + final void testInitializeSdcClient() { assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName())) .doesNotThrowAnyException(); } @Test - public final void testInitializeSdcClient_Failure() { + final void testInitializeSdcClient_Failure() { - Mockito.when(successfulClientInitResult.getDistributionActionResult()) + when(successfulClientInitResult.getDistributionActionResult()) .thenReturn(DistributionActionResultEnum.FAIL).thenReturn(DistributionActionResultEnum.SUCCESS); assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName())) .doesNotThrowAnyException(); } @Test - public final void testStartSdcClient_Failure() { + final void testStartSdcClient_Failure() { assertThatCode(() -> { - Mockito.when(distributionClient.start()).thenReturn(failureClientInitResult) + when(distributionClient.start()).thenReturn(failureClientInitResult) .thenReturn(successfulClientInitResult); sypHandler.initializeReception(pssdConfigParameters.getName()); }).doesNotThrowAnyException(); } @Test - public final void testStopSdcClient() { + final void testStopSdcClient() { assertThatCode(() -> { sypHandler.initializeReception(pssdConfigParameters.getName()); sypHandler.destroy(); @@ -168,27 +159,27 @@ public class TestSdcReceptionHandler { } @Test - public final void testStopSdcClient_Failure() { + final void testStopSdcClient_Failure() { sypHandler.initializeReception(pssdConfigParameters.getName()); - Mockito.when(distributionClient.stop()).thenReturn(failureClientInitResult) + when(distributionClient.stop()).thenReturn(failureClientInitResult) .thenReturn(successfulClientInitResult); assertThatCode(() -> sypHandler.destroy()).doesNotThrowAnyException(); } @Test - public final void testStopSdcClientWithoutStart() { + final void testStopSdcClientWithoutStart() { assertThatCode(() -> sypHandler.destroy()).doesNotThrowAnyException(); } @Test - public void testNotificationCallBack() throws NoSuchFieldException, SecurityException, IllegalArgumentException, + void testNotificationCallBack() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, PluginInitializationException { - final DummyDecoder policyDecoder = new DummyDecoder(); + final var policyDecoder = new DummyDecoder(); final Collection> policyDecoders = new ArrayList<>(); policyDecoders.add(policyDecoder); - final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder(); + final var policyForwarder = new DummyPolicyForwarder(); final Collection policyForwarders = new ArrayList<>(); policyForwarders.add(policyForwarder); @@ -208,17 +199,17 @@ public class TestSdcReceptionHandler { } @Test - public void testDownloadArtifactFailure() throws NoSuchFieldException, SecurityException, IllegalArgumentException, + void testDownloadArtifactFailure() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, PluginInitializationException { - Mockito.when(successfulClientDownloadResult.getDistributionActionResult()) + when(successfulClientDownloadResult.getDistributionActionResult()) .thenReturn(DistributionActionResultEnum.FAIL); - final DummyDecoder policyDecoder = new DummyDecoder(); + final var policyDecoder = new DummyDecoder(); final Collection> policyDecoders = new ArrayList<>(); policyDecoders.add(policyDecoder); - final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder(); + final var policyForwarder = new DummyPolicyForwarder(); final Collection policyForwarders = new ArrayList<>(); policyForwarders.add(policyForwarder); @@ -237,20 +228,20 @@ public class TestSdcReceptionHandler { } @Test - public void testSendDistributionStatusFailure() throws NoSuchFieldException, SecurityException, + void testSendDistributionStatusFailure() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, PluginInitializationException { - Mockito.when(successfulClientDownloadResult.getDistributionActionResult()) + when(successfulClientDownloadResult.getDistributionActionResult()) .thenReturn(DistributionActionResultEnum.FAIL); - Mockito.when(distributionClient.sendDownloadStatus(any(), any())).thenReturn(failureClientInitResult); - Mockito.when(distributionClient.sendDeploymentStatus(any(), any())).thenReturn(failureClientInitResult); - Mockito.when(distributionClient.sendComponentDoneStatus(any(), any())).thenReturn(failureClientInitResult); + when(distributionClient.sendDownloadStatus(any(), any())).thenReturn(failureClientInitResult); + when(distributionClient.sendDeploymentStatus(any(), any())).thenReturn(failureClientInitResult); + when(distributionClient.sendComponentDoneStatus(any(), any())).thenReturn(failureClientInitResult); - final DummyDecoder policyDecoder = new DummyDecoder(); + final var policyDecoder = new DummyDecoder(); final Collection> policyDecoders = new ArrayList<>(); policyDecoders.add(policyDecoder); - final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder(); + final var policyForwarder = new DummyPolicyForwarder(); final Collection policyForwarders = new ArrayList<>(); policyForwarders.add(policyForwarder); @@ -267,34 +258,34 @@ public class TestSdcReceptionHandler { final Collection forwarders) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, PluginInitializationException { - final PluginHandlerParameters pluginParameters = getPluginHandlerParameters(); + final var pluginParameters = getPluginHandlerParameters(); pluginParameters.setName("DummyDistributionGroup"); ParameterService.register(pluginParameters); - final PluginHandler pluginHandler = new PluginHandler(pluginParameters.getName()); + final var pluginHandler = new PluginHandler(pluginParameters.getName()); - final Field decodersField = pluginHandler.getClass().getDeclaredField("policyDecoders"); + final var decodersField = pluginHandler.getClass().getDeclaredField("policyDecoders"); decodersField.setAccessible(true); decodersField.set(pluginHandler, decoders); - final Field forwardersField = pluginHandler.getClass().getDeclaredField("policyForwarders"); + final var forwardersField = pluginHandler.getClass().getDeclaredField("policyForwarders"); forwardersField.setAccessible(true); forwardersField.set(pluginHandler, forwarders); - final Field pluginHandlerField = AbstractReceptionHandler.class.getDeclaredField("pluginHandler"); + final var pluginHandlerField = AbstractReceptionHandler.class.getDeclaredField("pluginHandler"); pluginHandlerField.setAccessible(true); pluginHandlerField.set(receptionHandler, pluginHandler); ParameterService.deregister(pluginParameters.getName()); } private PluginHandlerParameters getPluginHandlerParameters() { - final Map policyDecoders = getPolicyDecoders(); - final Map policyForwarders = getPolicyForwarders(); + final var policyDecoders = getPolicyDecoders(); + final var policyForwarders = getPolicyForwarders(); return new PluginHandlerParameters(policyDecoders, policyForwarders); } private Map getPolicyDecoders() { final Map policyDecoders = new HashMap<>(); - final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("DummyDecoder", + final var pDParameters = new PolicyDecoderParameters("DummyDecoder", "org.onap.policy.distribution.reception.handling.sdc.DummyDecoder", "DummyDecoderConfiguration"); policyDecoders.put("DummyDecoderKey", pDParameters); return policyDecoders; @@ -302,7 +293,7 @@ public class TestSdcReceptionHandler { private Map getPolicyForwarders() { final Map policyForwarders = new HashMap<>(); - final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("DummyForwarder", + final var pFParameters = new PolicyForwarderParameters("DummyForwarder", "org.onap.policy.distribution.reception.handling.sdc.DummyPolicyForwarder", "DummyConfiguration"); policyForwarders.put("DummyForwarderKey", pFParameters); return policyForwarders; diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java index 717f635d..0bf85681 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java @@ -22,35 +22,33 @@ package org.onap.policy.distribution.reception.handling.sdc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.io.FileReader; import java.io.IOException; import java.util.Arrays; -import org.junit.Test; -import org.onap.policy.common.parameters.ValidationResult; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.ValidationStatus; /** * Class to perform unit test of {@link SdcConfiguration}. * */ -public class TestSdcReceptionHandlerConfigurationParameterGroup { +class TestSdcReceptionHandlerConfigurationParameterGroup { @Test - public void testSdcConfiguration() throws IOException { - SdcReceptionHandlerConfigurationParameterGroup configParameters = null; - final Gson gson = new GsonBuilder().create(); - configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"), + void testSdcConfiguration() throws IOException { + final var gson = new GsonBuilder().create(); + var configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"), SdcReceptionHandlerConfigurationParameterGroup.class); - final ValidationResult validationResult = configParameters.validate(); + final var validationResult = configParameters.validate(); assertTrue(validationResult.isValid()); - final SdcConfiguration config = new SdcConfiguration(configParameters); + final var config = new SdcConfiguration(configParameters); assertEquals(Arrays.asList("TOSCA_CSAR", "HEAT"), config.getRelevantArtifactTypes()); assertEquals("localhost", config.getSdcAddress()); assertEquals("policy", config.getUser()); @@ -62,44 +60,41 @@ public class TestSdcReceptionHandlerConfigurationParameterGroup { assertEquals("TEST", config.getEnvironmentName()); assertEquals("null", config.getKeyStorePath()); assertEquals("null", config.getKeyStorePassword()); - assertEquals(false, config.activateServerTLSAuth()); - assertEquals(true, config.isFilterInEmptyResources()); - assertEquals(false, config.isUseHttpsWithSDC()); + assertFalse(config.activateServerTLSAuth()); + assertTrue(config.isFilterInEmptyResources()); + assertFalse(config.isUseHttpsWithSDC()); } @Test - public void testSdcConfigurationNullParameters() throws IOException { - SdcReceptionHandlerConfigurationParameterGroup configParameters = null; - final Gson gson = new GsonBuilder().create(); - configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc-null-parameters.json"), + void testSdcConfigurationNullParameters() throws IOException { + final var gson = new GsonBuilder().create(); + var configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc-null-parameters.json"), SdcReceptionHandlerConfigurationParameterGroup.class); - final ValidationResult validationResult = configParameters.validate(); + final var validationResult = configParameters.validate(); assertTrue(validationResult.isValid()); - final SdcConfiguration config = new SdcConfiguration(configParameters); - assertEquals(null, config.getKeyStorePath()); - assertEquals(null, config.getKeyStorePassword()); + final var config = new SdcConfiguration(configParameters); + assertThat(config.getKeyStorePath()).isNull(); + assertThat(config.getKeyStorePassword()).isNull(); //if boolean parameters are null they are set to false - assertEquals(false, config.activateServerTLSAuth()); - assertEquals(false, config.isFilterInEmptyResources()); + assertFalse(config.activateServerTLSAuth()); + assertFalse(config.isFilterInEmptyResources()); } @Test - public void testInvalidSdcConfiguration() throws IOException { - SdcReceptionHandlerConfigurationParameterGroup configParameters = null; - - final Gson gson = new GsonBuilder().create(); - configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"), + void testInvalidSdcConfiguration() throws IOException { + final var gson = new GsonBuilder().create(); + var configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"), SdcReceptionHandlerConfigurationParameterGroup.class); - final ValidationResult validationResult = configParameters.validate(); + final var validationResult = configParameters.validate(); assertFalse(validationResult.isValid()); } @Test - public void testEmptyParameters() { - final SdcReceptionHandlerConfigurationParameterGroup configurationParameters = + void testEmptyParameters() { + final var configurationParameters = CommonTestData.getPolicyDecoderParameters("src/test/resources/parameters/EmptyParameters.json", SdcReceptionHandlerConfigurationParameterGroup.class); diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/TestExceptions.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/TestExceptions.java index 2b6c98dc..3d409575 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/TestExceptions.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/TestExceptions.java @@ -20,13 +20,13 @@ package org.onap.policy.distribution.reception.handling.sdc.exceptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.test.ExceptionsTester; -public class TestExceptions { +class TestExceptions { @Test - public void test() { + void test() { new ExceptionsTester().test(ArtifactDownloadException.class); } } -- cgit 1.2.3-korg