4ec5839cb627303a68aed99c7c4d7e87441df53d
[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 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Ignore;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.onap.so.adapters.catalogdb.CatalogDBApplication;
29 import org.onap.so.db.catalog.beans.CloudSite;
30 import org.onap.so.db.catalog.beans.CloudifyManager;
31 import org.onap.so.db.catalog.beans.InstanceGroup;
32 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
33 import org.onap.so.db.catalog.beans.Service;
34 import org.onap.so.db.catalog.beans.ServiceRecipe;
35 import org.onap.so.db.catalog.beans.VfModule;
36 import org.onap.so.db.catalog.beans.VfModuleCustomization;
37 import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
38 import org.onap.so.db.catalog.beans.VnfRecipe;
39 import org.onap.so.db.catalog.beans.VnfResource;
40 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.boot.context.embedded.LocalServerPort;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.test.context.ActiveProfiles;
45 import org.springframework.test.context.junit4.SpringRunner;
46
47 import java.util.List;
48 import java.util.UUID;
49
50 @RunWith(SpringRunner.class)
51 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
52 @ActiveProfiles("test")
53 public class CatalogDbClientTest {
54     public static final String MTN13 = "mtn13";
55     @LocalServerPort
56     private int port;
57     @Autowired
58     CatalogDbClientPortChanger client;
59
60     @Before
61     public void initialize() {
62         client.wiremockPort = String.valueOf(port);
63     }
64
65     @Test
66     public void testGetCloudSiteHappyPath() throws Exception {
67         CloudSite cloudSite = client.getCloudSite(MTN13);
68         Assert.assertNotNull(cloudSite);
69         Assert.assertNotNull(cloudSite.getIdentityService());
70         Assert.assertEquals("MDT13", cloudSite.getClli());
71         Assert.assertEquals("mtn13", cloudSite.getRegionId());
72         Assert.assertEquals("MTN13", cloudSite.getIdentityServiceId());
73     }
74
75     @Test
76     public void testGetCloudSiteNotFound() throws Exception {
77         CloudSite cloudSite = client.getCloudSite(UUID.randomUUID().toString());
78         Assert.assertNull(cloudSite);
79     }
80
81     @Test
82     public void testGetCloudifyManagerHappyPath() throws Exception {
83         CloudifyManager cloudifyManager = client.getCloudifyManager("mtn13");
84         Assert.assertNotNull(cloudifyManager);
85         Assert.assertEquals("http://localhost:28090/v2.0", cloudifyManager.getCloudifyUrl());
86
87     }
88
89     @Test
90     public void testGetCloudifyManagerNotFound() throws Exception {
91         CloudifyManager cloudifyManager = client.getCloudifyManager(UUID.randomUUID().toString());
92         Assert.assertNull(cloudifyManager);
93     }
94
95
96     @Test
97     public void testGetCloudSiteByClliAndAicVersionHappyPath() throws Exception {
98         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "2.5");
99         Assert.assertNotNull(cloudSite);
100     }
101
102     @Test
103     public void testGetCloudSiteByClliAndAicVersionNotFound() throws Exception {
104         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "232496239746328");
105         Assert.assertNull(cloudSite);
106     }
107
108     @Test
109     public void testGetServiceByID() throws Exception {
110         Service serviceByID = client.getServiceByID("5df8b6de-2083-11e7-93ae-92361f002671");
111         Assert.assertNotNull(serviceByID);
112         Assert.assertEquals("MSOTADevInfra_vSAMP10a_Service", serviceByID.getModelName());
113         Assert.assertEquals("NA", serviceByID.getServiceType());
114         Assert.assertEquals("NA", serviceByID.getServiceRole());
115     }
116
117     @Test
118     public void testGetServiceByIDNotFound() throws Exception {
119         Service serviceByID = client.getServiceByID(UUID.randomUUID().toString());
120         Assert.assertNull(serviceByID);
121     }
122
123     @Test
124     public void testGetVfModuleByModelUUID() throws Exception {
125         VfModule vfModule = client.getVfModuleByModelUUID("20c4431c-246d-11e7-93ae-92361f002671");
126         Assert.assertNotNull(vfModule);
127         Assert.assertNotNull(vfModule.getVfModuleCustomization());
128         Assert.assertEquals("78ca26d0-246d-11e7-93ae-92361f002671", vfModule.getModelInvariantUUID());
129         Assert.assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
130     }
131
132     @Test
133     public void testGetVfModuleByModelUUIDNotFound() throws Exception {
134         VfModule vfModule = client.getVfModuleByModelUUID(UUID.randomUUID().toString());
135         Assert.assertNull(vfModule);
136     }
137
138     @Test
139     public void testGetVnfResourceByModelUUID() throws Exception {
140         VnfResource vnfResource = client.getVnfResourceByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
141         Assert.assertNotNull(vnfResource);
142         Assert.assertEquals("vSAMP10a", vnfResource.getModelName());
143     }
144
145     @Test
146     public void testGetVnfResourceByModelUUIDNotFound() throws Exception {
147         VnfResource vnfResource = client.getVnfResourceByModelUUID(UUID.randomUUID().toString());
148         Assert.assertNull(vnfResource);
149     }
150
151     @Test
152     public void testGetVnfResourceCustomizationByModelCustomizationUUID() {
153         VnfResourceCustomization vnfResourceCustomization = client.getVnfResourceCustomizationByModelCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002671");
154         Assert.assertNotNull(vnfResourceCustomization);
155         Assert.assertEquals("vSAMP", vnfResourceCustomization.getNfRole());
156         Assert.assertNotNull(vnfResourceCustomization.getModelCustomizationUUID());
157         Assert.assertNotNull(vnfResourceCustomization.getVnfResources());
158         Assert.assertNotNull(vnfResourceCustomization.getVfModuleCustomizations());
159         Assert.assertEquals("vSAMP10a", vnfResourceCustomization.getVnfResources().getModelName());
160
161     }
162
163     @Test
164     public void testGetVnfResourceCustomizationByModelCustomizationUUINotFound() {
165         VnfResourceCustomization vnfResourceCustomization = client.getVnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
166         Assert.assertNull(vnfResourceCustomization);
167     }
168
169     @Test
170     public void testGetInstanceGroupByModelUUID() {
171         InstanceGroup instanceGroup = client.getInstanceGroupByModelUUID("0c8692ef-b9c0-435d-a738-edf31e71f38b");
172         Assert.assertNotNull(instanceGroup);
173         Assert.assertEquals("network_collection_resource_1806..NetworkCollection..0", instanceGroup.getModelName());
174         Assert.assertEquals("org.openecomp.resource.cr.NetworkCollectionResource1806", instanceGroup.getToscaNodeType().toString());
175     }
176
177     @Test
178     public void testGetVfModuleCustomizationByModelCuztomizationUUID() {
179         VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCuztomizationUUID("cb82ffd8-252a-11e7-93ae-92361f002671");
180         Assert.assertNotNull(vfModuleCustomization);
181         Assert.assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
182         Assert.assertEquals("base", vfModuleCustomization.getLabel());
183     }
184
185     @Test
186     public void testGetVfModuleCustomizationByModelCuztomizationUUIDNotFound() {
187         VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCuztomizationUUID(UUID.randomUUID().toString());
188         Assert.assertNull(vfModuleCustomization);
189     }
190
191     @Test
192     public void testGetNetworkResourceCustomizationByModelCustomizationUUID() {
193         NetworkResourceCustomization networkResourceCustomization = client.getNetworkResourceCustomizationByModelCustomizationUUID("3bdbb104-476c-483e-9f8b-c095b3d308ac");
194         Assert.assertNotNull(networkResourceCustomization);
195         Assert.assertNotNull(networkResourceCustomization.getModelCustomizationUUID());
196         Assert.assertEquals("CONTRAIL30_GNDIRECT 9", networkResourceCustomization.getModelInstanceName());
197         Assert.assertNotNull(networkResourceCustomization.getNetworkResource());
198     }
199
200     @Test
201     public void testGetNetworkResourceCustomizationByModelCustomizationUUIDNotFound() {
202         NetworkResourceCustomization networkResourceCustomization = client.getNetworkResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
203         Assert.assertNull(networkResourceCustomization);
204     }
205
206     @Test
207     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID() {
208         VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID("cb82ffd8-252a-11e7-93ae-92361f002672", "20c4431c-246d-11e7-93ae-92361f002672");
209         Assert.assertNotNull(vfModuleCustomization);
210         Assert.assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
211         Assert.assertNotNull(vfModuleCustomization.getVfModule());
212         Assert.assertEquals("base", vfModuleCustomization.getLabel());
213     }
214
215     @Test
216     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUIDNotFound() {
217         VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID("cb82ffd8-252a-11e7-93ae-92361f002672", UUID.randomUUID().toString());
218         Assert.assertNull(vfModuleCustomization);
219     }
220
221     @Test
222     public void testGetFirstByServiceModelUUIDAndAction() {
223         ServiceRecipe serviceRecipe = client.getFirstByServiceModelUUIDAndAction("4694a55f-58b3-4f17-92a5-796d6f5ffd0d", "createInstance");
224         Assert.assertNotNull(serviceRecipe);
225         Assert.assertNotNull(serviceRecipe.getServiceModelUUID());
226         Assert.assertNotNull(serviceRecipe.getAction());
227         Assert.assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri());
228         Assert.assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
229     }
230
231     @Test
232     public void testGetFirstByServiceModelUUIDAndActionNotFound() {
233         ServiceRecipe serviceRecipe = client.getFirstByServiceModelUUIDAndAction("5df8b6de-2083-11e7-93ae-92361f002671", UUID.randomUUID().toString());
234         Assert.assertNull(serviceRecipe);
235     }
236     
237     @Test
238     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersion() {
239         VnfResource vnfResource = client.getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671", "2.0");
240         Assert.assertNotNull(vnfResource);
241         Assert.assertNotNull(vnfResource.getModelInvariantId());
242         Assert.assertNotNull(vnfResource.getModelVersion());
243         Assert.assertNotNull(vnfResource.getHeatTemplates());
244         Assert.assertNotNull(vnfResource.getVnfResourceCustomizations());
245         Assert.assertEquals("vSAMP10a", vnfResource.getModelName());
246     }
247
248     @Test
249     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersionNotFound() {
250         VnfResource vnfResource = client.getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671", UUID.randomUUID().toString());
251         Assert.assertNull(vnfResource);
252     }
253
254     @Test
255     public void testGetFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources() {
256         VnfResource vnfr = new VnfResource();
257         vnfr.setModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
258         VnfResourceCustomization firstVnfResourceCustomizationByModelInstanceNameAndVnfResources = client.getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources("vSAMP10a 1", vnfr);
259         Assert.assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources);
260         Assert.assertEquals("vSAMP", firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getNfRole());
261         Assert.assertEquals("vSAMP10a 1", firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getModelInstanceName());
262         Assert.assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVnfResources());
263         Assert.assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVfModuleCustomizations());
264     }
265
266     @Test
267     public void testGetFirstVnfRecipeByNfRoleAndAction() {
268         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction("GR-API-DEFAULT", "createInstance");
269         Assert.assertNotNull(vnfRecipe);
270         Assert.assertNotNull(vnfRecipe.getNfRole());
271         Assert.assertNotNull(vnfRecipe.getAction());
272         Assert.assertEquals("Gr api recipe to create vnf", vnfRecipe.getDescription());
273         Assert.assertEquals("/mso/async/services/WorkflowActionBB", vnfRecipe.getOrchestrationUri());
274     }
275
276     @Test
277     public void testGetFirstVnfRecipeByNfRoleAndActionNotFound() {
278         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction(UUID.randomUUID().toString(), "createInstance");
279         Assert.assertNull(vnfRecipe);
280     }
281
282     @Test
283     public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction() {
284         VnfComponentsRecipe vnfComponentsRecipe = client.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction("20c4431c-246d-11e7-93ae-92361f002671", "volumeGroup", "createInstance");
285         Assert.assertNotNull(vnfComponentsRecipe);
286         Assert.assertNotNull(vnfComponentsRecipe.getAction());
287         Assert.assertNotNull(vnfComponentsRecipe.getVfModuleModelUUID());
288         Assert.assertNotNull(vnfComponentsRecipe.getVnfComponentType());
289         Assert.assertEquals("Gr api recipe to create volume-group", vnfComponentsRecipe.getDescription());
290         Assert.assertEquals("/mso/async/services/WorkflowActionBB", vnfComponentsRecipe.getOrchestrationUri());
291
292     }
293
294
295     @Test
296     public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndActionNotFound() {
297         VnfComponentsRecipe vnfComponentsRecipe = client.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(UUID.randomUUID().toString(), "volumeGroup", "createInstance");
298         Assert.assertNull(vnfComponentsRecipe);
299     }
300
301     @Test
302     public void testGetFirstVnfComponentsRecipeByVnfComponentTypeAndAction() {
303         VnfComponentsRecipe vnfComponentsRecipe = client.getFirstVnfComponentsRecipeByVnfComponentTypeAndAction("volumeGroup", "createInstance");
304         Assert.assertNotNull(vnfComponentsRecipe);
305         Assert.assertNotNull(vnfComponentsRecipe.getAction());
306         Assert.assertNotNull(vnfComponentsRecipe.getVnfComponentType());
307         Assert.assertEquals("VID_DEFAULT recipe t", vnfComponentsRecipe.getDescription());
308         Assert.assertEquals("/mso/async/services/CreateVfModuleVolumeInfraV1", vnfComponentsRecipe.getOrchestrationUri());
309     }
310
311     @Test
312     public void testGetServiceByModelVersionAndModelInvariantUUID() {
313         Service service = client.getServiceByModelVersionAndModelInvariantUUID("2.0", "9647dfc4-2083-11e7-93ae-92361f002671");
314         Assert.assertNotNull(service);
315         Assert.assertNotNull(service.getModelVersion());
316         Assert.assertNotNull(service.getModelInvariantUUID());
317         Assert.assertEquals("MSOTADevInfra_vSAMP10a_Service", service.getModelName());
318         Assert.assertEquals("NA", service.getServiceRole());
319     }
320
321     @Test
322     public void testGetServiceByModelVersionAndModelInvariantUUIDNotFound() {
323         Service service = client.getServiceByModelVersionAndModelInvariantUUID("2.0", UUID.randomUUID().toString());
324         Assert.assertNull(service);
325     }
326
327     @Test
328     public void testGetVfModuleByModelInvariantUUIDAndModelVersion() {
329         VfModule vfModule = client.getVfModuleByModelInvariantUUIDAndModelVersion("78ca26d0-246d-11e7-93ae-92361f002671", "2");
330         Assert.assertNotNull(vfModule);
331         Assert.assertNotNull(vfModule.getModelVersion());
332         Assert.assertNotNull(vfModule.getModelInvariantUUID());
333         Assert.assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
334         Assert.assertEquals("vSAMP10a DEV Base", vfModule.getDescription());
335     }
336
337     @Test
338     public void testGetVfModuleByModelInvariantUUIDAndModelVersionNotFound() {
339         VfModule vfModule = client.getVfModuleByModelInvariantUUIDAndModelVersion(UUID.randomUUID().toString(), "2");
340         Assert.assertNull(vfModule);
341     }
342     
343     @Test
344     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDesc() {
345         List<Service> serviceList = client.getServiceByModelInvariantUUIDOrderByModelVersionDesc("9647dfc4-2083-11e7-93ae-92361f002671");
346         Assert.assertFalse(serviceList.isEmpty());
347         Assert.assertEquals(2, serviceList.size());
348         Service service = serviceList.get(0);
349         Assert.assertEquals("2.0", service.getModelVersion());
350     }
351
352     @Test
353     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDescNotFound() {
354         List<Service> serviceList = client.getServiceByModelInvariantUUIDOrderByModelVersionDesc(UUID.randomUUID().toString());
355         Assert.assertTrue(serviceList.isEmpty());
356     }
357
358     @Test
359     public void testGetVfModuleByModelInvariantUUIDOrderByModelVersionDesc() {
360         List<VfModule> moduleList = client.getVfModuleByModelInvariantUUIDOrderByModelVersionDesc("78ca26d0-246d-11e7-93ae-92361f002671");
361         Assert.assertFalse(moduleList.isEmpty());
362         Assert.assertEquals(2, moduleList.size());
363         VfModule module = moduleList.get(0);
364         Assert.assertEquals("vSAMP10a DEV Base",module.getDescription());
365     }
366 }