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