diff options
Diffstat (limited to 'plugins/reception-plugins/src/test/java')
6 files changed, 49 insertions, 102 deletions
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 80c520a4..ac8a75df 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 @@ -92,6 +92,6 @@ public class AutomationCompositionDecoderFileInCsarTest { assertTrue(decoder.canHandle(csar)); assertThatThrownBy(() -> decoder.decode(csar)).isInstanceOf(PolicyDecodingException.class) - .hasMessageContaining("Failed decoding the acm"); + .hasMessageContaining("Couldn't read the zipFile"); } } 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 e76e9f38..45dd167c 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,7 +105,7 @@ public class PolicyDecoderFileInCsarToPolicyTest { assertTrue(decoder.canHandle(csar)); assertThatThrownBy(() -> decoder.decode(csar)).isInstanceOf(PolicyDecodingException.class) - .hasMessageContaining("Failed decoding the policy"); + .hasMessageContaining("Couldn't read the zipFile"); } 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 c9debdd9..e7a97a24 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 @@ -1,8 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Intel. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2020 Nordix Foundation + * Copyright (C) 2019-2020, 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,11 +38,9 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,13 +65,10 @@ public class TestFileSystemReceptionHandler { * * @throws IOException if it occurs * @throws SecurityException if it occurs - * @throws NoSuchFieldException if it occurs - * @throws IllegalAccessException if it occurs * @throws IllegalArgumentException if it occurs */ @Before - public final void init() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, - IllegalAccessException { + public final void init() throws IOException, SecurityException, IllegalArgumentException { DistributionStatisticsManager.resetAllStatistics(); final Gson gson = new GsonBuilder().create(); @@ -90,7 +84,7 @@ public class TestFileSystemReceptionHandler { } @Test - public final void testInit() throws IOException, InterruptedException { + public final void testInit() throws IOException { final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler); Mockito.doNothing().when(sypHandler).initFileWatcher(Mockito.isA(String.class), Mockito.anyInt()); @@ -110,9 +104,9 @@ public class TestFileSystemReceptionHandler { } @Test - public void testMain() throws IOException, PolicyDecodingException { + public void testMain() throws IOException { final Object lock = new Object(); - final String watchPath = tempFolder.getRoot().getAbsolutePath().toString(); + final String watchPath = tempFolder.getRoot().getAbsolutePath(); class Processed { public boolean processed = false; @@ -121,15 +115,12 @@ public class TestFileSystemReceptionHandler { final Processed cond = new Processed(); final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler); - Mockito.doAnswer(new Answer<Object>() { - @Override - public Object answer(final InvocationOnMock invocation) { - synchronized (lock) { - cond.processed = true; - lock.notifyAll(); - } - return null; + Mockito.doAnswer((Answer<Object>) invocation -> { + synchronized (lock) { + cond.processed = true; + lock.notifyAll(); } + return null; }).when(sypHandler).createPolicyInputAndCallHandler(Mockito.isA(String.class)); final Thread th = new Thread(() -> { diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyDecoder.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyDecoder.java index f8b87f82..6c9b8bd0 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyDecoder.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyDecoder.java @@ -3,6 +3,7 @@ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +23,11 @@ package org.onap.policy.distribution.reception.handling.sdc; -import java.util.Arrays; import java.util.Collection; +import java.util.List; import org.onap.policy.distribution.model.Csar; import org.onap.policy.distribution.model.PolicyInput; import org.onap.policy.distribution.reception.decoding.PolicyDecoder; -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; /** * Class to create a dummy decoder for test cases. @@ -50,10 +50,10 @@ public class DummyDecoder implements PolicyDecoder<Csar, DummyPolicy> { * {@inheritDoc}. */ @Override - public Collection<DummyPolicy> decode(final Csar input) throws PolicyDecodingException { + public Collection<DummyPolicy> decode(final Csar input) { final DummyPolicy dummyPolicy = new DummyPolicy(input.getCsarFilePath()); decodedPolicy = dummyPolicy; - return Arrays.asList(dummyPolicy); + return List.of(dummyPolicy); } /** 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 58933c1f..3e8f4a63 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Intel. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019, 2022 Nordix Foundation. * Modifications Copyright (C) 2020 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,6 +24,7 @@ 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; @@ -33,9 +34,9 @@ import java.io.FileReader; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.After; import org.junit.Before; @@ -92,19 +93,16 @@ public class TestSdcReceptionHandler { /** * Setup for the test cases. * - * @throws IOException if it occurs - * @throws SecurityException if it occurs - * @throws NoSuchFieldException if it occurs - * @throws IllegalAccessException if it occurs + * @throws IOException if it occurs + * @throws SecurityException if it occurs * @throws IllegalArgumentException if it occurs */ @Before - public final void init() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, - IllegalAccessException { + public final void init() throws IOException, SecurityException, IllegalArgumentException { DistributionStatisticsManager.resetAllStatistics(); final Gson gson = new GsonBuilder().create(); pssdConfigParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"), - SdcReceptionHandlerConfigurationParameterGroup.class); + SdcReceptionHandlerConfigurationParameterGroup.class); ParameterService.register(pssdConfigParameters); final SdcReceptionHandler sdcHandler = new SdcReceptionHandler(); sypHandler = Mockito.spy(sdcHandler); @@ -120,15 +118,15 @@ public class TestSdcReceptionHandler { 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(Arrays.asList(artifactInfo)); + 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()) - .thenReturn(DistributionActionResultEnum.SUCCESS); + .thenReturn(DistributionActionResultEnum.SUCCESS); Mockito.when(successfulClientDownloadResult.getDistributionActionResult()) - .thenReturn(DistributionActionResultEnum.SUCCESS); + .thenReturn(DistributionActionResultEnum.SUCCESS); Mockito.when(failureClientInitResult.getDistributionActionResult()) - .thenReturn(DistributionActionResultEnum.FAIL); + .thenReturn(DistributionActionResultEnum.FAIL); } @@ -139,7 +137,7 @@ public class TestSdcReceptionHandler { @Test public final void testInitializeSdcClient() { - assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName())) + assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName())) .doesNotThrowAnyException(); } @@ -147,7 +145,7 @@ public class TestSdcReceptionHandler { public final void testInitializeSdcClient_Failure() { Mockito.when(successfulClientInitResult.getDistributionActionResult()) - .thenReturn(DistributionActionResultEnum.FAIL).thenReturn(DistributionActionResultEnum.SUCCESS); + .thenReturn(DistributionActionResultEnum.FAIL).thenReturn(DistributionActionResultEnum.SUCCESS); assertThatCode(() -> sypHandler.initializeReception(pssdConfigParameters.getName())) .doesNotThrowAnyException(); } @@ -156,7 +154,7 @@ public class TestSdcReceptionHandler { public final void testStartSdcClient_Failure() { assertThatCode(() -> { Mockito.when(distributionClient.start()).thenReturn(failureClientInitResult) - .thenReturn(successfulClientInitResult); + .thenReturn(successfulClientInitResult); sypHandler.initializeReception(pssdConfigParameters.getName()); }).doesNotThrowAnyException(); } @@ -170,10 +168,10 @@ public class TestSdcReceptionHandler { } @Test - public final void testStopSdcClient_Failure() throws PluginInitializationException { + public final void testStopSdcClient_Failure() { sypHandler.initializeReception(pssdConfigParameters.getName()); Mockito.when(distributionClient.stop()).thenReturn(failureClientInitResult) - .thenReturn(successfulClientInitResult); + .thenReturn(successfulClientInitResult); assertThatCode(() -> sypHandler.destroy()).doesNotThrowAnyException(); } @@ -184,7 +182,7 @@ public class TestSdcReceptionHandler { @Test public void testNotificationCallBack() throws NoSuchFieldException, SecurityException, IllegalArgumentException, - IllegalAccessException, PluginInitializationException { + IllegalAccessException, PluginInitializationException { final DummyDecoder policyDecoder = new DummyDecoder(); final Collection<PolicyDecoder<Csar, DummyPolicy>> policyDecoders = new ArrayList<>(); @@ -211,10 +209,10 @@ public class TestSdcReceptionHandler { @Test public void testDownloadArtifactFailure() throws NoSuchFieldException, SecurityException, IllegalArgumentException, - IllegalAccessException, PluginInitializationException { + IllegalAccessException, PluginInitializationException { Mockito.when(successfulClientDownloadResult.getDistributionActionResult()) - .thenReturn(DistributionActionResultEnum.FAIL); + .thenReturn(DistributionActionResultEnum.FAIL); final DummyDecoder policyDecoder = new DummyDecoder(); final Collection<PolicyDecoder<Csar, DummyPolicy>> policyDecoders = new ArrayList<>(); @@ -228,7 +226,7 @@ public class TestSdcReceptionHandler { sypHandler.initializeReception(pssdConfigParameters.getName()); sypHandler.activateCallback(notificationData); - assertEquals(null, policyDecoder.getDecodedPolicy()); + assertNull(policyDecoder.getDecodedPolicy()); assertEquals(0, policyForwarder.getNumberOfPoliciesReceived()); assertEquals(1, DistributionStatisticsManager.getTotalDistributionCount()); assertEquals(0, DistributionStatisticsManager.getDistributionSuccessCount()); @@ -240,10 +238,10 @@ public class TestSdcReceptionHandler { @Test public void testSendDistributionStatusFailure() throws NoSuchFieldException, SecurityException, - IllegalArgumentException, IllegalAccessException, PluginInitializationException { + IllegalArgumentException, IllegalAccessException, PluginInitializationException { Mockito.when(successfulClientDownloadResult.getDistributionActionResult()) - .thenReturn(DistributionActionResultEnum.FAIL); + .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); @@ -260,14 +258,15 @@ public class TestSdcReceptionHandler { sypHandler.initializeReception(pssdConfigParameters.getName()); sypHandler.activateCallback(notificationData); - assertEquals(null, policyDecoder.getDecodedPolicy()); + assertNull(policyDecoder.getDecodedPolicy()); assertEquals(0, policyForwarder.getNumberOfPoliciesReceived()); } private void setUpPlugins(final AbstractReceptionHandler receptionHandler, - final Collection<PolicyDecoder<Csar, DummyPolicy>> decoders, final Collection<PolicyForwarder> forwarders) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, - PluginInitializationException { + final Collection<PolicyDecoder<Csar, DummyPolicy>> decoders, + final Collection<PolicyForwarder> forwarders) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, + PluginInitializationException { final PluginHandlerParameters pluginParameters = getPluginHandlerParameters(); pluginParameters.setName("DummyDistributionGroup"); ParameterService.register(pluginParameters); @@ -290,24 +289,21 @@ public class TestSdcReceptionHandler { private PluginHandlerParameters getPluginHandlerParameters() { final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders(); final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders(); - final PluginHandlerParameters pluginHandlerParameters = - new PluginHandlerParameters(policyDecoders, policyForwarders); - return pluginHandlerParameters; + return new PluginHandlerParameters(policyDecoders, policyForwarders); } private Map<String, PolicyDecoderParameters> getPolicyDecoders() { - final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<String, PolicyDecoderParameters>(); + final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>(); final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("DummyDecoder", - "org.onap.policy.distribution.reception.handling.sdc.DummyDecoder", "DummyDecoderConfiguration"); + "org.onap.policy.distribution.reception.handling.sdc.DummyDecoder", "DummyDecoderConfiguration"); policyDecoders.put("DummyDecoderKey", pDParameters); return policyDecoders; } private Map<String, PolicyForwarderParameters> getPolicyForwarders() { - final Map<String, PolicyForwarderParameters> policyForwarders = - new HashMap<String, PolicyForwarderParameters>(); + final Map<String, PolicyForwarderParameters> policyForwarders = new HashMap<>(); final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("DummyForwarder", - "org.onap.policy.distribution.reception.handling.sdc.DummyPolicyForwarder", "DummyConfiguration"); + "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/util/ReceptionUtilTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/util/ReceptionUtilTest.java deleted file mode 100644 index 6747618e..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/util/ReceptionUtilTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.util; - -import org.assertj.core.api.Assertions; -import org.junit.Test; - -/** - * Class for testing {@link ReceptionUtil}. - */ - -public class ReceptionUtilTest { - - @Test - public void testValidateZipEntry_InvalidSize() { - long invalidFileSize = 512L * 2048; - - Assertions.assertThatThrownBy(() -> - ReceptionUtil.validateZipEntry("entryName", "csarPath", invalidFileSize)) - .hasMessage("Zip entry for entryName is too large " + invalidFileSize); - } -} |