From c5c005a74157d8436bffd714c316ce257d2700ca Mon Sep 17 00:00:00 2001 From: Michal Banka Date: Fri, 12 Feb 2021 09:36:30 +0100 Subject: Remove Sonar code smells - Reorganized test classes to match source code structure - Removed Sonar code smells - Removed unused test dependency from pom.xml Change-Id: If8fda0caf01fe9d91aa7c784a3875a856d87f63d Signed-off-by: Michal Banka Issue-ID: DCAEGEN2-2575 --- pom.xml | 7 - .../config/DistributionClientConfigTest.java | 2 +- .../manager/config/ValidatorPropertiesTest.java | 2 +- .../model/DistributionStatusMessageTest.java | 2 +- .../manager/service/ArtifactsCollectorTest.java | 106 ++++++++++++++ .../manager/service/ClientCallbackTest.java | 154 +++++++++++++++++++++ .../notification/ArtifactsCollectorTest.java | 106 -------------- .../service/notification/ClientCallbackTest.java | 153 -------------------- 8 files changed, 263 insertions(+), 269 deletions(-) create mode 100644 src/test/java/org/onap/ves/openapi/manager/service/ArtifactsCollectorTest.java create mode 100644 src/test/java/org/onap/ves/openapi/manager/service/ClientCallbackTest.java delete mode 100644 src/test/java/org/onap/ves/openapi/manager/service/notification/ArtifactsCollectorTest.java delete mode 100644 src/test/java/org/onap/ves/openapi/manager/service/notification/ClientCallbackTest.java diff --git a/pom.xml b/pom.xml index 93140cd..6f26677 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,6 @@ org.onap.dcaegen2.platform yyyyMMdd'T'HHmmss 3.5.1 - 0.13 @@ -207,12 +206,6 @@ ${mockito-core.version} test - - com.google.code.bean-matchers - bean-matchers - ${bean-matchers.version} - test - diff --git a/src/test/java/org/onap/ves/openapi/manager/config/DistributionClientConfigTest.java b/src/test/java/org/onap/ves/openapi/manager/config/DistributionClientConfigTest.java index 9118f82..bb2a2e5 100644 --- a/src/test/java/org/onap/ves/openapi/manager/config/DistributionClientConfigTest.java +++ b/src/test/java/org/onap/ves/openapi/manager/config/DistributionClientConfigTest.java @@ -33,7 +33,7 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -public class DistributionClientConfigTest { +class DistributionClientConfigTest { @Test void shouldCreateDistributionClientConfig() { diff --git a/src/test/java/org/onap/ves/openapi/manager/config/ValidatorPropertiesTest.java b/src/test/java/org/onap/ves/openapi/manager/config/ValidatorPropertiesTest.java index 57b3725..f73dfc9 100644 --- a/src/test/java/org/onap/ves/openapi/manager/config/ValidatorPropertiesTest.java +++ b/src/test/java/org/onap/ves/openapi/manager/config/ValidatorPropertiesTest.java @@ -30,7 +30,7 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -public class ValidatorPropertiesTest { +class ValidatorPropertiesTest { @Test void shouldCreateDistributionClientConfig() { diff --git a/src/test/java/org/onap/ves/openapi/manager/model/DistributionStatusMessageTest.java b/src/test/java/org/onap/ves/openapi/manager/model/DistributionStatusMessageTest.java index e84b919..4adbdc7 100644 --- a/src/test/java/org/onap/ves/openapi/manager/model/DistributionStatusMessageTest.java +++ b/src/test/java/org/onap/ves/openapi/manager/model/DistributionStatusMessageTest.java @@ -29,7 +29,7 @@ import java.time.ZoneOffset; import static org.assertj.core.api.Assertions.assertThat; -public class DistributionStatusMessageTest { +class DistributionStatusMessageTest { @Test void shouldCreateDistributionStatusMessage() { //given diff --git a/src/test/java/org/onap/ves/openapi/manager/service/ArtifactsCollectorTest.java b/src/test/java/org/onap/ves/openapi/manager/service/ArtifactsCollectorTest.java new file mode 100644 index 0000000..3955f9a --- /dev/null +++ b/src/test/java/org/onap/ves/openapi/manager/service/ArtifactsCollectorTest.java @@ -0,0 +1,106 @@ +/* + * ============LICENSE_START======================================================= + * VES-OPENAPI-MANAGER + * ================================================================================ + * Copyright (C) 2021 Nokia. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.ves.openapi.manager.service; + +import org.junit.jupiter.api.Test; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.http.SdcConnectorClient; +import org.onap.sdc.impl.DistributionClientDownloadResultImpl; +import org.onap.sdc.utils.DistributionActionResultEnum; +import org.onap.ves.openapi.manager.config.DistributionClientConfig; +import org.onap.ves.openapi.manager.exceptions.ArtifactException; +import org.onap.ves.openapi.manager.model.Artifact; +import org.onap.ves.openapi.manager.service.ArtifactsCollector; +import org.onap.ves.openapi.manager.service.testModel.ArtifactInfo; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class ArtifactsCollectorTest { + + private static final String NOT_VES_ARTIFACT = "NOT_VES_ARTIFACT"; + private final SdcConnectorClient sdcConnectorClient = mock(SdcConnectorClient.class); + private final ArtifactsCollector artifactsCollector = new ArtifactsCollector(sdcConnectorClient); + + @Test + void shouldReturnArtifactsContentWhenVESArtifactsAreDistributed() throws IOException { + //given + IArtifactInfo vesArtifact = new ArtifactInfo(DistributionClientConfig.VES_EVENTS_ARTIFACT_TYPE); + List artifacts = List.of(vesArtifact); + + byte[] payload = getVesArtifactPayload(); + DistributionClientDownloadResultImpl artifactDownloadResult = new DistributionClientDownloadResultImpl( + DistributionActionResultEnum.SUCCESS, "sample-message", "artifact-name", + payload); + when(sdcConnectorClient.downloadArtifact(vesArtifact)).thenReturn(artifactDownloadResult); + List expectedArtifacts = List.of(new Artifact(vesArtifact, payload)); + + //when + List artifactContents = artifactsCollector.pullArtifacts(artifacts); + + //then + assertThat(artifactContents).isEqualTo(expectedArtifacts); + } + + @Test + void shouldNotReturnArtifactsContentWhenNoVESArtifactsAreDistributed() { + //given + IArtifactInfo notVesArtifact = new ArtifactInfo(NOT_VES_ARTIFACT); + List artifactsDefinitions = List.of(notVesArtifact); + List expectedArtifacts = List.of(); + + //when + List artifacts = artifactsCollector.pullArtifacts(artifactsDefinitions); + + //then + assertThat(artifacts).isEqualTo(expectedArtifacts); + } + + @Test + void shouldThrowExceptionWhenArtifactNameIsEmpty() { + //given + IArtifactInfo vesArtifact = new ArtifactInfo(DistributionClientConfig.VES_EVENTS_ARTIFACT_TYPE); + List artifacts = List.of(vesArtifact); + + byte[] payload = new byte[0]; + DistributionClientDownloadResultImpl artifactDownloadResult = new DistributionClientDownloadResultImpl( + DistributionActionResultEnum.SUCCESS, "sample-message", "", + payload); + when(sdcConnectorClient.downloadArtifact(vesArtifact)).thenReturn(artifactDownloadResult); + + //when then + assertThrows( + ArtifactException.class, + () -> artifactsCollector.pullArtifacts(artifacts) + ); + } + + private byte[] getVesArtifactPayload() throws IOException { + return Files.readAllBytes(Paths.get("src/test/resources/ves_artifact_stndDefined_events.yaml")); + } +} diff --git a/src/test/java/org/onap/ves/openapi/manager/service/ClientCallbackTest.java b/src/test/java/org/onap/ves/openapi/manager/service/ClientCallbackTest.java new file mode 100644 index 0000000..8b0d275 --- /dev/null +++ b/src/test/java/org/onap/ves/openapi/manager/service/ClientCallbackTest.java @@ -0,0 +1,154 @@ +/* + * ============LICENSE_START======================================================= + * VES-OPENAPI-MANAGER + * ================================================================================ + * Copyright (C) 2021 Nokia. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.ves.openapi.manager.service; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.ves.openapi.manager.model.Artifact; +import org.onap.ves.openapi.manager.model.ArtifactValidationResult; +import org.onap.ves.openapi.manager.service.notification.ArtifactsCollectorStatusSender; +import org.onap.ves.openapi.manager.service.notification.FinalStatusSender; +import org.onap.ves.openapi.manager.service.notification.ValidationStatusSender; +import org.onap.ves.openapi.manager.service.testModel.Service; +import org.onap.ves.openapi.manager.service.validation.ArtifactsValidator; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class ClientCallbackTest { + + private ArtifactsCollector artifactsCollector; + private ArtifactsCollectorStatusSender artifactsCollectorStatusSender; + private ValidationStatusSender validationStatusSender; + private FinalStatusSender finalStatusSender; + private ArtifactsValidator artifactsValidator; + private List validators; + private ClientCallback callback; + + @BeforeEach + void setUpMocks() { + artifactsCollector = mock(ArtifactsCollector.class); + artifactsCollectorStatusSender = mock(ArtifactsCollectorStatusSender.class); + validationStatusSender = mock(ValidationStatusSender.class); + finalStatusSender = mock(FinalStatusSender.class); + artifactsValidator = mock(ArtifactsValidator.class); + validators = new ArrayList<>(); + validators.add(artifactsValidator); + + callback = new ClientCallback(validators, artifactsCollector, artifactsCollectorStatusSender, + validationStatusSender, finalStatusSender); + } + + @Test + void shouldNotValidateAnyArtifactsOrSendAnyStatusIfPulledArtifactsListIsEmpty() { + testClientCallback(0); + } + + @Test + void shouldValidateArtifactUsingValidatorAndSendStatusIfPulledArtifactsListContainsOneArtifact() { + testClientCallback(1); + } + + @Test + void shouldValidateArtifactsUsingValidatorAndSendStatusesIfPulledArtifactsListContainsMultipleArtifacts() { + testClientCallback(3); + } + + @Test + void shouldValidateArtifactUsingMultipleValidatorsAndSendStatusIfPulledArtifactsListContainsOneArtifact() { + ArtifactsValidator extraArtifactsValidator = mock(ArtifactsValidator.class); + testClientCallback(1, extraArtifactsValidator); + } + + @Test + void shouldValidateArtifactUsingMultipleValidatorsAndSendStatusIfPulledArtifactsListContainsMultipleArtifacts() { + ArtifactsValidator extraArtifactsValidator = mock(ArtifactsValidator.class); + testClientCallback(3, extraArtifactsValidator); + } + + private void testClientCallback(int numberOfPulledArtefacts, ArtifactsValidator... extraValidators) { + // given + validators.addAll(Arrays.asList(extraValidators)); + final INotificationData service = new Service(numberOfPulledArtefacts); + ExpectedTestParameters testParameters = setupCallbackTest(service); + + // when + callback.activateCallback(service); + + // then + verifyMockedMethodCalls(testParameters, numberOfPulledArtefacts); + for(ArtifactsValidator validator: extraValidators) { + verify(validator, times(1)).validate(testParameters.getExpectedPulledArtifacts()); + } + } + + private ExpectedTestParameters setupCallbackTest(INotificationData service) { + final List expectedArtifactsList = service.getResources().get(0).getArtifacts(); + + final List expectedPulledArtifacts = new ArrayList<>(); + final List expectedValidationResults = new ArrayList<>(); + for(IArtifactInfo artifactInfo: expectedArtifactsList) { + final Artifact artifact = setUpTestArtifact(artifactInfo); + expectedPulledArtifacts.add(artifact); + final ArtifactValidationResult expectedValidationResult = new ArtifactValidationResult( + artifactInfo, true, artifactInfo.getArtifactName() + " validated", artifactsValidator + ); + expectedValidationResults.add(expectedValidationResult); + } + + when(artifactsCollector.pullArtifacts(expectedArtifactsList)).thenReturn(expectedPulledArtifacts); + when(artifactsValidator.validate(expectedPulledArtifacts)).thenReturn(expectedValidationResults); + + return new ExpectedTestParameters(expectedPulledArtifacts, expectedValidationResults, expectedArtifactsList); + } + + private Artifact setUpTestArtifact(IArtifactInfo artifactInfo) { + final byte[] expectedArtifactContent = ("test content " + artifactInfo.getArtifactName()).getBytes(); + return new Artifact(artifactInfo, expectedArtifactContent); + } + + private void verifyMockedMethodCalls(ExpectedTestParameters testParameters, int numberOfPulledArtifacts) { + verify(artifactsCollector, times(1)).pullArtifacts(testParameters.getExpectedArtifactsList()); + verify(artifactsCollectorStatusSender, times(numberOfPulledArtifacts)).sendDownloadOk(any(), eq(testParameters.getExpectedArtifactsList())); + verify(validationStatusSender, times(1)).send(any(), eq(testParameters.getExpectedValidationResults())); + validators.forEach(validator -> verify(validator, times(1)).validate(testParameters.getExpectedPulledArtifacts())); + } + + @Getter + @AllArgsConstructor + private static class ExpectedTestParameters { + final private List expectedPulledArtifacts; + final private List expectedValidationResults; + final private List expectedArtifactsList; + } +} diff --git a/src/test/java/org/onap/ves/openapi/manager/service/notification/ArtifactsCollectorTest.java b/src/test/java/org/onap/ves/openapi/manager/service/notification/ArtifactsCollectorTest.java deleted file mode 100644 index 3da47f7..0000000 --- a/src/test/java/org/onap/ves/openapi/manager/service/notification/ArtifactsCollectorTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * VES-OPENAPI-MANAGER - * ================================================================================ - * Copyright (C) 2021 Nokia. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ves.openapi.manager.service.notification; - -import org.junit.jupiter.api.Test; -import org.onap.sdc.api.notification.IArtifactInfo; -import org.onap.sdc.http.SdcConnectorClient; -import org.onap.sdc.impl.DistributionClientDownloadResultImpl; -import org.onap.sdc.utils.DistributionActionResultEnum; -import org.onap.ves.openapi.manager.config.DistributionClientConfig; -import org.onap.ves.openapi.manager.exceptions.ArtifactException; -import org.onap.ves.openapi.manager.model.Artifact; -import org.onap.ves.openapi.manager.service.ArtifactsCollector; -import org.onap.ves.openapi.manager.service.testModel.ArtifactInfo; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class ArtifactsCollectorTest { - - private static final String NOT_VES_ARTIFACT = "NOT_VES_ARTIFACT"; - private final SdcConnectorClient sdcConnectorClient = mock(SdcConnectorClient.class); - private final ArtifactsCollector artifactsCollector = new ArtifactsCollector(sdcConnectorClient); - - @Test - void shouldReturnArtifactsContentWhenVESArtifactsAreDistributed() throws IOException { - //given - IArtifactInfo vesArtifact = new ArtifactInfo(DistributionClientConfig.VES_EVENTS_ARTIFACT_TYPE); - List artifacts = List.of(vesArtifact); - - byte[] payload = getVesArtifactPayload(); - DistributionClientDownloadResultImpl artifactDownloadResult = new DistributionClientDownloadResultImpl( - DistributionActionResultEnum.SUCCESS, "sample-message", "artifact-name", - payload); - when(sdcConnectorClient.downloadArtifact(vesArtifact)).thenReturn(artifactDownloadResult); - List expectedArtifacts = List.of(new Artifact(vesArtifact, payload)); - - //when - List artifactContents = artifactsCollector.pullArtifacts(artifacts); - - //then - assertThat(artifactContents).isEqualTo(expectedArtifacts); - } - - @Test - void shouldNotReturnArtifactsContentWhenNoVESArtifactsAreDistributed() { - //given - IArtifactInfo notVesArtifact = new ArtifactInfo(NOT_VES_ARTIFACT); - List artifactsDefinitions = List.of(notVesArtifact); - List expectedArtifacts = List.of(); - - //when - List artifacts = artifactsCollector.pullArtifacts(artifactsDefinitions); - - //then - assertThat(artifacts).isEqualTo(expectedArtifacts); - } - - @Test - void shouldThrowExceptionWhenArtifactNameIsEmpty() { - //given - IArtifactInfo vesArtifact = new ArtifactInfo(DistributionClientConfig.VES_EVENTS_ARTIFACT_TYPE); - List artifacts = List.of(vesArtifact); - - byte[] payload = new byte[0]; - DistributionClientDownloadResultImpl artifactDownloadResult = new DistributionClientDownloadResultImpl( - DistributionActionResultEnum.SUCCESS, "sample-message", "", - payload); - when(sdcConnectorClient.downloadArtifact(vesArtifact)).thenReturn(artifactDownloadResult); - - //when then - assertThrows( - ArtifactException.class, - () -> artifactsCollector.pullArtifacts(artifacts) - ); - } - - private byte[] getVesArtifactPayload() throws IOException { - return Files.readAllBytes(Paths.get("src/test/resources/ves_artifact_stndDefined_events.yaml")); - } -} diff --git a/src/test/java/org/onap/ves/openapi/manager/service/notification/ClientCallbackTest.java b/src/test/java/org/onap/ves/openapi/manager/service/notification/ClientCallbackTest.java deleted file mode 100644 index 91dfda7..0000000 --- a/src/test/java/org/onap/ves/openapi/manager/service/notification/ClientCallbackTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * VES-OPENAPI-MANAGER - * ================================================================================ - * Copyright (C) 2021 Nokia. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ves.openapi.manager.service.notification; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.sdc.api.notification.IArtifactInfo; -import org.onap.sdc.api.notification.INotificationData; -import org.onap.ves.openapi.manager.model.Artifact; -import org.onap.ves.openapi.manager.model.ArtifactValidationResult; -import org.onap.ves.openapi.manager.service.ArtifactsCollector; -import org.onap.ves.openapi.manager.service.ClientCallback; -import org.onap.ves.openapi.manager.service.testModel.Service; -import org.onap.ves.openapi.manager.service.validation.ArtifactsValidator; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -class ClientCallbackTest { - - private ArtifactsCollector artifactsCollector; - private ArtifactsCollectorStatusSender artifactsCollectorStatusSender; - private ValidationStatusSender validationStatusSender; - private FinalStatusSender finalStatusSender; - private ArtifactsValidator artifactsValidator; - private List validators; - private ClientCallback callback; - - @BeforeEach - void setUpMocks() { - artifactsCollector = mock(ArtifactsCollector.class); - artifactsCollectorStatusSender = mock(ArtifactsCollectorStatusSender.class); - validationStatusSender = mock(ValidationStatusSender.class); - finalStatusSender = mock(FinalStatusSender.class); - artifactsValidator = mock(ArtifactsValidator.class); - validators = new ArrayList<>(); - validators.add(artifactsValidator); - - callback = new ClientCallback(validators, artifactsCollector, artifactsCollectorStatusSender, - validationStatusSender, finalStatusSender); - } - - @Test - void shouldNotValidateAnyArtifactsOrSendAnyStatusIfPulledArtifactsListIsEmpty() { - testClientCallback(0); - } - - @Test - void shouldValidateArtifactUsingValidatorAndSendStatusIfPulledArtifactsListContainsOneArtifact() { - testClientCallback(1); - } - - @Test - void shouldValidateArtifactsUsingValidatorAndSendStatusesIfPulledArtifactsListContainsMultipleArtifacts() { - testClientCallback(3); - } - - @Test - void shouldValidateArtifactUsingMultipleValidatorsAndSendStatusIfPulledArtifactsListContainsOneArtifact() { - ArtifactsValidator extraArtifactsValidator = mock(ArtifactsValidator.class); - testClientCallback(1, extraArtifactsValidator); - } - - @Test - void shouldValidateArtifactUsingMultipleValidatorsAndSendStatusIfPulledArtifactsListContainsMultipleArtifacts() { - ArtifactsValidator extraArtifactsValidator = mock(ArtifactsValidator.class); - testClientCallback(3, extraArtifactsValidator); - } - - private void testClientCallback(int numberOfPulledArtefacts, ArtifactsValidator... extraValidators) { - // given - validators.addAll(Arrays.asList(extraValidators)); - final INotificationData service = new Service(numberOfPulledArtefacts); - ExpectedTestParameters testParameters = setupCallbackTest(service); - - // when - callback.activateCallback(service); - - // then - verifyMockedMethodCalls(testParameters, numberOfPulledArtefacts); - for(ArtifactsValidator validator: extraValidators) { - verify(validator, times(1)).validate(eq(testParameters.getExpectedPulledArtifacts())); - } - } - - private ExpectedTestParameters setupCallbackTest(INotificationData service) { - final List expectedArtifactsList = service.getResources().get(0).getArtifacts(); - - final List expectedPulledArtifacts = new ArrayList<>(); - final List expectedValidationResults = new ArrayList<>(); - for(IArtifactInfo artifactInfo: expectedArtifactsList) { - final Artifact artifact = setUpTestArtifact(artifactInfo); - expectedPulledArtifacts.add(artifact); - final ArtifactValidationResult expectedValidationResult = new ArtifactValidationResult( - artifactInfo, true, artifactInfo.getArtifactName() + " validated", artifactsValidator - ); - expectedValidationResults.add(expectedValidationResult); - } - - when(artifactsCollector.pullArtifacts(expectedArtifactsList)).thenReturn(expectedPulledArtifacts); - when(artifactsValidator.validate(expectedPulledArtifacts)).thenReturn(expectedValidationResults); - - return new ExpectedTestParameters(expectedPulledArtifacts, expectedValidationResults, expectedArtifactsList); - } - - private Artifact setUpTestArtifact(IArtifactInfo artifactInfo) { - final byte[] expectedArtifactContent = ("test content " + artifactInfo.getArtifactName()).getBytes(); - return new Artifact(artifactInfo, expectedArtifactContent); - } - - private void verifyMockedMethodCalls(ExpectedTestParameters testParameters, int numberOfPulledArtifacts) { - verify(artifactsCollector, times(1)).pullArtifacts(eq(testParameters.getExpectedArtifactsList())); - verify(artifactsCollectorStatusSender, times(numberOfPulledArtifacts)).sendDownloadOk(any(), eq(testParameters.getExpectedArtifactsList())); - verify(validationStatusSender, times(1)).send(any(), eq(testParameters.getExpectedValidationResults())); - validators.forEach(validator -> verify(validator, times(1)).validate(eq(testParameters.getExpectedPulledArtifacts()))); - } - - @Getter - @AllArgsConstructor - private static class ExpectedTestParameters { - final private List expectedPulledArtifacts; - final private List expectedValidationResults; - final private List expectedArtifactsList; - } -} -- cgit 1.2.3-korg