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