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 static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
27 import static org.onap.vid.model.VidNotions.ModelCategory.INFRASTRUCTURE_VPN;
28 import static org.onap.vid.model.VidNotions.ModelCategory.IS_5G_FABRIC_CONFIGURATION_MODEL;
29 import static org.onap.vid.model.VidNotions.ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL;
30 import static org.onap.vid.model.VidNotions.ModelCategory.OTHER;
31 import static org.onap.vid.model.VidNotions.ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE;
32 import static org.onap.vid.model.VidNotions.ModelCategory.Transport;
33 import static org.testng.AssertJUnit.assertEquals;
35 import com.google.common.collect.ImmutableList;
36 import java.util.Collections;
37 import java.util.List;
38 import java.util.UUID;
39 import org.mockito.InjectMocks;
40 import org.mockito.Mock;
41 import org.mockito.MockitoAnnotations;
42 import org.onap.vid.job.Job;
43 import org.onap.vid.job.JobAdapter;
44 import org.onap.vid.job.JobsBrokerService;
45 import org.onap.vid.job.impl.JobSharedData;
46 import org.onap.vid.model.Action;
47 import org.onap.vid.model.VidNotions;
48 import org.onap.vid.model.serviceInstantiation.BaseResource;
49 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
50 import org.onap.vid.mso.RestMsoImplementation;
51 import org.onap.vid.mso.rest.AsyncRequestStatus;
52 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
53 import org.onap.vid.services.AuditService;
54 import org.testng.annotations.BeforeClass;
55 import org.testng.annotations.DataProvider;
56 import org.testng.annotations.Test;
57 import org.togglz.core.manager.FeatureManager;
59 public class MacroServiceCommandTest {
62 private InProgressStatusService inProgressStatusService;
65 private WatchChildrenJobsBL watchChildrenJobsB;
68 private AsyncInstantiationBusinessLogic asyncInstantiationBL;
71 private JobsBrokerService jobsBrokerService;
74 private MsoRequestBuilder msoRequestBuilder;
77 private MsoResultHandlerService msoResultHandlerService;
80 private JobAdapter jobAdapter;
83 private RestMsoImplementation restMso;
86 private AuditService auditService;
89 FeatureManager featureManager;
92 private MacroServiceCommand macroServiceCommand;
95 public static Object[][] modelCategoryPre1806DataProvider() {
96 return new Object[][]{
97 {IS_5G_PROVIDER_NETWORK_MODEL, false},
98 {IS_5G_FABRIC_CONFIGURATION_MODEL, false},
100 {SERVICE_WITH_COLLECTION_RESOURCE, true},
101 {INFRASTRUCTURE_VPN, true},
107 public void initMocks() {
108 MockitoAnnotations.initMocks(this);
111 @Test(dataProvider = "modelCategoryPre1806DataProvider")
112 public void testShouldUsePre1806Request(VidNotions.ModelCategory modelCategory, boolean expectedResult) {
113 ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
114 VidNotions vidNotions = mock(VidNotions.class);
115 when(serviceInstantiation.getVidNotions()).thenReturn(vidNotions);
116 when(vidNotions.getModelCategory()).thenReturn(modelCategory);
117 assertEquals(macroServiceCommand.shouldUsePre1806Request(serviceInstantiation), expectedResult);
121 public static Object[][] MsoFilteredRequestsDataProvider() {
122 return new Object[][]{
123 {Collections.EMPTY_LIST},
124 {ImmutableList.of(new AsyncRequestStatus.Request())}
128 @Test(dataProvider = "MsoFilteredRequestsDataProvider")
129 public void givenResumeAction_whenCantRetrieveRequestIdFromMSO_thenJobIsFailed(List<AsyncRequestStatus.Request> requests) {
130 String instanceId = UUID.randomUUID().toString();
131 BaseResource baseResource = mock(BaseResource.class);
132 when(baseResource.getInstanceId()).thenReturn(instanceId);
133 when(baseResource.getAction()).thenReturn(Action.Resume);
134 macroServiceCommand.init(new JobSharedData(null, null, baseResource, null));
135 when(auditService.retrieveRequestsFromMsoByServiceIdAndRequestTypeAndScope(eq(instanceId), any(), any()))
136 .thenReturn(requests);
137 assertEquals(macroServiceCommand.resumeMyself(), Job.JobStatus.FAILED);