2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.db.catalog.client;
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;
53 import java.util.List;
54 import java.util.UUID;
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";
64 @Value("${mso.db.auth}")
65 private String msoAdaptersAuth;
68 CatalogDbClientPortChanger client;
71 public void initialize(){
72 client.wiremockPort= String.valueOf(port);
76 public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(){
77 RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", "*", "*", "*", "*");
78 Assert.assertEquals("Rollback", rainyDayHandlerStatus.getPolicy());
82 public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStepRecordNotFound(){
83 RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(UUID.randomUUID().toString(), "*", "*", "*", "*");
84 Assert.assertNull(rainyDayHandlerStatus);
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());
98 public void testGetCloudSiteNotFound() throws Exception {
99 CloudSite cloudSite = client.getCloudSite(UUID.randomUUID().toString());
100 Assert.assertNull(cloudSite);
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());
112 public void testGetCloudifyManagerNotFound() throws Exception {
113 CloudifyManager cloudifyManager = client.getCloudifyManager(UUID.randomUUID().toString());
114 Assert.assertNull(cloudifyManager);
119 public void testGetCloudSiteByClliAndAicVersionHappyPath() throws Exception {
120 CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "2.5");
121 Assert.assertNotNull(cloudSite);
125 public void testGetCloudSiteByClliAndAicVersionNotFound() throws Exception {
126 CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "232496239746328");
127 Assert.assertNull(cloudSite);
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());
140 public void testGetServiceByIDNotFound() throws Exception {
141 Service serviceByID = client.getServiceByID(UUID.randomUUID().toString());
142 Assert.assertNull(serviceByID);
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());
155 public void testGetVfModuleByModelUUIDNotFound() throws Exception {
156 VfModule vfModule = client.getVfModuleByModelUUID(UUID.randomUUID().toString());
157 Assert.assertNull(vfModule);
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());
168 public void testGetVnfResourceByModelUUIDNotFound() throws Exception {
169 VnfResource vnfResource = client.getVnfResourceByModelUUID(UUID.randomUUID().toString());
170 Assert.assertNull(vnfResource);
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());
186 public void testGetVnfResourceCustomizationByModelCustomizationUUINotFound() {
187 VnfResourceCustomization vnfResourceCustomization = client.getVnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
188 Assert.assertNull(vnfResourceCustomization);
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());
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());
208 public void testGetVfModuleCustomizationByModelCuztomizationUUIDNotFound() {
209 VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCuztomizationUUID(UUID.randomUUID().toString());
210 Assert.assertNull(vfModuleCustomization);
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());
223 public void testGetNetworkResourceCustomizationByModelCustomizationUUIDNotFound() {
224 NetworkResourceCustomization networkResourceCustomization = client.getNetworkResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
225 Assert.assertNull(networkResourceCustomization);
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());
238 public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUIDNotFound() {
239 VfModuleCustomization vfModuleCustomization = client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID("cb82ffd8-252a-11e7-93ae-92361f002672", UUID.randomUUID().toString());
240 Assert.assertNull(vfModuleCustomization);
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());
254 public void testGetFirstByServiceModelUUIDAndActionNotFound() {
255 ServiceRecipe serviceRecipe = client.getFirstByServiceModelUUIDAndAction("5df8b6de-2083-11e7-93ae-92361f002671", UUID.randomUUID().toString());
256 Assert.assertNull(serviceRecipe);
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());
271 public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersionNotFound() {
272 VnfResource vnfResource = client.getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671", UUID.randomUUID().toString());
273 Assert.assertNull(vnfResource);
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());
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());
299 public void testGetFirstVnfRecipeByNfRoleAndActionNotFound() {
300 VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction(UUID.randomUUID().toString(), "createInstance");
301 Assert.assertNull(vnfRecipe);
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());
318 public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndActionNotFound() {
319 VnfComponentsRecipe vnfComponentsRecipe = client.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(UUID.randomUUID().toString(), "volumeGroup", "createInstance");
320 Assert.assertNull(vnfComponentsRecipe);
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());
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());
344 public void testGetServiceByModelVersionAndModelInvariantUUIDNotFound() {
345 Service service = client.getServiceByModelVersionAndModelInvariantUUID("2.0", UUID.randomUUID().toString());
346 Assert.assertNull(service);
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());
360 public void testGetVfModuleByModelInvariantUUIDAndModelVersionNotFound() {
361 VfModule vfModule = client.getVfModuleByModelInvariantUUIDAndModelVersion(UUID.randomUUID().toString(), "2");
362 Assert.assertNull(vfModule);
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());
375 public void testGetServiceByModelInvariantUUIDOrderByModelVersionDescNotFound() {
376 List<Service> serviceList = client.getServiceByModelInvariantUUIDOrderByModelVersionDesc(UUID.randomUUID().toString());
377 Assert.assertTrue(serviceList.isEmpty());
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());
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");
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());