Merge "Sonar fixes Reduce selectExecutionList method"
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / bpmn / servicedecomposition / tasks / BBInputSetupMapperLayerTest.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.hamcrest.CoreMatchers.equalTo;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
29 import java.io.File;
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36 import org.junit.Test;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
52 import org.onap.so.bpmn.servicedecomposition.bbobjects.Tenant;
53 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
54 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
55 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
56 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
57 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
58 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoCollection;
59 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration;
60 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
61 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
62 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork;
63 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
64 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
65 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
66 import org.onap.so.db.catalog.beans.CollectionResource;
67 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
68 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
69 import org.onap.so.db.catalog.beans.ConfigurationResource;
70 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
71 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
72 import org.onap.so.db.catalog.beans.CvnfcCustomization;
73 import org.onap.so.db.catalog.beans.InstanceGroup;
74 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
75 import org.onap.so.db.catalog.beans.OrchestrationStatus;
76 import org.onap.so.db.catalog.beans.Service;
77 import org.onap.so.db.catalog.beans.VfModuleCustomization;
78 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
79 import org.onap.so.db.catalog.beans.VnfcCustomization;
80 import org.onap.so.serviceinstancebeans.CloudConfiguration;
81 import org.onap.so.serviceinstancebeans.RequestDetails;
82 import com.fasterxml.jackson.core.JsonParseException;
83 import com.fasterxml.jackson.databind.JsonMappingException;
84 import com.fasterxml.jackson.databind.ObjectMapper;
85
86 public class BBInputSetupMapperLayerTest {
87
88     BBInputSetupMapperLayer bbInputSetupMapperLayer = new BBInputSetupMapperLayer();
89
90     ObjectMapper mapper = new ObjectMapper();
91
92     private static final String RESOURCE_PATH = "src/test/resources/__files/ExecuteBuildingBlock/";
93
94     @Test
95     public void testMapOrchestrationStatusFromAAI() {
96         OrchestrationStatus expected = OrchestrationStatus.INVENTORIED;
97         String orchStatusInput = "Inventoried";
98         OrchestrationStatus actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
99         assertThat(actual, sameBeanAs(expected));
100
101         expected = OrchestrationStatus.ASSIGNED;
102         orchStatusInput = "Assigned";
103         actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
104         assertThat(actual, sameBeanAs(expected));
105
106         expected = OrchestrationStatus.ACTIVE;
107         orchStatusInput = "Active";
108         actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
109         assertThat(actual, sameBeanAs(expected));
110
111         expected = OrchestrationStatus.CREATED;
112         orchStatusInput = "Created";
113         actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
114         assertThat(actual, sameBeanAs(expected));
115
116         expected = OrchestrationStatus.PRECREATED;
117         orchStatusInput = "PreCreated";
118         actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
119         assertThat(actual, sameBeanAs(expected));
120
121         expected = OrchestrationStatus.PENDING_CREATE;
122         orchStatusInput = "PendingCreate";
123         actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
124         assertThat(actual, sameBeanAs(expected));
125
126         expected = OrchestrationStatus.PENDING_DELETE;
127         orchStatusInput = "PendingDelete";
128         actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
129         assertThat(actual, sameBeanAs(expected));
130
131         expected = OrchestrationStatus.PENDING;
132         orchStatusInput = "Pending";
133         actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
134         assertThat(actual, sameBeanAs(expected));
135
136         expected = OrchestrationStatus.PENDING_ACTIVATION;
137         orchStatusInput = "PendingActivation";
138         actual = bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(orchStatusInput);
139         assertThat(actual, sameBeanAs(expected));
140     }
141
142     @Test
143     public void testMapOrchestrationFuzzyCases() {
144         List<String> values = Arrays.asList("pending-create", "pending_Create", "pendinggcreate", "PendingCreate");
145         values.forEach(value -> {
146             assertThat(bbInputSetupMapperLayer.mapOrchestrationStatusFromAAI(value),
147                     equalTo(OrchestrationStatus.PENDING_CREATE));
148         });
149     }
150
151     @Test
152     public void testMapAAICustomer() throws IOException {
153         Customer expected = mapper.readValue(new File(RESOURCE_PATH + "Customer.json"), Customer.class);
154
155         org.onap.aai.domain.yang.Customer customerAAI = mapper.readValue(new File(RESOURCE_PATH + "Customer_AAI.json"),
156                 org.onap.aai.domain.yang.Customer.class);
157
158         Customer actual = bbInputSetupMapperLayer.mapAAICustomer(customerAAI);
159
160         assertThat(actual, sameBeanAs(expected));
161     }
162
163     @Test
164     public void testMapAAIServiceSubscription() throws IOException {
165         ServiceSubscription expected = mapper.readValue(new File(RESOURCE_PATH + "ServiceSubscriptionExpected.json"),
166                 ServiceSubscription.class);
167
168         org.onap.aai.domain.yang.ServiceSubscription svcSubscriptionAAI =
169                 mapper.readValue(new File(RESOURCE_PATH + "ServiceSubscription_AAI.json"),
170                         org.onap.aai.domain.yang.ServiceSubscription.class);
171
172         ServiceSubscription actual = bbInputSetupMapperLayer.mapAAIServiceSubscription(svcSubscriptionAAI);
173
174         assertThat(actual, sameBeanAs(expected));
175     }
176
177     @Test
178     public void testMapAAIProject() throws IOException {
179         Project expected = mapper.readValue(new File(RESOURCE_PATH + "Project.json"), Project.class);
180
181         org.onap.aai.domain.yang.Project projectAAI = new org.onap.aai.domain.yang.Project();
182         projectAAI.setProjectName("projectName");
183
184         Project actual = bbInputSetupMapperLayer.mapAAIProject(projectAAI);
185
186         assertThat(actual, sameBeanAs(expected));
187     }
188
189     @Test
190     public void testMapRequestProject() throws IOException {
191         Project expected = mapper.readValue(new File(RESOURCE_PATH + "Project.json"), Project.class);
192
193         org.onap.so.serviceinstancebeans.Project requestProject = new org.onap.so.serviceinstancebeans.Project();
194         requestProject.setProjectName("projectName");
195
196         Project actual = bbInputSetupMapperLayer.mapRequestProject(requestProject);
197
198         assertThat(actual, sameBeanAs(expected));
199     }
200
201     @Test
202     public void testMapAAIOwningEntity() throws IOException {
203         OwningEntity expected = mapper.readValue(new File(RESOURCE_PATH + "OwningEntity.json"), OwningEntity.class);
204
205         org.onap.aai.domain.yang.OwningEntity entityAAI = new org.onap.aai.domain.yang.OwningEntity();
206         entityAAI.setOwningEntityId("owningEntityId");
207         entityAAI.setOwningEntityName("owningEntityName");
208
209         OwningEntity actual = bbInputSetupMapperLayer.mapAAIOwningEntity(entityAAI);
210
211         assertThat(actual, sameBeanAs(expected));
212     }
213
214     @Test
215     public void testMapRequestOwningEntity() throws IOException {
216         OwningEntity expected = mapper.readValue(new File(RESOURCE_PATH + "OwningEntity.json"), OwningEntity.class);
217
218         org.onap.so.serviceinstancebeans.OwningEntity requestOwningEntity =
219                 new org.onap.so.serviceinstancebeans.OwningEntity();
220         requestOwningEntity.setOwningEntityId("owningEntityId");
221         requestOwningEntity.setOwningEntityName("owningEntityName");
222
223         OwningEntity actual = bbInputSetupMapperLayer.mapRequestOwningEntity(requestOwningEntity);
224
225         assertThat(actual, sameBeanAs(expected));
226     }
227
228     @Test
229     public void testMapAAIPlatform() throws IOException {
230         Platform expected = mapper.readValue(new File(RESOURCE_PATH + "Platform.json"), Platform.class);
231
232         org.onap.aai.domain.yang.Platform platformAAI = new org.onap.aai.domain.yang.Platform();
233         platformAAI.setPlatformName("platformName");
234
235         Platform actual = bbInputSetupMapperLayer.mapAAIPlatform(platformAAI);
236
237         assertThat(actual, sameBeanAs(expected));
238     }
239
240     @Test
241     public void testMapAAILineOfBusiness() throws IOException {
242         LineOfBusiness expected =
243                 mapper.readValue(new File(RESOURCE_PATH + "LineOfBusiness.json"), LineOfBusiness.class);
244
245         org.onap.aai.domain.yang.LineOfBusiness lobAAI = new org.onap.aai.domain.yang.LineOfBusiness();
246         lobAAI.setLineOfBusinessName("lineOfBusinessName");
247
248         LineOfBusiness actual = bbInputSetupMapperLayer.mapAAILineOfBusiness(lobAAI);
249
250         assertThat(actual, sameBeanAs(expected));
251     }
252
253     @Test
254     public void testMapAAINetworkPolicy() throws JsonParseException, JsonMappingException, IOException {
255         NetworkPolicy expectedNetworkPolicy =
256                 mapper.readValue(new File(RESOURCE_PATH + "NetworkPolicy.json"), NetworkPolicy.class);
257
258         org.onap.aai.domain.yang.NetworkPolicy aaiNetworkPolicy = new org.onap.aai.domain.yang.NetworkPolicy();
259         aaiNetworkPolicy.setNetworkPolicyId("networkPolicyId");
260         aaiNetworkPolicy.setNetworkPolicyFqdn("networkPolicyFqdn");
261         aaiNetworkPolicy.setHeatStackId("heatStackId");
262         aaiNetworkPolicy.setResourceVersion("resourceVersion");
263
264         NetworkPolicy actualNetworkPolicy = bbInputSetupMapperLayer.mapAAINetworkPolicy(aaiNetworkPolicy);
265
266         assertThat(actualNetworkPolicy, sameBeanAs(expectedNetworkPolicy));
267     }
268
269     @Test
270     public void testMapAAIVolumeGroup() throws JsonParseException, JsonMappingException, IOException {
271         VolumeGroup expectedVolumeGroup =
272                 mapper.readValue(new File(RESOURCE_PATH + "VolumeGroup.json"), VolumeGroup.class);
273
274         org.onap.aai.domain.yang.VolumeGroup aaiVolumeGroup = mapper.readValue(
275                 new File(RESOURCE_PATH + "VolumeGroup_AAI.json"), org.onap.aai.domain.yang.VolumeGroup.class);
276
277         VolumeGroup actualVolumeGroup = bbInputSetupMapperLayer.mapAAIVolumeGroup(aaiVolumeGroup);
278
279         assertThat(actualVolumeGroup, sameBeanAs(expectedVolumeGroup));
280     }
281
282     @Test
283     public void testMapCatalogServiceIntoServiceInstance() throws IOException {
284         ModelInfoServiceInstance expected = mapper.readValue(new File(RESOURCE_PATH + "ModelInfoServiceInstance.json"),
285                 ModelInfoServiceInstance.class);
286
287         Service catalogService = mapper.readValue(new File(RESOURCE_PATH + "CatalogServiceInput.json"), Service.class);
288
289         ModelInfoServiceInstance actual = bbInputSetupMapperLayer.mapCatalogServiceIntoServiceInstance(catalogService);
290
291         assertThat(actual, sameBeanAs(expected));
292     }
293
294     @Test
295     public void testMapCatalogInstanceGroupToInstanceGroup() throws IOException {
296         ModelInfoInstanceGroup expected =
297                 mapper.readValue(new File(RESOURCE_PATH + "ModelInfoInstanceGroup.json"), ModelInfoInstanceGroup.class);
298
299         InstanceGroup instanceGroup =
300                 mapper.readValue(new File(RESOURCE_PATH + "InstanceGroup.json"), InstanceGroup.class);
301         instanceGroup.setCollectionInstanceGroupCustomizations(new ArrayList<>());
302         CollectionResourceInstanceGroupCustomization collectionInstanceGroupCust =
303                 new CollectionResourceInstanceGroupCustomization();
304         collectionInstanceGroupCust.setModelCustomizationUUID("modelCustomizationUUID");
305         collectionInstanceGroupCust.setFunction("function");
306         collectionInstanceGroupCust.setDescription("description");
307         instanceGroup.getCollectionInstanceGroupCustomizations().add(collectionInstanceGroupCust);
308         CollectionResourceCustomization collectionResourceCust = new CollectionResourceCustomization();
309         collectionResourceCust.setModelCustomizationUUID("modelCustomizationUUID");
310         ModelInfoInstanceGroup actual =
311                 bbInputSetupMapperLayer.mapCatalogInstanceGroupToInstanceGroup(collectionResourceCust, instanceGroup);
312
313         assertThat(actual, sameBeanAs(expected));
314     }
315
316     @Test
317     public void testMapCollectionNetworkResourceCustToNetworkResourceCust() {
318         String modelCustomizationUUID = "modelCustomizationUUID";
319         String modelInstanceName = "modelInstanceName";
320         String networkRole = "networkRole";
321         String networkScope = "networkScope";
322         String networkTechnology = "networkTechnology";
323         String networkType = "networkType";
324
325         NetworkResourceCustomization expected = new NetworkResourceCustomization();
326         expected.setModelCustomizationUUID(modelCustomizationUUID);
327         expected.setModelInstanceName(modelInstanceName);
328         expected.setNetworkRole(networkRole);
329         expected.setNetworkScope(networkScope);
330         expected.setNetworkTechnology(networkTechnology);
331         expected.setNetworkType(networkType);
332         CollectionNetworkResourceCustomization collectionNetworkResourceCust =
333                 new CollectionNetworkResourceCustomization();
334         collectionNetworkResourceCust.setModelCustomizationUUID(modelCustomizationUUID);
335         collectionNetworkResourceCust.setModelInstanceName(modelInstanceName);
336         collectionNetworkResourceCust.setNetworkRole(networkRole);
337         collectionNetworkResourceCust.setNetworkScope(networkScope);
338         collectionNetworkResourceCust.setNetworkTechnology(networkTechnology);
339         collectionNetworkResourceCust.setNetworkType(networkType);
340         NetworkResourceCustomization actual = bbInputSetupMapperLayer
341                 .mapCollectionNetworkResourceCustToNetworkResourceCust(collectionNetworkResourceCust);
342
343         assertThat(actual, sameBeanAs(expected));
344     }
345
346     @Test
347     public void testMapCatalogCollectionToCollection() throws IOException {
348         ModelInfoCollection expected =
349                 mapper.readValue(new File(RESOURCE_PATH + "ModelInfoCollection.json"), ModelInfoCollection.class);
350
351         CollectionResourceCustomization collectionCust =
352                 mapper.readValue(new File(RESOURCE_PATH + "CollectionResourceCustomization.json"),
353                         CollectionResourceCustomization.class);
354
355         CollectionResource collectionResource =
356                 mapper.readValue(new File(RESOURCE_PATH + "CollectionResource.json"), CollectionResource.class);
357
358         ModelInfoCollection actual =
359                 bbInputSetupMapperLayer.mapCatalogCollectionToCollection(collectionCust, collectionResource);
360
361         assertThat(actual, sameBeanAs(expected));
362     }
363
364     @Test
365     public void testMapAAIServiceInstanceIntoServiceInstance() throws IOException {
366         ServiceInstance expected = mapper.readValue(
367                 new File(RESOURCE_PATH + "ServiceInstance_aaiServiceInstanceToSI.json"), ServiceInstance.class);
368
369         org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI =
370                 mapper.readValue(new File(RESOURCE_PATH + "ServiceInstanceAAIInput.json"),
371                         org.onap.aai.domain.yang.ServiceInstance.class);
372
373         ServiceInstance actual = bbInputSetupMapperLayer.mapAAIServiceInstanceIntoServiceInstance(serviceInstanceAAI);
374
375         assertThat(actual, sameBeanAs(expected));
376     }
377
378     @Test
379     public void testSetPlatformAndLOB() throws IOException {
380         ServiceInstance expected = mapper.readValue(
381                 new File(RESOURCE_PATH + "ServiceInstance_aaiPlatformAndLOBToSI.json"), ServiceInstance.class);
382
383         Map<ResourceKey, String> resourcesToBeOrchestrated = new HashMap<>();
384         resourcesToBeOrchestrated.put(ResourceKey.GENERIC_VNF_ID, "vnfId");
385         Platform platformMSO = new Platform();
386         platformMSO.setPlatformName("platformName");
387         LineOfBusiness lineOfBusinessMSO = new LineOfBusiness();
388         lineOfBusinessMSO.setLineOfBusinessName("lineOfBusinessName");
389
390         ServiceInstance actual = mapper.readValue(
391                 new File(RESOURCE_PATH + "ServiceInstanceAAIPlatformAndLOBInput.json"), ServiceInstance.class);
392
393         bbInputSetupMapperLayer.setPlatformAndLOBIntoServiceInstance(platformMSO, lineOfBusinessMSO, actual,
394                 resourcesToBeOrchestrated);
395
396         assertThat(actual, sameBeanAs(expected));
397     }
398
399     @Test
400     public void testMapAAIL3NetworkIntoL3Network() throws IOException {
401         L3Network expected =
402                 mapper.readValue(new File(RESOURCE_PATH + "l3NetworkExpectedWithSubnet.json"), L3Network.class);
403
404         org.onap.aai.domain.yang.L3Network aaiL3Network =
405                 mapper.readValue(new File(RESOURCE_PATH + "aaiL3NetworkInputWithSubnets.json"),
406                         org.onap.aai.domain.yang.L3Network.class);
407
408         L3Network actual = bbInputSetupMapperLayer.mapAAIL3Network(aaiL3Network);
409
410         assertThat(actual, sameBeanAs(expected));
411     }
412
413     @Test
414     public void testMapAAIGenericVnfIntoGenericVnf() throws IOException {
415         GenericVnf expected = mapper.readValue(new File(RESOURCE_PATH + "GenericVnfExpected.json"), GenericVnf.class);
416         org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = mapper.readValue(
417                 new File(RESOURCE_PATH + "aaiGenericVnfInput.json"), org.onap.aai.domain.yang.GenericVnf.class);
418
419         GenericVnf actual = bbInputSetupMapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnf);
420
421         assertThat(actual, sameBeanAs(expected));
422     }
423
424     @Test
425     public void testMapAAIPnfIntoPnf() throws IOException {
426         Pnf expected = mapper.readValue(new File(RESOURCE_PATH + "PnfExpected.json"), Pnf.class);
427         org.onap.aai.domain.yang.Pnf aaiPnf =
428                 mapper.readValue(new File(RESOURCE_PATH + "aaiPnfInput.json"), org.onap.aai.domain.yang.Pnf.class);
429
430         Pnf actual = bbInputSetupMapperLayer.mapAAIPnfIntoPnf(aaiPnf);
431
432         assertThat(actual, sameBeanAs(expected));
433     }
434
435     @Test
436     public void testMapAAICollectionIntoCollection() throws JsonParseException, JsonMappingException, IOException {
437         org.onap.aai.domain.yang.Collection aaiCollection = mapper
438                 .readValue(new File(RESOURCE_PATH + "CollectionInput.json"), org.onap.aai.domain.yang.Collection.class);
439
440         Collection expectedCollection =
441                 mapper.readValue(new File(RESOURCE_PATH + "CollectionExpected.json"), Collection.class);
442
443         Collection actualCollection = bbInputSetupMapperLayer.mapAAICollectionIntoCollection(aaiCollection);
444
445         assertThat(actualCollection, sameBeanAs(expectedCollection));
446     }
447
448     @Test
449     public void testMapAAIInstanceGroupIntoInstanceGroup()
450             throws JsonParseException, JsonMappingException, IOException {
451         org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup = mapper.readValue(
452                 new File(RESOURCE_PATH + "InstanceGroupInput.json"), org.onap.aai.domain.yang.InstanceGroup.class);
453
454         org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup expectedInstanceGroup =
455                 mapper.readValue(new File(RESOURCE_PATH + "InstanceGroupExpected.json"),
456                         org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup.class);
457
458         org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup actualInstanceGroup =
459                 bbInputSetupMapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstanceGroup);
460
461         assertThat(actualInstanceGroup, sameBeanAs(expectedInstanceGroup));
462     }
463
464     @Test
465     public void testMapAAIRouteTableReferenceIntoRouteTableReference()
466             throws JsonParseException, JsonMappingException, IOException {
467         org.onap.aai.domain.yang.RouteTableReference aaiRouteTableReference =
468                 mapper.readValue(new File(RESOURCE_PATH + "RouteTableReferenceInput.json"),
469                         org.onap.aai.domain.yang.RouteTableReference.class);
470
471         RouteTableReference expectedRouteTableReference = mapper
472                 .readValue(new File(RESOURCE_PATH + "RouteTableReferenceExpected.json"), RouteTableReference.class);
473
474         RouteTableReference actualRouteTableReference =
475                 bbInputSetupMapperLayer.mapAAIRouteTableReferenceIntoRouteTableReference(aaiRouteTableReference);
476
477         assertThat(actualRouteTableReference, sameBeanAs(expectedRouteTableReference));
478     }
479
480     @Test
481     public void testMapCatalogNetworkToNetwork() throws JsonParseException, JsonMappingException, IOException {
482         NetworkResourceCustomization networkResourceCustomization = mapper.readValue(
483                 new File(RESOURCE_PATH + "NetworkResourceCustomizationInput.json"), NetworkResourceCustomization.class);
484
485         ModelInfoNetwork expectedModelInfoNetwork =
486                 mapper.readValue(new File(RESOURCE_PATH + "ModelInfoNetworkExpected.json"), ModelInfoNetwork.class);
487
488         ModelInfoNetwork actualModelInfoNetwork =
489                 bbInputSetupMapperLayer.mapCatalogNetworkToNetwork(networkResourceCustomization);
490
491         assertThat(actualModelInfoNetwork, sameBeanAs(expectedModelInfoNetwork));
492     }
493
494     @Test
495     public void testMapCatalogVnfToVnf() throws IOException {
496         VnfResourceCustomization vnfResourceCustomization = mapper.readValue(
497                 new File(RESOURCE_PATH + "VnfResourceCustomizationInput.json"), VnfResourceCustomization.class);
498
499         ModelInfoGenericVnf expectedModelInfoGenericVnf = mapper
500                 .readValue(new File(RESOURCE_PATH + "ModelInfoGenericVnfExpected.json"), ModelInfoGenericVnf.class);
501
502         ModelInfoGenericVnf actualModelInfoGenericVnf =
503                 bbInputSetupMapperLayer.mapCatalogVnfToVnf(vnfResourceCustomization);
504
505         assertThat(actualModelInfoGenericVnf, sameBeanAs(expectedModelInfoGenericVnf));
506     }
507
508     @Test
509     public void testMapCatalogVfModuleToVfModule() throws JsonParseException, JsonMappingException, IOException {
510         VfModuleCustomization vfResourceCustomization = mapper
511                 .readValue(new File(RESOURCE_PATH + "VfModuleCustomizationInput.json"), VfModuleCustomization.class);
512
513         ModelInfoVfModule expectedModelInfoVfModule =
514                 mapper.readValue(new File(RESOURCE_PATH + "ModelInfoVfModuleExpected.json"), ModelInfoVfModule.class);
515
516         ModelInfoVfModule actualModelInfoVfModule =
517                 bbInputSetupMapperLayer.mapCatalogVfModuleToVfModule(vfResourceCustomization);
518
519         assertThat(actualModelInfoVfModule, sameBeanAs(expectedModelInfoVfModule));
520     }
521
522     @Test
523     public void testMapRequestPlatform() throws JsonParseException, JsonMappingException, IOException {
524         org.onap.so.serviceinstancebeans.Platform platform = mapper.readValue(
525                 new File(RESOURCE_PATH + "RequestPlatformInput.json"), org.onap.so.serviceinstancebeans.Platform.class);
526
527         Platform expectedPlatform = mapper.readValue(new File(RESOURCE_PATH + "PlatformExpected.json"), Platform.class);
528
529         Platform actualPlatform = bbInputSetupMapperLayer.mapRequestPlatform(platform);
530
531         assertThat(actualPlatform, sameBeanAs(expectedPlatform));
532     }
533
534     @Test
535     public void testMapRequestLineOfBusiness() throws JsonParseException, JsonMappingException, IOException {
536         org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness =
537                 mapper.readValue(new File(RESOURCE_PATH + "RequestLineOfBusinessInput.json"),
538                         org.onap.so.serviceinstancebeans.LineOfBusiness.class);
539
540         LineOfBusiness expectedLineOfBusiness =
541                 mapper.readValue(new File(RESOURCE_PATH + "LineOfBusinessExpected.json"), LineOfBusiness.class);
542
543         LineOfBusiness actualLineOfBusiness = bbInputSetupMapperLayer.mapRequestLineOfBusiness(lineOfBusiness);
544
545         assertThat(actualLineOfBusiness, sameBeanAs(expectedLineOfBusiness));
546     }
547
548     @Test
549     public void testMapAAIConfiguration() throws JsonParseException, JsonMappingException, IOException {
550         org.onap.aai.domain.yang.Configuration configurationAAI = mapper.readValue(
551                 new File(RESOURCE_PATH + "ConfigurationInput.json"), org.onap.aai.domain.yang.Configuration.class);
552
553         Configuration expectedConfiguration =
554                 mapper.readValue(new File(RESOURCE_PATH + "ConfigurationExpected.json"), Configuration.class);
555
556         Configuration actualConfiguration = bbInputSetupMapperLayer.mapAAIConfiguration(configurationAAI);
557
558         assertThat(actualConfiguration, sameBeanAs(expectedConfiguration));
559     }
560
561     @Test
562     public void testMapRequestContext() throws IOException {
563         RequestContext expected =
564                 mapper.readValue(new File(RESOURCE_PATH + "RequestContextExpected.json"), RequestContext.class);
565
566         RequestDetails requestDetails = mapper
567                 .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_mapReqContext.json"), RequestDetails.class);
568         RequestContext actual = bbInputSetupMapperLayer.mapRequestContext(requestDetails);
569
570         assertThat(actual, sameBeanAs(expected));
571     }
572
573     @Test
574     public void testMapOrchestrationContext() throws IOException {
575         OrchestrationContext expected = new OrchestrationContext();
576         expected.setIsRollbackEnabled(true);
577
578         RequestDetails requestDetails = mapper
579                 .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_mapReqContext.json"), RequestDetails.class);
580
581         OrchestrationContext actual = bbInputSetupMapperLayer.mapOrchestrationContext(requestDetails);
582
583         assertThat(actual, sameBeanAs(expected));
584     }
585
586     @Test
587     public void testMapOrchestrationContextNoRequestInfo() throws IOException {
588         OrchestrationContext expected = new OrchestrationContext();
589         expected.setIsRollbackEnabled(false);
590
591         RequestDetails requestDetails = mapper.readValue(
592                 new File(RESOURCE_PATH + "RequestDetailsInput_mapReqContextNoRequestInfo.json"), RequestDetails.class);
593
594         OrchestrationContext actual = bbInputSetupMapperLayer.mapOrchestrationContext(requestDetails);
595
596         assertThat(actual, sameBeanAs(expected));
597     }
598
599     @Test
600     public void testMapLocationContext() {
601         CloudRegion expected = new CloudRegion();
602         expected.setCloudOwner("test-owner-name");
603         expected.setLcpCloudRegionId("cloudRegionId");
604         expected.setComplex("complexName");
605         expected.setTenantId("tenantId");
606         CloudConfiguration cloudConfig = new CloudConfiguration();
607         cloudConfig.setTenantId("tenantId");
608         cloudConfig.setLcpCloudRegionId("cloudRegionId");
609         cloudConfig.setAicNodeClli("aicNodeClli");
610         org.onap.aai.domain.yang.CloudRegion cloudRegion = new org.onap.aai.domain.yang.CloudRegion();
611         cloudRegion.setCloudOwner("test-owner-name");
612         cloudRegion.setCloudRegionId("cloudRegionId");
613         cloudRegion.setComplexName("complexName");
614
615         CloudRegion actual = bbInputSetupMapperLayer.mapCloudRegion(cloudConfig, cloudRegion);
616
617         assertThat(actual, sameBeanAs(expected));
618     }
619
620     @Test
621     public void testMapCloudRegion() {
622         CloudRegion expected = new CloudRegion();
623         expected.setCloudOwner("test-owner-name");
624         expected.setLcpCloudRegionId("cloudRegionId");
625         expected.setTenantId("tenantId");
626         expected.setCloudRegionVersion("cloudRegionVersion");
627
628         CloudConfiguration cloudConfig = new CloudConfiguration();
629         cloudConfig.setTenantId("tenantId");
630         cloudConfig.setLcpCloudRegionId("cloudRegionId");
631         cloudConfig.setAicNodeClli("aicNodeClli");
632
633         org.onap.aai.domain.yang.CloudRegion cloudRegion = new org.onap.aai.domain.yang.CloudRegion();
634         cloudRegion.setCloudOwner("test-owner-name");
635         cloudRegion.setCloudRegionId("cloudRegionId");
636         cloudRegion.setCloudRegionVersion("cloudRegionVersion");
637
638         CloudRegion actual = bbInputSetupMapperLayer.mapCloudRegion(cloudConfig, cloudRegion);
639
640         assertThat(actual, sameBeanAs(expected));
641     }
642
643     @Test
644     public void testMapTenant() {
645         Tenant expected = new Tenant();
646         expected.setTenantId("tenantId");
647         expected.setTenantName("tenantName");
648         expected.setTenantContext("tenantContext");
649
650         org.onap.aai.domain.yang.Tenant aaiTenant = new org.onap.aai.domain.yang.Tenant();
651         aaiTenant.setTenantId("tenantId");
652         aaiTenant.setTenantName("tenantName");
653         aaiTenant.setTenantContext("tenantContext");
654
655         Tenant actual = bbInputSetupMapperLayer.mapTenant(aaiTenant);
656
657         assertThat(actual, sameBeanAs(expected));
658     }
659
660     @Test
661     public void testMapCloudRegionWithNullCheck() {
662         CloudRegion expected = new CloudRegion();
663
664         CloudRegion actual = bbInputSetupMapperLayer.mapCloudRegion(null, null);
665
666         assertThat(actual, sameBeanAs(expected));
667     }
668
669     @Test
670     public void testmapCatalogConfigurationToConfiguration() {
671         String modelCustUUID = "modelCustomizationUUID";
672         String modelInvariantUUID = "modelInvariantUUID";
673         String modelVersionUUID = "modelUUID";
674         String policyName = "policyName";
675         ModelInfoConfiguration expected = new ModelInfoConfiguration();
676         expected.setModelCustomizationId(modelCustUUID);
677         expected.setModelInvariantId(modelInvariantUUID);
678         expected.setModelVersionId(modelVersionUUID);
679         expected.setPolicyName(policyName);
680         ConfigurationResourceCustomization configurationResourceCustomization =
681                 new ConfigurationResourceCustomization();
682         configurationResourceCustomization.setModelCustomizationUUID(modelCustUUID);
683         configurationResourceCustomization.setConfigurationResource(new ConfigurationResource());
684         configurationResourceCustomization.getConfigurationResource().setModelInvariantUUID(modelInvariantUUID);
685         configurationResourceCustomization.getConfigurationResource().setModelUUID(modelVersionUUID);
686         CvnfcConfigurationCustomization policyNameTable = new CvnfcConfigurationCustomization();
687         policyNameTable.setCvnfcCustomization(new CvnfcCustomization());
688         policyNameTable.getCvnfcCustomization().setVnfcCustomization(new VnfcCustomization());
689         policyNameTable.setPolicyName(policyName);
690
691         ModelInfoConfiguration actual = bbInputSetupMapperLayer
692                 .mapCatalogConfigurationToConfiguration(configurationResourceCustomization, policyNameTable);
693
694         assertThat(actual, sameBeanAs(expected));
695     }
696
697     @Test
698     public void testmapCatalogConfigurationToFabricConfiguration() {
699         String modelCustUUID = "modelCustomizationUUID";
700         String modelInvariantUUID = "modelInvariantUUID";
701         String modelVersionUUID = "modelUUID";
702         String policyName = "policyName";
703         ModelInfoConfiguration expected = new ModelInfoConfiguration();
704         expected.setModelCustomizationId(modelCustUUID);
705         expected.setModelInvariantId(modelInvariantUUID);
706         expected.setModelVersionId(modelVersionUUID);
707         expected.setPolicyName(policyName);
708
709         CvnfcConfigurationCustomization fabricCustomization = new CvnfcConfigurationCustomization();
710         fabricCustomization.setCvnfcCustomization(new CvnfcCustomization());
711         fabricCustomization.getCvnfcCustomization().setVnfcCustomization(new VnfcCustomization());
712         fabricCustomization.setPolicyName(policyName);
713         fabricCustomization.setModelCustomizationUUID(modelCustUUID);
714
715         ConfigurationResource configurationResource = new ConfigurationResource();
716         configurationResource.setModelUUID(modelVersionUUID);
717         configurationResource.setModelInvariantUUID(modelInvariantUUID);
718         fabricCustomization.setConfigurationResource(configurationResource);
719
720         ModelInfoConfiguration actual =
721                 bbInputSetupMapperLayer.mapCatalogConfigurationToConfiguration(fabricCustomization);
722
723         assertThat(actual, sameBeanAs(expected));
724     }
725
726     @Test
727     public void testMapNameValueUserParams() throws IOException {
728         RequestDetails requestDetails = mapper
729                 .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_mapReqContext.json"), RequestDetails.class);
730         Map<String, Object> actual =
731                 bbInputSetupMapperLayer.mapNameValueUserParams(requestDetails.getRequestParameters());
732
733         assertTrue(actual.containsKey("mns_vfw_protected_route_prefixes"));
734         assertTrue(actual.get("mns_vfw_protected_route_prefixes").toString()
735                 .contains("interface_route_table_routes_route"));
736         assertTrue(actual.get("mns_vfw_protected_route_prefixes").toString().contains("1.1.1.1/32"));
737         assertTrue(actual.get("mns_vfw_protected_route_prefixes").toString().contains("0::1/128"));
738         assertTrue(actual.containsKey("name1"));
739         assertTrue(actual.containsValue("value1"));
740         assertTrue(actual.get("name1").equals("value1"));
741
742         assertFalse(actual.containsKey("ignore"));
743         assertFalse(actual.containsValue("ignore"));
744     }
745
746     @Test
747     public void testMapRequestParameters() throws IOException {
748         RequestDetails requestDetails = mapper
749                 .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_mapReqContext.json"), RequestDetails.class);
750         RequestParameters actual = bbInputSetupMapperLayer.mapRequestParameters(requestDetails.getRequestParameters());
751
752         assertEquals(actual.getUsePreload(), requestDetails.getRequestParameters().getUsePreload());
753         assertEquals(actual.getSubscriptionServiceType(),
754                 requestDetails.getRequestParameters().getSubscriptionServiceType());
755         assertEquals(actual.getPayload(), requestDetails.getRequestParameters().getPayload());
756     }
757
758     protected RequestParameters mapRequestParameters(
759             org.onap.so.serviceinstancebeans.RequestParameters requestParameters) {
760         RequestParameters requestParams = new RequestParameters();
761         requestParams.setaLaCarte(requestParameters.getALaCarte());
762         requestParams.setUsePreload(requestParameters.getUsePreload());
763         requestParams.setSubscriptionServiceType(requestParameters.getSubscriptionServiceType());
764         requestParams.setUserParams(requestParameters.getUserParams());
765         requestParams.setPayload(requestParameters.getPayload());
766         return requestParams;
767     }
768
769 }