54e513e7d98b4da2bc73e8e88cf397a8fdb89574
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / bpmn / servicedecomposition / tasks / BBInputSetupUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.servicedecomposition.tasks;
22
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
27 import static org.mockito.ArgumentMatchers.any;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.ArgumentMatchers.isA;
30 import static org.mockito.Mockito.doReturn;
31 import static org.mockito.Mockito.times;
32 import static org.mockito.Mockito.verify;
33
34 import java.io.File;
35 import java.io.IOException;
36 import java.util.Arrays;
37 import java.util.List;
38 import java.util.Optional;
39
40 import org.junit.Before;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.junit.rules.ExpectedException;
44 import org.junit.runner.RunWith;
45 import org.mockito.InjectMocks;
46 import org.mockito.Mock;
47 import org.mockito.Mockito;
48 import org.mockito.junit.MockitoJUnitRunner;
49 import org.onap.aai.domain.yang.CloudRegion;
50 import org.onap.aai.domain.yang.Configuration;
51 import org.onap.aai.domain.yang.GenericVnf;
52 import org.onap.aai.domain.yang.GenericVnfs;
53 import org.onap.aai.domain.yang.L3Network;
54 import org.onap.aai.domain.yang.L3Networks;
55 import org.onap.aai.domain.yang.ServiceInstance;
56 import org.onap.aai.domain.yang.ServiceInstances;
57 import org.onap.aai.domain.yang.VolumeGroup;
58 import org.onap.aai.domain.yang.VolumeGroups;
59 import org.onap.so.bpmn.common.InjectionHelper;
60 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
61 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
62 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException;
63 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException;
64 import org.onap.so.client.aai.AAIObjectPlurals;
65 import org.onap.so.client.aai.AAIObjectType;
66 import org.onap.so.client.aai.AAIResourcesClient;
67 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
68 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
69 import org.onap.so.client.graphinventory.entities.uri.Depth;
70
71 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
72 import org.onap.so.db.catalog.beans.Service;
73 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
74 import org.onap.so.db.catalog.client.CatalogDbClient;
75 import org.onap.so.db.request.beans.InfraActiveRequests;
76 import org.onap.so.db.request.client.RequestsDbClient;
77 import org.onap.so.serviceinstancebeans.CloudConfiguration;
78 import org.onap.so.serviceinstancebeans.ModelInfo;
79 import org.onap.so.serviceinstancebeans.RequestDetails;
80
81 import com.fasterxml.jackson.core.JsonParseException;
82 import com.fasterxml.jackson.databind.JsonMappingException;
83 import com.fasterxml.jackson.databind.ObjectMapper;
84
85 @RunWith(MockitoJUnitRunner.class)
86 public class BBInputSetupUtilsTest {
87         protected ObjectMapper mapper = new ObjectMapper();
88         private static final String RESOURCE_PATH = "src/test/resources/__files/ExecuteBuildingBlock/";
89         
90         @InjectMocks
91         BBInputSetupUtils bbInputSetupUtils = new BBInputSetupUtils();
92         
93         @Mock
94         protected CatalogDbClient MOCK_catalogDbClient;
95         
96         @Mock
97         protected RequestsDbClient MOCK_requestsDbClient;
98         
99         @Mock
100         protected AAIResourcesClient MOCK_aaiResourcesClient;
101         
102         @Mock
103         protected InjectionHelper MOCK_injectionHelper;
104         
105         @Rule
106         public ExpectedException expectedException = ExpectedException.none();
107
108         @Before
109         public void setup(){
110                 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
111         }
112
113         @Test
114         public void testGetCatalogServiceByModelUUID() throws JsonParseException, JsonMappingException, IOException {
115                 Service expected = mapper.readValue(
116                                 new File(RESOURCE_PATH + "CatalogServiceExpected.json"), Service.class);
117
118                 RequestDetails requestDetails = new RequestDetails();
119                 ModelInfo modelInfo = new ModelInfo();
120                 modelInfo.setModelVersionId("modelUUID");
121                 requestDetails.setModelInfo(modelInfo);
122                 doReturn(expected).when(MOCK_catalogDbClient).getServiceByID("modelUUID");
123                 Service actual = bbInputSetupUtils.getCatalogServiceByModelUUID(modelInfo.getModelVersionId());
124
125                 assertThat(actual, sameBeanAs(expected));
126         }
127
128         @Test
129         public void testGetCatalogServiceByModelVersionAndModelInvariantUUID() throws JsonParseException, JsonMappingException, IOException {
130                 String modelVersion = "modelVersion";
131                 String modelInvariantUUID = "modelInvariantUUID";
132                 Service expectedService = mapper.readValue(
133                                 new File(RESOURCE_PATH + "CatalogServiceExpected.json"), Service.class);
134                 
135                 doReturn(expectedService).when(MOCK_catalogDbClient).getServiceByModelVersionAndModelInvariantUUID(isA(String.class), isA(String.class));
136                 
137                 Service actualService = bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(modelVersion, modelInvariantUUID);
138                 
139                 assertThat(actualService, sameBeanAs(expectedService));
140         }
141         
142         @Test
143         public void testGetVnfcInstanceGroups() throws JsonParseException, JsonMappingException, IOException {
144                 VnfcInstanceGroupCustomization vnfc = mapper.readValue(
145                                 new File(RESOURCE_PATH + "VnfcInstanceGroupCustomization.json"), VnfcInstanceGroupCustomization.class);
146                 String modelCustomizationUUID = "modelCustomizationUUID";
147                 
148                 doReturn(Arrays.asList(vnfc)).when(MOCK_catalogDbClient).getVnfcInstanceGroupsByVnfResourceCust(isA(String.class));
149                 
150                 List<VnfcInstanceGroupCustomization> actualVnfcList = bbInputSetupUtils.getVnfcInstanceGroups(modelCustomizationUUID);
151                 
152                 assertThat(actualVnfcList, sameBeanAs(Arrays.asList(vnfc)));
153         }
154
155         @Test
156         public void testGetRequestDetails() throws JsonParseException, JsonMappingException, IOException {
157                 InfraActiveRequests infraActiveRequest = mapper.readValue(
158                                 new File(RESOURCE_PATH + "InfraActiveRequestExpected.json"),
159                                 InfraActiveRequests.class);
160
161                 RequestDetails expected = mapper.readValue(
162                                 new File(RESOURCE_PATH + "RequestDetailsExpected.json"),
163                                 RequestDetails.class);
164                 String requestId = "requestId";
165                 doReturn(infraActiveRequest).when(MOCK_requestsDbClient).getInfraActiveRequestbyRequestId(requestId);
166                 RequestDetails actual = bbInputSetupUtils.getRequestDetails(requestId);
167
168                 assertThat(actual, sameBeanAs(expected));
169         }
170
171         @Test
172         public void getRequestDetailsNullTest() throws IOException {
173                 RequestDetails requestDetails = bbInputSetupUtils.getRequestDetails("");
174                 
175                 assertNull(requestDetails);
176         }
177
178         @Test
179         public void testGetCloudRegion() {
180                 CloudConfiguration cloudConfig = new CloudConfiguration();
181                 cloudConfig.setLcpCloudRegionId("lcpCloudRegionId");
182                 Optional<org.onap.aai.domain.yang.CloudRegion> expected = Optional.of(new org.onap.aai.domain.yang.CloudRegion());
183                 expected.get().setCloudOwner("cloudOwner");
184                 expected.get().setCloudRegionId("lcpCloudRegionId");
185                 doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.CloudRegion.class,
186                                 AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudConfig.getCloudOwner(),
187                                                 cloudConfig.getLcpCloudRegionId()).depth(Depth.TWO));
188
189                 AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudConfig.getCloudOwner(),
190                                 cloudConfig.getLcpCloudRegionId()).depth(Depth.TWO);
191                 bbInputSetupUtils.getCloudRegion(cloudConfig);
192                 
193                 verify(MOCK_aaiResourcesClient, times(1)).get(CloudRegion.class, expectedUri);
194         }
195         
196         @Test
197         public void testGetCloudRegionExceptionTest() {
198
199                 CloudConfiguration cloudConfig = new CloudConfiguration();
200                 cloudConfig.setLcpCloudRegionId("lcpCloudRegionId");
201
202                 RequestDetails requestDetails = new RequestDetails();
203                 requestDetails.setCloudConfiguration(cloudConfig);
204                 
205                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
206                 
207                 CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfig);
208                 
209                 assertNull(cloudRegion);
210         }
211
212         @Test
213         public void testGetCloudRegionEmptyId() {
214                 CloudConfiguration cloudConfig = new CloudConfiguration();
215                 cloudConfig.setLcpCloudRegionId("");
216                 
217                 RequestDetails requestDetails = new RequestDetails();
218                 requestDetails.setCloudConfiguration(cloudConfig);
219                 
220                 CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfig);
221                 
222                 assertNull(cloudRegion);
223         }
224
225         @Test
226         public void testGetCloudRegionEmptyConfiguration() {
227                 RequestDetails requestDetails = new RequestDetails();
228
229                 CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(requestDetails.getCloudConfiguration());
230
231                 assertNull(cloudRegion);
232         }
233
234         @Test
235         public void testGetAAIInstanceGroup() {
236                 Optional<org.onap.aai.domain.yang.InstanceGroup> expected = Optional.of(new org.onap.aai.domain.yang.InstanceGroup());
237                 String instanceGroupId = "instanceGroupId";
238                 expected.get().setId(instanceGroupId);
239                 doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.InstanceGroup.class,
240                                 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId));
241                 AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId);
242
243                 bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId);
244                 verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.InstanceGroup.class, expectedUri);
245         }
246
247         @Test
248         public void testGetAAIInstanceGroupThrowNotFound() {
249                 String instanceGroupId = "instanceGroupId";
250                 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
251                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.InstanceGroup.class,
252                                 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId));
253
254                 org.onap.aai.domain.yang.InstanceGroup actual = bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId);
255
256                 assertNull(actual);
257         }
258
259         @Test
260         public void testGetAAICustomer() {
261                 Optional<org.onap.aai.domain.yang.Customer> expected = Optional.of(new org.onap.aai.domain.yang.Customer());
262                 String globalSubscriberId = "globalSubscriberId";
263                 expected.get().setGlobalCustomerId(globalSubscriberId);
264                 doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.Customer.class,
265                                 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId));
266                 AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId);
267
268                 bbInputSetupUtils.getAAICustomer(globalSubscriberId);
269                 verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.Customer.class, expectedUri);
270         }
271
272         @Test
273         public void testGetAAICustomerThrowNotFound() {
274                 String globalSubscriberId = "globalSubscriberId";
275                 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
276                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.Customer.class,
277                                 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId));
278
279                 org.onap.aai.domain.yang.Customer actual = bbInputSetupUtils.getAAICustomer(globalSubscriberId);
280
281                 assertNull(actual);
282         }
283
284         @Test
285         public void testGetAAIServiceSubscription() {
286                 Optional<org.onap.aai.domain.yang.ServiceSubscription> expected = Optional.of(new org.onap.aai.domain.yang.ServiceSubscription());
287                 String globalSubscriberId = "globalSubscriberId";
288                 String subscriptionServiceType = "subscriptionServiceType";
289                 expected.get().setServiceType(subscriptionServiceType);
290                 doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.ServiceSubscription.class,
291                                 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId,
292                                                 subscriptionServiceType));
293                 AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId,
294                                 subscriptionServiceType);
295
296                 bbInputSetupUtils.getAAIServiceSubscription(globalSubscriberId, subscriptionServiceType);
297                 verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceSubscription.class, expectedUri);
298         }
299         
300         @Test
301         public void testGetAAIServiceSubscriptionErrors() {
302                 String globalSubId = null;
303                 String subServiceType = null;
304                 org.onap.aai.domain.yang.ServiceSubscription actual = bbInputSetupUtils.getAAIServiceSubscription(globalSubId, subServiceType);
305                 assertNull(actual);
306                 
307                 String globalSubId2 = "";
308                 String subServiceType2 = "";
309                 org.onap.aai.domain.yang.ServiceSubscription actual2 = bbInputSetupUtils.getAAIServiceSubscription(globalSubId2, subServiceType2);
310                 assertNull(actual2);
311                 
312                 String globalSubId3 = "";
313                 String subServiceType3 = null;
314                 org.onap.aai.domain.yang.ServiceSubscription actual3 = bbInputSetupUtils.getAAIServiceSubscription(globalSubId3, subServiceType3);
315                 assertNull(actual3);
316                 
317                 String globalSubId4 = null;
318                 String subServiceType4 = "";
319                 org.onap.aai.domain.yang.ServiceSubscription actual4 = bbInputSetupUtils.getAAIServiceSubscription(globalSubId4, subServiceType4);
320                 assertNull(actual4);
321         }
322
323         @Test
324         public void testGetAAIServiceSubscriptionThrowNotFound() {
325                 String globalSubscriberId = "globalSubscriberId";
326                 String subscriptionServiceType = "subscriptionServiceType";
327                 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
328                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient)
329                                 .get(org.onap.aai.domain.yang.ServiceSubscription.class, AAIUriFactory.createResourceUri(
330                                                 AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId, subscriptionServiceType));
331                 org.onap.aai.domain.yang.ServiceSubscription actual = bbInputSetupUtils
332                                 .getAAIServiceSubscription(globalSubscriberId, subscriptionServiceType);
333                 assertNull(actual);
334         }
335
336         @Test
337         public void testGetAAIServiceInstanceById() {
338                 String serviceInstanceId = "serviceInstanceId";
339                 
340                 ServiceInstance expectedServiceInstance = new ServiceInstance();
341                 
342                 doReturn(Optional.of(expectedServiceInstance)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
343                 
344                 ServiceInstance actualServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
345                 
346                 assertThat(actualServiceInstance, sameBeanAs(expectedServiceInstance));
347         }
348         
349         @Test
350         public void testGetAAIServiceInstanceByIdThrowNotFound() {
351                 String serviceInstanceId = "serviceInstanceId";
352                                 
353                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
354                 
355                 ServiceInstance actualServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
356                 
357                 assertNull(actualServiceInstance);
358         }
359
360         @Test
361         public void testGetAAIServiceInstanceByIdAndCustomer() {
362                 String globalCustomerId = "globalCustomerId";
363                 String serviceType = "serviceType";
364                 String serviceInstanceId = "serviceInstanceId";
365                 ServiceInstance expected = new ServiceInstance();
366                 expected.setServiceInstanceId(serviceInstanceId);
367                 doReturn(Optional.of(expected)).when(MOCK_aaiResourcesClient).get(isA(Class.class),
368                                 isA(AAIResourceUri.class));
369                 AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(
370                                 AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId).depth(Depth.TWO);
371                 this.bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(globalCustomerId, serviceType, serviceInstanceId);
372
373                 verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceInstance.class, expectedUri);
374
375         }
376
377         @Test
378         public void testGetAAIServiceInstanceByIdAndCustomerThrowNotFound() {
379                 String globalCustomerId = "globalCustomerId";
380                 String serviceType = "serviceType";
381                 String serviceInstanceId = "serviceInstanceId";
382
383                 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
384                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class),
385                                 isA(AAIResourceUri.class));
386                 ServiceInstance actual = this.bbInputSetupUtils
387                                 .getAAIServiceInstanceByIdAndCustomer(globalCustomerId, serviceType, serviceInstanceId);
388
389                 assertNull(actual);
390         }
391         
392         @Test
393         public void testGetAAIServiceInstanceByName() throws Exception {
394                 String serviceInstanceName = "serviceInstanceName";
395                 
396                 ServiceInstance expectedServiceInstance = new ServiceInstance();
397                 expectedServiceInstance.setServiceInstanceId("serviceInstanceId");
398                 
399                 ServiceSubscription serviceSubscription = new ServiceSubscription();
400                 serviceSubscription.setServiceType("serviceType");
401                 
402                 Customer customer = new Customer();
403                 customer.setGlobalCustomerId("globalCustomerId");
404                 customer.setServiceSubscription(serviceSubscription);
405                 
406                 ServiceInstances serviceInstances = new ServiceInstances();
407                 serviceInstances.getServiceInstance().add(expectedServiceInstance);
408                 
409                 doReturn(Optional.of(serviceInstances)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
410                 AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, customer.getGlobalCustomerId(),
411                                 customer.getServiceSubscription().getServiceType())
412                                 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO);
413                 bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer);
414
415                 verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceInstances.class, expectedUri);
416         }
417         
418         @Test
419         public void testGetAAIServiceInstanceByNameException() throws Exception {
420                 expectedException.expect(Exception.class);
421                 
422                 String serviceInstanceName = "serviceInstanceName";
423                 
424                 ServiceInstance serviceInstance = new ServiceInstance();
425                 serviceInstance.setServiceInstanceId("serviceInstanceId");
426                 
427                 ServiceSubscription serviceSubscription = new ServiceSubscription();
428                 serviceSubscription.setServiceType("serviceType");
429                 
430                 Customer customer = new Customer();
431                 customer.setGlobalCustomerId("globalCustomerId");
432                 customer.setServiceSubscription(serviceSubscription);
433                 
434                 ServiceInstances serviceInstances = new ServiceInstances();
435                 serviceInstances.getServiceInstance().add(serviceInstance);
436                 serviceInstances.getServiceInstance().add(serviceInstance);
437                 
438                 doReturn(Optional.of(serviceInstances)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
439                 
440                 bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer);
441         }
442         
443         @Test
444         public void testGetAAIServiceInstanceByNameNull() throws Exception {
445                 String serviceInstanceName = "serviceInstanceName";
446                 
447                 ServiceInstance serviceInstance = new ServiceInstance();
448                 serviceInstance.setServiceInstanceId("serviceInstanceId");
449                 
450                 ServiceSubscription serviceSubscription = new ServiceSubscription();
451                 serviceSubscription.setServiceType("serviceType");
452                 
453                 Customer customer = new Customer();
454                 customer.setGlobalCustomerId("globalCustomerId");
455                 customer.setServiceSubscription(serviceSubscription);
456
457                 ServiceInstances serviceInstances = new ServiceInstances();
458                 serviceInstances.getServiceInstance().add(serviceInstance);
459                 serviceInstances.getServiceInstance().add(serviceInstance);
460                 
461                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
462                 
463                 ServiceInstance actualServiceInstance = bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer);
464                 
465                 assertNull(actualServiceInstance);
466         }
467         
468         @Test
469         public void testGetOptionalAAIServiceInstanceByNameException() throws Exception {
470                 expectedException.expect(Exception.class);
471                 
472                 String globalCustomerId = "globalCustomerId";
473                 String serviceType = "serviceType";
474                 String serviceInstanceId = "serviceInstanceId";
475                 
476                 ServiceInstance serviceInstance = new ServiceInstance();
477                 serviceInstance.setServiceInstanceId("serviceInstanceId");
478                 serviceInstance.setServiceType(serviceType);
479                 serviceInstance.setServiceInstanceName("serviceInstanceName");
480
481                 ServiceInstances serviceInstances = new ServiceInstances();
482                 serviceInstances.getServiceInstance().add(serviceInstance);
483                 serviceInstances.getServiceInstance().add(serviceInstance);
484
485                 doReturn(Optional.of(serviceInstances)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
486                 
487                 bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, serviceInstanceId);
488         }
489         
490         @Test
491         public void testGetOptionalAAIServiceInstanceByNameNull() throws Exception {
492                 String globalCustomerId = "globalCustomerId";
493                 String serviceType = "serviceType";
494                 String serviceInstanceId = "serviceInstanceId";
495
496                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
497                 Optional<ServiceInstance> actual = this.bbInputSetupUtils
498                                 .getAAIServiceInstanceByName(globalCustomerId, serviceType, serviceInstanceId);
499
500                 assertThat(actual, sameBeanAs(Optional.empty()));
501         }
502         
503         @Test
504         public void testGetCatalogInstanceGroup() throws JsonParseException, JsonMappingException, IOException {
505                 String modelUUID = "modelUUID";
506                 
507                 org.onap.so.db.catalog.beans.InstanceGroup expectedInstanceGroup = mapper.readValue(
508                                 new File(RESOURCE_PATH + "InstanceGroup.json"), org.onap.so.db.catalog.beans.InstanceGroup.class);
509                 
510                 doReturn(expectedInstanceGroup).when(MOCK_catalogDbClient).getInstanceGroupByModelUUID(isA(String.class));
511                 
512                 org.onap.so.db.catalog.beans.InstanceGroup actualInstanceGroup = bbInputSetupUtils.getCatalogInstanceGroup(modelUUID);
513                 
514                 assertThat(actualInstanceGroup, sameBeanAs(expectedInstanceGroup));
515         }
516         
517         @Test
518         public void testGetCollectionResourceInstanceGroupCustomization() {
519                 String modelCustomizationUUID = "modelCustomizationUUID";
520                 
521                 CollectionResourceInstanceGroupCustomization expectedCollection = new CollectionResourceInstanceGroupCustomization();
522                 
523                 doReturn(Arrays.asList(expectedCollection)).when(MOCK_catalogDbClient)
524                                 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
525                 
526                 List<CollectionResourceInstanceGroupCustomization> actualCollection = bbInputSetupUtils
527                                 .getCollectionResourceInstanceGroupCustomization(modelCustomizationUUID);
528                 
529                 assertThat(actualCollection, sameBeanAs(Arrays.asList(expectedCollection)));
530         }
531         
532         @Test
533         public void testGetAAIGenericVnf() throws JsonParseException, JsonMappingException, IOException {
534                 String vnfId = "vnfId";
535                 
536                 GenericVnf expectedAaiVnf = mapper.readValue(
537                                 new File(RESOURCE_PATH + "aaiGenericVnfInput.json"), GenericVnf.class);
538                 
539                 doReturn(Optional.of(expectedAaiVnf)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
540                 AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE);
541                 GenericVnf actualAaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
542                 
543                 assertThat(actualAaiVnf, sameBeanAs(expectedAaiVnf));
544
545                 verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.GenericVnf.class, expectedUri);
546         }
547         
548         @Test
549         public void testGetAAIConfiguration() throws JsonParseException, JsonMappingException, IOException {
550                 String configurationId = "configurationId";
551                 
552                 Configuration expectedAaiConfiguration = mapper.readValue(
553                                 new File(RESOURCE_PATH + "ConfigurationInput.json"), Configuration.class);
554                 
555                 doReturn(Optional.of(expectedAaiConfiguration)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
556                 AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId).depth(Depth.ONE);
557                 bbInputSetupUtils.getAAIConfiguration(configurationId);
558
559                 verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.Configuration.class, expectedUri);
560         }
561         
562         @Test
563         public void testGetAAIGenericVnfThrowNotFound() throws JsonParseException, JsonMappingException, IOException {
564                 String vnfId = "vnfId";
565                 
566                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
567                 
568                 GenericVnf actualAaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
569                 
570                 assertNull(actualAaiVnf);
571         }
572         
573         @Test
574         public void testGetAAIResourceDepthOne() {
575                 String vnfId = "vnfId";
576                 AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
577                 AAIResourceUri expectedUri = aaiResourceUri.clone().depth(Depth.ONE);
578                 AAIResourceUri aaiResourceUriClone = aaiResourceUri.clone();
579                 bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri);
580                 
581                 verify(MOCK_aaiResourcesClient, times(1)).get(expectedUri);
582                 assertEquals("Uri should not have changed", aaiResourceUriClone.build(), aaiResourceUri.build());
583         }
584         
585         @Test
586         public void testGetAAIResourceDepthTwo() {
587                 String vnfId = "vnfId";
588                 AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
589                 AAIResourceUri expectedUri = aaiResourceUri.clone().depth(Depth.TWO);
590                 AAIResourceUri aaiResourceUriClone = aaiResourceUri.clone();
591                 bbInputSetupUtils.getAAIResourceDepthTwo(aaiResourceUri);
592                 
593                 verify(MOCK_aaiResourcesClient, times(1)).get(expectedUri);
594                 assertEquals("Uri should not have changed", aaiResourceUriClone.build(), aaiResourceUri.build());
595         }
596
597         @Test
598         public void getRelatedNetworkByNameFromServiceInstanceTest() throws Exception {
599                 Optional<L3Networks> expected = Optional.of(new L3Networks());
600                 L3Network network = new L3Network();
601                 network.setNetworkId("id123");
602                 network.setNetworkName("name123");
603                 expected.get().getL3Network().add(network);
604                 doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class));
605                 Optional<L3Network> actual = this.bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance("id123", "name123");
606                 assertEquals(actual.get().getNetworkId(), expected.get().getL3Network().get(0).getNetworkId());
607         }
608         
609         @Test
610         public void getRelatedNetworkByNameFromServiceInstanceMultipleNetworksExceptionTest() throws Exception {
611                 expectedException.expect(Exception.class);
612                 
613                 String serviceInstanceId = "serviceInstanceId";
614                 String networkName = "networkName";
615                 
616                 L3Network network = new L3Network();
617                 network.setNetworkId("id123");
618                 network.setNetworkName("name123");
619                 
620                 L3Networks expected = new L3Networks();
621                 expected.getL3Network().add(network);
622                 expected.getL3Network().add(network);
623                 
624                 doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class));
625                 
626                 bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(serviceInstanceId, networkName);
627         }
628         
629         @Test
630         public void getRelatedNetworkByNameFromServiceInstanceNotFoundTest() throws Exception {
631                 String serviceInstanceId = "serviceInstanceId";
632                 String networkName = "networkName";
633                 
634                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class));
635                 
636                 Optional<L3Network> actualNetwork = bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(serviceInstanceId, networkName);
637                 
638                 assertEquals(Optional.empty(), actualNetwork);
639         }
640         
641         @Test
642         public void getRelatedServiceInstanceFromInstanceGroupTest() throws Exception {
643                 Optional<ServiceInstances> expected = Optional.of(new ServiceInstances());
644                 ServiceInstance serviceInstance = new ServiceInstance();
645                 serviceInstance.setServiceInstanceId("serviceInstanceId");
646                 serviceInstance.setServiceInstanceName("serviceInstanceName");
647                 expected.get().getServiceInstance().add(serviceInstance);
648                 
649                 doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIResourceUri.class));
650                 Optional<ServiceInstance> actual = this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
651                 assertEquals(actual.get().getServiceInstanceId(), expected.get().getServiceInstance().get(0).getServiceInstanceId());
652         }
653         
654         @Test
655         public void getRelatedServiceInstanceFromInstanceGroupMultipleTest() throws Exception {
656                 expectedException.expect(MultipleObjectsFoundException.class);
657                 Optional<ServiceInstances> serviceInstances = Optional.of(new ServiceInstances());
658                 ServiceInstance si1 = Mockito.mock(ServiceInstance.class);
659                 ServiceInstance si2 = Mockito.mock(ServiceInstance.class);
660                 serviceInstances.get().getServiceInstance().add(si1);
661                 serviceInstances.get().getServiceInstance().add(si2);
662                 
663                 doReturn(serviceInstances).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIResourceUri.class));
664                 this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
665         }
666         
667         @Test
668         public void getRelatedServiceInstanceFromInstanceGroupNotFoundTest() throws Exception {
669                 expectedException.expect(NoServiceInstanceFoundException.class);
670                 Optional<ServiceInstances> serviceInstances = Optional.of(new ServiceInstances());
671                 
672                 doReturn(serviceInstances).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIResourceUri.class));
673                 this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
674         }
675         
676         @Test
677         public void getRelatedVnfByNameFromServiceInstanceTest() throws Exception {
678                 Optional<GenericVnfs> expected = Optional.of(new GenericVnfs());
679                 GenericVnf vnf = new GenericVnf();
680                 vnf.setVnfId("id123");
681                 vnf.setVnfName("name123");
682                 expected.get().getGenericVnf().add(vnf);
683                 doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class));
684                 Optional<GenericVnf> actual = this.bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance("id123", "name123");
685                 assertEquals(actual.get().getVnfId(), expected.get().getGenericVnf().get(0).getVnfId());
686         }
687         
688         @Test
689         public void getRelatedVnfByNameFromServiceInstanceMultipleVnfsExceptionTest() throws Exception {
690                 expectedException.expect(Exception.class);
691                 
692                 String serviceInstanceId = "serviceInstanceId";
693                 String vnfName = "vnfName";
694                 
695                 GenericVnf vnf = new GenericVnf();
696                 vnf.setVnfId("id123");
697                 vnf.setVnfName("name123");
698                 
699                 GenericVnfs expectedVnf = new GenericVnfs();
700                 expectedVnf.getGenericVnf().add(vnf);
701                 expectedVnf.getGenericVnf().add(vnf);
702                 
703                 doReturn(expectedVnf).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class));
704                 
705                 bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName);
706         }
707         
708         @Test
709         public void getRelatedVnfByNameFromServiceInstanceNotFoundTest() throws Exception {
710                 String serviceInstanceId = "serviceInstanceId";
711                 String vnfName = "vnfName";
712                 
713                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class));
714                 
715                 Optional<GenericVnf> actualVnf = this.bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName);
716                 
717                 assertEquals(actualVnf, Optional.empty());
718         }
719         
720         @Test
721         public void getRelatedVolumeGroupByNameFromVnfTest() throws Exception {
722                 Optional<VolumeGroups> expected = Optional.of(new VolumeGroups());
723                 VolumeGroup volumeGroup = new VolumeGroup();
724                 volumeGroup.setVolumeGroupId("id123");
725                 volumeGroup.setVolumeGroupName("name123");
726                 expected.get().getVolumeGroup().add(volumeGroup);
727                 doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
728                 Optional<VolumeGroup> actual = this.bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "name123");
729                 assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId());
730         }
731         
732         @Test
733         public void getRelatedVolumeGroupByNameFromVnfMultipleVolumeGroupsExceptionTest() throws Exception {
734                 expectedException.expect(Exception.class);
735                 
736                 String vnfId = "vnfId";
737                 String volumeGroupName = "volumeGroupName";
738                 
739                 VolumeGroup volumeGroup = new VolumeGroup();
740                 volumeGroup.setVolumeGroupId("id123");
741                 volumeGroup.setVolumeGroupName("name123");
742                 
743                 VolumeGroups expectedVolumeGroup = new VolumeGroups();
744                 expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
745                 expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
746                 
747                 doReturn(expectedVolumeGroup).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
748                 
749                 bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(vnfId, volumeGroupName);
750         }
751         
752         @Test
753         public void getRelatedVolumeGroupByNameFromVnfNotFoundTest() throws Exception {
754                 String vnfId = "vnfId";
755                 String volumeGroupName = "volumeGroupName";
756                 
757                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
758                 
759                 Optional<VolumeGroup> actualVolumeGroup = bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(vnfId, volumeGroupName);
760                 
761                 assertEquals(actualVolumeGroup, Optional.empty());
762         }
763         
764         @Test
765         public void getRelatedVolumeGroupByNameFromVfModuleTest() throws Exception {
766                 Optional<VolumeGroups> expected = Optional.of(new VolumeGroups());
767                 VolumeGroup volumeGroup = new VolumeGroup();
768                 volumeGroup.setVolumeGroupId("id123");
769                 volumeGroup.setVolumeGroupName("name123");
770                 expected.get().getVolumeGroup().add(volumeGroup);
771                 doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
772                 Optional<VolumeGroup> actual = this.bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule("id123", "id123", "name123");
773                 assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId());
774         }
775         
776         @Test
777         public void getRelatedVolumeGroupByNameFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception {
778                 expectedException.expect(Exception.class);
779                 
780                 String vnfId = "vnfId";
781                 String volumeGroupId = "volumeGroupId";
782                 String volumeGroupName = "volumeGroupName";
783                 
784                 VolumeGroup volumeGroup = new VolumeGroup();
785                 volumeGroup.setVolumeGroupId("id123");
786                 volumeGroup.setVolumeGroupName("name123");
787                 
788                 VolumeGroups expectedVolumeGroup = new VolumeGroups();
789                 expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
790                 expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
791                 
792                 doReturn(expectedVolumeGroup).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
793                 
794                 bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, volumeGroupId, volumeGroupName);
795         }
796         
797         @Test
798         public void getRelatedVolumeGroupByNameFromVfModuleNotFoundTest() throws Exception {
799                 String vnfId = "vnfId";
800                 String volumeGroupId = "volumeGroupId";
801                 String volumeGroupName = "volumeGroupName";
802                 
803                 doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
804                 
805                 Optional<VolumeGroup> actualVolumeGroup = bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, volumeGroupId, volumeGroupName);
806                 
807                 assertEquals(actualVolumeGroup, Optional.empty());
808         }
809 }