1 package org.onap.vid.job.command;
3 import org.mockito.InjectMocks;
4 import org.mockito.Mock;
5 import org.mockito.MockitoAnnotations;
6 import org.onap.portalsdk.core.service.DataAccessService;
7 import org.onap.vid.job.Job;
8 import org.onap.vid.job.NextCommand;
9 import org.onap.vid.job.impl.JobSharedData;
10 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
11 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
12 import org.testng.annotations.BeforeClass;
13 import org.testng.annotations.DataProvider;
14 import org.testng.annotations.Test;
16 import java.util.List;
17 import java.util.UUID;
19 import static org.hamcrest.MatcherAssert.assertThat;
20 import static org.hamcrest.core.Is.is;
21 import static org.mockito.Matchers.eq;
22 import static org.mockito.Mockito.*;
24 public class WatchingCommandTest {
27 private AsyncInstantiationBusinessLogic asyncInstantiationBL;
30 private DataAccessService dataAccessService;
33 private WatchChildrenJobsBL watchChildrenJobsBL;
36 private WatchingCommand watchingCommand = new WatchingCommand();
41 public void initMocks() {
42 MockitoAnnotations.initMocks(this);
46 public static Object[][] testWatchingDataProvider() {
47 return new Object[][]{
48 {"all children final, no failed child, is service", Job.JobStatus.COMPLETED, true, Job.JobStatus.COMPLETED},
49 {"all children final, there is failed child, is service", Job.JobStatus.COMPLETED_WITH_ERRORS, true, Job.JobStatus.COMPLETED_WITH_ERRORS},
50 {"not all children final, is service", Job.JobStatus.IN_PROGRESS, true, Job.JobStatus.IN_PROGRESS},
51 {"all children final, no failed child, not service", Job.JobStatus.COMPLETED, false, Job.JobStatus.COMPLETED},
52 {"all children final, there is failed child, not service", Job.JobStatus.COMPLETED_WITH_ERRORS, false, Job.JobStatus.COMPLETED_WITH_ERRORS},
53 {"not all children final, not service", Job.JobStatus.IN_PROGRESS, false, Job.JobStatus.RESOURCE_IN_PROGRESS},
59 @Test(dataProvider = "testWatchingDataProvider")
60 public void whenGetChildrenStatus_thenJobStatusAsExpected(String desc, Job.JobStatus childrenComulativeStatus, boolean isService, Job.JobStatus expectedCommandStatus) {
61 UUID jobUUID = UUID.randomUUID();
62 JobSharedData sharedData = new JobSharedData(jobUUID, "mockedUserID", mock(ServiceInstantiation.class));
63 List<String> uuids = mock(List.class);
64 watchingCommand.init(sharedData, uuids, isService);
65 when(watchChildrenJobsBL.retrieveChildrenJobsStatus(eq(uuids))).thenReturn(childrenComulativeStatus);
66 when(watchChildrenJobsBL.cumulateJobStatus(eq(childrenComulativeStatus),eq(Job.JobStatus.COMPLETED))).thenReturn(childrenComulativeStatus);
68 //execute command and verify
69 NextCommand nextCommand = watchingCommand.call();
70 assertThat(nextCommand.getStatus(), is(expectedCommandStatus));
71 if (!expectedCommandStatus.equals(Job.JobStatus.IN_PROGRESS) && isService) {
72 verify(asyncInstantiationBL).updateServiceInfoAndAuditStatus(jobUUID, expectedCommandStatus);
74 verify(asyncInstantiationBL, never()).updateServiceInfoAndAuditStatus(jobUUID, expectedCommandStatus);