599c99b435421110b377150b9e5ac47071602dff
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / db / catalog / client / CatalogDbClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.db.catalog.client;
22
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.List;
29 import java.util.UUID;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.onap.so.adapters.catalogdb.CatalogDBApplication;
35 import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest;
36 import org.onap.so.db.catalog.beans.AuthenticationType;
37 import org.onap.so.db.catalog.beans.CloudIdentity;
38 import org.onap.so.db.catalog.beans.CloudSite;
39 import org.onap.so.db.catalog.beans.CloudifyManager;
40 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
41 import org.onap.so.db.catalog.beans.HomingInstance;
42 import org.onap.so.db.catalog.beans.InstanceGroup;
43 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
44 import org.onap.so.db.catalog.beans.PnfResource;
45 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
46 import org.onap.so.db.catalog.beans.ServerType;
47 import org.onap.so.db.catalog.beans.Service;
48 import org.onap.so.db.catalog.beans.ServiceRecipe;
49 import org.onap.so.db.catalog.beans.VfModule;
50 import org.onap.so.db.catalog.beans.VfModuleCustomization;
51 import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
52 import org.onap.so.db.catalog.beans.VnfRecipe;
53 import org.onap.so.db.catalog.beans.VnfResource;
54 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
55 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
56 import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
57 import org.springframework.beans.factory.annotation.Autowired;
58 import org.springframework.beans.factory.annotation.Value;
59 import org.springframework.boot.test.context.SpringBootTest;
60 import org.springframework.boot.web.server.LocalServerPort;
61 import org.springframework.test.context.ActiveProfiles;
62 import org.springframework.test.context.junit4.SpringRunner;
63
64 public class CatalogDbClientTest extends CatalogDbAdapterBaseTest {
65
66     public static final String MTN13 = "mtn13";
67
68     @LocalServerPort
69     private int port;
70
71     @Value("${mso.db.auth}")
72     private String msoAdaptersAuth;
73
74     @Autowired
75     CatalogDbClientPortChanger client;
76
77     @Before
78     public void initialize() {
79         client.wiremockPort = String.valueOf(port);
80     }
81
82     @Test
83     public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep() {
84         RainyDayHandlerStatus rainyDayHandlerStatus = client
85             .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(
86                 "AssignServiceInstanceBB", "*", "*", "*", "*");
87         Assert.assertEquals("Rollback", rainyDayHandlerStatus.getPolicy());
88     }
89
90     @Test
91     public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStepRecordNotFound() {
92         RainyDayHandlerStatus rainyDayHandlerStatus = client
93             .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(
94                 UUID.randomUUID().toString(), "*", "*", "*", "*");
95         Assert.assertNull(rainyDayHandlerStatus);
96     }
97
98     @Test
99     public void testGetCloudSiteHappyPath() throws Exception {
100         CloudSite cloudSite = client.getCloudSite(MTN13);
101         Assert.assertNotNull(cloudSite);
102         Assert.assertNotNull(cloudSite.getIdentityService());
103         Assert.assertEquals("MDT13", cloudSite.getClli());
104         Assert.assertEquals("mtn13", cloudSite.getRegionId());
105         Assert.assertEquals("MTN13", cloudSite.getIdentityServiceId());
106     }
107
108     @Test
109     public void testGetCloudSiteNotFound() throws Exception {
110         CloudSite cloudSite = client.getCloudSite(UUID.randomUUID().toString());
111         Assert.assertNull(cloudSite);
112     }
113
114     @Test
115     public void testGetCloudifyManagerHappyPath() throws Exception {
116         CloudifyManager cloudifyManager = client.getCloudifyManager("mtn13");
117         Assert.assertNotNull(cloudifyManager);
118         Assert.assertEquals("http://localhost:28090/v2.0", cloudifyManager.getCloudifyUrl());
119
120     }
121
122     @Test
123     public void testGetCloudifyManagerNotFound() throws Exception {
124         CloudifyManager cloudifyManager = client.getCloudifyManager(UUID.randomUUID().toString());
125         Assert.assertNull(cloudifyManager);
126     }
127
128
129     @Test
130     public void testGetCloudSiteByClliAndAicVersionHappyPath() throws Exception {
131         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "2.5");
132         Assert.assertNotNull(cloudSite);
133     }
134
135     @Test
136     public void testGetCloudSiteByClliAndAicVersionNotFound() throws Exception {
137         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "232496239746328");
138         Assert.assertNull(cloudSite);
139     }
140
141     @Test
142     public void testGetServiceByID() throws Exception {
143         Service serviceByID = client.getServiceByID("5df8b6de-2083-11e7-93ae-92361f002671");
144         Assert.assertNotNull(serviceByID);
145         Assert.assertEquals("MSOTADevInfra_vSAMP10a_Service", serviceByID.getModelName());
146         Assert.assertEquals("NA", serviceByID.getServiceType());
147         Assert.assertEquals("NA", serviceByID.getServiceRole());
148     }
149
150     @Test
151     public void testGetServiceByIDNotFound() throws Exception {
152         Service serviceByID = client.getServiceByID(UUID.randomUUID().toString());
153         Assert.assertNull(serviceByID);
154     }
155
156     @Test
157     public void testGetVfModuleByModelUUID() throws Exception {
158         VfModule vfModule = client.getVfModuleByModelUUID("20c4431c-246d-11e7-93ae-92361f002671");
159         Assert.assertNotNull(vfModule);
160         Assert.assertNotNull(vfModule.getVfModuleCustomization());
161         Assert.assertEquals("78ca26d0-246d-11e7-93ae-92361f002671", vfModule.getModelInvariantUUID());
162         Assert.assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
163     }
164
165     @Test
166     public void testGetVfModuleByModelUUIDNotFound() throws Exception {
167         VfModule vfModule = client.getVfModuleByModelUUID(UUID.randomUUID().toString());
168         Assert.assertNull(vfModule);
169     }
170
171     @Test
172     public void testGetVnfResourceByModelUUID() throws Exception {
173         VnfResource vnfResource = client.getVnfResourceByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
174         Assert.assertNotNull(vnfResource);
175         Assert.assertEquals("vSAMP10a", vnfResource.getModelName());
176     }
177
178     @Test
179     public void testGetVnfResourceByModelUUIDNotFound() throws Exception {
180         VnfResource vnfResource = client.getVnfResourceByModelUUID(UUID.randomUUID().toString());
181         Assert.assertNull(vnfResource);
182     }
183
184     @Test
185     public void testGetVnfResourceCustomizationByModelCustomizationUUID() {
186         VnfResourceCustomization vnfResourceCustomization = client
187             .getVnfResourceCustomizationByModelCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002671");
188         Assert.assertNotNull(vnfResourceCustomization);
189         Assert.assertEquals("vSAMP", vnfResourceCustomization.getNfRole());
190         Assert.assertNotNull(vnfResourceCustomization.getModelCustomizationUUID());
191         Assert.assertNotNull(vnfResourceCustomization.getVnfResources());
192         Assert.assertNotNull(vnfResourceCustomization.getVfModuleCustomizations());
193         Assert.assertEquals("vSAMP10a", vnfResourceCustomization.getVnfResources().getModelName());
194         assertTrue("skip post instantiation configuration", vnfResourceCustomization.isSkipPostInstConf());
195     }
196
197     @Test
198     public void testGetVnfResourceCustomizationByModelCustomizationUUINotFound() {
199         VnfResourceCustomization vnfResourceCustomization = client
200             .getVnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
201         Assert.assertNull(vnfResourceCustomization);
202     }
203
204     @Test
205     public void testGetInstanceGroupByModelUUID() {
206         InstanceGroup instanceGroup = client.getInstanceGroupByModelUUID("0c8692ef-b9c0-435d-a738-edf31e71f38b");
207         Assert.assertNotNull(instanceGroup);
208         Assert.assertEquals("network_collection_resource_1806..NetworkCollection..0", instanceGroup.getModelName());
209         Assert.assertEquals("org.openecomp.resource.cr.NetworkCollectionResource1806",
210             instanceGroup.getToscaNodeType().toString());
211     }
212
213     @Test
214     public void testGetVfModuleCustomizationByModelCuztomizationUUID() {
215         VfModuleCustomization vfModuleCustomization = client
216             .getVfModuleCustomizationByModelCuztomizationUUID("cb82ffd8-252a-11e7-93ae-92361f002671");
217         Assert.assertNotNull(vfModuleCustomization);
218         Assert.assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
219         Assert.assertEquals("base", vfModuleCustomization.getLabel());
220     }
221
222     @Test
223     public void testGetVfModuleCustomizationByModelCuztomizationUUIDNotFound() {
224         VfModuleCustomization vfModuleCustomization = client
225             .getVfModuleCustomizationByModelCuztomizationUUID(UUID.randomUUID().toString());
226         Assert.assertNull(vfModuleCustomization);
227     }
228
229     @Test
230     public void testGetNetworkResourceCustomizationByModelCustomizationUUID() {
231         NetworkResourceCustomization networkResourceCustomization = client
232             .getNetworkResourceCustomizationByModelCustomizationUUID("3bdbb104-476c-483e-9f8b-c095b3d308ac");
233         Assert.assertNotNull(networkResourceCustomization);
234         Assert.assertNotNull(networkResourceCustomization.getModelCustomizationUUID());
235         Assert.assertEquals("CONTRAIL30_GNDIRECT 9", networkResourceCustomization.getModelInstanceName());
236         Assert.assertNotNull(networkResourceCustomization.getNetworkResource());
237     }
238
239     @Test
240     public void testGetNetworkResourceCustomizationByModelCustomizationUUIDNotFound() {
241         NetworkResourceCustomization networkResourceCustomization = client
242             .getNetworkResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
243         Assert.assertNull(networkResourceCustomization);
244     }
245
246     @Test
247     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID() {
248         VfModuleCustomization vfModuleCustomization = client
249             .getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
250                 "cb82ffd8-252a-11e7-93ae-92361f002672", "20c4431c-246d-11e7-93ae-92361f002672");
251         Assert.assertNotNull(vfModuleCustomization);
252         Assert.assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
253         Assert.assertNotNull(vfModuleCustomization.getVfModule());
254         Assert.assertEquals("base", vfModuleCustomization.getLabel());
255     }
256
257     @Test
258     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUIDNotFound() {
259         VfModuleCustomization vfModuleCustomization = client
260             .getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
261                 "cb82ffd8-252a-11e7-93ae-92361f002672", UUID.randomUUID().toString());
262         Assert.assertNull(vfModuleCustomization);
263     }
264
265     @Test
266     public void testGetFirstByServiceModelUUIDAndAction() {
267         ServiceRecipe serviceRecipe = client
268             .getFirstByServiceModelUUIDAndAction("4694a55f-58b3-4f17-92a5-796d6f5ffd0d", "createInstance");
269         Assert.assertNotNull(serviceRecipe);
270         Assert.assertNotNull(serviceRecipe.getServiceModelUUID());
271         Assert.assertNotNull(serviceRecipe.getAction());
272         Assert.assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance",
273             serviceRecipe.getOrchestrationUri());
274         Assert.assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
275     }
276
277     @Test
278     public void testGetFirstByServiceModelUUIDAndActionNotFound() {
279         ServiceRecipe serviceRecipe = client
280             .getFirstByServiceModelUUIDAndAction("5df8b6de-2083-11e7-93ae-92361f002671", UUID.randomUUID().toString());
281         Assert.assertNull(serviceRecipe);
282     }
283
284     @Test
285     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersion() {
286         VnfResource vnfResource = client
287             .getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671", "2.0");
288         Assert.assertNotNull(vnfResource);
289         Assert.assertNotNull(vnfResource.getModelInvariantId());
290         Assert.assertNotNull(vnfResource.getModelVersion());
291         Assert.assertNotNull(vnfResource.getHeatTemplates());
292         Assert.assertNotNull(vnfResource.getVnfResourceCustomizations());
293         Assert.assertEquals("vSAMP10a", vnfResource.getModelName());
294     }
295
296     @Test
297     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersionNotFound() {
298         VnfResource vnfResource = client
299             .getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671",
300                 UUID.randomUUID().toString());
301         Assert.assertNull(vnfResource);
302     }
303
304     @Test
305     public void testGetFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources() {
306         VnfResource vnfr = new VnfResource();
307         vnfr.setModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
308         VnfResourceCustomization firstVnfResourceCustomizationByModelInstanceNameAndVnfResources = client
309             .getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources("vSAMP10a 1", vnfr);
310         Assert.assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources);
311         Assert.assertEquals("vSAMP", firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getNfRole());
312         Assert.assertEquals("vSAMP10a 1",
313             firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getModelInstanceName());
314         Assert.assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVnfResources());
315         Assert
316             .assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVfModuleCustomizations());
317     }
318
319     @Test
320     public void testGetFirstVnfRecipeByNfRoleAndAction() {
321         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction("GR-API-DEFAULT", "createInstance");
322         Assert.assertNotNull(vnfRecipe);
323         Assert.assertNotNull(vnfRecipe.getNfRole());
324         Assert.assertNotNull(vnfRecipe.getAction());
325         Assert.assertEquals("Gr api recipe to create vnf", vnfRecipe.getDescription());
326         Assert.assertEquals("/mso/async/services/WorkflowActionBB", vnfRecipe.getOrchestrationUri());
327     }
328
329     @Test
330     public void testGetFirstVnfRecipeByNfRoleAndActionNotFound() {
331         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction(UUID.randomUUID().toString(), "createInstance");
332         Assert.assertNull(vnfRecipe);
333     }
334
335     @Test
336     public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction() {
337         VnfComponentsRecipe vnfComponentsRecipe = client
338             .getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(
339                 "20c4431c-246d-11e7-93ae-92361f002671", "volumeGroup", "createInstance");
340         Assert.assertNotNull(vnfComponentsRecipe);
341         Assert.assertNotNull(vnfComponentsRecipe.getAction());
342         Assert.assertNotNull(vnfComponentsRecipe.getVfModuleModelUUID());
343         Assert.assertNotNull(vnfComponentsRecipe.getVnfComponentType());
344         Assert.assertEquals("Gr api recipe to create volume-group", vnfComponentsRecipe.getDescription());
345         Assert.assertEquals("/mso/async/services/WorkflowActionBB", vnfComponentsRecipe.getOrchestrationUri());
346
347     }
348
349
350     @Test
351     public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndActionNotFound() {
352         VnfComponentsRecipe vnfComponentsRecipe = client
353             .getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(UUID.randomUUID().toString(),
354                 "volumeGroup", "createInstance");
355         Assert.assertNull(vnfComponentsRecipe);
356     }
357
358     @Test
359     public void testGetFirstVnfComponentsRecipeByVnfComponentTypeAndAction() {
360         VnfComponentsRecipe vnfComponentsRecipe = client
361             .getFirstVnfComponentsRecipeByVnfComponentTypeAndAction("volumeGroup", "createInstance");
362         Assert.assertNotNull(vnfComponentsRecipe);
363         Assert.assertNotNull(vnfComponentsRecipe.getAction());
364         Assert.assertNotNull(vnfComponentsRecipe.getVnfComponentType());
365         Assert.assertEquals("VID_DEFAULT recipe t", vnfComponentsRecipe.getDescription());
366         Assert
367             .assertEquals("/mso/async/services/CreateVfModuleVolumeInfraV1", vnfComponentsRecipe.getOrchestrationUri());
368     }
369
370     @Test
371     public void testGetServiceByModelVersionAndModelInvariantUUID() {
372         Service service = client
373             .getServiceByModelVersionAndModelInvariantUUID("2.0", "9647dfc4-2083-11e7-93ae-92361f002671");
374         Assert.assertNotNull(service);
375         Assert.assertNotNull(service.getModelVersion());
376         Assert.assertNotNull(service.getModelInvariantUUID());
377         Assert.assertEquals("MSOTADevInfra_vSAMP10a_Service", service.getModelName());
378         Assert.assertEquals("NA", service.getServiceRole());
379     }
380
381     @Test
382     public void testGetServiceByModelVersionAndModelInvariantUUIDNotFound() {
383         Service service = client.getServiceByModelVersionAndModelInvariantUUID("2.0", UUID.randomUUID().toString());
384         Assert.assertNull(service);
385     }
386
387     @Test
388     public void testGetVfModuleByModelInvariantUUIDAndModelVersion() {
389         VfModule vfModule = client
390             .getVfModuleByModelInvariantUUIDAndModelVersion("78ca26d0-246d-11e7-93ae-92361f002671", "2");
391         Assert.assertNotNull(vfModule);
392         Assert.assertNotNull(vfModule.getModelVersion());
393         Assert.assertNotNull(vfModule.getModelInvariantUUID());
394         Assert.assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
395         Assert.assertEquals("vSAMP10a DEV Base", vfModule.getDescription());
396     }
397
398     @Test
399     public void testGetVfModuleByModelInvariantUUIDAndModelVersionNotFound() {
400         VfModule vfModule = client.getVfModuleByModelInvariantUUIDAndModelVersion(UUID.randomUUID().toString(), "2");
401         Assert.assertNull(vfModule);
402     }
403
404     @Test
405     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDesc() {
406         List<Service> serviceList = client
407             .getServiceByModelInvariantUUIDOrderByModelVersionDesc("9647dfc4-2083-11e7-93ae-92361f002671");
408         Assert.assertFalse(serviceList.isEmpty());
409         Assert.assertEquals(2, serviceList.size());
410         Service service = serviceList.get(0);
411         Assert.assertEquals("2.0", service.getModelVersion());
412     }
413
414     @Test
415     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDescNotFound() {
416         List<Service> serviceList = client
417             .getServiceByModelInvariantUUIDOrderByModelVersionDesc(UUID.randomUUID().toString());
418         Assert.assertTrue(serviceList.isEmpty());
419     }
420
421     @Test
422     public void testGetVfModuleByModelInvariantUUIDOrderByModelVersionDesc() {
423         List<VfModule> moduleList = client
424             .getVfModuleByModelInvariantUUIDOrderByModelVersionDesc("78ca26d0-246d-11e7-93ae-92361f002671");
425         Assert.assertFalse(moduleList.isEmpty());
426         Assert.assertEquals(2, moduleList.size());
427         VfModule module = moduleList.get(0);
428         Assert.assertEquals("vSAMP10a DEV Base", module.getDescription());
429     }
430
431     @Test
432     public void testPostCloudSite() {
433         CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger(
434             "http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
435         CloudSite cloudSite = new CloudSite();
436         cloudSite.setId("MTN6");
437         cloudSite.setClli("TESTCLLI");
438         cloudSite.setRegionId("regionId");
439         cloudSite.setCloudVersion("VERSION");
440         cloudSite.setPlatform("PLATFORM");
441
442         CloudIdentity cloudIdentity = new CloudIdentity();
443         cloudIdentity.setId("RANDOMID");
444         cloudIdentity.setIdentityUrl("URL");
445         cloudIdentity.setMsoId("MSO_ID");
446         cloudIdentity.setMsoPass("MSO_PASS");
447         cloudIdentity.setAdminTenant("ADMIN_TENANT");
448         cloudIdentity.setMemberRole("ROLE");
449         cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
450         cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
451         cloudSite.setIdentityService(cloudIdentity);
452         localClient.postCloudSite(cloudSite);
453         CloudSite getCloudSite = this.client.getCloudSite("MTN6");
454         Assert.assertNotNull(getCloudSite);
455         Assert.assertNotNull(getCloudSite.getIdentityService());
456         Assert.assertEquals("TESTCLLI", getCloudSite.getClli());
457         Assert.assertEquals("regionId", getCloudSite.getRegionId());
458         Assert.assertEquals("RANDOMID", getCloudSite.getIdentityServiceId());
459     }
460
461     @Test
462     public void testGetHomingInstance() {
463         HomingInstance homingInstance = client.getHomingInstance("5df8b6de-2083-11e7-93ae-92361f232671");
464         Assert.assertNotNull(homingInstance);
465         Assert.assertNotNull(homingInstance.getCloudOwner());
466         Assert.assertNotNull(homingInstance.getCloudRegionId());
467         Assert.assertNotNull(homingInstance.getOofDirectives());
468     }
469
470     @Test
471     public void testPostHomingInstance() {
472         CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger(
473             "http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
474         HomingInstance homingInstance = new HomingInstance();
475         homingInstance.setServiceInstanceId("5df8d6be-2083-11e7-93ae-92361f232671");
476         homingInstance.setCloudOwner("CloudOwner-1");
477         homingInstance.setCloudRegionId("CloudRegionOne");
478         homingInstance.setOofDirectives("{\n" +
479             "\"directives\": [\n" +
480             "{\n" +
481             "\"directives\": [\n" +
482             "{\n" +
483             "\"attributes\": [\n" +
484             "{\n" +
485             "\"attribute_value\": \"onap.hpa.flavor31\",\n" +
486             "\"attribute_name\": \"firewall_flavor_name\"\n" +
487             "}\n" +
488             "],\n" +
489             "\"type\": \"flavor_directives\"\n" +
490             "}\n" +
491             "],\n" +
492             "\"type\": \"vnfc\",\n" +
493             "\"id\": \"vfw\"\n" +
494             "},\n" +
495             "{\n" +
496             "\"directives\": [\n" +
497             "{\n" +
498             "\"attributes\": [\n" +
499             "{\n" +
500             "\"attribute_value\": \"onap.hpa.flavor32\",\n" +
501             "\"attribute_name\": \"packetgen_flavor_name\"\n" +
502             "}\n" +
503             "],\n" +
504             "\"type\": \"flavor_directives\"\n" +
505             "}\n" +
506             "],\n" +
507             "\"type\": \"vnfc\",\n" +
508             "\"id\": \"vgenerator\"\n" +
509             "},\n" +
510             "{\n" +
511             "\"directives\": [\n" +
512             "{\n" +
513             "\"attributes\": [\n" +
514             "{\n" +
515             "\"attribute_value\": \"onap.hpa.flavor31\",\n" +
516             "\"attribute_name\": \"sink_flavor_name\"\n" +
517             "}\n" +
518             "],\n" +
519             "\"type\": \"flavor_directives\"\n" +
520             "}\n" +
521             "],\n" +
522             "\"type\": \"vnfc\",\n" +
523             "\"id\": \"vsink\"\n" +
524             "}\n" +
525             "]\n" +
526             "}");
527         localClient.postHomingInstance(homingInstance);
528         HomingInstance getHomingInstance = this.client.getHomingInstance("5df8d6be-2083-11e7-93ae-92361f232671");
529         Assert.assertNotNull(getHomingInstance);
530         Assert.assertNotNull(getHomingInstance.getCloudRegionId());
531         Assert.assertNotNull(getHomingInstance.getCloudOwner());
532         Assert.assertEquals("CloudOwner-1", getHomingInstance.getCloudOwner());
533         Assert.assertEquals("CloudRegionOne", getHomingInstance.getCloudRegionId());
534     }
535
536     @Test
537     public void testGetServiceByModelName() {
538         Service service = client.getServiceByModelName("MSOTADevInfra_Test_Service");
539         Assert.assertNotNull(service);
540         Assert.assertNotNull(service.getModelVersion());
541         Assert.assertNotNull(service.getModelInvariantUUID());
542         Assert.assertEquals("MSOTADevInfra_Test_Service", service.getModelName());
543         Assert.assertEquals("NA", service.getServiceRole());
544     }
545
546     @Test
547     public void testGetServiceByModelNameNotFound() {
548         Service service = client.getServiceByModelName("Not_Found");
549         Assert.assertNull(service);
550     }
551
552     @Test
553     public void testGetServiceByModelUUID() {
554         Service service = client.getServiceByModelUUID("5df8b6de-2083-11e7-93ae-92361f002679");
555         Assert.assertNotNull(service);
556         Assert.assertNotNull(service.getModelVersion());
557         Assert.assertNotNull(service.getModelInvariantUUID());
558         Assert.assertEquals("5df8b6de-2083-11e7-93ae-92361f002679", service.getModelUUID());
559         Assert.assertEquals("NA", service.getServiceRole());
560     }
561
562     @Test
563     public void testGetServiceByModelUUIDNotFound() {
564         Service service = client.getServiceByModelUUID("Not_Found");
565         Assert.assertNull(service);
566     }
567
568     @Test
569     public void testGetNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner() {
570         NorthBoundRequest northBoundRequest = new NorthBoundRequest();
571         northBoundRequest.setAction("createService");
572         northBoundRequest.setRequestScope("service");
573         northBoundRequest.setIsAlacarte(true);
574         northBoundRequest.setCloudOwner("my-custom-cloud-owner");
575         client.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner("createService", "service", true,
576             "my-custom-cloud-owner");
577         Assert.assertNotNull(northBoundRequest);
578         Assert.assertEquals("createService", northBoundRequest.getAction());
579         Assert.assertEquals("service", northBoundRequest.getRequestScope());
580         Assert.assertEquals(true, northBoundRequest.getIsAlacarte());
581         Assert.assertEquals("my-custom-cloud-owner", northBoundRequest.getCloudOwner());
582     }
583
584     @Test
585     public void testFindServiceRecipeByActionAndServiceModelUUID() {
586         ServiceRecipe serviceRecipe = client
587             .findServiceRecipeByActionAndServiceModelUUID("createInstance", "4694a55f-58b3-4f17-92a5-796d6f5ffd0d");
588         Assert.assertNotNull(serviceRecipe);
589         Assert.assertNotNull(serviceRecipe.getServiceModelUUID());
590         Assert.assertNotNull(serviceRecipe.getAction());
591         Assert.assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance",
592             serviceRecipe.getOrchestrationUri());
593         Assert.assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
594     }
595
596     @Test
597     public void testFindServiceRecipeByActionAndServiceModelUUIDNotFound() {
598         ServiceRecipe serviceRecipe = client
599             .findServiceRecipeByActionAndServiceModelUUID("not_found", "5df8b6de-2083-11e7-93ae-test");
600         Assert.assertNull(serviceRecipe);
601     }
602
603     @Test
604     public void testFindExternalToInternalServiceByServiceName() {
605         ExternalServiceToInternalService externalServiceToInternalService = client
606             .findExternalToInternalServiceByServiceName("MySpecialServiceName");
607         Assert.assertNotNull(externalServiceToInternalService);
608         Assert.assertNotNull(externalServiceToInternalService.getServiceName());
609         Assert.assertNotNull(externalServiceToInternalService.getServiceModelUUID());
610         Assert.assertEquals("MySpecialServiceName", externalServiceToInternalService.getServiceName());
611     }
612
613     @Test
614     public void testFindExternalToInternalServiceByServiceNameNotFound() {
615         ExternalServiceToInternalService externalServiceToInternalService = client
616             .findExternalToInternalServiceByServiceName("Not_Found");
617         Assert.assertNull(externalServiceToInternalService);
618     }
619
620     @Test
621     public void getPnfResourceByModelUUID_validUuid_expectedOutput() {
622         PnfResource pnfResource = client.getPnfResourceByModelUUID("ff2ae348-214a-11e7-93ae-92361f002680");
623         Assert.assertNotNull(pnfResource);
624         assertEquals("PNFResource modelUUID", "ff2ae348-214a-11e7-93ae-92361f002680", pnfResource.getModelUUID());
625         assertEquals("PNFResource modelInvariantUUID", "2fff5b20-214b-11e7-93ae-92361f002680",
626             pnfResource.getModelInvariantUUID());
627         assertEquals("PNFResource modelVersion", "1.0", pnfResource.getModelVersion());
628         assertEquals("PNFResource orchestration mode", "", pnfResource.getOrchestrationMode());
629     }
630
631     @Test
632     public void getPnfResourceByModelUUID_invalidUuid_NullOutput() {
633         PnfResource pnfResource = client.getPnfResourceByModelUUID(UUID.randomUUID().toString());
634         Assert.assertNull(pnfResource);
635     }
636
637     @Test
638     public void getPnfResourceCustomizationByModelCustomizationUUID_validUuid_expectedOutput() {
639         PnfResourceCustomization pnfResourceCustomization = client
640             .getPnfResourceCustomizationByModelCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002680");
641         assertEquals("modelInstanceName", "PNF routing", pnfResourceCustomization.getModelInstanceName());
642         assertEquals("blueprintName", "test_configuration_restconf", pnfResourceCustomization.getBlueprintName());
643         assertEquals("blueprintVersion", "1.0.0", pnfResourceCustomization.getBlueprintVersion());
644         assertTrue("skip post instantiation configuration", pnfResourceCustomization.isSkipPostInstConf());
645         PnfResource pnfResource = pnfResourceCustomization.getPnfResources();
646         assertNotNull(pnfResource);
647         assertEquals("PNFResource modelUUID", "ff2ae348-214a-11e7-93ae-92361f002680", pnfResource.getModelUUID());
648         assertEquals("PNFResource modelInvariantUUID", "2fff5b20-214b-11e7-93ae-92361f002680",
649             pnfResource.getModelInvariantUUID());
650         assertEquals("PNFResource modelVersion", "1.0", pnfResource.getModelVersion());
651         assertEquals("PNFResource orchestration mode", "", pnfResource.getOrchestrationMode());
652     }
653
654     @Test
655     public void getPnfResourceCustomizationByModelCustomizationUUID_invalidUuid_nullOutput() {
656         PnfResourceCustomization pnfResourceCustomization = client
657             .getPnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
658         Assert.assertNull(pnfResourceCustomization);
659     }
660
661 }