2 * ============LICENSE_START=======================================================
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
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.vid.job.command;
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;
38 import java.util.UUID;
39 import java.util.stream.Stream;
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;
46 public class InProgressStatusServiceTest {
49 private RestMsoImplementation restMso;
52 private AsyncInstantiationBusinessLogic asyncInstantiationBL;
55 private InProgressStatusService inProgressStatusService;
58 public void initMocks() {
59 MockitoAnnotations.initMocks(this);
63 public static Object[][] jobStatuses() {
64 return Stream.of(Job.JobStatus.values())
65 .map(student -> new Object[] { student })
66 .toArray(Object[][]::new);
69 @Test(dataProvider = "jobStatuses")
70 public void whenGetFromMsoRequestStatus_returnItToCaller(Job.JobStatus expectedJobStatus) {
72 UUID jobUuid = UUID.randomUUID();
73 String userId = "mockedUserID";
74 String requestId = UUID.randomUUID().toString();
75 ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
77 when(asyncInstantiationBL.getOrchestrationRequestsPath()).thenReturn("");
79 RestObject<AsyncRequestStatus> msoResponse = mock(RestObject.class);
80 AsyncRequestStatus requestStatus = AsyncInstantiationBaseTest.asyncRequestStatusResponse("");
82 when(msoResponse.getStatusCode()).thenReturn(200);
83 when(msoResponse.get()).thenReturn(requestStatus);
84 when(restMso.GetForObject(contains(requestId), eq(AsyncRequestStatus.class))).thenReturn(msoResponse);
86 when(asyncInstantiationBL.calcStatus(any())).thenReturn(expectedJobStatus);
88 ExpiryChecker expiryChecker = mock(ExpiryChecker.class);
89 when(expiryChecker.isExpired(any())).thenReturn(false);
91 JobSharedData sharedData = new JobSharedData(jobUuid, userId, serviceInstantiation);
92 Job.JobStatus actualJobStatus = inProgressStatusService.call(expiryChecker, sharedData, requestId);
93 assertEquals(expectedJobStatus, actualJobStatus);
95 verify(asyncInstantiationBL).auditMsoStatus(eq(jobUuid), same(requestStatus.request));
97 //verify we don't update service info during this case, which shall stay in_progress
98 verify(asyncInstantiationBL, never()).updateServiceInfo(any(), any());