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