c8772ee76d0196252ca3851dcc03cfa2dbe84080
[vid.git] / vid-app-common / src / test / java / org / onap / vid / job / command / InProgressStatusServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 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.vid.job.command;
22
23 import org.mockito.InjectMocks;
24 import org.mockito.Mock;
25 import org.mockito.MockitoAnnotations;
26 import org.onap.vid.job.Job;
27 import org.onap.vid.job.impl.JobSharedData;
28 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
29 import org.onap.vid.mso.RestMsoImplementation;
30 import org.onap.vid.mso.RestObject;
31 import org.onap.vid.mso.rest.AsyncRequestStatus;
32 import org.onap.vid.services.AsyncInstantiationBaseTest;
33 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.DataProvider;
36 import org.testng.annotations.Test;
37
38 import java.util.UUID;
39 import java.util.stream.Stream;
40
41 import static org.mockito.ArgumentMatchers.any;
42 import static org.mockito.ArgumentMatchers.eq;
43 import static org.mockito.Mockito.*;
44 import static org.testng.AssertJUnit.assertEquals;
45
46 public class InProgressStatusServiceTest {
47
48     @Mock
49     private RestMsoImplementation restMso;
50
51     @Mock
52     private AsyncInstantiationBusinessLogic asyncInstantiationBL;
53
54     @InjectMocks
55     private InProgressStatusService inProgressStatusService;
56
57     @BeforeClass
58     public void initMocks() {
59         MockitoAnnotations.initMocks(this);
60     }
61
62     @DataProvider
63     public static Object[][] jobStatuses() {
64         return Stream.of(Job.JobStatus.values())
65                 .map(student -> new Object[] { student })
66                 .toArray(Object[][]::new);
67     }
68
69     @Test(dataProvider = "jobStatuses")
70     public void whenGetFromMsoRequestStatus_returnItToCaller(Job.JobStatus expectedJobStatus) {
71
72         UUID jobUuid = UUID.randomUUID();
73         String userId = "mockedUserID";
74         String requestId = UUID.randomUUID().toString();
75         ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
76
77         when(asyncInstantiationBL.getOrchestrationRequestsPath()).thenReturn("");
78
79         RestObject<AsyncRequestStatus> msoResponse = mock(RestObject.class);
80         AsyncRequestStatus requestStatus = AsyncInstantiationBaseTest.asyncRequestStatusResponse("");
81
82         when(msoResponse.getStatusCode()).thenReturn(200);
83         when(msoResponse.get()).thenReturn(requestStatus);
84         when(restMso.GetForObject(contains(requestId), eq(AsyncRequestStatus.class))).thenReturn(msoResponse);
85
86         when(asyncInstantiationBL.calcStatus(any())).thenReturn(expectedJobStatus);
87
88         ExpiryChecker expiryChecker = mock(ExpiryChecker.class);
89         when(expiryChecker.isExpired(any())).thenReturn(false);
90
91         JobSharedData sharedData = new JobSharedData(jobUuid, userId, serviceInstantiation);
92         Job.JobStatus actualJobStatus = inProgressStatusService.call(expiryChecker, sharedData, requestId);
93         assertEquals(expectedJobStatus, actualJobStatus);
94
95         verify(asyncInstantiationBL).auditMsoStatus(eq(jobUuid), same(requestStatus.request));
96
97         //verify we don't update service info during this case, which shall stay in_progress
98         verify(asyncInstantiationBL, never()).updateServiceInfo(any(), any());
99
100
101     }
102
103 }