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