8ce4051b24147b99180abe175db20ff364d4bc36
[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.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30 import java.util.List;
31 import java.util.UUID;
32 import org.junit.Before;
33 import org.junit.Test;
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.BBNameSelectionReference;
37 import org.onap.so.db.catalog.beans.CloudIdentity;
38 import org.onap.so.db.catalog.beans.CloudSite;
39 import org.onap.so.db.catalog.beans.CloudifyManager;
40 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
41 import org.onap.so.db.catalog.beans.HomingInstance;
42 import org.onap.so.db.catalog.beans.InstanceGroup;
43 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
44 import org.onap.so.db.catalog.beans.PnfResource;
45 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
46 import org.onap.so.db.catalog.beans.ProcessingFlags;
47 import org.onap.so.db.catalog.beans.ServerType;
48 import org.onap.so.db.catalog.beans.Service;
49 import org.onap.so.db.catalog.beans.ServiceRecipe;
50 import org.onap.so.db.catalog.beans.VfModule;
51 import org.onap.so.db.catalog.beans.VfModuleCustomization;
52 import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
53 import org.onap.so.db.catalog.beans.VnfRecipe;
54 import org.onap.so.db.catalog.beans.VnfResource;
55 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
56 import org.onap.so.db.catalog.beans.Workflow;
57 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
58 import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.beans.factory.annotation.Value;
61 import org.springframework.boot.web.server.LocalServerPort;
62
63 public class CatalogDbClientTest extends CatalogDbAdapterBaseTest {
64
65     public static final String MTN13 = "mtn13";
66
67     @LocalServerPort
68     private int port;
69
70     @Value("${mso.db.auth}")
71     private String msoAdaptersAuth;
72
73     @Autowired
74     CatalogDbClientPortChanger client;
75
76
77
78     @Before
79     public void initialize() {
80         client.wiremockPort = String.valueOf(port);
81         client.setEndpoint(getEndpoint(port));
82     }
83
84     protected String getEndpoint(int port) {
85         return "http://localhost:" + port;
86     }
87
88     @Test
89     public void testGetRainyDayHandler_Regex() {
90         RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatus("AssignServiceInstanceBB", "*",
91                 "*", "*", "*", "The Flavor ID (nd.c6r16d20) could not be found.", "*");
92         assertEquals("Rollback", rainyDayHandlerStatus.getPolicy());
93     }
94
95     @Test
96     public void testGetRainyDayHandler__Encoding_Regex() {
97         RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatus("AssignServiceInstanceBB", "*",
98                 "*", "*", "*",
99                 "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",
100                 "*");
101         assertEquals("Rollback", rainyDayHandlerStatus.getPolicy());
102     }
103
104     @Test
105     public void testGetCloudSiteHappyPath() throws Exception {
106         CloudSite cloudSite = client.getCloudSite(MTN13);
107         assertNotNull(cloudSite);
108         assertNotNull(cloudSite.getIdentityService());
109         assertEquals("MDT13", cloudSite.getClli());
110         assertEquals("mtn13", cloudSite.getRegionId());
111         assertEquals("MTN13", cloudSite.getIdentityServiceId());
112     }
113
114     @Test
115     public void testGetCloudSiteNotFound() throws Exception {
116         CloudSite cloudSite = client.getCloudSite(UUID.randomUUID().toString());
117         assertNull(cloudSite);
118     }
119
120     @Test
121     public void testGetCloudifyManagerHappyPath() throws Exception {
122         CloudifyManager cloudifyManager = client.getCloudifyManager("mtn13");
123         assertNotNull(cloudifyManager);
124         assertEquals("http://localhost:28090/v2.0", cloudifyManager.getCloudifyUrl());
125
126     }
127
128     @Test
129     public void testGetCloudifyManagerNotFound() throws Exception {
130         CloudifyManager cloudifyManager = client.getCloudifyManager(UUID.randomUUID().toString());
131         assertNull(cloudifyManager);
132     }
133
134
135     @Test
136     public void testGetCloudSiteByClliAndAicVersionHappyPath() throws Exception {
137         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "2.5");
138         assertNotNull(cloudSite);
139     }
140
141     @Test
142     public void testGetCloudSiteByClliAndAicVersionNotFound() throws Exception {
143         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "232496239746328");
144         assertNull(cloudSite);
145     }
146
147     @Test
148     public void testGetServiceByID() throws Exception {
149         Service serviceByID = client.getServiceByID("5df8b6de-2083-11e7-93ae-92361f002671");
150         assertNotNull(serviceByID);
151         assertEquals("MSOTADevInfra_vSAMP10a_Service", serviceByID.getModelName());
152         assertEquals("NA", serviceByID.getServiceType());
153         assertEquals("NA", serviceByID.getServiceRole());
154     }
155
156     @Test
157     public void testGetServiceByIDNotFound() throws Exception {
158         Service serviceByID = client.getServiceByID(UUID.randomUUID().toString());
159         assertNull(serviceByID);
160     }
161
162     @Test
163     public void testGetVfModuleByModelUUID() throws Exception {
164         VfModule vfModule = client.getVfModuleByModelUUID("20c4431c-246d-11e7-93ae-92361f002671");
165         assertNotNull(vfModule);
166         assertNotNull(vfModule.getVfModuleCustomization());
167         assertEquals("78ca26d0-246d-11e7-93ae-92361f002671", vfModule.getModelInvariantUUID());
168         assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
169     }
170
171     @Test
172     public void testGetVfModuleByModelUUIDNotFound() throws Exception {
173         VfModule vfModule = client.getVfModuleByModelUUID(UUID.randomUUID().toString());
174         assertNull(vfModule);
175     }
176
177     @Test
178     public void testGetVnfResourceByModelUUID() throws Exception {
179         VnfResource vnfResource = client.getVnfResourceByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
180         assertNotNull(vnfResource);
181         assertEquals("vSAMP10a", vnfResource.getModelName());
182     }
183
184     @Test
185     public void testGetVnfResourceByModelUUIDNotFound() throws Exception {
186         VnfResource vnfResource = client.getVnfResourceByModelUUID(UUID.randomUUID().toString());
187         assertNull(vnfResource);
188     }
189
190     @Test
191     public void testGetVnfResourceCustomizationByModelCustomizationUUID() {
192         VnfResourceCustomization vnfResourceCustomization =
193                 client.getVnfResourceCustomizationByModelCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002671");
194         assertNotNull(vnfResourceCustomization);
195         assertEquals("vSAMP", vnfResourceCustomization.getNfRole());
196         assertNotNull(vnfResourceCustomization.getModelCustomizationUUID());
197         assertNotNull(vnfResourceCustomization.getVnfResources());
198         assertNotNull(vnfResourceCustomization.getVfModuleCustomizations());
199         assertEquals("vSAMP10a", vnfResourceCustomization.getVnfResources().getModelName());
200         assertFalse("skip post instantiation configuration",
201                 vnfResourceCustomization.getSkipPostInstConf().booleanValue());
202     }
203
204     @Test
205     public void testGetVnfResourceCustomizationByModelCustomizationUUINotFound() {
206         VnfResourceCustomization vnfResourceCustomization =
207                 client.getVnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
208         assertNull(vnfResourceCustomization);
209     }
210
211     @Test
212     public void testGetInstanceGroupByModelUUID() {
213         InstanceGroup instanceGroup = client.getInstanceGroupByModelUUID("0c8692ef-b9c0-435d-a738-edf31e71f38b");
214         assertNotNull(instanceGroup);
215         assertEquals("network_collection_resource_1806..NetworkCollection..0", instanceGroup.getModelName());
216         assertEquals("org.openecomp.resource.cr.NetworkCollectionResource1806",
217                 instanceGroup.getToscaNodeType().toString());
218     }
219
220     @Test
221     public void testGetVfModuleCustomizationByModelCuztomizationUUID() {
222         VfModuleCustomization vfModuleCustomization =
223                 client.getVfModuleCustomizationByModelCuztomizationUUID("cb82ffd8-252a-11e7-93ae-92361f002671");
224         assertNotNull(vfModuleCustomization);
225         assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
226         assertEquals("base", vfModuleCustomization.getLabel());
227     }
228
229     @Test
230     public void testGetVfModuleCustomizationByModelCuztomizationUUIDNotFound() {
231         VfModuleCustomization vfModuleCustomization =
232                 client.getVfModuleCustomizationByModelCuztomizationUUID(UUID.randomUUID().toString());
233         assertNull(vfModuleCustomization);
234     }
235
236     @Test
237     public void testGetNetworkResourceCustomizationByModelCustomizationUUID() {
238         NetworkResourceCustomization networkResourceCustomization =
239                 client.getNetworkResourceCustomizationByModelCustomizationUUID("3bdbb104-476c-483e-9f8b-c095b3d308ac");
240         assertNotNull(networkResourceCustomization);
241         assertNotNull(networkResourceCustomization.getModelCustomizationUUID());
242         assertEquals("CONTRAIL30_GNDIRECT 9", networkResourceCustomization.getModelInstanceName());
243         assertNotNull(networkResourceCustomization.getNetworkResource());
244     }
245
246     @Test
247     public void testGetNetworkResourceCustomizationByModelCustomizationUUIDNotFound() {
248         NetworkResourceCustomization networkResourceCustomization =
249                 client.getNetworkResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
250         assertNull(networkResourceCustomization);
251     }
252
253     @Test
254     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID() {
255         VfModuleCustomization vfModuleCustomization =
256                 client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
257                         "cb82ffd8-252a-11e7-93ae-92361f002672", "20c4431c-246d-11e7-93ae-92361f002672");
258         assertNotNull(vfModuleCustomization);
259         assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
260         assertNotNull(vfModuleCustomization.getVfModule());
261         assertEquals("base", vfModuleCustomization.getLabel());
262     }
263
264     @Test
265     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUIDNotFound() {
266         VfModuleCustomization vfModuleCustomization =
267                 client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
268                         "cb82ffd8-252a-11e7-93ae-92361f002672", UUID.randomUUID().toString());
269         assertNull(vfModuleCustomization);
270     }
271
272     @Test
273     public void testGetFirstByServiceModelUUIDAndAction() {
274         ServiceRecipe serviceRecipe =
275                 client.getFirstByServiceModelUUIDAndAction("4694a55f-58b3-4f17-92a5-796d6f5ffd0d", "createInstance");
276         assertNotNull(serviceRecipe);
277         assertNotNull(serviceRecipe.getServiceModelUUID());
278         assertNotNull(serviceRecipe.getAction());
279         assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri());
280         assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
281     }
282
283     @Test
284     public void testGetFirstByServiceModelUUIDAndActionNotFound() {
285         ServiceRecipe serviceRecipe = client.getFirstByServiceModelUUIDAndAction("5df8b6de-2083-11e7-93ae-92361f002671",
286                 UUID.randomUUID().toString());
287         assertNull(serviceRecipe);
288     }
289
290     @Test
291     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersion() {
292         VnfResource vnfResource = client
293                 .getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671", "2.0");
294         assertNotNull(vnfResource);
295         assertNotNull(vnfResource.getModelInvariantId());
296         assertNotNull(vnfResource.getModelVersion());
297         assertNotNull(vnfResource.getHeatTemplates());
298         assertEquals("vSAMP10a", vnfResource.getModelName());
299     }
300
301     @Test
302     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersionNotFound() {
303         VnfResource vnfResource = client.getFirstVnfResourceByModelInvariantUUIDAndModelVersion(
304                 "2fff5b20-214b-11e7-93ae-92361f002671", UUID.randomUUID().toString());
305         assertNull(vnfResource);
306     }
307
308     @Test
309     public void testGetFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources() {
310         VnfResource vnfr = new VnfResource();
311         vnfr.setModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
312         VnfResourceCustomization firstVnfResourceCustomizationByModelInstanceNameAndVnfResources =
313                 client.getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources("vSAMP10a 1", vnfr);
314         assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources);
315         assertEquals("vSAMP", firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getNfRole());
316         assertEquals("vSAMP10a 1",
317                 firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getModelInstanceName());
318         assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVnfResources());
319         assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVfModuleCustomizations());
320     }
321
322     @Test
323     public void testGetFirstVnfRecipeByNfRoleAndAction() {
324         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction("GR-API-DEFAULT", "createInstance");
325         assertNotNull(vnfRecipe);
326         assertNotNull(vnfRecipe.getNfRole());
327         assertNotNull(vnfRecipe.getAction());
328         assertEquals("Gr api recipe to create vnf", vnfRecipe.getDescription());
329         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         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         assertNotNull(vnfComponentsRecipe);
344         assertNotNull(vnfComponentsRecipe.getAction());
345         assertNotNull(vnfComponentsRecipe.getVfModuleModelUUID());
346         assertNotNull(vnfComponentsRecipe.getVnfComponentType());
347         assertEquals("Gr api recipe to create volume-group", vnfComponentsRecipe.getDescription());
348         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         assertNull(vnfComponentsRecipe);
359     }
360
361     @Test
362     public void testGetFirstVnfComponentsRecipeByVnfComponentTypeAndAction() {
363         VnfComponentsRecipe vnfComponentsRecipe =
364                 client.getFirstVnfComponentsRecipeByVnfComponentTypeAndAction("volumeGroup", "createInstance");
365         assertNotNull(vnfComponentsRecipe);
366         assertNotNull(vnfComponentsRecipe.getAction());
367         assertNotNull(vnfComponentsRecipe.getVnfComponentType());
368         assertEquals("VID_DEFAULT recipe t", vnfComponentsRecipe.getDescription());
369         assertEquals("/mso/async/services/CreateVfModuleVolumeInfraV1", vnfComponentsRecipe.getOrchestrationUri());
370     }
371
372     @Test
373     public void testGetServiceByModelVersionAndModelInvariantUUID() {
374         Service service =
375                 client.getServiceByModelVersionAndModelInvariantUUID("2.0", "9647dfc4-2083-11e7-93ae-92361f002671");
376         assertNotNull(service);
377         assertNotNull(service.getModelVersion());
378         assertNotNull(service.getModelInvariantUUID());
379         assertEquals("MSOTADevInfra_vSAMP10a_Service", service.getModelName());
380         assertEquals("NA", service.getServiceRole());
381     }
382
383     @Test
384     public void testGetServiceByModelVersionAndModelInvariantUUIDNotFound() {
385         Service service = client.getServiceByModelVersionAndModelInvariantUUID("2.0", UUID.randomUUID().toString());
386         assertNull(service);
387     }
388
389     @Test
390     public void testGetVfModuleByModelInvariantUUIDAndModelVersion() {
391         VfModule vfModule =
392                 client.getVfModuleByModelInvariantUUIDAndModelVersion("78ca26d0-246d-11e7-93ae-92361f002671", "2");
393         assertNotNull(vfModule);
394         assertNotNull(vfModule.getModelVersion());
395         assertNotNull(vfModule.getModelInvariantUUID());
396         assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
397         assertEquals("vSAMP10a DEV Base", vfModule.getDescription());
398     }
399
400     @Test
401     public void testGetVfModuleByModelInvariantUUIDAndModelVersionNotFound() {
402         VfModule vfModule = client.getVfModuleByModelInvariantUUIDAndModelVersion(UUID.randomUUID().toString(), "2");
403         assertNull(vfModule);
404     }
405
406     @Test
407     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDesc() {
408         List<Service> serviceList =
409                 client.getServiceByModelInvariantUUIDOrderByModelVersionDesc("9647dfc4-2083-11e7-93ae-92361f002671");
410         assertFalse(serviceList.isEmpty());
411         assertEquals(2, serviceList.size());
412         Service service = serviceList.get(0);
413         assertEquals("2.0", service.getModelVersion());
414     }
415
416     @Test
417     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDescNotFound() {
418         List<Service> serviceList =
419                 client.getServiceByModelInvariantUUIDOrderByModelVersionDesc(UUID.randomUUID().toString());
420         assertTrue(serviceList.isEmpty());
421     }
422
423     @Test
424     public void testGetVfModuleByModelInvariantUUIDOrderByModelVersionDesc() {
425         List<VfModule> moduleList =
426                 client.getVfModuleByModelInvariantUUIDOrderByModelVersionDesc("78ca26d0-246d-11e7-93ae-92361f002671");
427         assertFalse(moduleList.isEmpty());
428         assertEquals(2, moduleList.size());
429         VfModule module = moduleList.get(0);
430         assertEquals("vSAMP10a DEV Base", module.getDescription());
431     }
432
433     @Test
434     public void testCloudSiteClient() {
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         assertNotNull(getCloudSite);
457         assertNotNull(getCloudSite.getIdentityService());
458         assertEquals("TESTCLLI", getCloudSite.getClli());
459         assertEquals("regionId", getCloudSite.getRegionId());
460         assertEquals("RANDOMID", getCloudSite.getIdentityServiceId());
461
462         getCloudSite.setClli("clli2");
463         getCloudSite.setRegionId("region2");
464
465         CloudSite updatedCloudSite = this.client.updateCloudSite(getCloudSite);
466         assertNotNull(updatedCloudSite);
467         assertNotNull(updatedCloudSite.getIdentityService());
468         assertEquals("clli2", updatedCloudSite.getClli());
469         assertEquals("region2", updatedCloudSite.getRegionId());
470
471         this.client.deleteCloudSite(getCloudSite.getId());
472         getCloudSite = this.client.getCloudSite("MTN6");
473         assertNull(getCloudSite);
474     }
475
476     @Test
477     public void testGetHomingInstance() {
478         HomingInstance homingInstance = client.getHomingInstance("5df8b6de-2083-11e7-93ae-92361f232671");
479         assertNotNull(homingInstance);
480         assertNotNull(homingInstance.getCloudOwner());
481         assertNotNull(homingInstance.getCloudRegionId());
482         assertNotNull(homingInstance.getOofDirectives());
483     }
484
485     @Test
486     public void testPostHomingInstance() {
487         CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger(
488                 "http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
489         HomingInstance homingInstance = new HomingInstance();
490         homingInstance.setServiceInstanceId("5df8d6be-2083-11e7-93ae-92361f232671");
491         homingInstance.setCloudOwner("CloudOwner-1");
492         homingInstance.setCloudRegionId("CloudRegionOne");
493         homingInstance.setOofDirectives("{\n" + "\"directives\": [\n" + "{\n" + "\"directives\": [\n" + "{\n"
494                 + "\"attributes\": [\n" + "{\n" + "\"attribute_value\": \"onap.hpa.flavor31\",\n"
495                 + "\"attribute_name\": \"firewall_flavor_name\"\n" + "}\n" + "],\n"
496                 + "\"type\": \"flavor_directives\"\n" + "}\n" + "],\n" + "\"type\": \"vnfc\",\n" + "\"id\": \"vfw\"\n"
497                 + "},\n" + "{\n" + "\"directives\": [\n" + "{\n" + "\"attributes\": [\n" + "{\n"
498                 + "\"attribute_value\": \"onap.hpa.flavor32\",\n" + "\"attribute_name\": \"packetgen_flavor_name\"\n"
499                 + "}\n" + "],\n" + "\"type\": \"flavor_directives\"\n" + "}\n" + "],\n" + "\"type\": \"vnfc\",\n"
500                 + "\"id\": \"vgenerator\"\n" + "},\n" + "{\n" + "\"directives\": [\n" + "{\n" + "\"attributes\": [\n"
501                 + "{\n" + "\"attribute_value\": \"onap.hpa.flavor31\",\n" + "\"attribute_name\": \"sink_flavor_name\"\n"
502                 + "}\n" + "],\n" + "\"type\": \"flavor_directives\"\n" + "}\n" + "],\n" + "\"type\": \"vnfc\",\n"
503                 + "\"id\": \"vsink\"\n" + "}\n" + "]\n" + "}");
504         localClient.postHomingInstance(homingInstance);
505         HomingInstance getHomingInstance = this.client.getHomingInstance("5df8d6be-2083-11e7-93ae-92361f232671");
506         assertNotNull(getHomingInstance);
507         assertNotNull(getHomingInstance.getCloudRegionId());
508         assertNotNull(getHomingInstance.getCloudOwner());
509         assertEquals("CloudOwner-1", getHomingInstance.getCloudOwner());
510         assertEquals("CloudRegionOne", getHomingInstance.getCloudRegionId());
511     }
512
513     @Test
514     public void testGetServiceByModelName() {
515         Service service = client.getServiceByModelName("MSOTADevInfra_Test_Service");
516         assertNotNull(service);
517         assertNotNull(service.getModelVersion());
518         assertNotNull(service.getModelInvariantUUID());
519         assertEquals("MSOTADevInfra_Test_Service", service.getModelName());
520         assertEquals("NA", service.getServiceRole());
521     }
522
523     @Test
524     public void testGetServiceByModelNameNotFound() {
525         Service service = client.getServiceByModelName("Not_Found");
526         assertNull(service);
527     }
528
529     @Test
530     public void testGetServiceByModelUUID() {
531         Service service = client.getServiceByModelUUID("5df8b6de-2083-11e7-93ae-92361f002679");
532         assertNotNull(service);
533         assertNotNull(service.getModelVersion());
534         assertNotNull(service.getModelInvariantUUID());
535         assertEquals("5df8b6de-2083-11e7-93ae-92361f002679", service.getModelUUID());
536         assertEquals("NA", service.getServiceRole());
537     }
538
539     @Test
540     public void testGetServiceByModelUUIDNotFound() {
541         Service service = client.getServiceByModelUUID("Not_Found");
542         assertNull(service);
543     }
544
545     @Test
546     public void testGetNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner() {
547         NorthBoundRequest northBoundRequest = new NorthBoundRequest();
548         northBoundRequest.setAction("createService");
549         northBoundRequest.setRequestScope("service");
550         northBoundRequest.setIsAlacarte(true);
551         northBoundRequest.setCloudOwner("my-custom-cloud-owner");
552         client.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner("createService", "service", true,
553                 "my-custom-cloud-owner");
554         assertNotNull(northBoundRequest);
555         assertEquals("createService", northBoundRequest.getAction());
556         assertEquals("service", northBoundRequest.getRequestScope());
557         assertEquals(true, northBoundRequest.getIsAlacarte());
558         assertEquals("my-custom-cloud-owner", northBoundRequest.getCloudOwner());
559     }
560
561     @Test
562     public void testFindServiceRecipeByActionAndServiceModelUUID() {
563         ServiceRecipe serviceRecipe = client.findServiceRecipeByActionAndServiceModelUUID("createInstance",
564                 "4694a55f-58b3-4f17-92a5-796d6f5ffd0d");
565         assertNotNull(serviceRecipe);
566         assertNotNull(serviceRecipe.getServiceModelUUID());
567         assertNotNull(serviceRecipe.getAction());
568         assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri());
569         assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
570     }
571
572     @Test
573     public void testFindServiceRecipeByActionAndServiceModelUUIDNotFound() {
574         ServiceRecipe serviceRecipe =
575                 client.findServiceRecipeByActionAndServiceModelUUID("not_found", "5df8b6de-2083-11e7-93ae-test");
576         assertNull(serviceRecipe);
577     }
578
579     @Test
580     public void testFindExternalToInternalServiceByServiceName() {
581         ExternalServiceToInternalService externalServiceToInternalService =
582                 client.findExternalToInternalServiceByServiceName("MySpecialServiceName");
583         assertNotNull(externalServiceToInternalService);
584         assertNotNull(externalServiceToInternalService.getServiceName());
585         assertNotNull(externalServiceToInternalService.getServiceModelUUID());
586         assertEquals("MySpecialServiceName", externalServiceToInternalService.getServiceName());
587     }
588
589     @Test
590     public void testFindExternalToInternalServiceByServiceNameNotFound() {
591         ExternalServiceToInternalService externalServiceToInternalService =
592                 client.findExternalToInternalServiceByServiceName("Not_Found");
593         assertNull(externalServiceToInternalService);
594     }
595
596     @Test
597     public void getPnfResourceByModelUUID_validUuid_expectedOutput() {
598         PnfResource pnfResource = client.getPnfResourceByModelUUID("ff2ae348-214a-11e7-93ae-92361f002680");
599         assertNotNull(pnfResource);
600         assertEquals("PNFResource modelUUID", "ff2ae348-214a-11e7-93ae-92361f002680", pnfResource.getModelUUID());
601         assertEquals("PNFResource modelInvariantUUID", "2fff5b20-214b-11e7-93ae-92361f002680",
602                 pnfResource.getModelInvariantUUID());
603         assertEquals("PNFResource modelVersion", "1.0", pnfResource.getModelVersion());
604         assertEquals("PNFResource orchestration mode", "", pnfResource.getOrchestrationMode());
605     }
606
607     @Test
608     public void getPnfResourceByModelUUID_invalidUuid_NullOutput() {
609         PnfResource pnfResource = client.getPnfResourceByModelUUID(UUID.randomUUID().toString());
610         assertNull(pnfResource);
611     }
612
613     @Test
614     public void getPnfResourceCustomizationByModelCustomizationUUID_validUuid_expectedOutput() {
615         PnfResourceCustomization pnfResourceCustomization =
616                 client.getPnfResourceCustomizationByModelCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002680");
617         assertEquals("modelInstanceName", "PNF routing", pnfResourceCustomization.getModelInstanceName());
618         assertEquals("blueprintName", "test_configuration_restconf", pnfResourceCustomization.getBlueprintName());
619         assertEquals("blueprintVersion", "1.0.0", pnfResourceCustomization.getBlueprintVersion());
620         assertTrue("skip post instantiation configuration", pnfResourceCustomization.getSkipPostInstConf());
621         PnfResource pnfResource = pnfResourceCustomization.getPnfResources();
622         assertNotNull(pnfResource);
623         assertEquals("PNFResource modelUUID", "ff2ae348-214a-11e7-93ae-92361f002680", pnfResource.getModelUUID());
624         assertEquals("PNFResource modelInvariantUUID", "2fff5b20-214b-11e7-93ae-92361f002680",
625                 pnfResource.getModelInvariantUUID());
626         assertEquals("PNFResource modelVersion", "1.0", pnfResource.getModelVersion());
627         assertEquals("PNFResource orchestration mode", "", pnfResource.getOrchestrationMode());
628     }
629
630     @Test
631     public void getPnfResourceCustomizationByModelCustomizationUUID_invalidUuid_nullOutput() {
632         PnfResourceCustomization pnfResourceCustomization =
633                 client.getPnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
634         assertNull(pnfResourceCustomization);
635     }
636
637     @Test
638     public void getPnfResourceCustomizationFromJoinTable_validServiceUuid_expectedOutput() {
639         List<PnfResourceCustomization> pnfResourceCustomizationList =
640                 client.getPnfResourceCustomizationByModelUuid("5df8b6de-2083-11e7-93ae-92361f002676");
641         assertEquals(1, pnfResourceCustomizationList.size());
642
643         PnfResourceCustomization pnfResourceCustomization = pnfResourceCustomizationList.get(0);
644         assertEquals("modelInstanceName", "PNF routing", pnfResourceCustomization.getModelInstanceName());
645         assertEquals("blueprintName", "test_configuration_restconf", pnfResourceCustomization.getBlueprintName());
646         assertEquals("blueprintVersion", "1.0.0", pnfResourceCustomization.getBlueprintVersion());
647         PnfResource pnfResource = pnfResourceCustomization.getPnfResources();
648         assertNotNull(pnfResource);
649
650         assertEquals("PNFResource modelUUID", "ff2ae348-214a-11e7-93ae-92361f002680", pnfResource.getModelUUID());
651         assertEquals("PNFResource modelInvariantUUID", "2fff5b20-214b-11e7-93ae-92361f002680",
652                 pnfResource.getModelInvariantUUID());
653         assertEquals("PNFResource modelVersion", "1.0", pnfResource.getModelVersion());
654         assertEquals("PNFResource orchestration mode", "", pnfResource.getOrchestrationMode());
655     }
656
657     @Test
658     public void getPnfResourceCustomizationFromJoinTable_invalidServiceUuid_nullOutput() {
659         List<PnfResourceCustomization> pnfResourceCustomizationList =
660                 client.getPnfResourceCustomizationByModelUuid(UUID.randomUUID().toString());
661         assertEquals(0, pnfResourceCustomizationList.size());
662     }
663
664     @Test
665     public void testGetServiceTopologyById() throws Exception {
666         org.onap.so.rest.catalog.beans.Service serviceByID =
667                 client.getServiceModelInformation("5df8b6de-2083-11e7-93ae-92361f002671", "2");
668         assertNotNull(serviceByID);
669         assertEquals("MSOTADevInfra_vSAMP10a_Service", serviceByID.getModelName());
670         assertEquals("NA", serviceByID.getServiceType());
671         assertEquals("NA", serviceByID.getServiceRole());
672     }
673
674     @Test
675     public void testGetServices() throws Exception {
676         List<org.onap.so.rest.catalog.beans.Service> services = client.getServices();
677         assertEquals(false, services.isEmpty());
678     }
679
680     @Test
681     public void testVnf() throws Exception {
682         org.onap.so.rest.catalog.beans.Vnf vnf = client.getVnfModelInformation("5df8b6de-2083-11e7-93ae-92361f002671",
683                 "68dc9a92-214c-11e7-93ae-92361f002671", "0");
684         assertNotNull(vnf);
685         assertEquals("vSAMP10a", vnf.getModelName());
686         assertEquals(false, vnf.getNfDataValid());
687         assertEquals("vSAMP", vnf.getNfFunction());
688         assertEquals("vSAMP", vnf.getNfNamingCode());
689         assertEquals("vSAMP", vnf.getNfRole());
690         assertEquals("vSAMP", vnf.getNfType());
691
692         vnf.setNfDataValid(true);
693         vnf.setNfFunction("nfFunction");
694         vnf.setNfRole("nfRole");
695         vnf.setNfType("nfType");
696         vnf.setNfNamingCode("nfNamingCode");
697
698         client.updateVnf("5df8b6de-2083-11e7-93ae-92361f002671", vnf);
699         vnf = client.getVnfModelInformation("5df8b6de-2083-11e7-93ae-92361f002671",
700                 "68dc9a92-214c-11e7-93ae-92361f002671", "0");
701         assertEquals("vSAMP10a", vnf.getModelName());
702         assertEquals(true, vnf.getNfDataValid());
703         assertEquals("nfFunction", vnf.getNfFunction());
704         assertEquals("nfNamingCode", vnf.getNfNamingCode());
705         assertEquals("nfRole", vnf.getNfRole());
706         assertEquals("nfType", vnf.getNfType());
707
708
709     }
710
711     @Test
712     public void getWorkflowByArtifactUUID_validUuid_expectedOutput() {
713         Workflow workflow = client.findWorkflowByArtifactUUID("5b0c4322-643d-4c9f-b184-4516049e99b1");
714         assertEquals("artifactName", "testingWorkflow.bpmn", workflow.getArtifactName());
715     }
716
717     @Test
718     public void getWorkflowByArtifactUUID_invalidUuid_nullOutput() {
719         Workflow workflow = client.findWorkflowByArtifactUUID(UUID.randomUUID().toString());
720         assertNull(workflow);
721     }
722
723     @Test
724     public void getWorkflowByVnfModelUUID_validUuid_expectedOutput() {
725         List<Workflow> workflows = client.findWorkflowByVnfModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
726         assertTrue(workflows != null);
727         assertTrue(workflows.size() != 0);
728
729         assertEquals("testingWorkflow.bpmn", workflows.get(0).getArtifactName());
730     }
731
732     @Test
733     public void getWorkflowByModelUUID_invalidUuid_nullOutput() {
734         Workflow workflow = client.findWorkflowByArtifactUUID(UUID.randomUUID().toString());
735         assertNull(workflow);
736     }
737
738     @Test
739     public void getWorkflowBySource_validSource_expectedOutput() {
740         List<Workflow> workflows = client.findWorkflowBySource("sdc");
741         assertTrue(workflows != null);
742         assertTrue(workflows.size() != 0);
743
744         assertEquals("testingWorkflow.bpmn", workflows.get(0).getArtifactName());
745     }
746
747     @Test
748     public void getWorkflowBySource_invalidSource_nullOutput() {
749         List<Workflow> workflow = client.findWorkflowBySource("abc");
750         assertNull(workflow);
751     }
752
753     @Test
754     public void getCloudSites() {
755         List<CloudSite> cloudSites = client.getCloudSites();
756         assertNotNull(cloudSites);
757         assertNotEquals(0, cloudSites.size());
758     }
759
760     @Test
761     public void getBBNameSelectionReference_validData_expectedOutput() {
762         BBNameSelectionReference bbNameSelectionReference =
763                 client.getBBNameSelectionReference("APPC", "vfModule", "healthCheck");
764         assertNotNull(bbNameSelectionReference);
765         assertEquals("GenericVnfHealthCheckBB", bbNameSelectionReference.getBbName());
766     }
767
768     @Test
769     public void getBBNameSelectionReference_invalidData_nullOutput() {
770         BBNameSelectionReference bbNameSelectionReference =
771                 client.getBBNameSelectionReference("ABC", "vfModule", "healthCheck");
772         assertNull(bbNameSelectionReference);
773
774     }
775
776     @Test
777     public void testGetProcessingFlagsFromFlag() {
778         ProcessingFlags processingFlags = client.findProcessingFlagsByFlag("TESTFLAG");
779         assertNotNull(processingFlags);
780         assertEquals(processingFlags.getEndpoint(), "TESTENDPOINT");
781     }
782
783
784 }