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