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