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.services;
23 import static com.google.common.collect.Maps.newHashMap;
24 import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
25 import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
26 import static org.hamcrest.MatcherAssert.assertThat;
27 import static org.hamcrest.core.IsEqual.equalTo;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.Mockito.doReturn;
30 import static org.mockito.Mockito.spy;
31 import static org.mockito.Mockito.when;
33 import com.fasterxml.jackson.databind.JsonNode;
34 import com.fasterxml.jackson.databind.ObjectMapper;
35 import com.google.common.collect.ImmutableList;
36 import com.google.common.collect.ImmutableMap;
37 import java.io.IOException;
38 import java.lang.reflect.Method;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collections;
43 import java.util.HashMap;
44 import java.util.List;
46 import java.util.UUID;
47 import java.util.stream.Collectors;
48 import javax.inject.Inject;
49 import org.apache.commons.io.IOUtils;
50 import org.hibernate.SessionFactory;
51 import org.mockito.Mock;
52 import org.mockito.Mockito;
53 import org.mockito.MockitoAnnotations;
54 import org.onap.portalsdk.core.service.DataAccessService;
55 import org.onap.portalsdk.core.util.SystemProperties;
56 import org.onap.vid.aai.model.ResourceType;
57 import org.onap.vid.changeManagement.RequestDetailsWrapper;
58 import org.onap.vid.config.DataSourceConfig;
59 import org.onap.vid.config.MockedAaiClientAndFeatureManagerConfig;
60 import org.onap.vid.dal.AsyncInstantiationRepository;
61 import org.onap.vid.job.JobAdapter;
62 import org.onap.vid.job.JobsBrokerService;
63 import org.onap.vid.job.command.MsoRequestBuilder;
64 import org.onap.vid.model.Action;
65 import org.onap.vid.model.serviceInstantiation.InstanceGroup;
66 import org.onap.vid.model.serviceInstantiation.Network;
67 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
68 import org.onap.vid.model.serviceInstantiation.VfModule;
69 import org.onap.vid.model.serviceInstantiation.Vnf;
70 import org.onap.vid.mso.MsoOperationalEnvironmentTest;
71 import org.onap.vid.mso.model.AddOrRemoveInstanceGroupMemberRequestDetails;
72 import org.onap.vid.mso.model.InstanceGroupInstantiationRequestDetails;
73 import org.onap.vid.mso.model.ModelInfo;
74 import org.onap.vid.mso.model.NetworkInstantiationRequestDetails;
75 import org.onap.vid.mso.model.ServiceDeletionRequestDetails;
76 import org.onap.vid.mso.model.ServiceInstantiationRequestDetails;
77 import org.onap.vid.mso.model.VfModuleInstantiationRequestDetails;
78 import org.onap.vid.mso.model.VfModuleMacro;
79 import org.onap.vid.mso.model.VnfInstantiationRequestDetails;
80 import org.onap.vid.mso.model.VolumeGroupRequestDetails;
81 import org.onap.vid.properties.Features;
82 import org.onap.vid.testUtils.TestUtils;
83 import org.springframework.beans.factory.annotation.Autowired;
84 import org.springframework.test.context.ContextConfiguration;
85 import org.testng.Assert;
86 import org.testng.annotations.BeforeClass;
87 import org.testng.annotations.DataProvider;
88 import org.testng.annotations.Test;
89 import org.togglz.core.manager.FeatureManager;
91 @ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class})
92 public class MsoRequestBuilderTest extends AsyncInstantiationBaseTest {
95 private DataAccessService dataAccessService;
98 private JobAdapter jobAdapterMock;
101 private JobsBrokerService jobsBrokerServiceMock;
103 private AsyncInstantiationRepository asyncInstantiationRepository;
105 private AuditService auditService;
108 private SessionFactory sessionFactory;
110 private AsyncInstantiationBusinessLogicImpl asyncInstantiationBL;
112 private MsoRequestBuilder msoRequestBuilder;
116 void initServicesInfoService() {
117 MockitoAnnotations.initMocks(this);
118 AsyncInstantiationRepository realAsyncInstantiationRepository = new AsyncInstantiationRepository(dataAccessService);
119 asyncInstantiationRepository = spy(realAsyncInstantiationRepository);
121 auditService = new AuditServiceImpl(null, asyncInstantiationRepository);
123 AsyncInstantiationBusinessLogicImpl realAsyncInstantiationBL = new AsyncInstantiationBusinessLogicImpl(jobAdapterMock, jobsBrokerServiceMock, sessionFactory, aaiClient, featureManager, cloudOwnerService, asyncInstantiationRepository, auditService);
124 asyncInstantiationBL = Mockito.spy(realAsyncInstantiationBL);
126 msoRequestBuilder = new MsoRequestBuilder(asyncInstantiationBL, cloudOwnerService, aaiClient, featureManager);
128 createInstanceParamsMaps();
131 @Test(dataProvider = "pauseAndInstanceParams", enabled = false) //Test is irrelevant with unique names feature
132 public void createMacroServiceInstantiationMsoRequest(Boolean isPause, HashMap<String, String> vfModuleInstanceParamsMap, List vnfInstanceParams) throws Exception {
133 ServiceInstantiation serviceInstantiationPayload = generateMacroMockServiceInstantiationPayload(isPause, createVnfList(vfModuleInstanceParamsMap, vnfInstanceParams, true));
134 final URL resource = this.getClass().getResource("/payload_jsons/bulk_macro_service_request.json");
135 RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
136 msoRequestBuilder.generateMacroServiceInstantiationRequest(null, serviceInstantiationPayload, serviceInstantiationPayload.getInstanceName(), "az2016");
137 String expected = IOUtils.toString(resource, "UTF-8");
138 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
142 public void createServiceInfo_WithUserProvidedNamingFalse_ServiceInfoIsAsExpected() throws IOException {
143 createMacroServiceInfo_WithUserProvidedNamingFalse_ServiceInfoIsAsExpected(true,
148 public void createServiceInfo_WithUserProvidedNamingFalseAndNoVfmodules_ServiceInfoIsAsExpected() throws IOException {
149 createMacroServiceInfo_WithUserProvidedNamingFalse_ServiceInfoIsAsExpected(false, false);
153 public void shouldCreateServiceInfoWithHomingSolutionDisabled() throws IOException {
154 doReturn(true).when(featureManager).isActive(Features.FLAG_DISABLE_HOMING);
156 createMacroServiceInfo_WithUserProvidedNamingFalse_ServiceInfoIsAsExpected(true, true);
159 private void createMacroServiceInfo_WithUserProvidedNamingFalse_ServiceInfoIsAsExpected(boolean withVfmodules, boolean disabledHoming) throws IOException {
161 ServiceInstantiation serviceInstantiationPayload = generateMockMacroServiceInstantiationPayload(true,
162 createVnfList(vfModuleInstanceParamsMapWithParamsToRemove, Collections.EMPTY_LIST, false),
164 false, PROJECT_NAME, true);
166 if (disabledHoming) {
167 resource = this.getClass().getResource("/payload_jsons/bulk_service_no_homing.json");
168 } else if (withVfmodules) {
169 resource = this.getClass().getResource("/payload_jsons/bulk_service_request_ecomp_naming.json");
171 // remove the vf modules
172 serviceInstantiationPayload.getVnfs().values().forEach(vnf -> vnf.getVfModules().clear());
173 resource = this.getClass().getResource("/payload_jsons/bulk_service_request_no_vfmodule_ecomp_naming.json");
176 RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
177 msoRequestBuilder.generateMacroServiceInstantiationRequest(null, serviceInstantiationPayload, serviceInstantiationPayload.getInstanceName(), "az2016");
179 String expected = IOUtils.toString(resource, "UTF-8");
180 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
184 public void createALaCarteService_WithUserProvidedNamingFalse_RequestDetailsIsAsExpected() throws IOException {
185 ServiceInstantiation serviceInstantiationPayload = generateMockALaCarteServiceInstantiationPayload(false,
190 false, PROJECT_NAME, true, null);
192 RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
193 msoRequestBuilder.generateALaCarteServiceInstantiationRequest(serviceInstantiationPayload, serviceInstantiationPayload.getInstanceName(), "az2016");
195 URL resource = this.getClass().getResource("/payload_jsons/bulk_alacarte_service_request_naming_false.json");
196 String expected = IOUtils.toString(resource, "UTF-8");
197 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
201 public void generateALaCarteServiceInstantiationRequest_withVnfList_HappyFllow() throws IOException {
202 ServiceInstantiation serviceInstantiationPayload = generateALaCarteWithVnfsServiceInstantiationPayload();
203 RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
204 msoRequestBuilder.generateALaCarteServiceInstantiationRequest(serviceInstantiationPayload, serviceInstantiationPayload.getInstanceName(), "az2016");
206 String serviceExpected = IOUtils.toString(this.getClass().getResource("/payload_jsons/bulk_alacarte_service_request.json"), "UTF-8");
207 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(serviceExpected, result);
211 public void generateALaCarteServiceInstantiationRequest_verifyRequestIsAsExpected() throws IOException {
212 ServiceInstantiation serviceInstantiationPayload = generateALaCarteServiceInstantiationPayload();
213 final URL resource = this.getClass().getResource("/payload_jsons/bulk_alacarte_service_request.json");
214 RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
215 msoRequestBuilder.generateALaCarteServiceInstantiationRequest(serviceInstantiationPayload, serviceInstantiationPayload.getInstanceName(), "az2016");
216 String expected = IOUtils.toString(resource, "UTF-8");
217 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
221 public void generateALaCarteServiceDeletionRequest_verifyRequestIsAsExpected() throws IOException {
222 String expected = generateServiceDeletionRequest(true, "VNF_API");
224 ServiceInstantiation serviceDeletionPayload = generateALaCarteServiceDeletionPayload();
225 RequestDetailsWrapper<ServiceDeletionRequestDetails> result =
226 msoRequestBuilder.generateServiceDeletionRequest(serviceDeletionPayload, "az2016");
228 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
231 private ServiceInstantiation generateALaCarteServiceDeletionPayload() {
232 return generateMockAlaCarteServiceDeletionPayload(false, Collections.EMPTY_MAP, Collections.EMPTY_MAP, Collections.EMPTY_MAP, 1, true, PROJECT_NAME, false, "VNF_API", "1234567890");
236 public void generateServiceDeletionRequest_verifyRequestIsAsExpected() throws IOException {
237 String expected = generateServiceDeletionRequest(false, null);
239 ServiceInstantiation serviceDeletionPayload = generateServiceDeletionPayload();
240 RequestDetailsWrapper<ServiceDeletionRequestDetails> result =
241 msoRequestBuilder.generateServiceDeletionRequest(serviceDeletionPayload, "az2016");
243 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
246 private String generateServiceDeletionRequest(boolean isAlaCarte, String testApi) {
247 String expected = TestUtils.readFileAsString("/payload_jsons/bulk_alacarte_service_deletion_request.json");
248 expected = expected.replace("[TEST_API]", String.valueOf(testApi));
249 expected = expected.replace("[IS_ALACARTE]", Boolean.toString(isAlaCarte));
253 private ServiceInstantiation generateServiceDeletionPayload() {
254 return generateMockServiceDeletionPayload(false, Collections.EMPTY_MAP, Collections.EMPTY_MAP, Collections.EMPTY_MAP, 1, true, PROJECT_NAME, false, "VNF_API", "1234567890");
258 public static Object[][] createVnfParameters() {
259 return new Object[][]{
260 {true, true, "/payload_jsons/vnf/bulk_vnf_request.json"},
261 {false, true, "/payload_jsons/vnf/bulk_vnf_request_without_cloud_owner.json"},
262 {true, false, "/payload_jsons/vnf/bulk_vnf_request_without_instance_name.json"},
266 @Test(dataProvider = "createVnfParameters")
267 public void createVnfRequestDetails_detailsAreAsExpected(boolean isFlagAddCloudOwnerActive, boolean isUserProvidedNaming, String expectedFile) throws IOException {
268 final List<Vnf> vnfList = new ArrayList<>(createVnfList(new HashMap<>(), null, isUserProvidedNaming, true).values());
269 createVnfPayloadAndAssert(vnfList.get(0), isFlagAddCloudOwnerActive, expectedFile);
273 public static Object[][] inputVnfEndExpectedResult() {
274 return new Object[][]{
275 {"/payload_jsons/vnf/vnf_without_lob_user_input.json", "/payload_jsons/vnf/vnf_without_lob_expected.json"},
279 @Test(dataProvider = "inputVnfEndExpectedResult")
280 public void createVnfRequestFromJson_andCompre(String userInputFile, String expectedFile) throws IOException {
281 Vnf vnf = TestUtils.readJsonResourceFileAsObject(userInputFile, Vnf.class);
282 createVnfPayloadAndAssert(vnf, true, expectedFile);
285 private void createVnfPayloadAndAssert(Vnf vnf, boolean isFlagAddCloudOwnerActive, String expectedFile) throws IOException {
286 ModelInfo siModelInfo = createServiceModelInfo();
287 String serviceInstanceId = "aa3514e3-5a33-55df-13ab-12abad84e7aa";
288 Mockito.reset(aaiClient);
289 mockAaiClientAaiStatusOK();
290 enableAddCloudOwnerOnMsoRequest(isFlagAddCloudOwnerActive);
291 final RequestDetailsWrapper<VnfInstantiationRequestDetails> result = msoRequestBuilder.generateVnfInstantiationRequest(vnf, siModelInfo, serviceInstanceId, "pa0916", "VNF_API");
292 String expected = IOUtils.toString(this.getClass().getResource(expectedFile), "UTF-8");
293 assertThat(result, jsonEquals(expected).when(IGNORING_ARRAY_ORDER));
297 public static Object[][] testBuildVnfInstanceParamsDataProvider(Method test) {
298 return new Object[][]{
300 Collections.EMPTY_LIST,
302 ImmutableList.of(ImmutableMap.of("k1", "v1", "k2", "v2")),
303 ImmutableList.of(ImmutableMap.of("k3", "v3", "k2", "v2"))
305 ImmutableList.of(ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"))
308 ImmutableList.of(ImmutableMap.of("j1", "w1", "k1", "v1", "vnf_name", "w2", "vf_module_name", "w3")), //vnf_name, vf_module_name are excluded
310 ImmutableList.of(ImmutableMap.of("k1", "v1", "k2", "v2")),
311 ImmutableList.of(ImmutableMap.of("k3", "v3", "k2", "v2")),
312 ImmutableList.of(Collections.EMPTY_MAP),
313 Collections.singletonList(null)
315 ImmutableList.of(ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "j1", "w1"))
318 Collections.EMPTY_LIST,
319 Arrays.asList(null, null),
320 Collections.EMPTY_LIST //mso is expect to empty list and not list with empty map
323 ImmutableList.of(Collections.EMPTY_MAP),
325 ImmutableList.of(Collections.EMPTY_MAP),
326 ImmutableList.of(Collections.EMPTY_MAP)
328 Collections.EMPTY_LIST //mso is expect to empty list and not list with empty map
333 @Test(dataProvider = "testBuildVnfInstanceParamsDataProvider")
334 public void testBuildVnfInstanceParams(List<Map<String, String>> currentVnfInstanceParams,
335 List<List<Map<String, String>>> vfModulesInstanceParams,
336 List<Map<String, String>> expectedResult) {
337 List<VfModuleMacro> vfModules =
338 vfModulesInstanceParams.stream().map(params -> new VfModuleMacro(new ModelInfo(), null, null, params)).collect(Collectors.toList());
339 List<Map<String, String>> actual = msoRequestBuilder.buildVnfInstanceParams(currentVnfInstanceParams, vfModules);
340 assertThat(actual, equalTo(expectedResult));
344 public static Object[][] vfModuleRequestDetails(Method test) {
345 return new Object[][]{
346 {"cc3514e3-5a33-55df-13ab-12abad84e7cc", true, "/payload_jsons/vfmodule_instantiation_request.json"},
347 {null, true, "/payload_jsons/vfmodule_instantiation_request_without_volume_group.json"},
348 {null, false, "/payload_jsons/vfmodule_instantiation_request_without_instance_name.json"}
352 @Test(dataProvider = "vfModuleRequestDetails")
353 public void createVfModuleRequestDetails_detailsAreAsExpected(String volumeGroupInstanceId, boolean isUserProvidedNaming, String fileName) throws IOException {
355 ModelInfo siModelInfo = createServiceModelInfo();
356 ModelInfo vnfModelInfo = createVnfModelInfo(true);
357 List<Map<String, String>> instanceParams = ImmutableList.of(ImmutableMap.of("vmx_int_net_len", "24",
358 "vre_a_volume_size_0", "120"));
359 Map<String, String> supplementaryParams = ImmutableMap.of("vre_a_volume_size_0", "100",
360 "availability_zone_0", "mtpocdv-kvm-az01");
361 VfModule vfModule = createVfModule("201673MowAvpnVpeBvL..AVPN_vRE_BV..module-1", "56e2b103-637c-4d1a-adc8-3a7f4a6c3240",
362 "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", instanceParams, supplementaryParams,
363 (isUserProvidedNaming ? "vmxnjr001_AVPN_base_vRE_BV_expansion" : null), "myVgName", true);
365 String serviceInstanceId = "aa3514e3-5a33-55df-13ab-12abad84e7aa";
366 String vnfInstanceId = "bb3514e3-5a33-55df-13ab-12abad84e7bb";
368 Mockito.reset(aaiClient);
369 mockAaiClientAaiStatusOK();
370 enableAddCloudOwnerOnMsoRequest();
371 when(aaiClient.isNodeTypeExistsByName(eq("vmxnjr001_AVPN_base_vRE_BV_expansion"), eq(ResourceType.VF_MODULE))).thenReturn(false);
373 String expected = IOUtils.toString(this.getClass().getResource(fileName), "UTF-8");
374 final RequestDetailsWrapper<VfModuleInstantiationRequestDetails> result = msoRequestBuilder.generateVfModuleInstantiationRequest(
375 vfModule, siModelInfo, serviceInstanceId,
376 vnfModelInfo, vnfInstanceId, volumeGroupInstanceId, "pa0916", "VNF_API");
377 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
381 public static Object[][] expectedAggregatedParams() {
382 return new Object[][]{
383 {ImmutableMap.of("a", "b", "c", "d"), ImmutableMap.of("e", "f", "g", "h"), ImmutableList.of(ImmutableMap.of("c", "d", "a", "b", "e", "f", "g", "h"))},
384 {ImmutableMap.of("a", "b", "c", "g"), ImmutableMap.of("c", "d", "e", "f"), ImmutableList.of(ImmutableMap.of("a", "b", "c", "d", "e", "f"))},
385 {ImmutableMap.of(), ImmutableMap.of("c", "d", "e", "f"), ImmutableList.of(ImmutableMap.of("c", "d", "e", "f"))},
386 {ImmutableMap.of("a", "b", "c", "g"), ImmutableMap.of(), ImmutableList.of(ImmutableMap.of("a", "b", "c", "g"))},
387 {ImmutableMap.of(), ImmutableMap.of(), ImmutableList.of()},
388 {null, ImmutableMap.of(), ImmutableList.of()},
389 {ImmutableMap.of(), null, ImmutableList.of()},
393 @Test(dataProvider = "expectedAggregatedParams")
394 public void testAggregateInstanceParamsAndSuppFile(Map<String, String> instanceParams, Map<String, String> suppParams, List<VfModuleInstantiationRequestDetails.UserParamMap<String, String>> expected) {
395 List<VfModuleInstantiationRequestDetails.UserParamMap<String, String>> aggParams = msoRequestBuilder.aggregateAllInstanceParams(instanceParams, suppParams);
396 assertThat("Aggregated params are not as expected", aggParams, equalTo(expected));
400 public void createVolumeGroup_verifyResultAsExpected() throws IOException {
401 final URL resource = this.getClass().getResource("/payload_jsons/volumegroup_instantiation_request.json");
402 VfModule vfModule = createVfModule("201673MowAvpnVpeBvL..AVPN_vRE_BV..module-1",
403 "56e2b103-637c-4d1a-adc8-3a7f4a6c3240",
404 "72d9d1cd-f46d-447a-abdb-451d6fb05fa8",
405 Collections.emptyList(),
406 Collections.emptyMap(),
407 "vmxnjr001_AVPN_base_vRE_BV_expansion",
410 vfModule.getModelInfo().setModelInvariantId("ff5256d2-5a33-55df-13ab-12abad84e7ff");
411 vfModule.getModelInfo().setModelVersion("1");
412 ModelInfo vnfModelInfo = createVnfModelInfo(true);
413 RequestDetailsWrapper<VolumeGroupRequestDetails> result =
414 msoRequestBuilder.generateVolumeGroupInstantiationRequest(vfModule,
415 createServiceModelInfo(),
416 "ff3514e3-5a33-55df-13ab-12abad84e7ff",
421 String expected = IOUtils.toString(resource, "UTF-8");
422 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
426 public static Object[][] expectedNetworkRequestDetailsParameters() {
427 return new Object[][]{
428 {VNF_NAME, "/payload_jsons/network_instantiation_request.json"},
429 {null, "/payload_jsons/network_instantiation_request_without_instance_name.json"}
433 @Test(dataProvider = "expectedNetworkRequestDetailsParameters")
434 public void createNetworkRequestDetails_detailsAreAsExpected(String networkName, String filePath) throws IOException {
436 List<NetworkDetails> networkDetails = Collections.singletonList(new NetworkDetails(networkName, "ab153b6e-c364-44c0-bef6-1f2982117f04"));
437 final List<Network> networksList = new ArrayList<>(createNetworkList(null, networkDetails, true).values());
438 ModelInfo siModelInfo = createServiceModelInfo();
439 String serviceInstanceId = "aa3514e3-5a33-55df-13ab-12abad84e7aa";
441 Mockito.reset(aaiClient);
442 mockAaiClientAaiStatusOK();
443 enableAddCloudOwnerOnMsoRequest();
445 String expected = IOUtils.toString(this.getClass().getResource(filePath), "UTF-8");
446 final RequestDetailsWrapper<NetworkInstantiationRequestDetails> result = msoRequestBuilder.generateNetworkInstantiationRequest(networksList.get(0), siModelInfo, serviceInstanceId, "pa0916", "VNF_API");
447 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
451 public void createInstanceGroupRequestDetails_detailsAreAsExpected() throws IOException {
453 final InstanceGroup instanceGroup = createInstanceGroup(true, Action.Create);
454 ModelInfo siModelInfo = createServiceModelInfo();
455 String serviceInstanceId = "aa3514e3-5a33-55df-13ab-12abad84e7aa";
457 Mockito.reset(aaiClient);
458 mockAaiClientAaiStatusOK();
459 enableAddCloudOwnerOnMsoRequest();
461 String expected = IOUtils.toString(this.getClass().getResource("/payload_jsons/instance_group_instantiation_request.json"), "UTF-8");
462 final RequestDetailsWrapper<InstanceGroupInstantiationRequestDetails> result = msoRequestBuilder.generateInstanceGroupInstantiationRequest(instanceGroup, siModelInfo, serviceInstanceId, "az2018", "VNF_API");
463 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
467 public void generateAddOrRemoveInstanceGroupMemberRequest_verifyResultAsExpected() throws IOException {
468 String expected = " {" +
469 " \"requestDetails\": {" +
470 " \"requestInfo\": {" +
471 " \"source\": \"VID\"," +
472 " \"requestorId\": \"az2018\"" +
474 " \"relatedInstanceList\": [" +
476 " \"relatedInstance\": {" +
477 " \"instanceId\": \"aa3514e3-5a33-55df-13ab-12abad84e7aa\"," +
478 " \"modelInfo\": {" +
479 " \"modelType\": \"vnf\"" +
486 RequestDetailsWrapper<AddOrRemoveInstanceGroupMemberRequestDetails> result =
487 msoRequestBuilder.generateInstanceGroupMemberRequest("aa3514e3-5a33-55df-13ab-12abad84e7aa", "az2018");
488 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
492 public void checkIfNullProjectNameSentToMso() {
493 ServiceInstantiation serviceInstantiationPayload = generateMockMacroServiceInstantiationPayload(true,
494 createVnfList(vfModuleInstanceParamsMapWithParamsToRemove, Collections.EMPTY_LIST, false),
497 RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
498 msoRequestBuilder.generateMacroServiceInstantiationRequest(null, serviceInstantiationPayload, serviceInstantiationPayload.getInstanceName(), "az2016");
499 JsonNode jsonNode = new ObjectMapper().valueToTree(result.requestDetails);
500 Assert.assertTrue(jsonNode.get("project").isNull());
501 serviceInstantiationPayload = generateMockMacroServiceInstantiationPayload(true,
502 createVnfList(vfModuleInstanceParamsMapWithParamsToRemove, Collections.EMPTY_LIST, false),
504 false, "not null", false);
505 result = msoRequestBuilder.generateMacroServiceInstantiationRequest(null, serviceInstantiationPayload, serviceInstantiationPayload.getInstanceName(), "az2016");
506 jsonNode = new ObjectMapper().valueToTree(result.requestDetails);
507 Assert.assertTrue(jsonNode.get("project").get("projectName").asText().equalsIgnoreCase("not null"));
511 public void generateDeleteVnfRequest_verifyResultAsExpected() throws IOException {
514 "\"requestDetails\" : {\n" +
515 " \"modelInfo\" : {\n" +
516 " \"modelCustomizationName\" : \"2016-73_MOW-AVPN-vPE-BV-L 0\",\n" +
517 " \"modelCustomizationId\" : \"ab153b6e-c364-44c0-bef6-1f2982117f04\",\n" +
518 " \"modelInvariantId\" : \"11111111-f63c-463e-ba94-286933b895f9\",\n" +
519 " \"modelVersionId\" : \"7f40c192-f63c-463e-ba94-286933b895f8\",\n" +
520 " \"modelName\" : \"2016-73_MOW-AVPN-vPE-BV-L\",\n" +
521 " \"modelType\" : \"vnf\",\n" +
522 " \"modelVersion\" : \"10.0\"\n" +
524 " \"cloudConfiguration\" : {\n" +
525 " \"lcpCloudRegionId\" : \"AAIAIC25\",\n" +
526 " \"tenantId\" : \"092eb9e8e4b7412e8787dd091bc58e86\",\n" +
527 " \"cloudOwner\" : \"irma-aic\"\n" +
529 " \"requestInfo\" : {\n" +
530 " \"source\" : \"VID\",\n" +
531 " \"requestorId\" : \"az2018\"\n" +
535 Vnf vnfDetails = new Vnf(createVnfModelInfo(true), "productFamily", "instanceName", Action.Delete.name(), "platform", "AAIAIC25", null,
536 "092eb9e8e4b7412e8787dd091bc58e86", null, null, false, "VNF_INSTANCE_ID", null, UUID.randomUUID().toString(), null, null,
538 RequestDetailsWrapper<VnfInstantiationRequestDetails> result =
539 msoRequestBuilder.generateDeleteVnfRequest(vnfDetails, "az2018");
540 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
544 public void generateDeleteVfModuleRequest_verifyResultAsExpected() throws IOException {
547 "\"requestDetails\" : {" +
548 " \"modelInfo\" : {" +
549 " \"modelCustomizationName\" : \"201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0\"," +
550 " \"modelCustomizationId\" : \"a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f\"," +
551 " \"modelVersionId\" : \"4c75f813-fa91-45a4-89d0-790ff5f1ae79\"," +
552 " \"modelInvariantId\" : \"22222222-f63c-463e-ba94-286933b895f9\"," +
553 " \"modelName\" : \"201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0\"," +
554 " \"modelType\" : \"vfModule\"," +
555 " \"modelVersion\" : \"10.0\"" +
557 " \"cloudConfiguration\" : {" +
558 " \"lcpCloudRegionId\" : \"mdt1\"," +
559 " \"tenantId\" : \"88a6ca3ee0394ade9403f075db23167e\"," +
560 " \"cloudOwner\" : \"irma-aic\"" +
562 " \"requestInfo\" : {" +
563 " \"source\" : \"VID\"," +
564 " \"requestorId\" : \"az2018\"" +
568 VfModule vfModuleDetails = createVfModule("201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0", VF_MODULE_0_MODEL_VERSION_ID, VF_MODULE_0_MODEL_CUSTOMIZATION_NAME, null, new HashMap<>(), "vmxnjr001_AVPN_base_vPE_BV_base", null, true);
569 RequestDetailsWrapper<VfModuleInstantiationRequestDetails> result =
570 msoRequestBuilder.generateDeleteVfModuleRequest(vfModuleDetails, "az2018");
571 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
574 @Test(dataProvider = "cloudConfigurationPermutations")
575 public void createPre1806TransportServiceInstantiationMsoRequest(String tenantId, String lcpCloudRegionId, String jsonFile) throws IOException {
576 ServiceInstantiation serviceInstantiationPayload = generatePre1806MacroTransportServiceInstantiationPayload(tenantId, lcpCloudRegionId);
578 final URL resource = this.getClass().getResource(jsonFile);
579 RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
580 msoRequestBuilder.generateMacroServicePre1806InstantiationRequest(serviceInstantiationPayload, "az2016");
581 String expected = IOUtils.toString(resource, "UTF-8");
582 MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
586 public static Object[][] cloudConfigurationPermutations() {
587 return new Object[][]{
588 {"88a6ca3ee0394ade9403f075db23167e", "mdt1", "/payload_jsons/pre_1806_macro_service_instantiation_request.json"},
589 {"", "mdt1", "/payload_jsons/pre_1806_macro_without_cloudConfiguration.json"},
590 {"88a6ca3ee0394ade9403f075db23167e", "", "/payload_jsons/pre_1806_macro_without_cloudConfiguration.json"},
591 {null, null, "/payload_jsons/pre_1806_macro_without_cloudConfiguration.json"}
596 public void createPre1806MacroWithVrfEntry() throws IOException {
597 ServiceInstantiation serviceInstantiationPayload = TestUtils.readJsonResourceFileAsObject(
598 "/payload_jsons/vrfEntry/service_with_vrf_entry_fe_input.json",
599 ServiceInstantiation.class);
601 when(featureManager.isActive(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)).thenReturn(true);
602 when(aaiClient.getCloudOwnerByCloudRegionId("lcpCloudRegionId")).thenReturn("irma-aic");
604 RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
605 msoRequestBuilder.generateMacroServicePre1806InstantiationRequest(serviceInstantiationPayload, "az2016");
607 final URL url = this.getClass().getResource("/payload_jsons/vrfEntry/service_with_vrf_instantiation_request.json");
608 String expected = IOUtils.toString(url, "UTF-8");
610 assertThat(result, jsonEquals(expected).when(IGNORING_ARRAY_ORDER));
614 public void generateReplaceVfModuleRequest_verifyResultAsExpected() throws IOException {
615 String expected = TestUtils.readFileAsString("/payload_jsons/vfmodule/replace_vfmodule.json");
616 when(featureManager.isActive(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)).thenReturn(true);
617 when(aaiClient.getCloudOwnerByCloudRegionId("regionOne")).thenReturn("irma-aic");
619 ModelInfo vfModuleModelInfo = createVfModuleModelInfo("newest-model-name-vfm", "newest-model-version-vfm", "newest-model-uuid-vfm",
620 "f7a867f2-596b-4f4a-a128-421e825a6190", "newest-model-customization-uuid-vfm","newest-model-customization-name-vfm" );
622 VfModule vfModuleDetails = createVfModuleForReplace(vfModuleModelInfo, "replace_module", "regionOne", "0422ffb57ba042c0800a29dc85ca70f8");
624 ModelInfo serviceModelInfo = createServiceModelInfo("newest-model-name-service", "newest-model-version-service", "newest-model-uuid-service", "b16a9398-ffa3-4041-b78c-2956b8ad9c7b", null, null );
626 ModelInfo vnfModelInfo = createVnfModelInfo("newest-model-name-vnf", "newest-model-version-vnf", "newest-model-uuid-vnf", "23122c9b-dd7f-483f-bf0a-e069303db2f7", "newest-model-customization-uuid-vnf", "newest-model-customization-name-vnf" );
628 RequestDetailsWrapper<VfModuleInstantiationRequestDetails> result =
629 msoRequestBuilder.generateVfModuleInstantiationRequest(vfModuleDetails, serviceModelInfo, "e9993045-cc96-4f3f-bf9a-71b2a400a956", vnfModelInfo, "5c9c2896-1fe6-4055-b7ec-d0a01e5f9bf5", null,"az2016", "GR_API");
631 assertThat(result, jsonEquals(expected).when(IGNORING_ARRAY_ORDER));