0bb92e32ff06ab78929b0668de681e6c7d85ed3e
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2020 Nokia
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.servicedecomposition.tasks;
24
25 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
26 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
27 import static org.hamcrest.CoreMatchers.containsString;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNull;
30 import static org.mockito.ArgumentMatchers.any;
31 import static org.mockito.ArgumentMatchers.anyString;
32 import static org.mockito.ArgumentMatchers.eq;
33 import static org.mockito.ArgumentMatchers.isA;
34 import static org.mockito.Mockito.doReturn;
35 import static org.mockito.Mockito.times;
36 import static org.mockito.Mockito.verify;
37 import java.io.File;
38 import java.io.IOException;
39 import java.util.Arrays;
40 import java.util.List;
41 import java.util.Optional;
42 import org.junit.Before;
43 import org.junit.Rule;
44 import org.junit.Test;
45 import org.junit.rules.ExpectedException;
46 import org.junit.runner.RunWith;
47 import org.mockito.InjectMocks;
48 import org.mockito.Mock;
49 import org.mockito.Mockito;
50 import org.mockito.junit.MockitoJUnitRunner;
51 import org.onap.aai.domain.yang.CloudRegion;
52 import org.onap.aai.domain.yang.Configuration;
53 import org.onap.aai.domain.yang.Configurations;
54 import org.onap.aai.domain.yang.GenericVnf;
55 import org.onap.aai.domain.yang.GenericVnfs;
56 import org.onap.aai.domain.yang.L3Network;
57 import org.onap.aai.domain.yang.L3Networks;
58 import org.onap.aai.domain.yang.ServiceInstance;
59 import org.onap.aai.domain.yang.ServiceInstances;
60 import org.onap.aai.domain.yang.VolumeGroup;
61 import org.onap.aai.domain.yang.VolumeGroups;
62 import org.onap.aai.domain.yang.VpnBinding;
63 import org.onap.so.bpmn.common.InjectionHelper;
64 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
65 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
66 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
67 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException;
68 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException;
69 import org.onap.so.client.aai.AAIObjectPlurals;
70 import org.onap.so.client.aai.AAIObjectType;
71 import org.onap.so.client.aai.AAIResourcesClient;
72 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
73 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
74 import org.onap.so.client.graphinventory.entities.uri.Depth;
75 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
76 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
77 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
78 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
79 import org.onap.so.db.catalog.beans.VfModuleCustomization;
80 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
81 import org.onap.so.db.catalog.beans.Service;
82 import org.onap.so.db.catalog.client.CatalogDbClient;
83 import org.onap.so.db.request.beans.InfraActiveRequests;
84 import org.onap.so.db.request.beans.RequestProcessingData;
85 import org.onap.so.db.request.client.RequestsDbClient;
86 import org.onap.so.serviceinstancebeans.CloudConfiguration;
87 import org.onap.so.serviceinstancebeans.ModelInfo;
88 import org.onap.so.serviceinstancebeans.RequestDetails;
89 import com.fasterxml.jackson.core.JsonParseException;
90 import com.fasterxml.jackson.databind.JsonMappingException;
91 import com.fasterxml.jackson.databind.ObjectMapper;
92
93 @RunWith(MockitoJUnitRunner.class)
94 public class BBInputSetupUtilsTest {
95     protected ObjectMapper mapper = new ObjectMapper();
96     private static final String RESOURCE_PATH = "src/test/resources/__files/ExecuteBuildingBlock/";
97
98     @InjectMocks
99     BBInputSetupUtils bbInputSetupUtils = new BBInputSetupUtils();
100
101     @Mock
102     protected CatalogDbClient MOCK_catalogDbClient;
103
104     @Mock
105     protected RequestsDbClient MOCK_requestsDbClient;
106
107     @Mock
108     protected AAIResourcesClient MOCK_aaiResourcesClient;
109
110     @Mock
111     protected InjectionHelper MOCK_injectionHelper;
112
113     @Rule
114     public ExpectedException expectedException = ExpectedException.none();
115
116     @Before
117     public void setup() {
118         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
119     }
120
121     @Test
122     public void testGetCatalogServiceByModelUUID() throws JsonParseException, JsonMappingException, IOException {
123         Service expected = mapper.readValue(new File(RESOURCE_PATH + "CatalogServiceExpected.json"), Service.class);
124
125         RequestDetails requestDetails = new RequestDetails();
126         ModelInfo modelInfo = new ModelInfo();
127         modelInfo.setModelVersionId("modelUUID");
128         requestDetails.setModelInfo(modelInfo);
129         doReturn(expected).when(MOCK_catalogDbClient).getServiceByID("modelUUID");
130         Service actual = bbInputSetupUtils.getCatalogServiceByModelUUID(modelInfo.getModelVersionId());
131
132         assertThat(actual, sameBeanAs(expected));
133     }
134
135     @Test
136     public void testGetCatalogServiceByModelVersionAndModelInvariantUUID()
137             throws JsonParseException, JsonMappingException, IOException {
138         String modelVersion = "modelVersion";
139         String modelInvariantUUID = "modelInvariantUUID";
140         Service expectedService =
141                 mapper.readValue(new File(RESOURCE_PATH + "CatalogServiceExpected.json"), Service.class);
142
143         doReturn(expectedService).when(MOCK_catalogDbClient)
144                 .getServiceByModelVersionAndModelInvariantUUID(isA(String.class), isA(String.class));
145
146         Service actualService = bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(modelVersion,
147                 modelInvariantUUID);
148
149         assertThat(actualService, sameBeanAs(expectedService));
150     }
151
152     @Test
153     public void testGetVnfcInstanceGroups() throws JsonParseException, JsonMappingException, IOException {
154         VnfcInstanceGroupCustomization vnfc = mapper.readValue(
155                 new File(RESOURCE_PATH + "VnfcInstanceGroupCustomization.json"), VnfcInstanceGroupCustomization.class);
156         String modelCustomizationUUID = "modelCustomizationUUID";
157
158         doReturn(Arrays.asList(vnfc)).when(MOCK_catalogDbClient)
159                 .getVnfcInstanceGroupsByVnfResourceCust(isA(String.class));
160
161         List<VnfcInstanceGroupCustomization> actualVnfcList =
162                 bbInputSetupUtils.getVnfcInstanceGroups(modelCustomizationUUID);
163
164         assertThat(actualVnfcList, sameBeanAs(Arrays.asList(vnfc)));
165     }
166
167     @Test
168     public void testGetRequestDetails() throws JsonParseException, JsonMappingException, IOException {
169         InfraActiveRequests infraActiveRequest = mapper
170                 .readValue(new File(RESOURCE_PATH + "InfraActiveRequestExpected.json"), InfraActiveRequests.class);
171
172         RequestDetails expected =
173                 mapper.readValue(new File(RESOURCE_PATH + "RequestDetailsExpected.json"), RequestDetails.class);
174         String requestId = "requestId";
175         doReturn(infraActiveRequest).when(MOCK_requestsDbClient).getInfraActiveRequestbyRequestId(requestId);
176         RequestDetails actual = bbInputSetupUtils.getRequestDetails(requestId);
177
178         assertThat(actual, sameBeanAs(expected));
179     }
180
181     @Test
182     public void getRequestDetailsNullTest() throws IOException {
183         RequestDetails requestDetails = bbInputSetupUtils.getRequestDetails("");
184
185         assertNull(requestDetails);
186     }
187
188     @Test
189     public void testGetCloudRegion() {
190         CloudConfiguration cloudConfig = new CloudConfiguration();
191         cloudConfig.setLcpCloudRegionId("lcpCloudRegionId");
192         Optional<org.onap.aai.domain.yang.CloudRegion> expected =
193                 Optional.of(new org.onap.aai.domain.yang.CloudRegion());
194         expected.get().setCloudOwner("cloudOwner");
195         expected.get().setCloudRegionId("lcpCloudRegionId");
196         doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.CloudRegion.class,
197                 AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudConfig.getCloudOwner(),
198                         cloudConfig.getLcpCloudRegionId()).depth(Depth.TWO));
199
200         AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION,
201                 cloudConfig.getCloudOwner(), cloudConfig.getLcpCloudRegionId()).depth(Depth.TWO);
202         bbInputSetupUtils.getCloudRegion(cloudConfig);
203
204         verify(MOCK_aaiResourcesClient, times(1)).get(CloudRegion.class, expectedUri);
205     }
206
207     @Test
208     public void testGetCloudRegionExceptionTest() {
209
210         CloudConfiguration cloudConfig = new CloudConfiguration();
211         cloudConfig.setLcpCloudRegionId("lcpCloudRegionId");
212
213         RequestDetails requestDetails = new RequestDetails();
214         requestDetails.setCloudConfiguration(cloudConfig);
215
216         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
217
218         CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfig);
219
220         assertNull(cloudRegion);
221     }
222
223     @Test
224     public void testGetCloudRegionEmptyId() {
225         CloudConfiguration cloudConfig = new CloudConfiguration();
226         cloudConfig.setLcpCloudRegionId("");
227
228         RequestDetails requestDetails = new RequestDetails();
229         requestDetails.setCloudConfiguration(cloudConfig);
230
231         CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfig);
232
233         assertNull(cloudRegion);
234     }
235
236     @Test
237     public void testGetCloudRegionEmptyConfiguration() {
238         RequestDetails requestDetails = new RequestDetails();
239
240         CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(requestDetails.getCloudConfiguration());
241
242         assertNull(cloudRegion);
243     }
244
245     @Test
246     public void testGetAAIInstanceGroup() {
247         Optional<org.onap.aai.domain.yang.InstanceGroup> expected =
248                 Optional.of(new org.onap.aai.domain.yang.InstanceGroup());
249         String instanceGroupId = "instanceGroupId";
250         expected.get().setId(instanceGroupId);
251         doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.InstanceGroup.class,
252                 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId));
253         AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId);
254
255         bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId);
256         verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.InstanceGroup.class, expectedUri);
257     }
258
259     @Test
260     public void testGetAAIInstanceGroupThrowNotFound() {
261         String instanceGroupId = "instanceGroupId";
262         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
263         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.InstanceGroup.class,
264                 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId));
265
266         org.onap.aai.domain.yang.InstanceGroup actual = bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId);
267
268         assertNull(actual);
269     }
270
271     @Test
272     public void testGetAAICustomer() {
273         Optional<org.onap.aai.domain.yang.Customer> expected = Optional.of(new org.onap.aai.domain.yang.Customer());
274         String globalSubscriberId = "globalSubscriberId";
275         expected.get().setGlobalCustomerId(globalSubscriberId);
276         doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.Customer.class,
277                 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId));
278         AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId);
279
280         bbInputSetupUtils.getAAICustomer(globalSubscriberId);
281         verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.Customer.class, expectedUri);
282     }
283
284     @Test
285     public void testGetAAICustomerThrowNotFound() {
286         String globalSubscriberId = "globalSubscriberId";
287         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
288         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.Customer.class,
289                 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId));
290
291         org.onap.aai.domain.yang.Customer actual = bbInputSetupUtils.getAAICustomer(globalSubscriberId);
292
293         assertNull(actual);
294     }
295
296     @Test
297     public void testGetAAIServiceSubscription() {
298         Optional<org.onap.aai.domain.yang.ServiceSubscription> expected =
299                 Optional.of(new org.onap.aai.domain.yang.ServiceSubscription());
300         String globalSubscriberId = "globalSubscriberId";
301         String subscriptionServiceType = "subscriptionServiceType";
302         expected.get().setServiceType(subscriptionServiceType);
303         doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.ServiceSubscription.class,
304                 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId,
305                         subscriptionServiceType));
306         AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION,
307                 globalSubscriberId, subscriptionServiceType);
308
309         bbInputSetupUtils.getAAIServiceSubscription(globalSubscriberId, subscriptionServiceType);
310         verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceSubscription.class, expectedUri);
311     }
312
313     @Test
314     public void testGetAAIServiceSubscriptionErrors() {
315         String globalSubId = null;
316         String subServiceType = null;
317         org.onap.aai.domain.yang.ServiceSubscription actual =
318                 bbInputSetupUtils.getAAIServiceSubscription(globalSubId, subServiceType);
319         assertNull(actual);
320
321         String globalSubId2 = "";
322         String subServiceType2 = "";
323         org.onap.aai.domain.yang.ServiceSubscription actual2 =
324                 bbInputSetupUtils.getAAIServiceSubscription(globalSubId2, subServiceType2);
325         assertNull(actual2);
326
327         String globalSubId3 = "";
328         String subServiceType3 = null;
329         org.onap.aai.domain.yang.ServiceSubscription actual3 =
330                 bbInputSetupUtils.getAAIServiceSubscription(globalSubId3, subServiceType3);
331         assertNull(actual3);
332
333         String globalSubId4 = null;
334         String subServiceType4 = "";
335         org.onap.aai.domain.yang.ServiceSubscription actual4 =
336                 bbInputSetupUtils.getAAIServiceSubscription(globalSubId4, subServiceType4);
337         assertNull(actual4);
338     }
339
340     @Test
341     public void testGetAAIServiceSubscriptionThrowNotFound() {
342         String globalSubscriberId = "globalSubscriberId";
343         String subscriptionServiceType = "subscriptionServiceType";
344         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
345         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.ServiceSubscription.class,
346                 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId,
347                         subscriptionServiceType));
348         org.onap.aai.domain.yang.ServiceSubscription actual =
349                 bbInputSetupUtils.getAAIServiceSubscription(globalSubscriberId, subscriptionServiceType);
350         assertNull(actual);
351     }
352
353     @Test
354     public void testGetAAIServiceInstanceById() {
355         String serviceInstanceId = "serviceInstanceId";
356
357         ServiceInstance expectedServiceInstance = new ServiceInstance();
358
359         doReturn(Optional.of(expectedServiceInstance)).when(MOCK_aaiResourcesClient).get(isA(Class.class),
360                 isA(AAIResourceUri.class));
361
362         ServiceInstance actualServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
363
364         assertThat(actualServiceInstance, sameBeanAs(expectedServiceInstance));
365     }
366
367     @Test
368     public void testGetAAIServiceInstanceByIdThrowNotFound() {
369         String serviceInstanceId = "serviceInstanceId";
370
371         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
372
373         ServiceInstance actualServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
374
375         assertNull(actualServiceInstance);
376     }
377
378     @Test
379     public void testGetAAIServiceInstanceByIdAndCustomer() {
380         String globalCustomerId = "globalCustomerId";
381         String serviceType = "serviceType";
382         String serviceInstanceId = "serviceInstanceId";
383         ServiceInstance expected = new ServiceInstance();
384         expected.setServiceInstanceId(serviceInstanceId);
385         doReturn(Optional.of(expected)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
386         AAIResourceUri expectedUri = AAIUriFactory
387                 .createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId)
388                 .depth(Depth.TWO);
389         this.bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(globalCustomerId, serviceType, serviceInstanceId);
390
391         verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceInstance.class, expectedUri);
392
393     }
394
395     @Test
396     public void testGetAAIServiceInstanceByIdAndCustomerThrowNotFound() {
397         String globalCustomerId = "globalCustomerId";
398         String serviceType = "serviceType";
399         String serviceInstanceId = "serviceInstanceId";
400
401         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
402         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
403         ServiceInstance actual = this.bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(globalCustomerId,
404                 serviceType, serviceInstanceId);
405
406         assertNull(actual);
407     }
408
409     @Test
410     public void testGetAAIServiceInstanceByName() throws Exception {
411         String serviceInstanceName = "serviceInstanceName";
412
413         ServiceInstance expectedServiceInstance = new ServiceInstance();
414         expectedServiceInstance.setServiceInstanceId("serviceInstanceId");
415
416         ServiceSubscription serviceSubscription = new ServiceSubscription();
417         serviceSubscription.setServiceType("serviceType");
418
419         Customer customer = new Customer();
420         customer.setGlobalCustomerId("globalCustomerId");
421         customer.setServiceSubscription(serviceSubscription);
422
423         ServiceInstances serviceInstances = new ServiceInstances();
424         serviceInstances.getServiceInstance().add(expectedServiceInstance);
425
426         doReturn(Optional.of(serviceInstances)).when(MOCK_aaiResourcesClient).get(isA(Class.class),
427                 isA(AAIResourceUri.class));
428         AAIResourceUri expectedUri = AAIUriFactory
429                 .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, customer.getGlobalCustomerId(),
430                         customer.getServiceSubscription().getServiceType())
431                 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO);
432         bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer);
433
434         verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceInstances.class, expectedUri);
435     }
436
437     @Test
438     public void testGetAAIServiceInstanceByNameException() throws Exception {
439         expectedException.expect(Exception.class);
440
441         String serviceInstanceName = "serviceInstanceName";
442
443         ServiceInstance serviceInstance = new ServiceInstance();
444         serviceInstance.setServiceInstanceId("serviceInstanceId");
445
446         ServiceSubscription serviceSubscription = new ServiceSubscription();
447         serviceSubscription.setServiceType("serviceType");
448
449         Customer customer = new Customer();
450         customer.setGlobalCustomerId("globalCustomerId");
451         customer.setServiceSubscription(serviceSubscription);
452
453         ServiceInstances serviceInstances = new ServiceInstances();
454         serviceInstances.getServiceInstance().add(serviceInstance);
455         serviceInstances.getServiceInstance().add(serviceInstance);
456
457         doReturn(Optional.of(serviceInstances)).when(MOCK_aaiResourcesClient).get(isA(Class.class),
458                 isA(AAIResourceUri.class));
459
460         bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer);
461     }
462
463     @Test
464     public void testGetAAIServiceInstanceByNameNull() throws Exception {
465         String serviceInstanceName = "serviceInstanceName";
466
467         ServiceInstance serviceInstance = new ServiceInstance();
468         serviceInstance.setServiceInstanceId("serviceInstanceId");
469
470         ServiceSubscription serviceSubscription = new ServiceSubscription();
471         serviceSubscription.setServiceType("serviceType");
472
473         Customer customer = new Customer();
474         customer.setGlobalCustomerId("globalCustomerId");
475         customer.setServiceSubscription(serviceSubscription);
476
477         ServiceInstances serviceInstances = new ServiceInstances();
478         serviceInstances.getServiceInstance().add(serviceInstance);
479         serviceInstances.getServiceInstance().add(serviceInstance);
480
481         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
482
483         ServiceInstance actualServiceInstance =
484                 bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer);
485
486         assertNull(actualServiceInstance);
487     }
488
489     @Test
490     public void testGetOptionalAAIServiceInstanceByNameException() throws Exception {
491         expectedException.expect(MultipleObjectsFoundException.class);
492         expectedException.expectMessage(containsString(
493                 "Multiple service instances found for customer-id: globalCustomerId, service-type: serviceType and service-instance-name: serviceInstanceId."));
494
495         String globalCustomerId = "globalCustomerId";
496         String serviceType = "serviceType";
497         String serviceInstanceId = "serviceInstanceId";
498
499         ServiceInstance serviceInstance = new ServiceInstance();
500         serviceInstance.setServiceInstanceId("serviceInstanceId");
501         serviceInstance.setServiceType(serviceType);
502         serviceInstance.setServiceInstanceName("serviceInstanceName");
503
504         ServiceInstances serviceInstances = new ServiceInstances();
505         serviceInstances.getServiceInstance().add(serviceInstance);
506         serviceInstances.getServiceInstance().add(serviceInstance);
507
508         doReturn(Optional.of(serviceInstances)).when(MOCK_aaiResourcesClient).get(isA(Class.class),
509                 isA(AAIResourceUri.class));
510
511         bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, serviceInstanceId);
512     }
513
514     @Test
515     public void testGetOptionalAAIServiceInstanceByNameNull() throws Exception {
516         String globalCustomerId = "globalCustomerId";
517         String serviceType = "serviceType";
518         String serviceInstanceId = "serviceInstanceId";
519
520         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
521         Optional<ServiceInstance> actual =
522                 this.bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, serviceInstanceId);
523
524         assertThat(actual, sameBeanAs(Optional.empty()));
525     }
526
527     @Test
528     public void testGetCatalogInstanceGroup() throws JsonParseException, JsonMappingException, IOException {
529         String modelUUID = "modelUUID";
530
531         org.onap.so.db.catalog.beans.InstanceGroup expectedInstanceGroup = mapper.readValue(
532                 new File(RESOURCE_PATH + "InstanceGroup.json"), org.onap.so.db.catalog.beans.InstanceGroup.class);
533
534         doReturn(expectedInstanceGroup).when(MOCK_catalogDbClient).getInstanceGroupByModelUUID(isA(String.class));
535
536         org.onap.so.db.catalog.beans.InstanceGroup actualInstanceGroup =
537                 bbInputSetupUtils.getCatalogInstanceGroup(modelUUID);
538
539         assertThat(actualInstanceGroup, sameBeanAs(expectedInstanceGroup));
540     }
541
542     @Test
543     public void testGetCollectionResourceInstanceGroupCustomization() {
544         String modelCustomizationUUID = "modelCustomizationUUID";
545
546         CollectionResourceInstanceGroupCustomization expectedCollection =
547                 new CollectionResourceInstanceGroupCustomization();
548
549         doReturn(Arrays.asList(expectedCollection)).when(MOCK_catalogDbClient)
550                 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
551
552         List<CollectionResourceInstanceGroupCustomization> actualCollection =
553                 bbInputSetupUtils.getCollectionResourceInstanceGroupCustomization(modelCustomizationUUID);
554
555         assertThat(actualCollection, sameBeanAs(Arrays.asList(expectedCollection)));
556     }
557
558     @Test
559     public void testGetAAIGenericVnf() throws JsonParseException, JsonMappingException, IOException {
560         String vnfId = "vnfId";
561
562         GenericVnf expectedAaiVnf =
563                 mapper.readValue(new File(RESOURCE_PATH + "aaiGenericVnfInput.json"), GenericVnf.class);
564
565         doReturn(Optional.of(expectedAaiVnf)).when(MOCK_aaiResourcesClient).get(isA(Class.class),
566                 isA(AAIResourceUri.class));
567         AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE);
568         GenericVnf actualAaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
569
570         assertThat(actualAaiVnf, sameBeanAs(expectedAaiVnf));
571
572         verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.GenericVnf.class, expectedUri);
573     }
574
575     @Test
576     public void testGetAAIConfiguration() throws JsonParseException, JsonMappingException, IOException {
577         String configurationId = "configurationId";
578
579         Configuration expectedAaiConfiguration =
580                 mapper.readValue(new File(RESOURCE_PATH + "ConfigurationInput.json"), Configuration.class);
581
582         doReturn(Optional.of(expectedAaiConfiguration)).when(MOCK_aaiResourcesClient).get(isA(Class.class),
583                 isA(AAIResourceUri.class));
584         AAIResourceUri expectedUri =
585                 AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId).depth(Depth.ONE);
586         bbInputSetupUtils.getAAIConfiguration(configurationId);
587
588         verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.Configuration.class, expectedUri);
589     }
590
591     @Test
592     public void testGetAAIGenericVnfThrowNotFound() throws JsonParseException, JsonMappingException, IOException {
593         String vnfId = "vnfId";
594
595         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
596
597         GenericVnf actualAaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
598
599         assertNull(actualAaiVnf);
600     }
601
602     @Test
603     public void testGetAAIResourceDepthOne() {
604         String vnfId = "vnfId";
605         AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
606         AAIResourceUri expectedUri = aaiResourceUri.clone().depth(Depth.ONE);
607         AAIResourceUri aaiResourceUriClone = aaiResourceUri.clone();
608         bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri);
609
610         verify(MOCK_aaiResourcesClient, times(1)).get(expectedUri);
611         assertEquals("Uri should not have changed", aaiResourceUriClone.build(), aaiResourceUri.build());
612     }
613
614     @Test
615     public void testGetAAIResourceDepthTwo() {
616         String vnfId = "vnfId";
617         AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
618         AAIResourceUri expectedUri = aaiResourceUri.clone().depth(Depth.TWO);
619         AAIResourceUri aaiResourceUriClone = aaiResourceUri.clone();
620         bbInputSetupUtils.getAAIResourceDepthTwo(aaiResourceUri);
621
622         verify(MOCK_aaiResourcesClient, times(1)).get(expectedUri);
623         assertEquals("Uri should not have changed", aaiResourceUriClone.build(), aaiResourceUri.build());
624     }
625
626     @Test
627     public void getRelatedNetworkByNameFromServiceInstanceTest() throws Exception {
628         Optional<L3Networks> expected = Optional.of(new L3Networks());
629         L3Network network = new L3Network();
630         network.setNetworkId("id123");
631         network.setNetworkName("name123");
632         expected.get().getL3Network().add(network);
633         doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class));
634         Optional<L3Network> actual =
635                 this.bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance("id123", "name123");
636         assertEquals(actual.get().getNetworkId(), expected.get().getL3Network().get(0).getNetworkId());
637     }
638
639     @Test
640     public void getRelatedNetworkByNameFromServiceInstanceMultipleNetworksExceptionTest() throws Exception {
641         expectedException.expect(MultipleObjectsFoundException.class);
642         expectedException.expectMessage(containsString(
643                 "Multiple networks found for service-instance-id: serviceInstanceId and network-name: networkName."));
644
645         String serviceInstanceId = "serviceInstanceId";
646         String networkName = "networkName";
647
648         L3Network network = new L3Network();
649         network.setNetworkId("id123");
650         network.setNetworkName("name123");
651
652         L3Networks l3Networks = new L3Networks();
653         l3Networks.getL3Network().add(network);
654         l3Networks.getL3Network().add(network);
655         Optional<L3Networks> optNetworks = Optional.of(l3Networks);
656
657         doReturn(optNetworks).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class));
658
659         bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(serviceInstanceId, networkName);
660     }
661
662     @Test
663     public void getRelatedNetworkByNameFromServiceInstanceNotFoundTest() throws Exception {
664         String serviceInstanceId = "serviceInstanceId";
665         String networkName = "networkName";
666
667         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class));
668
669         Optional<L3Network> actualNetwork =
670                 bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(serviceInstanceId, networkName);
671
672         assertEquals(Optional.empty(), actualNetwork);
673     }
674
675     @Test
676     public void getRelatedServiceInstanceFromInstanceGroupTest() throws Exception {
677         Optional<ServiceInstances> expected = Optional.of(new ServiceInstances());
678         ServiceInstance serviceInstance = new ServiceInstance();
679         serviceInstance.setServiceInstanceId("serviceInstanceId");
680         serviceInstance.setServiceInstanceName("serviceInstanceName");
681         expected.get().getServiceInstance().add(serviceInstance);
682
683         doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIResourceUri.class));
684         Optional<ServiceInstance> actual = this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
685         assertEquals(actual.get().getServiceInstanceId(),
686                 expected.get().getServiceInstance().get(0).getServiceInstanceId());
687     }
688
689     @Test
690     public void getRelatedServiceInstanceFromInstanceGroupMultipleTest() throws Exception {
691         expectedException.expect(MultipleObjectsFoundException.class);
692         Optional<ServiceInstances> serviceInstances = Optional.of(new ServiceInstances());
693         ServiceInstance si1 = Mockito.mock(ServiceInstance.class);
694         ServiceInstance si2 = Mockito.mock(ServiceInstance.class);
695         serviceInstances.get().getServiceInstance().add(si1);
696         serviceInstances.get().getServiceInstance().add(si2);
697
698         doReturn(serviceInstances).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class),
699                 any(AAIResourceUri.class));
700         this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
701     }
702
703     @Test
704     public void getRelatedServiceInstanceFromInstanceGroupNotFoundTest() throws Exception {
705         expectedException.expect(NoServiceInstanceFoundException.class);
706         Optional<ServiceInstances> serviceInstances = Optional.of(new ServiceInstances());
707
708         doReturn(serviceInstances).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class),
709                 any(AAIResourceUri.class));
710         this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
711     }
712
713     @Test
714     public void getRelatedVnfByNameFromServiceInstanceTest() throws Exception {
715         Optional<GenericVnfs> expected = Optional.of(new GenericVnfs());
716         GenericVnf vnf = new GenericVnf();
717         vnf.setVnfId("id123");
718         vnf.setVnfName("name123");
719         expected.get().getGenericVnf().add(vnf);
720         doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class));
721         Optional<GenericVnf> actual = this.bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance("id123", "name123");
722         assertEquals(actual.get().getVnfId(), expected.get().getGenericVnf().get(0).getVnfId());
723     }
724
725     @Test
726     public void getRelatedVnfByNameFromServiceInstanceMultipleVnfsExceptionTest() throws Exception {
727         expectedException.expect(MultipleObjectsFoundException.class);
728         expectedException.expectMessage(containsString(
729                 "Multiple vnfs found for service-instance-id: serviceInstanceId and vnf-name: vnfName."));
730
731         String serviceInstanceId = "serviceInstanceId";
732         String vnfName = "vnfName";
733
734         GenericVnf vnf = new GenericVnf();
735         vnf.setVnfId("id123");
736         vnf.setVnfName("name123");
737
738         GenericVnfs vnfs = new GenericVnfs();
739         vnfs.getGenericVnf().add(vnf);
740         vnfs.getGenericVnf().add(vnf);
741
742         Optional<GenericVnfs> optVnfs = Optional.of(vnfs);
743
744         doReturn(optVnfs).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class));
745
746         bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName);
747     }
748
749     @Test
750     public void getRelatedVnfByNameFromServiceInstanceNotFoundTest() throws Exception {
751         String serviceInstanceId = "serviceInstanceId";
752         String vnfName = "vnfName";
753
754         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class));
755
756         Optional<GenericVnf> actualVnf =
757                 this.bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName);
758
759         assertEquals(actualVnf, Optional.empty());
760     }
761
762     @Test
763     public void getRelatedVolumeGroupByNameFromVnfTest() throws Exception {
764         Optional<VolumeGroups> expected = Optional.of(new VolumeGroups());
765         VolumeGroup volumeGroup = new VolumeGroup();
766         volumeGroup.setVolumeGroupId("id123");
767         volumeGroup.setVolumeGroupName("name123");
768         expected.get().getVolumeGroup().add(volumeGroup);
769         doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
770         Optional<VolumeGroup> actual = this.bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "name123");
771         assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId());
772     }
773
774     @Test
775     public void getRelatedVolumeGroupByNameFromVnfMultipleVolumeGroupsExceptionTest() throws Exception {
776         expectedException.expect(MultipleObjectsFoundException.class);
777         expectedException.expectMessage(containsString(
778                 "Multiple volume-groups found for vnf-id: vnfId and volume-group-name: volumeGroupName."));
779
780
781         String vnfId = "vnfId";
782         String volumeGroupName = "volumeGroupName";
783
784         VolumeGroup volumeGroup = new VolumeGroup();
785         volumeGroup.setVolumeGroupId("id123");
786         volumeGroup.setVolumeGroupName("name123");
787
788         VolumeGroups volumeGroups = new VolumeGroups();
789         volumeGroups.getVolumeGroup().add(volumeGroup);
790         volumeGroups.getVolumeGroup().add(volumeGroup);
791         Optional<VolumeGroups> optVolumeGroups = Optional.of(volumeGroups);
792
793         doReturn(optVolumeGroups).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
794
795         bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(vnfId, volumeGroupName);
796     }
797
798     @Test
799     public void getRelatedVolumeGroupByNameFromVnfNotFoundTest() throws Exception {
800         String vnfId = "vnfId";
801         String volumeGroupName = "volumeGroupName";
802
803         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
804
805         Optional<VolumeGroup> actualVolumeGroup =
806                 bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(vnfId, volumeGroupName);
807
808         assertEquals(actualVolumeGroup, Optional.empty());
809     }
810
811     @Test
812     public void getRelatedVolumeGroupByNameFromVfModuleTest() throws Exception {
813         Optional<VolumeGroups> expected = Optional.of(new VolumeGroups());
814         VolumeGroup volumeGroup = new VolumeGroup();
815         volumeGroup.setVolumeGroupId("id123");
816         volumeGroup.setVolumeGroupName("name123");
817         expected.get().getVolumeGroup().add(volumeGroup);
818         doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
819         Optional<VolumeGroup> actual =
820                 this.bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule("id123", "id123", "name123");
821         assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId());
822     }
823
824     @Test
825     public void getRelatedVolumeGroupFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception {
826         expectedException.expect(Exception.class);
827
828         String vnfId = "vnfId";
829         String volumeGroupId = "volumeGroupId";
830
831         VolumeGroup volumeGroup = new VolumeGroup();
832         volumeGroup.setVolumeGroupId("id123");
833         volumeGroup.setVolumeGroupName("name123");
834
835         VolumeGroups expectedVolumeGroup = new VolumeGroups();
836         expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
837         expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
838
839         doReturn(expectedVolumeGroup).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class),
840                 any(AAIResourceUri.class));
841
842         bbInputSetupUtils.getRelatedVolumeGroupFromVfModule(vnfId, volumeGroupId);
843     }
844
845     @Test
846     public void getRelatedVolumeGroupFromVfModuleNotFoundTest() throws Exception {
847         String vnfId = "vnfId";
848         String volumeGroupId = "volumeGroupId";
849
850         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
851
852         Optional<VolumeGroup> actualVolumeGroup =
853                 bbInputSetupUtils.getRelatedVolumeGroupFromVfModule(vnfId, volumeGroupId);
854
855         assertEquals(actualVolumeGroup, Optional.empty());
856     }
857
858     @Test
859     public void getRelatedVolumeGroupFromVfModuleTest() throws Exception {
860         Optional<VolumeGroups> expected = Optional.of(new VolumeGroups());
861         VolumeGroup volumeGroup = new VolumeGroup();
862         volumeGroup.setVolumeGroupId("id123");
863         expected.get().getVolumeGroup().add(volumeGroup);
864         doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
865         Optional<VolumeGroup> actual = this.bbInputSetupUtils.getRelatedVolumeGroupFromVfModule("id123", "id123");
866         assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId());
867     }
868
869     @Test
870     public void getRelatedVolumeGroupByNameFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception {
871         expectedException.expect(MultipleObjectsFoundException.class);
872         expectedException.expectMessage(containsString(
873                 "Multiple voulme-groups found for vnf-id: vnfId, vf-module-id: volumeGroupId and volume-group-name: volumeGroupName."));
874         String vnfId = "vnfId";
875         String volumeGroupId = "volumeGroupId";
876         String volumeGroupName = "volumeGroupName";
877
878         VolumeGroup volumeGroup = new VolumeGroup();
879         volumeGroup.setVolumeGroupId("id123");
880         volumeGroup.setVolumeGroupName("name123");
881
882         VolumeGroups volumeGroups = new VolumeGroups();
883         volumeGroups.getVolumeGroup().add(volumeGroup);
884         volumeGroups.getVolumeGroup().add(volumeGroup);
885
886         Optional<VolumeGroups> optVolumeGroups = Optional.of(volumeGroups);
887
888         doReturn(optVolumeGroups).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
889
890         bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, volumeGroupId, volumeGroupName);
891     }
892
893     @Test
894     public void getRelatedVolumeGroupByNameFromVfModuleNotFoundTest() throws Exception {
895         String vnfId = "vnfId";
896         String volumeGroupId = "volumeGroupId";
897         String volumeGroupName = "volumeGroupName";
898
899         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
900
901         Optional<VolumeGroup> actualVolumeGroup =
902                 bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, volumeGroupId, volumeGroupName);
903
904         assertEquals(actualVolumeGroup, Optional.empty());
905     }
906
907
908     @Test
909     public void loadOriginalFlowExecutionPathTest() throws Exception {
910
911         String requestId = "123";
912         String flowsToExecuteString =
913                 "[{\"buildingBlock\":{\"mso-id\":\"2f9ddc4b-4dcf-4129-a35f-be1625ae0176\",\"bpmn-flow-name\":\"DeactivateFabricConfigurationBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":{\"vfModuleCustomizationUUID\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"vnfResourceCustomizationUUID\":\"a80f05b8-d651-44af-b999-8ed78fb4582f\",\"cvnfcCustomizationUUID\":\"69cce457-9ffd-4359-962b-0596a1e83ad1\",\"vnfcName\":\"zauk51bmcmr01mcm001\"}},{\"buildingBlock\":{\"mso-id\":\"1ca5584e-38a9-4c3f-a4b4-99b0d42089ba\",\"bpmn-flow-name\":\"UnassignFabricConfigurationBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":{\"vfModuleCustomizationUUID\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"vnfResourceCustomizationUUID\":\"a80f05b8-d651-44af-b999-8ed78fb4582f\",\"cvnfcCustomizationUUID\":\"69cce457-9ffd-4359-962b-0596a1e83ad1\",\"vnfcName\":\"zauk51bmcmr01mcm001\"}},{\"buildingBlock\":{\"mso-id\":\"68d16097-4810-477d-803b-8322106106ef\",\"bpmn-flow-name\":\"DeactivateVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null},{\"buildingBlock\":{\"mso-id\":\"0b02eb09-bc23-4329-b19e-716dcca4e4a6\",\"bpmn-flow-name\":\"DeleteVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null},{\"buildingBlock\":{\"mso-id\":\"bcf95d05-0782-44ff-920d-d5100525c275\",\"bpmn-flow-name\":\"UnassignVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null}]";
914         ObjectMapper om = new ObjectMapper();
915         List<ExecuteBuildingBlock> expectedFlowsToExecute = null;
916         try {
917             ExecuteBuildingBlock[] asArray = om.readValue(flowsToExecuteString, ExecuteBuildingBlock[].class);
918             expectedFlowsToExecute = Arrays.asList(asArray);
919         } catch (Exception e) {
920             // TODO Auto-generated catch block
921             e.printStackTrace();
922         }
923
924         InfraActiveRequests request = new InfraActiveRequests();
925         request.setRequestId("requestId");
926         request.setOriginalRequestId("originalRequestId");
927         doReturn(request).when(MOCK_requestsDbClient).getInfraActiveRequestbyRequestId(anyString());
928         RequestProcessingData rpd = new RequestProcessingData();
929         rpd.setValue(flowsToExecuteString);
930         doReturn(rpd).when(MOCK_requestsDbClient).getRequestProcessingDataBySoRequestIdAndName(anyString(),
931                 anyString());
932
933         List<ExecuteBuildingBlock> flowsToExecute = bbInputSetupUtils.loadOriginalFlowExecutionPath(requestId);
934         assertEquals(expectedFlowsToExecute.size(), flowsToExecute.size());
935     }
936
937     @Test
938     public void getRelatedConfigurationByNameFromServiceInstanceExceptionTest() throws Exception {
939         Configuration configuration = new Configuration();
940         configuration.setConfigurationId("id123");
941
942         Configurations configurations = new Configurations();
943         configurations.getConfiguration().add(configuration);
944         configurations.getConfiguration().add(configuration);
945
946         Optional<Configurations> optConfigurations = Optional.of(configurations);
947
948         doReturn(optConfigurations).when(MOCK_aaiResourcesClient).get(eq(Configurations.class),
949                 any(AAIResourceUri.class));
950
951         expectedException.expect(MultipleObjectsFoundException.class);
952         this.bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123");
953     }
954
955     @Test
956     public void getRelatedConfigurationByNameFromServiceInstanceNotFoundTest() throws Exception {
957         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(Configurations.class),
958                 any(AAIResourceUri.class));
959         Optional<Configuration> actualConfiguration =
960                 bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123");
961         assertEquals(actualConfiguration, Optional.empty());
962     }
963
964     @Test
965     public void getRelatedConfigurationByNameFromServiceInstanceTest() throws Exception {
966         Optional<Configurations> expected = Optional.of(new Configurations());
967         Configuration configuration = new Configuration();
968         configuration.setConfigurationId("id123");
969         expected.get().getConfiguration().add(configuration);
970         doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(Configurations.class), any(AAIResourceUri.class));
971         Optional<Configuration> actual =
972                 this.bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123");
973         assertEquals(actual.get().getConfigurationId(), expected.get().getConfiguration().get(0).getConfigurationId());
974     }
975
976     @Test
977     public void existsAAIVfModuleGloballyByNameTest() throws Exception {
978         AAIResourceUri expectedUri =
979                 AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE).queryParam("vf-module-name", "testVfModule");
980         bbInputSetupUtils.existsAAIVfModuleGloballyByName("testVfModule");
981         verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri);
982     }
983
984     @Test
985     public void existsAAIConfigurationGloballyByNameTest() throws Exception {
986         AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION)
987                 .queryParam("configuration-name", "testConfig");
988         bbInputSetupUtils.existsAAIConfigurationGloballyByName("testConfig");
989         verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri);
990     }
991
992     @Test
993     public void existsAAINetworksGloballyByNameTest() throws Exception {
994         AAIResourceUri expectedUri =
995                 AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", "testNetwork");
996         bbInputSetupUtils.existsAAINetworksGloballyByName("testNetwork");
997         verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri);
998     }
999
1000     @Test
1001     public void existsAAIVolumeGroupGloballyByNameTest() throws Exception {
1002         AAIResourceUri expectedUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP)
1003                 .queryParam("volume-group-name", "testVoumeGroup");
1004         bbInputSetupUtils.existsAAIVolumeGroupGloballyByName("testVoumeGroup");
1005         verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri);
1006     }
1007
1008     @Test
1009     public void shouldChangeInfraActiveRequestVnfId() throws IOException {
1010         final String vnfId = "vnfId";
1011         InfraActiveRequests infraActiveRequests = loadExpectedInfraActiveRequest();
1012
1013         bbInputSetupUtils.updateInfraActiveRequestVnfId(infraActiveRequests, vnfId);
1014
1015         assertEquals(infraActiveRequests.getVnfId(), vnfId);
1016     }
1017
1018     @Test
1019     public void shouldChangeInfraActiveRequestVfModuleId() throws IOException {
1020         final String vfModuleId = "vfModuleId";
1021         InfraActiveRequests infraActiveRequests = loadExpectedInfraActiveRequest();
1022
1023         bbInputSetupUtils.updateInfraActiveRequestVfModuleId(infraActiveRequests, vfModuleId);
1024
1025         assertEquals(infraActiveRequests.getVfModuleId(), vfModuleId);
1026     }
1027
1028     @Test
1029     public void shouldChangeInfraActiveRequestVolumeGroupId() throws IOException {
1030         final String volumeGroupId = "volumeGroupId";
1031         InfraActiveRequests infraActiveRequests = loadExpectedInfraActiveRequest();
1032
1033         bbInputSetupUtils.updateInfraActiveRequestVolumeGroupId(infraActiveRequests, volumeGroupId);
1034
1035         assertEquals(infraActiveRequests.getVolumeGroupId(), volumeGroupId);
1036     }
1037
1038     @Test
1039     public void shouldChangeInfraActiveRequestNetworkId() throws IOException {
1040         final String networkId = "activeRequestNetworkId";
1041         InfraActiveRequests infraActiveRequests = loadExpectedInfraActiveRequest();
1042
1043         bbInputSetupUtils.updateInfraActiveRequestNetworkId(infraActiveRequests, networkId);
1044
1045         assertEquals(infraActiveRequests.getNetworkId(), networkId);
1046     }
1047
1048     @Test
1049     public void getAAIVpnBindingNullTest() {
1050         assertNull(bbInputSetupUtils.getAAIVpnBinding("vpnBindingId"));
1051     }
1052
1053     @Test
1054     public void getAAIVolumeGroupNullTest() {
1055         VolumeGroup actualAaiVnf =
1056                 bbInputSetupUtils.getAAIVolumeGroup("cloudOwnerId", "cloudRegionId", "volumeGroupId");
1057         assertNull(actualAaiVnf);
1058     }
1059
1060     @Test
1061     public void getAAIVfModuleNullTest() {
1062         assertNull(bbInputSetupUtils.getAAIVfModule("vnfId", "vfModuleId"));
1063     }
1064
1065     @Test
1066     public void getAAIL3NetworkNullTest() {
1067         assertNull(bbInputSetupUtils.getAAIL3Network("networkId"));
1068     }
1069
1070     @Test
1071     public void getAICVpnBindingFromNetwork_noVpnBindingTest() throws IOException {
1072         L3Network l3Network =
1073                 mapper.readValue(new File(RESOURCE_PATH + "aaiL3NetworkInputWithSubnets.json"), L3Network.class);
1074
1075         Optional<VpnBinding> actual = bbInputSetupUtils.getAICVpnBindingFromNetwork(l3Network);
1076         assertEquals(actual, Optional.empty());
1077     }
1078
1079     @Test
1080     public void getAAIServiceInstancesGloballyByName_noAAIResourceTest() {
1081         final String serviceInstanceName = "serviceInstanceName";
1082
1083         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
1084         ServiceInstances actualServiceInstances =
1085                 bbInputSetupUtils.getAAIServiceInstancesGloballyByName(serviceInstanceName);
1086
1087         assertNull(actualServiceInstances);
1088     }
1089
1090     @Test
1091     public void getAAIVnfsGloballyByName_noAAIResourceTest() {
1092         final String vnfName = "vnfName";
1093
1094         doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
1095         GenericVnfs actualGenericVnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(vnfName);
1096
1097         assertNull(actualGenericVnfs);
1098     }
1099
1100     private InfraActiveRequests loadExpectedInfraActiveRequest() throws IOException {
1101         return mapper.readValue(new File(RESOURCE_PATH + "InfraActiveRequestExpected.json"), InfraActiveRequests.class);
1102     }
1103 }