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