Merge 'origin/casablanca' into master
[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.mockito.Mockito.when;
26
27 import java.util.List;
28 import java.util.UUID;
29
30 import javax.ws.rs.core.UriBuilder;
31
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.onap.so.adapters.catalogdb.CatalogDBApplication;
37 import org.onap.so.db.catalog.beans.AuthenticationType;
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.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.ExternalServiceToInternalService;
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 import org.springframework.boot.test.context.SpringBootTest;
61 import org.springframework.boot.test.mock.mockito.MockBean;
62 import org.springframework.test.context.ActiveProfiles;
63 import org.springframework.test.context.junit4.SpringRunner;
64
65 import com.fasterxml.jackson.databind.ObjectMapper;
66
67 @RunWith(SpringRunner.class)
68 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
69 @ActiveProfiles("test")
70 public class CatalogDbClientTest {
71     public static final String MTN13 = "mtn13";
72     
73     @LocalServerPort
74     private int port;
75
76     @Value("${mso.db.auth}")
77     private String msoAdaptersAuth;
78         
79     @Autowired
80     CatalogDbClientPortChanger client;
81
82     @Before
83     public void initialize(){
84         client.wiremockPort= String.valueOf(port);
85     }
86
87     @Test
88     public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(){
89         RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", "*", "*", "*", "*");
90         Assert.assertEquals("Rollback", rainyDayHandlerStatus.getPolicy());
91     }
92
93     @Test
94     public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStepRecordNotFound(){
95         RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(UUID.randomUUID().toString(), "*", "*", "*", "*");
96         Assert.assertNull(rainyDayHandlerStatus);
97     }
98
99     @Test
100     public void testGetCloudSiteHappyPath() throws Exception {
101         CloudSite cloudSite = client.getCloudSite(MTN13);
102         Assert.assertNotNull(cloudSite);
103         Assert.assertNotNull(cloudSite.getIdentityService());
104         Assert.assertEquals("MDT13", cloudSite.getClli());
105         Assert.assertEquals("mtn13", cloudSite.getRegionId());
106         Assert.assertEquals("MTN13", cloudSite.getIdentityServiceId());
107     }
108
109     @Test
110     public void testGetCloudSiteNotFound() throws Exception {
111         CloudSite cloudSite = client.getCloudSite(UUID.randomUUID().toString());
112         Assert.assertNull(cloudSite);
113     }
114
115     @Test
116     public void testGetCloudifyManagerHappyPath() throws Exception {
117         CloudifyManager cloudifyManager = client.getCloudifyManager("mtn13");
118         Assert.assertNotNull(cloudifyManager);
119         Assert.assertEquals("http://localhost:28090/v2.0", cloudifyManager.getCloudifyUrl());
120
121     }
122
123     @Test
124     public void testGetCloudifyManagerNotFound() throws Exception {
125         CloudifyManager cloudifyManager = client.getCloudifyManager(UUID.randomUUID().toString());
126         Assert.assertNull(cloudifyManager);
127     }
128
129
130     @Test
131     public void testGetCloudSiteByClliAndAicVersionHappyPath() throws Exception {
132         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "2.5");
133         Assert.assertNotNull(cloudSite);
134     }
135
136     @Test
137     public void testGetCloudSiteByClliAndAicVersionNotFound() throws Exception {
138         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "232496239746328");
139         Assert.assertNull(cloudSite);
140     }
141
142     @Test
143     public void testGetServiceByID() throws Exception {
144         Service serviceByID = client.getServiceByID("5df8b6de-2083-11e7-93ae-92361f002671");
145         Assert.assertNotNull(serviceByID);
146         Assert.assertEquals("MSOTADevInfra_vSAMP10a_Service", serviceByID.getModelName());
147         Assert.assertEquals("NA", serviceByID.getServiceType());
148         Assert.assertEquals("NA", serviceByID.getServiceRole());
149     }
150
151     @Test
152     public void testGetServiceByIDNotFound() throws Exception {
153         Service serviceByID = client.getServiceByID(UUID.randomUUID().toString());
154         Assert.assertNull(serviceByID);
155     }
156
157     @Test
158     public void testGetVfModuleByModelUUID() throws Exception {
159         VfModule vfModule = client.getVfModuleByModelUUID("20c4431c-246d-11e7-93ae-92361f002671");
160         Assert.assertNotNull(vfModule);
161         Assert.assertNotNull(vfModule.getVfModuleCustomization());
162         Assert.assertEquals("78ca26d0-246d-11e7-93ae-92361f002671", vfModule.getModelInvariantUUID());
163         Assert.assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
164     }
165
166     @Test
167     public void testGetVfModuleByModelUUIDNotFound() throws Exception {
168         VfModule vfModule = client.getVfModuleByModelUUID(UUID.randomUUID().toString());
169         Assert.assertNull(vfModule);
170     }
171
172     @Test
173     public void testGetVnfResourceByModelUUID() throws Exception {
174         VnfResource vnfResource = client.getVnfResourceByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
175         Assert.assertNotNull(vnfResource);
176         Assert.assertEquals("vSAMP10a", vnfResource.getModelName());
177     }
178
179     @Test
180     public void testGetVnfResourceByModelUUIDNotFound() throws Exception {
181         VnfResource vnfResource = client.getVnfResourceByModelUUID(UUID.randomUUID().toString());
182         Assert.assertNull(vnfResource);
183     }
184
185     @Test
186     public void testGetVnfResourceCustomizationByModelCustomizationUUID() {
187         VnfResourceCustomization vnfResourceCustomization = client.getVnfResourceCustomizationByModelCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002671");
188         Assert.assertNotNull(vnfResourceCustomization);
189         Assert.assertEquals("vSAMP", vnfResourceCustomization.getNfRole());
190         Assert.assertNotNull(vnfResourceCustomization.getModelCustomizationUUID());
191         Assert.assertNotNull(vnfResourceCustomization.getVnfResources());
192         Assert.assertNotNull(vnfResourceCustomization.getVfModuleCustomizations());
193         Assert.assertEquals("vSAMP10a", vnfResourceCustomization.getVnfResources().getModelName());
194
195     }
196
197     @Test
198     public void testGetVnfResourceCustomizationByModelCustomizationUUINotFound() {
199         VnfResourceCustomization vnfResourceCustomization = client.getVnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
200         Assert.assertNull(vnfResourceCustomization);
201     }
202
203     @Test
204     public void testGetInstanceGroupByModelUUID() {
205         InstanceGroup instanceGroup = client.getInstanceGroupByModelUUID("0c8692ef-b9c0-435d-a738-edf31e71f38b");
206         Assert.assertNotNull(instanceGroup);
207         Assert.assertEquals("network_collection_resource_1806..NetworkCollection..0", instanceGroup.getModelName());
208         Assert.assertEquals("org.openecomp.resource.cr.NetworkCollectionResource1806", instanceGroup.getToscaNodeType().toString());
209     }
210
211     @Test
212     public void testGetVfModuleCustomizationByModelCuztomizationUUID() {
213         VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCuztomizationUUID("cb82ffd8-252a-11e7-93ae-92361f002671");
214         Assert.assertNotNull(vfModuleCustomization);
215         Assert.assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
216         Assert.assertEquals("base", vfModuleCustomization.getLabel());
217     }
218
219     @Test
220     public void testGetVfModuleCustomizationByModelCuztomizationUUIDNotFound() {
221         VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCuztomizationUUID(UUID.randomUUID().toString());
222         Assert.assertNull(vfModuleCustomization);
223     }
224
225     @Test
226     public void testGetNetworkResourceCustomizationByModelCustomizationUUID() {
227         NetworkResourceCustomization networkResourceCustomization = client.getNetworkResourceCustomizationByModelCustomizationUUID("3bdbb104-476c-483e-9f8b-c095b3d308ac");
228         Assert.assertNotNull(networkResourceCustomization);
229         Assert.assertNotNull(networkResourceCustomization.getModelCustomizationUUID());
230         Assert.assertEquals("CONTRAIL30_GNDIRECT 9", networkResourceCustomization.getModelInstanceName());
231         Assert.assertNotNull(networkResourceCustomization.getNetworkResource());
232     }
233
234     @Test
235     public void testGetNetworkResourceCustomizationByModelCustomizationUUIDNotFound() {
236         NetworkResourceCustomization networkResourceCustomization = client.getNetworkResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
237         Assert.assertNull(networkResourceCustomization);
238     }
239
240     @Test
241     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID() {
242         VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID("cb82ffd8-252a-11e7-93ae-92361f002672", "20c4431c-246d-11e7-93ae-92361f002672");
243         Assert.assertNotNull(vfModuleCustomization);
244         Assert.assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
245         Assert.assertNotNull(vfModuleCustomization.getVfModule());
246         Assert.assertEquals("base", vfModuleCustomization.getLabel());
247     }
248
249     @Test
250     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUIDNotFound() {
251         VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID("cb82ffd8-252a-11e7-93ae-92361f002672", UUID.randomUUID().toString());
252         Assert.assertNull(vfModuleCustomization);
253     }
254
255     @Test
256     public void testGetFirstByServiceModelUUIDAndAction() {
257         ServiceRecipe serviceRecipe = client.getFirstByServiceModelUUIDAndAction("4694a55f-58b3-4f17-92a5-796d6f5ffd0d", "createInstance");
258         Assert.assertNotNull(serviceRecipe);
259         Assert.assertNotNull(serviceRecipe.getServiceModelUUID());
260         Assert.assertNotNull(serviceRecipe.getAction());
261         Assert.assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri());
262         Assert.assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
263     }
264
265     @Test
266     public void testGetFirstByServiceModelUUIDAndActionNotFound() {
267         ServiceRecipe serviceRecipe = client.getFirstByServiceModelUUIDAndAction("5df8b6de-2083-11e7-93ae-92361f002671", UUID.randomUUID().toString());
268         Assert.assertNull(serviceRecipe);
269     }
270     
271     @Test
272     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersion() {
273         VnfResource vnfResource = client.getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671", "2.0");
274         Assert.assertNotNull(vnfResource);
275         Assert.assertNotNull(vnfResource.getModelInvariantId());
276         Assert.assertNotNull(vnfResource.getModelVersion());
277         Assert.assertNotNull(vnfResource.getHeatTemplates());
278         Assert.assertNotNull(vnfResource.getVnfResourceCustomizations());
279         Assert.assertEquals("vSAMP10a", vnfResource.getModelName());
280     }
281
282     @Test
283     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersionNotFound() {
284         VnfResource vnfResource = client.getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671", UUID.randomUUID().toString());
285         Assert.assertNull(vnfResource);
286     }
287
288     @Test
289     public void testGetFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources() {
290         VnfResource vnfr = new VnfResource();
291         vnfr.setModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
292         VnfResourceCustomization firstVnfResourceCustomizationByModelInstanceNameAndVnfResources = client.getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources("vSAMP10a 1", vnfr);
293         Assert.assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources);
294         Assert.assertEquals("vSAMP", firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getNfRole());
295         Assert.assertEquals("vSAMP10a 1", firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getModelInstanceName());
296         Assert.assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVnfResources());
297         Assert.assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVfModuleCustomizations());
298     }
299
300     @Test
301     public void testGetFirstVnfRecipeByNfRoleAndAction() {
302         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction("GR-API-DEFAULT", "createInstance");
303         Assert.assertNotNull(vnfRecipe);
304         Assert.assertNotNull(vnfRecipe.getNfRole());
305         Assert.assertNotNull(vnfRecipe.getAction());
306         Assert.assertEquals("Gr api recipe to create vnf", vnfRecipe.getDescription());
307         Assert.assertEquals("/mso/async/services/WorkflowActionBB", vnfRecipe.getOrchestrationUri());
308     }
309
310     @Test
311     public void testGetFirstVnfRecipeByNfRoleAndActionNotFound() {
312         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction(UUID.randomUUID().toString(), "createInstance");
313         Assert.assertNull(vnfRecipe);
314     }
315
316     @Test
317     public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction() {
318         VnfComponentsRecipe vnfComponentsRecipe = client.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction("20c4431c-246d-11e7-93ae-92361f002671", "volumeGroup", "createInstance");
319         Assert.assertNotNull(vnfComponentsRecipe);
320         Assert.assertNotNull(vnfComponentsRecipe.getAction());
321         Assert.assertNotNull(vnfComponentsRecipe.getVfModuleModelUUID());
322         Assert.assertNotNull(vnfComponentsRecipe.getVnfComponentType());
323         Assert.assertEquals("Gr api recipe to create volume-group", vnfComponentsRecipe.getDescription());
324         Assert.assertEquals("/mso/async/services/WorkflowActionBB", vnfComponentsRecipe.getOrchestrationUri());
325
326     }
327
328
329     @Test
330     public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndActionNotFound() {
331         VnfComponentsRecipe vnfComponentsRecipe = client.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(UUID.randomUUID().toString(), "volumeGroup", "createInstance");
332         Assert.assertNull(vnfComponentsRecipe);
333     }
334
335     @Test
336     public void testGetFirstVnfComponentsRecipeByVnfComponentTypeAndAction() {
337         VnfComponentsRecipe vnfComponentsRecipe = client.getFirstVnfComponentsRecipeByVnfComponentTypeAndAction("volumeGroup", "createInstance");
338         Assert.assertNotNull(vnfComponentsRecipe);
339         Assert.assertNotNull(vnfComponentsRecipe.getAction());
340         Assert.assertNotNull(vnfComponentsRecipe.getVnfComponentType());
341         Assert.assertEquals("VID_DEFAULT recipe t", vnfComponentsRecipe.getDescription());
342         Assert.assertEquals("/mso/async/services/CreateVfModuleVolumeInfraV1", vnfComponentsRecipe.getOrchestrationUri());
343     }
344
345     @Test
346     public void testGetServiceByModelVersionAndModelInvariantUUID() {
347         Service service = client.getServiceByModelVersionAndModelInvariantUUID("2.0", "9647dfc4-2083-11e7-93ae-92361f002671");
348         Assert.assertNotNull(service);
349         Assert.assertNotNull(service.getModelVersion());
350         Assert.assertNotNull(service.getModelInvariantUUID());
351         Assert.assertEquals("MSOTADevInfra_vSAMP10a_Service", service.getModelName());
352         Assert.assertEquals("NA", service.getServiceRole());
353     }
354
355     @Test
356     public void testGetServiceByModelVersionAndModelInvariantUUIDNotFound() {
357         Service service = client.getServiceByModelVersionAndModelInvariantUUID("2.0", UUID.randomUUID().toString());
358         Assert.assertNull(service);
359     }
360
361     @Test
362     public void testGetVfModuleByModelInvariantUUIDAndModelVersion() {
363         VfModule vfModule = client.getVfModuleByModelInvariantUUIDAndModelVersion("78ca26d0-246d-11e7-93ae-92361f002671", "2");
364         Assert.assertNotNull(vfModule);
365         Assert.assertNotNull(vfModule.getModelVersion());
366         Assert.assertNotNull(vfModule.getModelInvariantUUID());
367         Assert.assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
368         Assert.assertEquals("vSAMP10a DEV Base", vfModule.getDescription());
369     }
370
371     @Test
372     public void testGetVfModuleByModelInvariantUUIDAndModelVersionNotFound() {
373         VfModule vfModule = client.getVfModuleByModelInvariantUUIDAndModelVersion(UUID.randomUUID().toString(), "2");
374         Assert.assertNull(vfModule);
375     }
376     
377     @Test
378     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDesc() {
379         List<Service> serviceList = client.getServiceByModelInvariantUUIDOrderByModelVersionDesc("9647dfc4-2083-11e7-93ae-92361f002671");
380         Assert.assertFalse(serviceList.isEmpty());
381         Assert.assertEquals(2, serviceList.size());
382         Service service = serviceList.get(0);
383         Assert.assertEquals("2.0", service.getModelVersion());
384     }
385
386     @Test
387     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDescNotFound() {
388         List<Service> serviceList = client.getServiceByModelInvariantUUIDOrderByModelVersionDesc(UUID.randomUUID().toString());
389         Assert.assertTrue(serviceList.isEmpty());
390     }
391
392     @Test
393     public void testGetVfModuleByModelInvariantUUIDOrderByModelVersionDesc() {
394         List<VfModule> moduleList = client.getVfModuleByModelInvariantUUIDOrderByModelVersionDesc("78ca26d0-246d-11e7-93ae-92361f002671");
395         Assert.assertFalse(moduleList.isEmpty());
396         Assert.assertEquals(2, moduleList.size());
397         VfModule module = moduleList.get(0);
398         Assert.assertEquals("vSAMP10a DEV Base",module.getDescription());
399     }
400
401     @Test
402     public void testPostCloudSite() {
403         CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger("http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
404         CloudSite cloudSite = new CloudSite();
405         cloudSite.setId("MTN6");
406         cloudSite.setClli("TESTCLLI");
407         cloudSite.setRegionId("regionId");
408         cloudSite.setCloudVersion("VERSION");
409         cloudSite.setPlatform("PLATFORM");
410
411         CloudIdentity cloudIdentity = new CloudIdentity();
412         cloudIdentity.setId("RANDOMID");
413         cloudIdentity.setIdentityUrl("URL");
414         cloudIdentity.setMsoId("MSO_ID");
415         cloudIdentity.setMsoPass("MSO_PASS");
416         cloudIdentity.setAdminTenant("ADMIN_TENANT");
417         cloudIdentity.setMemberRole("ROLE");
418         cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
419         cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
420         cloudSite.setIdentityService(cloudIdentity);
421         localClient.postCloudSite(cloudSite);
422         CloudSite getCloudSite = this.client.getCloudSite("MTN6");
423         Assert.assertNotNull(getCloudSite);
424         Assert.assertNotNull(getCloudSite.getIdentityService());
425         Assert.assertEquals("TESTCLLI", getCloudSite.getClli());
426         Assert.assertEquals("regionId", getCloudSite.getRegionId());
427         Assert.assertEquals("RANDOMID", getCloudSite.getIdentityServiceId());
428     }
429
430     @Test
431     public void testGetHomingInstance() {
432         HomingInstance homingInstance = client.getHomingInstance("5df8b6de-2083-11e7-93ae-92361f232671");
433         Assert.assertNotNull(homingInstance);
434         Assert.assertNotNull(homingInstance.getCloudOwner());
435         Assert.assertNotNull(homingInstance.getCloudRegionId());
436         Assert.assertNotNull(homingInstance.getOofDirectives());
437     }
438
439     @Test
440     public void testPostHomingInstance() {
441         CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger("http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
442         HomingInstance homingInstance = new HomingInstance();
443         homingInstance.setServiceInstanceId("5df8d6be-2083-11e7-93ae-92361f232671");
444         homingInstance.setCloudOwner("CloudOwner-1");
445         homingInstance.setCloudRegionId("CloudRegionOne");
446         homingInstance.setOofDirectives("{\n" +
447                 "\"directives\": [\n" +
448                 "{\n" +
449                 "\"directives\": [\n" +
450                 "{\n" +
451                 "\"attributes\": [\n" +
452                 "{\n" +
453                 "\"attribute_value\": \"onap.hpa.flavor31\",\n" +
454                 "\"attribute_name\": \"firewall_flavor_name\"\n" +
455                 "}\n" +
456                 "],\n" +
457                 "\"type\": \"flavor_directives\"\n" +
458                 "}\n" +
459                 "],\n" +
460                 "\"type\": \"vnfc\",\n" +
461                 "\"id\": \"vfw\"\n" +
462                 "},\n" +
463                 "{\n" +
464                 "\"directives\": [\n" +
465                 "{\n" +
466                 "\"attributes\": [\n" +
467                 "{\n" +
468                 "\"attribute_value\": \"onap.hpa.flavor32\",\n" +
469                 "\"attribute_name\": \"packetgen_flavor_name\"\n" +
470                 "}\n" +
471                 "],\n" +
472                 "\"type\": \"flavor_directives\"\n" +
473                 "}\n" +
474                 "],\n" +
475                 "\"type\": \"vnfc\",\n" +
476                 "\"id\": \"vgenerator\"\n" +
477                 "},\n" +
478                 "{\n" +
479                 "\"directives\": [\n" +
480                 "{\n" +
481                 "\"attributes\": [\n" +
482                 "{\n" +
483                 "\"attribute_value\": \"onap.hpa.flavor31\",\n" +
484                 "\"attribute_name\": \"sink_flavor_name\"\n" +
485                 "}\n" +
486                 "],\n" +
487                 "\"type\": \"flavor_directives\"\n" +
488                 "}\n" +
489                 "],\n" +
490                 "\"type\": \"vnfc\",\n" +
491                 "\"id\": \"vsink\"\n" +
492                 "}\n" +
493                 "]\n" +
494                 "}");
495         localClient.postHomingInstance(homingInstance);
496         HomingInstance getHomingInstance = this.client.getHomingInstance("5df8d6be-2083-11e7-93ae-92361f232671");
497         Assert.assertNotNull(getHomingInstance);
498         Assert.assertNotNull(getHomingInstance.getCloudRegionId());
499         Assert.assertNotNull(getHomingInstance.getCloudOwner());
500         Assert.assertEquals("CloudOwner-1", getHomingInstance.getCloudOwner());
501         Assert.assertEquals("CloudRegionOne", getHomingInstance.getCloudRegionId());
502     }
503
504    @Test
505     public void testGetServiceByModelName() {
506         Service service = client.getServiceByModelName("MSOTADevInfra_Test_Service");
507         Assert.assertNotNull(service);
508         Assert.assertNotNull(service.getModelVersion());
509         Assert.assertNotNull(service.getModelInvariantUUID());
510         Assert.assertEquals("MSOTADevInfra_Test_Service", service.getModelName());
511         Assert.assertEquals("NA", service.getServiceRole());
512     }
513
514     @Test
515     public void testGetServiceByModelNameNotFound() {
516         Service service = client.getServiceByModelName("Not_Found");
517         Assert.assertNull(service);
518     }
519
520     @Test
521     public void testGetServiceByModelUUID() {
522         Service service = client.getServiceByModelUUID("5df8b6de-2083-11e7-93ae-92361f002679");
523         Assert.assertNotNull(service);
524         Assert.assertNotNull(service.getModelVersion());
525         Assert.assertNotNull(service.getModelInvariantUUID());
526         Assert.assertEquals("5df8b6de-2083-11e7-93ae-92361f002679", service.getModelUUID());
527         Assert.assertEquals("NA", service.getServiceRole());
528     }
529
530     @Test
531     public void testGetServiceByModelUUIDNotFound() {
532         Service service = client.getServiceByModelUUID("Not_Found");
533         Assert.assertNull(service);
534     }
535
536     @Test
537     public void testGetNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(){
538         NorthBoundRequest northBoundRequest = new NorthBoundRequest();
539         northBoundRequest.setAction("createService");
540         northBoundRequest.setRequestScope("service");
541         northBoundRequest.setIsAlacarte(true);
542         northBoundRequest.setCloudOwner("my-custom-cloud-owner");
543         client.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner("createService", "service", true, "my-custom-cloud-owner");
544         Assert.assertNotNull(northBoundRequest);
545         Assert.assertEquals("createService",northBoundRequest.getAction());
546         Assert.assertEquals("service",northBoundRequest.getRequestScope());
547         Assert.assertEquals(true,northBoundRequest.getIsAlacarte() );
548         Assert.assertEquals("my-custom-cloud-owner", northBoundRequest.getCloudOwner());
549     }
550    
551     @Test
552     public void testFindServiceRecipeByActionAndServiceModelUUID() {
553         ServiceRecipe serviceRecipe = client.findServiceRecipeByActionAndServiceModelUUID("createInstance","4694a55f-58b3-4f17-92a5-796d6f5ffd0d" );
554         Assert.assertNotNull(serviceRecipe);
555         Assert.assertNotNull(serviceRecipe.getServiceModelUUID());
556         Assert.assertNotNull(serviceRecipe.getAction());
557         Assert.assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri());
558         Assert.assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
559     }
560
561     @Test
562     public void testFindServiceRecipeByActionAndServiceModelUUIDNotFound() {
563         ServiceRecipe serviceRecipe = client.findServiceRecipeByActionAndServiceModelUUID("not_found","5df8b6de-2083-11e7-93ae-test" );
564         Assert.assertNull(serviceRecipe);
565     }
566
567     @Test
568     public void testFindExternalToInternalServiceByServiceName() {
569         ExternalServiceToInternalService externalServiceToInternalService = client.findExternalToInternalServiceByServiceName("MySpecialServiceName");
570         Assert.assertNotNull(externalServiceToInternalService);
571         Assert.assertNotNull(externalServiceToInternalService.getServiceName());
572         Assert.assertNotNull(externalServiceToInternalService.getServiceModelUUID());
573         Assert.assertEquals("MySpecialServiceName", externalServiceToInternalService.getServiceName());
574     }
575
576     @Test
577     public void testFindExternalToInternalServiceByServiceNameNotFound() {
578         ExternalServiceToInternalService externalServiceToInternalService = client.findExternalToInternalServiceByServiceName("Not_Found");
579         Assert.assertNull(externalServiceToInternalService);
580     }
581 }