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