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