2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.platform.mod.web.service.deploymentartifact;
23 import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact;
24 import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus;
25 import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.StatusChangeNotValidException;
26 import org.onap.dcaegen2.platform.mod.objectmothers.DeploymentArtifactObjectMother;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.mockito.Mock;
31 import org.mockito.junit.jupiter.MockitoExtension;
33 import java.util.List;
35 import static org.assertj.core.api.Assertions.assertThat;
36 import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
37 import static org.mockito.Mockito.*;
39 @ExtendWith(MockitoExtension.class)
40 class DeploymentArtifactStatusChangeHandlerTest {
42 DeploymentArtifactStatusChangeHandler artifactStatusChangeHandler;
45 DeploymentArtifactService deploymentArtifactService;
49 artifactStatusChangeHandler = new DeploymentArtifactStatusChangeHandler();
50 artifactStatusChangeHandler.setDeploymentArtifactService(deploymentArtifactService);
54 void test_DevCompleteToNotNeeded() throws Exception{
56 List<DeploymentArtifact> mockDeploymentArticats = DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(true);
57 DeploymentArtifact givenDAO = DeploymentArtifactObjectMother.createDeploymentArtifactDAO(DeploymentArtifactStatus.DEV_COMPLETE);
58 String msInstaneId = givenDAO.getMsInstanceInfo().getId();
60 when(deploymentArtifactService.findByMsInstanceId(msInstaneId)).thenReturn(mockDeploymentArticats);
63 artifactStatusChangeHandler.handleStatusChange(DeploymentArtifactStatus.NOT_NEEDED, givenDAO);
65 assertThat(givenDAO.getStatus()).isEqualTo(DeploymentArtifactStatus.NOT_NEEDED);
66 // verify(msInstanceStatusChangeHandler, times(1))
67 // .updateStatusBasedOnDeploymentArtifactsStatuses(msInstaneId);
72 void test_ValidateIfArtifactWithDevCompleteStatusNotFoundForTheSameInstance() throws Exception{
74 DeploymentArtifact givenDAO = DeploymentArtifactObjectMother.createDeploymentArtifactDAO(DeploymentArtifactStatus.IN_DEV);
75 String msInstaneId = givenDAO.getMsInstanceInfo().getId();
77 List<DeploymentArtifact> mockDeploymentArticats = DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(false);
78 when(deploymentArtifactService.findByMsInstanceId(msInstaneId)).thenReturn(mockDeploymentArticats);
81 artifactStatusChangeHandler.handleStatusChange(DeploymentArtifactStatus.DEV_COMPLETE, givenDAO);
84 assertThat(givenDAO.getStatus()).isEqualTo(DeploymentArtifactStatus.DEV_COMPLETE);
85 verify(deploymentArtifactService, times(1)).
86 findByMsInstanceId(givenDAO.getMsInstanceInfo().getId());
87 // verify(msInstanceStatusChangeHandler, times(1))
88 // .updateStatusBasedOnDeploymentArtifactsStatuses(msInstaneId);
93 void DoesntValidateIfArtifactWithDevCompleteStatusAlreadyExistsForTheSameInstance() throws Exception{
95 DeploymentArtifact givenDAO = DeploymentArtifactObjectMother.createDeploymentArtifactDAO(DeploymentArtifactStatus.IN_DEV);
96 List<DeploymentArtifact> mockDeploymentArticats = DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(true);
97 when(deploymentArtifactService.findByMsInstanceId("id-123")).thenReturn(mockDeploymentArticats);
100 assertThatExceptionOfType(StatusChangeNotValidException.class).isThrownBy(
101 () -> artifactStatusChangeHandler.handleStatusChange(DeploymentArtifactStatus.DEV_COMPLETE, givenDAO)