diff options
author | Dhrumin Desai <dd303q@att.com> | 2020-08-31 13:04:35 -0400 |
---|---|---|
committer | Dhrumin Desai <dd303q@att.com> | 2020-09-23 16:04:49 -0400 |
commit | dd74c5ec9c4761de2bec19f9fb53bba36c7c6c2c (patch) | |
tree | 997cd0277ec7e91f5114363aeb39bd591d26e986 /mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandlerTest.java | |
parent | b4287ad1fab97142df4d5260ec94d41bb782992a (diff) |
adding catalog-service for mod2
Issue-ID: DCAEGEN2-2317
Change-Id: I8a0a85a1db2512744b41efa0a22617747642747d
Signed-off-by: Dhrumin Desai <dd303q@att.com>
Diffstat (limited to 'mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandlerTest.java')
-rw-r--r-- | mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandlerTest.java | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandlerTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandlerTest.java new file mode 100644 index 0000000..5e9acfa --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandlerTest.java @@ -0,0 +1,106 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. 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.dcaegen2.platform.mod.web.service.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus; +import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.StatusChangeNotValidException; +import org.onap.dcaegen2.platform.mod.objectmothers.DeploymentArtifactObjectMother; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class DeploymentArtifactStatusChangeHandlerTest { + + DeploymentArtifactStatusChangeHandler artifactStatusChangeHandler; + + @Mock + DeploymentArtifactService deploymentArtifactService; + + @BeforeEach + void setUp() { + artifactStatusChangeHandler = new DeploymentArtifactStatusChangeHandler(); + artifactStatusChangeHandler.setDeploymentArtifactService(deploymentArtifactService); + } + + @Test + void test_DevCompleteToNotNeeded() throws Exception{ + //arrange + List<DeploymentArtifact> mockDeploymentArticats = DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(true); + DeploymentArtifact givenDAO = DeploymentArtifactObjectMother.createDeploymentArtifactDAO(DeploymentArtifactStatus.DEV_COMPLETE); + String msInstaneId = givenDAO.getMsInstanceInfo().getId(); + + when(deploymentArtifactService.findByMsInstanceId(msInstaneId)).thenReturn(mockDeploymentArticats); + + //act + artifactStatusChangeHandler.handleStatusChange(DeploymentArtifactStatus.NOT_NEEDED, givenDAO); + + assertThat(givenDAO.getStatus()).isEqualTo(DeploymentArtifactStatus.NOT_NEEDED); +// verify(msInstanceStatusChangeHandler, times(1)) +// .updateStatusBasedOnDeploymentArtifactsStatuses(msInstaneId); + + } + + @Test + void test_ValidateIfArtifactWithDevCompleteStatusNotFoundForTheSameInstance() throws Exception{ + //arrange + DeploymentArtifact givenDAO = DeploymentArtifactObjectMother.createDeploymentArtifactDAO(DeploymentArtifactStatus.IN_DEV); + String msInstaneId = givenDAO.getMsInstanceInfo().getId(); + + List<DeploymentArtifact> mockDeploymentArticats = DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(false); + when(deploymentArtifactService.findByMsInstanceId(msInstaneId)).thenReturn(mockDeploymentArticats); + + //act + artifactStatusChangeHandler.handleStatusChange(DeploymentArtifactStatus.DEV_COMPLETE, givenDAO); + + //assert + assertThat(givenDAO.getStatus()).isEqualTo(DeploymentArtifactStatus.DEV_COMPLETE); + verify(deploymentArtifactService, times(1)). + findByMsInstanceId(givenDAO.getMsInstanceInfo().getId()); +// verify(msInstanceStatusChangeHandler, times(1)) +// .updateStatusBasedOnDeploymentArtifactsStatuses(msInstaneId); + + } + + @Test + void DoesntValidateIfArtifactWithDevCompleteStatusAlreadyExistsForTheSameInstance() throws Exception{ + //arrange + DeploymentArtifact givenDAO = DeploymentArtifactObjectMother.createDeploymentArtifactDAO(DeploymentArtifactStatus.IN_DEV); + List<DeploymentArtifact> mockDeploymentArticats = DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(true); + when(deploymentArtifactService.findByMsInstanceId("id-123")).thenReturn(mockDeploymentArticats); + + //act/assert + assertThatExceptionOfType(StatusChangeNotValidException.class).isThrownBy( + () -> artifactStatusChangeHandler.handleStatusChange(DeploymentArtifactStatus.DEV_COMPLETE, givenDAO) + ); + + } + +}
\ No newline at end of file |