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