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