Merge "adding catalog-service for mod2"
[dcaegen2/platform.git] / mod2 / catalog-service / src / test / java / org / onap / dcaegen2 / platform / mod / web / service / MsInstanceStatusChangeHandlerTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  org.onap.dcae
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
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.dcaegen2.platform.mod.web.service;
22
23 import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance;
24 import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstanceStatus;
25 import org.onap.dcaegen2.platform.mod.objectmothers.DeploymentArtifactObjectMother;
26 import org.onap.dcaegen2.platform.mod.objectmothers.MsInstanceObjectMother;
27 import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactService;
28 import org.onap.dcaegen2.platform.mod.web.service.microserviceinstance.MsInstanceService;
29 import org.onap.dcaegen2.platform.mod.web.service.microserviceinstance.MsInstanceStatusChangeHandler;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32 import org.junit.jupiter.api.extension.ExtendWith;
33 import org.mockito.Mock;
34 import org.mockito.junit.jupiter.MockitoExtension;
35
36 import static org.assertj.core.api.Assertions.assertThat;
37 import static org.mockito.Mockito.*;
38
39 @ExtendWith(MockitoExtension.class)
40 class MsInstanceStatusChangeHandlerTest {
41
42     MsInstanceStatusChangeHandler statusChangeHandler;
43
44     @Mock
45     MsInstanceService msInstanceService;
46
47     @Mock
48     DeploymentArtifactService deploymentArtifactService;
49
50     @BeforeEach
51     void setup() throws Exception{
52         statusChangeHandler = new MsInstanceStatusChangeHandler();
53         statusChangeHandler.setMsInstanceService(msInstanceService);
54         statusChangeHandler.setDeploymentArtifactService(deploymentArtifactService);
55     }
56
57     @Test
58     void handleStatusChangeFromDeploymentArtifactsWithDevComplete() {
59         //arrange
60         MsInstance msInstance = MsInstanceObjectMother.getMsInstanceWithExistingDeploymentArtifactRef();
61
62         when(deploymentArtifactService.findByMsInstanceId(msInstance.getId())).thenReturn(
63                 DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(true)
64         );
65
66         //act
67         statusChangeHandler.updateStatusBasedOnDeploymentArtifactsStatuses(msInstance);
68
69         //assert
70         assertThat(msInstance.getStatus()).isEqualTo(MsInstanceStatus.DEV_COMPLETE);
71         verify(deploymentArtifactService, times(1)).findByMsInstanceId(msInstance.getId());
72     }
73
74     @Test
75     void handleStatusChangeFromDeploymentArtifactsWithoutDevComplete() {
76         //arrange
77         MsInstance msInstance = MsInstanceObjectMother.getMsInstanceWithExistingDeploymentArtifactRef();
78
79         //when(msInstanceService.getMsInstanceById(msInstance.getId())).thenReturn(msInstance);
80         when(deploymentArtifactService.findByMsInstanceId(msInstance.getId())).thenReturn(
81                 DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(false)
82         );
83
84         //act
85         statusChangeHandler.updateStatusBasedOnDeploymentArtifactsStatuses(msInstance);
86
87         //assert
88         assertThat(msInstance.getStatus()).isEqualTo(MsInstanceStatus.IN_DEV);
89         verify(deploymentArtifactService, times(1)).findByMsInstanceId(msInstance.getId());
90     }
91
92 }