Merge "Add resources summarizing function in service instance."
[vid.git] / vid-app-common / src / test / java / org / onap / vid / services / AsyncInstantiationBaseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.vid.services;
22
23 import static java.util.Collections.emptyList;
24 import static java.util.Collections.emptyMap;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.anyString;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.Mockito.when;
30 import static org.onap.vid.model.VidNotions.InstantiationType;
31 import static org.onap.vid.model.VidNotions.InstantiationUI;
32 import static org.onap.vid.model.VidNotions.ModelCategory;
33
34 import com.google.common.collect.ImmutableList;
35 import com.google.common.collect.ImmutableMap;
36 import java.time.LocalDateTime;
37 import java.time.ZoneId;
38 import java.time.ZonedDateTime;
39 import java.util.ArrayList;
40 import java.util.Collections;
41 import java.util.Date;
42 import java.util.HashMap;
43 import java.util.LinkedHashMap;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.UUID;
47 import java.util.stream.Collectors;
48 import java.util.stream.Stream;
49 import javax.inject.Inject;
50 import org.hibernate.SessionFactory;
51 import org.jetbrains.annotations.NotNull;
52 import org.onap.portalsdk.core.domain.FusionObject;
53 import org.onap.portalsdk.core.service.DataAccessService;
54 import org.onap.vid.aai.AaiClientInterface;
55 import org.onap.vid.aai.ExceptionWithRequestInfo;
56 import org.onap.vid.job.Job.JobStatus;
57 import org.onap.vid.model.Action;
58 import org.onap.vid.model.ServiceInfo;
59 import org.onap.vid.model.ServiceInfo.ServiceAction;
60 import org.onap.vid.model.VidNotions;
61 import org.onap.vid.model.serviceInstantiation.InstanceGroup;
62 import org.onap.vid.model.serviceInstantiation.Network;
63 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
64 import org.onap.vid.model.serviceInstantiation.VfModule;
65 import org.onap.vid.model.serviceInstantiation.Vnf;
66 import org.onap.vid.mso.RestObject;
67 import org.onap.vid.mso.model.ModelInfo;
68 import org.onap.vid.mso.rest.AsyncRequestStatus;
69 import org.onap.vid.mso.rest.RequestStatus;
70 import org.onap.vid.properties.Features;
71 import org.onap.vid.utils.DaoUtils;
72 import org.onap.vid.utils.TimeUtils;
73 import org.springframework.beans.factory.annotation.Autowired;
74 import org.springframework.http.HttpMethod;
75 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
76 import org.togglz.core.manager.FeatureManager;
77
78 public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests {
79
80     public static final String MODEL_UUID = "337be3fc-293e-43ec-af0b-cf932dad07e6";
81     public static final String MODEL_UUID_2 = "ce052844-22ba-4030-a838-822f2b39eb9b";
82
83     public static final String OWNING_ENTITY_ID = "038d99af-0427-42c2-9d15-971b99b9b489";
84     public static final String JULIO_ERICKSON = "JULIO ERICKSON";
85     public static final String PROJECT_NAME = "{some project name}";
86     public static final String SUBSCRIBER_ID = "{some subscriber id}";
87     public static final String SUBSCRIBER_NAME = "{some subscriber name}";
88     public static final String PRODUCT_FAMILY_ID = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb";
89     public static final String INSTANCE_NAME = "vPE_Service";
90     public static final String SUBSCRIPTION_SERVICE_TYPE = "VMX";
91     public static final String LCP_CLOUD_REGION_ID = "mdt1";
92     public static final String A6CA3EE0394ADE9403F075DB23167E = "88a6ca3ee0394ade9403f075db23167e";
93     public static final String TENANT_NAME = "USP-SIP-IC-24335-T-01";
94     public static final String AIC_ZONE_ID = "NFT1";
95     public static final String AIC_ZONE_NAME = "NFTJSSSS-NFT1";
96     public static final String TEST_API = "GR_API";
97     public static final String SERVICE_MODEL_VERSION_ID = "3c40d244-808e-42ca-b09a-256d83d19d0a";
98     public static final String VF_MODULE_0_MODEL_CUSTOMIZATION_NAME = "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f";
99     public static final String VF_MODULE_1_MODEL_CUSTOMIZATION_NAME = "72d9d1cd-f46d-447a-abdb-451d6fb05fa8";
100     public static final String VF_MODULE_0_MODEL_VERSION_ID = "4c75f813-fa91-45a4-89d0-790ff5f1ae79";
101     public static final String VF_MODULE_1_MODEL_VERSION_ID = "56e2b103-637c-4d1a-adc8-3a7f4a6c3240";
102     public static final String VNF_NAME = "vmxnjr001";
103     public static final String VNF_GROUP_NAME = "VNF_GROUP_NAME";
104
105     protected HashMap<String, String> instanceParamsMapWithoutParams;
106     protected HashMap<String, String> vfModuleInstanceParamsMapWithParamsToRemove;
107     protected HashMap<String, String> vnfInstanceParamsMapWithParamsToRemove;
108
109     protected int serviceCount = 0;
110
111
112     @Inject
113     protected DataAccessService dataAccessService;
114
115     @Inject
116     protected FeatureManager featureManager;
117
118     @Inject
119     protected AaiClientInterface aaiClient;
120
121     @Inject
122     protected CloudOwnerService cloudOwnerService;
123
124     @Autowired
125     protected SessionFactory sessionFactory;
126
127
128     protected static Date toDate(LocalDateTime localDateTime) {
129         return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
130     }
131
132     protected HashMap<String, Object> getPropsMap() {
133         HashMap<String, Object> props = new HashMap<>();
134         props.put(FusionObject.Parameters.PARAM_USERID, 0);
135         return props;
136     }
137
138
139     private void setCreateDateToServiceInfo(UUID jobUuid, LocalDateTime createDate) {
140         List<ServiceInfo> serviceInfoList = dataAccessService.getList(ServiceInfo.class, getPropsMap());
141         DaoUtils.tryWithSessionAndTransaction(sessionFactory, session -> {
142             serviceInfoList.stream()
143                 .filter(serviceInfo -> jobUuid.equals(serviceInfo.getJobId()))
144                 .forEach(serviceInfo -> {
145                     serviceInfo.setCreated(toDate(createDate));
146                     session.saveOrUpdate(serviceInfo);
147                 });
148             return 1;
149         });
150     }
151
152
153     protected void addNewServiceInfo(UUID uuid, String userId, String serviceName, LocalDateTime createDate,
154         LocalDateTime statusModifiedDate, JobStatus status, boolean isHidden, boolean retryEnabled,
155         String modelUUID) {
156         ServiceInfo serviceInfo = createServiceInfo(uuid, userId, serviceName, createDate, statusModifiedDate, status,
157             isHidden, retryEnabled, modelUUID);
158         dataAccessService.saveDomainObject(serviceInfo, getPropsMap());
159         setCreateDateToServiceInfo(uuid, createDate);
160         serviceCount++;
161     }
162     @NotNull
163     private ServiceInfo createServiceInfo(UUID uuid, String userId, String serviceName, LocalDateTime createDate,
164         LocalDateTime statusModifiedDate, JobStatus status, boolean isHidden, boolean retryEnabled, String modelUUID) {
165         ServiceInfo serviceInfo = new ServiceInfo();
166         serviceInfo.setJobId(uuid);
167         serviceInfo.setUserId(userId);
168         serviceInfo.setServiceInstanceName(serviceName);
169         serviceInfo.setStatusModifiedDate(toDate(statusModifiedDate));
170         serviceInfo.setJobStatus(status);
171         serviceInfo.setPause(false);
172         serviceInfo.setOwningEntityId("1234");
173         serviceInfo.setCreatedBulkDate(toDate(createDate));
174         serviceInfo.setRetryEnabled(retryEnabled);
175         serviceInfo.setServiceModelId(modelUUID);
176         serviceInfo.setHidden(isHidden);
177         return serviceInfo;
178     }
179
180     protected void addNewServiceInfoWithAction(UUID uuid, String userId, String serviceName, LocalDateTime createDate,
181         LocalDateTime statusModifiedDate, JobStatus status, boolean isHidden, boolean retryEnabled,
182         String modelUUID, ServiceAction action) {
183         ServiceInfo serviceInfo = createServiceInfo(uuid, userId, serviceName, createDate, statusModifiedDate, status,
184             isHidden, retryEnabled, modelUUID);
185         serviceInfo.setAction(action);
186         dataAccessService.saveDomainObject(serviceInfo, getPropsMap());
187         setCreateDateToServiceInfo(uuid, createDate);
188         serviceCount++;
189     }
190
191
192     public ServiceInstantiation generateMockMacroServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure) {
193         return generateMockServiceInstantiationPayload(isPause, vnfs, Collections.EMPTY_MAP, Collections.EMPTY_MAP, bulkSize, isUserProvidedNaming, projectName, rollbackOnFailure, false, null, Action.Create, null);
194     }
195
196     public ServiceInstantiation generateMockALaCarteServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, Map<String, Network> networks, Map<String, InstanceGroup> vnfGroups, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure, String testApi) {
197         return generateMockServiceInstantiationPayload(isPause, vnfs, networks, vnfGroups, bulkSize, isUserProvidedNaming, projectName, rollbackOnFailure, true, testApi, Action.Create, null);
198     }
199
200     public ServiceInstantiation generateMockAlaCarteServiceDeletionPayload(boolean isPause, Map<String, Vnf> vnfs, Map<String, Network> networks, Map<String, InstanceGroup> vnfGroups, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure, String testApi, String instanceId) {
201         return generateMockServiceInstantiationPayload(isPause, vnfs, networks, vnfGroups, bulkSize, isUserProvidedNaming, projectName, rollbackOnFailure, true, testApi, Action.Delete, instanceId);
202     }
203
204     public ServiceInstantiation generateMockServiceDeletionPayload(boolean isPause, Map<String, Vnf> vnfs, Map<String, Network> networks, Map<String, InstanceGroup> vnfGroups, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure, String testApi, String instanceId) {
205         return generateMockServiceInstantiationPayload(isPause, vnfs, networks, vnfGroups, bulkSize, isUserProvidedNaming, projectName, rollbackOnFailure, false, testApi, Action.Delete, instanceId);
206     }
207     private ServiceInstantiation generateMockServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, Map<String, Network> networks, Map<String, InstanceGroup> vnfGroups, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure, boolean isAlacarte, String testApi, Action action, String instanceId) {
208         ModelInfo modelInfo = createModelInfo();
209
210         List<Map<String,String>> instanceParams = createInstanceParams();
211
212         return new ServiceInstantiation( modelInfo,
213                 AsyncInstantiationBusinessLogicTest.OWNING_ENTITY_ID,
214                 AsyncInstantiationBusinessLogicTest.JULIO_ERICKSON,
215                 projectName,
216                 AsyncInstantiationBusinessLogicTest.SUBSCRIBER_ID,
217                 AsyncInstantiationBusinessLogicTest.SUBSCRIBER_NAME,
218                 AsyncInstantiationBusinessLogicTest.PRODUCT_FAMILY_ID,
219                 isUserProvidedNaming ? AsyncInstantiationBusinessLogicTest.INSTANCE_NAME : null,
220                 AsyncInstantiationBusinessLogicTest.SUBSCRIPTION_SERVICE_TYPE,
221                 AsyncInstantiationBusinessLogicTest.LCP_CLOUD_REGION_ID,
222                 null,
223                 AsyncInstantiationBusinessLogicTest.A6CA3EE0394ADE9403F075DB23167E,
224                 AsyncInstantiationBusinessLogicTest.TENANT_NAME,
225                 AsyncInstantiationBusinessLogicTest.AIC_ZONE_ID,
226                 AsyncInstantiationBusinessLogicTest.AIC_ZONE_NAME,
227                 vnfs,
228                 networks,
229                 vnfGroups,
230                 null,
231                 instanceParams,
232                 isPause,
233                 bulkSize,
234                 rollbackOnFailure,
235                 isAlacarte,
236                 testApi,
237                 instanceId,
238                 action.name(),
239                 UUID.randomUUID().toString(), null, null, null);
240     }
241
242     private List<Map<String,String>> createInstanceParams() {
243         List<Map<String, String>> instanceParams = new ArrayList<>();
244         HashMap<String, String> map = new HashMap<>();
245         map.put("instanceParams_test1" , "some text");
246         map.put("instanceParams_test2" , "another text");
247         instanceParams.add(map);
248         return instanceParams;
249     }
250
251     protected VfModule createVfModule(String modelName, String modelVersionId, String modelCustomizationId,
252                                     List<Map<String, String>> instanceParams, Map<String, String> supplementaryParams, String instanceName, String volumeGroupInstanceName, boolean isAlacarte) {
253         ModelInfo vfModuleInfo = new ModelInfo();
254         vfModuleInfo.setModelType("vfModule");
255         vfModuleInfo.setModelName(modelName);
256         vfModuleInfo.setModelVersionId(modelVersionId);
257         vfModuleInfo.setModelCustomizationId(modelCustomizationId);
258         vfModuleInfo.setModelCustomizationName(modelName);
259
260         if (isAlacarte) {
261             vfModuleInfo.setModelInvariantId("22222222-f63c-463e-ba94-286933b895f9");
262             vfModuleInfo.setModelVersion("10.0");
263             return new VfModule(vfModuleInfo, instanceName, volumeGroupInstanceName, Action.Create.name(), "mdt1", null,
264                     "88a6ca3ee0394ade9403f075db23167e", instanceParams, supplementaryParams, false, true, null, UUID.randomUUID().toString(), null, null,
265                 null, null, null);
266         }
267
268         return new VfModule(vfModuleInfo, instanceName, volumeGroupInstanceName, Action.Create.name(), null, null, null,
269                 instanceParams, supplementaryParams, false, false, null, UUID.randomUUID().toString(), null,
270             null, null, null, null);
271     }
272
273     protected ModelInfo createVfModuleModelInfo(String modelName, String modelVersion, String modelVersionId, String modelInvariantId, String modelCustomizationId, String modelCustomizationName) {
274         return createModelInfo("vfModule", modelName, modelVersion, modelVersionId, modelInvariantId, modelCustomizationId, modelCustomizationName);
275     }
276
277     protected VfModule createVfModuleForReplace(ModelInfo vfModuleModelInfo, String instanceName,
278         String lcpCloudRegionId, String tenantId, Boolean retainAssignments, Boolean retainVolumeGroups, Map<String, String> supplementaryParams) {
279         return new VfModule( vfModuleModelInfo, instanceName, null, Action.Upgrade.name(), lcpCloudRegionId, null, tenantId,
280                 null, supplementaryParams, true, null, null, UUID.randomUUID().toString(), null, null, retainAssignments, retainVolumeGroups, null);
281     }
282
283     protected ModelInfo createVnfModelInfo(boolean isAlacarte) {
284         ModelInfo vnfModelInfo = new ModelInfo();
285         vnfModelInfo.setModelType("vnf");
286         vnfModelInfo.setModelName("2016-73_MOW-AVPN-vPE-BV-L");
287         vnfModelInfo.setModelVersionId("7f40c192-f63c-463e-ba94-286933b895f8");
288         vnfModelInfo.setModelCustomizationName("2016-73_MOW-AVPN-vPE-BV-L 0");
289         vnfModelInfo.setModelCustomizationId("ab153b6e-c364-44c0-bef6-1f2982117f04");
290         //added two conditional fields according to MSO AID - needed only in alacarte
291         if (isAlacarte) {
292             vnfModelInfo.setModelInvariantId("11111111-f63c-463e-ba94-286933b895f9");
293             vnfModelInfo.setModelVersion("10.0");
294         }
295         return vnfModelInfo;
296     }
297
298     protected ModelInfo createVnfModelInfo(String modelName, String modelVersion, String modelVersionId, String modelInvariantId, String modelCustomizationId, String modelCustomizationName) {
299         return createModelInfo("vnf", modelName, modelVersion, modelVersionId, modelInvariantId, modelCustomizationId, modelCustomizationName);
300     }
301
302     private ModelInfo createNetworkModelInfo(boolean isAlacarte, String modelCustomizationId)
303     {
304         ModelInfo modelInfo = new ModelInfo();
305         modelInfo.setModelType("network");
306         modelInfo.setModelName("2016-73_MOW-AVPN-vPE-BV-L");
307         modelInfo.setModelVersionId("7f40c192-f63c-463e-ba94-286933b895f8");
308         modelInfo.setModelCustomizationName("2016-73_MOW-AVPN-vPE-BV-L 0");
309         modelInfo.setModelCustomizationId(modelCustomizationId);
310         //added two conditional fields according to MSO AID - needed only in alacarte
311         if (isAlacarte) {
312             modelInfo.setModelInvariantId("11111111-f63c-463e-ba94-286933b895f9");
313             modelInfo.setModelVersion("10.0");
314         }
315         return modelInfo;
316     }
317
318     private ModelInfo createModelInfo() {
319         ModelInfo modelInfo = new ModelInfo();
320         modelInfo.setModelType("service");
321         modelInfo.setModelVersionId(SERVICE_MODEL_VERSION_ID);
322         modelInfo.setModelVersion("10.0");
323         modelInfo.setModelInvariantId("5d48acb5-097d-4982-aeb2-f4a3bd87d31b");
324         modelInfo.setModelName("MOW AVPN vMX BV vPE 1 Service");
325         return modelInfo;
326     }
327
328     private ModelInfo createModelInfo(String modelType, String modelName, String modelVersion, String modelVersionId, String modelInvariantId, String modelCustomizationId, String modelCustomizationName ) {
329         ModelInfo modelInfo = new ModelInfo();
330         modelInfo.setModelType(modelType);
331         modelInfo.setModelVersionId(modelVersionId);
332         modelInfo.setModelVersion(modelVersion);
333         modelInfo.setModelInvariantId(modelInvariantId);
334         modelInfo.setModelName(modelName);
335         modelInfo.setModelCustomizationId(modelCustomizationId);
336         modelInfo.setModelCustomizationName(modelCustomizationName);
337         return modelInfo;
338     }
339
340     protected Map<String, Vnf> createVnfList(HashMap<String, String> vfModuleInstanceParamsMap, List vnfInstanceParams, boolean isUserProvidedNaming) {
341         return createVnfList(vfModuleInstanceParamsMap, vnfInstanceParams, isUserProvidedNaming, false);
342     }
343
344     protected Map<String, Vnf> createVnfList(HashMap<String, String> vfModuleInstanceParamsMap, List vnfInstanceParams, boolean isUserProvidedNaming, boolean isAlacarte) {
345         Map<String, Vnf> vnfs = new HashMap<>();
346         ModelInfo vnfModelInfo = createVnfModelInfo(isAlacarte);
347
348         Map<String, Map<String, VfModule>> vfModules = new HashMap<>();
349
350         List<Map<String, String>> instanceParams1 = ImmutableList.of((ImmutableMap.of("vmx_int_net_len", "24")));
351         VfModule vfModule1 = createVfModule("201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0", VF_MODULE_0_MODEL_VERSION_ID, VF_MODULE_0_MODEL_CUSTOMIZATION_NAME, instanceParams1, new HashMap<>(), (isUserProvidedNaming ? "vmxnjr001_AVPN_base_vPE_BV_base" : null), null, isAlacarte);
352         List<Map<String, String>> instanceParams2 = ImmutableList.of(vfModuleInstanceParamsMap);
353         VfModule vfModule2 = createVfModule("201673MowAvpnVpeBvL..AVPN_vRE_BV..module-1", VF_MODULE_1_MODEL_VERSION_ID, VF_MODULE_1_MODEL_CUSTOMIZATION_NAME, instanceParams2, new HashMap<>(), (isUserProvidedNaming ? "vmxnjr001_AVPN_base_vRE_BV_expansion": null), (isUserProvidedNaming ? "myVgName" : null), isAlacarte);
354
355         String vfModuleModelName = vfModule1.getModelInfo().getModelName();
356         vfModules.put(vfModuleModelName, new LinkedHashMap<>());
357
358         vfModules.get(vfModuleModelName).put(vfModuleModelName + ":001", vfModule1);
359         vfModules.get(vfModuleModelName).put(vfModuleModelName + ":002", vfModule2);
360
361         Vnf vnf = new Vnf(vnfModelInfo, "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", (isUserProvidedNaming ? VNF_NAME : null), Action.Create.name(),
362                 "platformName", "mdt1", null, "88a6ca3ee0394ade9403f075db23167e", vnfInstanceParams,"lineOfBusinessName" , false, null, vfModules,
363                 UUID.randomUUID().toString(), null, null, null);
364
365         vnfs.put(vnf.getModelInfo().getModelName(), vnf);
366         return vnfs;
367     }
368
369     protected void mockAaiClientAaiStatusOK() {
370         when(aaiClient.isNodeTypeExistsByName(eq(AsyncInstantiationBusinessLogicImpl.NAME_FOR_CHECK_AAI_STATUS), any())).thenReturn(false);
371     }
372
373     protected void enableAddCloudOwnerOnMsoRequest(boolean isActive) {
374         // always turn on the feature flag
375         when(featureManager.isActive(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)).thenReturn(isActive);
376         when(aaiClient.getCloudOwnerByCloudRegionId(anyString())).thenReturn("irma-aic");
377     }
378
379     protected void enableAddCloudOwnerOnMsoRequest() {
380         enableAddCloudOwnerOnMsoRequest(true);
381     }
382
383     protected ServiceInstantiation generateMacroMockServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs) {
384         return generateMockMacroServiceInstantiationPayload(isPause, vnfs, 1, true, PROJECT_NAME, false);
385     }
386
387     protected ServiceInstantiation generatePre1806MacroTransportServiceInstantiationPayload(String tenantId, String lcpCloudRegionId) {
388         List<Map<String, String>> instanceParams = ImmutableList
389             .of(ImmutableMap.of("someUserParam","someValue", "anotherUserParam","anotherValue"));
390         ServiceInstantiation serviceInstantiation = new ServiceInstantiation(createServiceModelInfo(), "038d99af-0427-42c2-9d15-971b99b9b489",
391                 "JULIO ERICKSON", "some_project_name", "some_subscriber_id", "some_subscriber_name",
392                 "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", null, "MOG", lcpCloudRegionId, null, tenantId,
393                 null, null, null, Collections.EMPTY_MAP, Collections.EMPTY_MAP, Collections.EMPTY_MAP, Collections.EMPTY_MAP, instanceParams, false, 1, false, false,
394                 null, null, null, null, null, null,
395                 new VidNotions(InstantiationUI.TRANSPORT_SERVICE, ModelCategory.Transport, InstantiationUI.TRANSPORT_SERVICE, InstantiationType.Macro)
396         );
397         return serviceInstantiation;
398     }
399
400     public static class NetworkDetails {
401
402         public NetworkDetails(String name, String modelCustomizationId) {
403             this.name = name;
404             this.modelCustomizationId = modelCustomizationId;
405         }
406
407         public String name;
408         public String modelCustomizationId;
409     }
410
411     protected Map<String, Network> createNetworkList(List instanceParams, List<NetworkDetails> networkDetails, boolean isALaCarte) {
412         Stream<Network> networkStream = networkDetails.stream().map(
413                 details->new Network(createNetworkModelInfo(isALaCarte, details.modelCustomizationId), "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
414                 details.name, Action.Create.name(),
415                 "platformName", "mdt1", null, "88a6ca3ee0394ade9403f075db23167e", instanceParams,"lineOfBusinessName" ,
416                 false, null, UUID.randomUUID().toString(), null, null, null));
417 //        I can't tell why compiler don't like the statement if it's only one line...
418         return networkStream.collect(Collectors.toMap(network -> network.getModelInfo().getModelCustomizationId(), network -> network));
419     }
420
421     protected InstanceGroup createInstanceGroup(boolean isUserProvidedNaming, Action action) {
422         ModelInfo modelInfo = new ModelInfo();
423         modelInfo.setModelType("instanceGroup");
424         modelInfo.setModelName("2016-73_MOW-AVPN-vPE-BV-L");
425         modelInfo.setModelVersionId("7f40c192-f63c-463e-ba94-286933b895f8");
426         modelInfo.setModelCustomizationName("2016-73_MOW-AVPN-vPE-BV-L 0");
427         modelInfo.setModelCustomizationId("ab153b6e-c364-44c0-bef6-1f2982117f04");
428         modelInfo.setModelInvariantId("11111111-f63c-463e-ba94-286933b895f9");
429         modelInfo.setModelVersion("10.0");
430
431         return new InstanceGroup(modelInfo, (isUserProvidedNaming ? VNF_GROUP_NAME : null), action.name(), false, null, emptyMap(), UUID.randomUUID().toString(), null, null,
432             null);
433     }
434
435     protected ModelInfo createServiceModelInfo() {
436         ModelInfo siModelInfo = new ModelInfo();
437         siModelInfo.setModelName("sriov");
438         siModelInfo.setModelType("service");
439         siModelInfo.setModelInvariantId("ff3514e3-5a33-55df-13ab-12abad84e7ff");
440         siModelInfo.setModelVersionId("fe6985cd-ea33-3346-ac12-ab121484a3fe");
441         siModelInfo.setModelVersion("1.0");
442
443         return siModelInfo;
444     }
445
446     protected ModelInfo createServiceModelInfo(String modelName, String modelVersion, String modelVersionId, String modelInvariantId, String modelCustomizationId, String modelCustomizationName) {
447         return createModelInfo("service", modelName, modelVersion, modelVersionId, modelInvariantId, modelCustomizationId, modelCustomizationName);
448     }
449
450     protected void createInstanceParamsMaps() {
451         instanceParamsMapWithoutParams = new HashMap<>();
452         instanceParamsMapWithoutParams.put("availability_zone_0" , "mtpocdv-kvm-az01");
453         instanceParamsMapWithoutParams.put("vre_a_volume_size_0" , "100");
454
455         vfModuleInstanceParamsMapWithParamsToRemove = new HashMap<>();
456         vfModuleInstanceParamsMapWithParamsToRemove.put(AsyncInstantiationBusinessLogic.PARAMS_TO_IGNORE.get(0), "should be removed");
457         vfModuleInstanceParamsMapWithParamsToRemove.put("availability_zone_0" , "mtpocdv-kvm-az01");
458         vfModuleInstanceParamsMapWithParamsToRemove.put("vre_a_volume_size_0" , "100");
459
460         vnfInstanceParamsMapWithParamsToRemove = new HashMap<>();
461         vnfInstanceParamsMapWithParamsToRemove.put(AsyncInstantiationBusinessLogic.PARAMS_TO_IGNORE.get(1), "should be removed");
462     }
463
464     public static AsyncRequestStatus asyncRequestStatusResponse(String msoStatus) {
465         AsyncRequestStatus asyncRequestStatus = new AsyncRequestStatus(new AsyncRequestStatus.Request(new RequestStatus()));
466         asyncRequestStatus.request.requestStatus.setRequestState(msoStatus);
467         asyncRequestStatus.request.requestId = UUID.randomUUID().toString();
468         asyncRequestStatus.request.startTime = TimeUtils.zonedDateTimeToString(ZonedDateTime.now());
469         return asyncRequestStatus;
470     }
471
472     public static RestObject<AsyncRequestStatus> asyncRequestStatusResponseAsRestObject(String msoStatus) {
473         return asyncRequestStatusResponseAsRestObject(msoStatus, 200);
474     }
475
476     public static RestObject<AsyncRequestStatus> asyncRequestStatusResponseAsRestObject(String msoStatus, int httpStatusCode) {
477         RestObject<AsyncRequestStatus> restObject = new RestObject<>();
478         restObject.set(asyncRequestStatusResponse(msoStatus));
479         restObject.setStatusCode(httpStatusCode);
480         return restObject;
481     }
482
483     protected void mockAaiClientAnyNameFree() {
484         when(aaiClient.isNodeTypeExistsByName(any(), any())).thenReturn(false);
485     }
486
487     protected ExceptionWithRequestInfo aaiNodeQueryBadResponseException() {
488         return new ExceptionWithRequestInfo(HttpMethod.GET, "url", "raw data", 500, null);
489     }
490
491     protected ServiceInstantiation generateALaCarteWithVnfsServiceInstantiationPayload() {
492         Map<String, Vnf> vnfs = createVnfList(vfModuleInstanceParamsMapWithParamsToRemove, Collections.singletonList(vnfInstanceParamsMapWithParamsToRemove) , true, true);
493         ServiceInstantiation serviceInstantiation = generateMockALaCarteServiceInstantiationPayload(false, vnfs, emptyMap(), emptyMap(), 1, true, PROJECT_NAME, false, "VNF_API");
494         return serviceInstantiation;
495     }
496
497     protected ServiceInstantiation generateALaCarteWithNetworksPayload(List<NetworkDetails> networkDetails) {
498         Map<String, Network> networks = createNetworkList(emptyList(), networkDetails, true);
499         ServiceInstantiation serviceInstantiation = generateMockALaCarteServiceInstantiationPayload(false, emptyMap(), networks, emptyMap(), 1, true, PROJECT_NAME, false, "VNF_API");
500         return serviceInstantiation;
501     }
502
503     protected ServiceInstantiation generateALaCarteUpdateWith1ExistingGroup2NewGroupsPayload() {
504         final InstanceGroup instanceGroup1 = createInstanceGroup(true, Action.None);
505         final InstanceGroup instanceGroup2 = createInstanceGroup(false, Action.Create);
506         final InstanceGroup instanceGroup3 = createInstanceGroup(true, Action.Create);
507         Map<String, InstanceGroup> groups = ImmutableMap.of(
508                 "foo:001", instanceGroup1,
509                 "foo:002", instanceGroup2,
510                 "foo:003", instanceGroup3
511         );
512         return generateMockServiceInstantiationPayload(false, emptyMap(), emptyMap(), groups,
513                 1, true, PROJECT_NAME, false, true, "VNF_API",
514                 Action.None, "1234567890");
515     }
516
517     protected ServiceInstantiation generateALaCarteServiceInstantiationPayload() {
518         return generateMockALaCarteServiceInstantiationPayload(false, Collections.EMPTY_MAP, Collections.EMPTY_MAP, Collections.EMPTY_MAP, 1, true, PROJECT_NAME, false, "VNF_API");
519     }
520 }