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;
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;
36 import static org.assertj.core.api.Assertions.assertThat;
37 import static org.mockito.Mockito.*;
39 @ExtendWith(MockitoExtension.class)
40 class MsInstanceStatusChangeHandlerTest {
42 MsInstanceStatusChangeHandler statusChangeHandler;
45 MsInstanceService msInstanceService;
48 DeploymentArtifactService deploymentArtifactService;
51 void setup() throws Exception{
52 statusChangeHandler = new MsInstanceStatusChangeHandler();
53 statusChangeHandler.setMsInstanceService(msInstanceService);
54 statusChangeHandler.setDeploymentArtifactService(deploymentArtifactService);
58 void handleStatusChangeFromDeploymentArtifactsWithDevComplete() {
60 MsInstance msInstance = MsInstanceObjectMother.getMsInstanceWithExistingDeploymentArtifactRef();
62 when(deploymentArtifactService.findByMsInstanceId(msInstance.getId())).thenReturn(
63 DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(true)
67 statusChangeHandler.updateStatusBasedOnDeploymentArtifactsStatuses(msInstance);
70 assertThat(msInstance.getStatus()).isEqualTo(MsInstanceStatus.DEV_COMPLETE);
71 verify(deploymentArtifactService, times(1)).findByMsInstanceId(msInstance.getId());
75 void handleStatusChangeFromDeploymentArtifactsWithoutDevComplete() {
77 MsInstance msInstance = MsInstanceObjectMother.getMsInstanceWithExistingDeploymentArtifactRef();
79 //when(msInstanceService.getMsInstanceById(msInstance.getId())).thenReturn(msInstance);
80 when(deploymentArtifactService.findByMsInstanceId(msInstance.getId())).thenReturn(
81 DeploymentArtifactObjectMother.createMockDeploymentArtifactsWithDifferentStatuses(false)
85 statusChangeHandler.updateStatusBasedOnDeploymentArtifactsStatuses(msInstance);
88 assertThat(msInstance.getStatus()).isEqualTo(MsInstanceStatus.IN_DEV);
89 verify(deploymentArtifactService, times(1)).findByMsInstanceId(msInstance.getId());