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.portalsdk.core.service.DataAccessService;
27 import org.onap.vid.job.Job;
28 import org.onap.vid.job.NextCommand;
29 import org.onap.vid.job.impl.JobSharedData;
30 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
31 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
32 import org.testng.annotations.BeforeClass;
33 import org.testng.annotations.DataProvider;
34 import org.testng.annotations.Test;
36 import java.util.List;
37 import java.util.UUID;
39 import static org.hamcrest.MatcherAssert.assertThat;
40 import static org.hamcrest.core.Is.is;
41 import static org.mockito.Matchers.eq;
42 import static org.mockito.Mockito.*;
44 public class WatchingCommandTest {
47 private AsyncInstantiationBusinessLogic asyncInstantiationBL;
50 private DataAccessService dataAccessService;
53 private WatchChildrenJobsBL watchChildrenJobsBL;
56 private WatchingCommand watchingCommand = new WatchingCommand();
61 public void initMocks() {
62 MockitoAnnotations.initMocks(this);
66 public static Object[][] testWatchingDataProvider() {
67 return new Object[][]{
68 {"all children final, no failed child, is service", Job.JobStatus.COMPLETED, true, Job.JobStatus.COMPLETED},
69 {"all children final, there is failed child, is service", Job.JobStatus.COMPLETED_WITH_ERRORS, true, Job.JobStatus.COMPLETED_WITH_ERRORS},
70 {"not all children final, is service", Job.JobStatus.IN_PROGRESS, true, Job.JobStatus.IN_PROGRESS},
71 {"all children final, no failed child, not service", Job.JobStatus.COMPLETED, false, Job.JobStatus.COMPLETED},
72 {"all children final, there is failed child, not service", Job.JobStatus.COMPLETED_WITH_ERRORS, false, Job.JobStatus.COMPLETED_WITH_ERRORS},
73 {"not all children final, not service", Job.JobStatus.IN_PROGRESS, false, Job.JobStatus.RESOURCE_IN_PROGRESS},
79 @Test(dataProvider = "testWatchingDataProvider")
80 public void whenGetChildrenStatus_thenJobStatusAsExpected(String desc, Job.JobStatus childrenComulativeStatus, boolean isService, Job.JobStatus expectedCommandStatus) {
81 UUID jobUUID = UUID.randomUUID();
82 JobSharedData sharedData = new JobSharedData(jobUUID, "mockedUserID", mock(ServiceInstantiation.class));
83 List<String> uuids = mock(List.class);
84 watchingCommand.init(sharedData, uuids, isService);
85 when(watchChildrenJobsBL.retrieveChildrenJobsStatus(eq(uuids))).thenReturn(childrenComulativeStatus);
86 when(watchChildrenJobsBL.cumulateJobStatus(eq(childrenComulativeStatus),eq(Job.JobStatus.COMPLETED))).thenReturn(childrenComulativeStatus);
88 //execute command and verify
89 NextCommand nextCommand = watchingCommand.call();
90 assertThat(nextCommand.getStatus(), is(expectedCommandStatus));
91 if (!expectedCommandStatus.equals(Job.JobStatus.IN_PROGRESS) && isService) {
92 verify(asyncInstantiationBL).updateServiceInfoAndAuditStatus(jobUUID, expectedCommandStatus);
94 verify(asyncInstantiationBL, never()).updateServiceInfoAndAuditStatus(jobUUID, expectedCommandStatus);