Merge from ECOMP's repository
[vid.git] / vid-app-common / src / test / java / org / onap / vid / job / command / InProgressStatusServiceTest.java
1 package org.onap.vid.job.command;
2
3 import org.mockito.InjectMocks;
4 import org.mockito.Mock;
5 import org.mockito.MockitoAnnotations;
6 import org.onap.vid.job.Job;
7 import org.onap.vid.job.impl.JobSharedData;
8 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
9 import org.onap.vid.mso.RestMsoImplementation;
10 import org.onap.vid.mso.RestObject;
11 import org.onap.vid.mso.rest.AsyncRequestStatus;
12 import org.onap.vid.services.AsyncInstantiationBaseTest;
13 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
14 import org.testng.annotations.BeforeClass;
15 import org.testng.annotations.DataProvider;
16 import org.testng.annotations.Test;
17
18 import java.util.UUID;
19 import java.util.stream.Stream;
20
21 import static org.mockito.ArgumentMatchers.any;
22 import static org.mockito.ArgumentMatchers.eq;
23 import static org.mockito.Mockito.*;
24 import static org.testng.AssertJUnit.assertEquals;
25
26 public class InProgressStatusServiceTest {
27
28     @Mock
29     private RestMsoImplementation restMso;
30
31     @Mock
32     private AsyncInstantiationBusinessLogic asyncInstantiationBL;
33
34     @InjectMocks
35     private InProgressStatusService inProgressStatusService;
36
37     @BeforeClass
38     public void initMocks() {
39         MockitoAnnotations.initMocks(this);
40     }
41
42     @DataProvider
43     public static Object[][] jobStatuses() {
44         return Stream.of(Job.JobStatus.values())
45                 .map(student -> new Object[] { student })
46                 .toArray(Object[][]::new);
47     }
48
49     @Test(dataProvider = "jobStatuses")
50     public void whenGetFromMsoRequestStatus_returnItToCaller(Job.JobStatus expectedJobStatus) {
51
52         UUID jobUuid = UUID.randomUUID();
53         String userId = "mockedUserID";
54         String requestId = UUID.randomUUID().toString();
55         ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
56
57         when(asyncInstantiationBL.getOrchestrationRequestsPath()).thenReturn("");
58
59         RestObject<AsyncRequestStatus> msoResponse = mock(RestObject.class);
60         AsyncRequestStatus requestStatus = AsyncInstantiationBaseTest.asyncRequestStatusResponse("");
61
62         when(msoResponse.getStatusCode()).thenReturn(200);
63         when(msoResponse.get()).thenReturn(requestStatus);
64         when(restMso.GetForObject(contains(requestId), eq(AsyncRequestStatus.class))).thenReturn(msoResponse);
65
66         when(asyncInstantiationBL.calcStatus(any())).thenReturn(expectedJobStatus);
67
68         ExpiryChecker expiryChecker = mock(ExpiryChecker.class);
69         when(expiryChecker.isExpired(any())).thenReturn(false);
70
71         JobSharedData sharedData = new JobSharedData(jobUuid, userId, serviceInstantiation);
72         Job.JobStatus actualJobStatus = inProgressStatusService.call(expiryChecker, sharedData, requestId);
73         assertEquals(expectedJobStatus, actualJobStatus);
74
75         verify(asyncInstantiationBL).auditMsoStatus(eq(jobUuid), same(requestStatus.request));
76
77         //verify we don't update service info during this case, which shall stay in_progress
78         verify(asyncInstantiationBL, never()).updateServiceInfo(any(), any());
79
80
81     }
82
83 }