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;
 
  24 import static org.junit.Assert.assertEquals;
 
  25 import static org.junit.Assert.assertFalse;
 
  26 import static org.junit.Assert.assertNotEquals;
 
  27 import static org.junit.Assert.assertNotNull;
 
  28 import static org.junit.Assert.assertNull;
 
  29 import static org.junit.Assert.assertTrue;
 
  30 import java.util.List;
 
  31 import java.util.UUID;
 
  32 import org.junit.Before;
 
  33 import org.junit.Test;
 
  34 import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest;
 
  35 import org.onap.so.db.catalog.beans.AuthenticationType;
 
  36 import org.onap.so.db.catalog.beans.CloudIdentity;
 
  37 import org.onap.so.db.catalog.beans.CloudSite;
 
  38 import org.onap.so.db.catalog.beans.CloudifyManager;
 
  39 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
 
  40 import org.onap.so.db.catalog.beans.HomingInstance;
 
  41 import org.onap.so.db.catalog.beans.InstanceGroup;
 
  42 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
 
  43 import org.onap.so.db.catalog.beans.PnfResource;
 
  44 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
 
  45 import org.onap.so.db.catalog.beans.ServerType;
 
  46 import org.onap.so.db.catalog.beans.Service;
 
  47 import org.onap.so.db.catalog.beans.ServiceRecipe;
 
  48 import org.onap.so.db.catalog.beans.VfModule;
 
  49 import org.onap.so.db.catalog.beans.VfModuleCustomization;
 
  50 import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
 
  51 import org.onap.so.db.catalog.beans.VnfRecipe;
 
  52 import org.onap.so.db.catalog.beans.VnfResource;
 
  53 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
 
  54 import org.onap.so.db.catalog.beans.Workflow;
 
  55 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
 
  56 import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
 
  57 import org.springframework.beans.factory.annotation.Autowired;
 
  58 import org.springframework.beans.factory.annotation.Value;
 
  59 import org.springframework.boot.web.server.LocalServerPort;
 
  61 public class CatalogDbClientTest extends CatalogDbAdapterBaseTest {
 
  63     public static final String MTN13 = "mtn13";
 
  68     @Value("${mso.db.auth}")
 
  69     private String msoAdaptersAuth;
 
  72     CatalogDbClientPortChanger client;
 
  77     public void initialize() {
 
  78         client.wiremockPort = String.valueOf(port);
 
  79         client.setEndpoint(getEndpoint(port));
 
  82     protected String getEndpoint(int port) {
 
  83         return "http://localhost:" + port;
 
  87     public void testGetRainyDayHandler_Regex() {
 
  88         RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatus("AssignServiceInstanceBB", "*",
 
  89                 "*", "*", "*", "The Flavor ID (nd.c6r16d20) could not be found.", "*");
 
  90         assertEquals("Rollback", rainyDayHandlerStatus.getPolicy());
 
  94     public void testGetRainyDayHandler__Encoding_Regex() {
 
  95         RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatus("AssignServiceInstanceBB", "*",
 
  97                 "resources.lba_0_dmz_vmi_0: Unknown id: Error: oper 1 url /fqname-to-id body {\"fq_name\": [\"zrdm6bvota05-dmz_sec_group\"], \"type\": \"security-group\"} response Name ['zrdm6bvota05-dmz_sec_group'] not found",
 
  99         assertEquals("Rollback", rainyDayHandlerStatus.getPolicy());
 
 103     public void testGetCloudSiteHappyPath() throws Exception {
 
 104         CloudSite cloudSite = client.getCloudSite(MTN13);
 
 105         assertNotNull(cloudSite);
 
 106         assertNotNull(cloudSite.getIdentityService());
 
 107         assertEquals("MDT13", cloudSite.getClli());
 
 108         assertEquals("mtn13", cloudSite.getRegionId());
 
 109         assertEquals("MTN13", cloudSite.getIdentityServiceId());
 
 113     public void testGetCloudSiteNotFound() throws Exception {
 
 114         CloudSite cloudSite = client.getCloudSite(UUID.randomUUID().toString());
 
 115         assertNull(cloudSite);
 
 119     public void testGetCloudifyManagerHappyPath() throws Exception {
 
 120         CloudifyManager cloudifyManager = client.getCloudifyManager("mtn13");
 
 121         assertNotNull(cloudifyManager);
 
 122         assertEquals("http://localhost:28090/v2.0", cloudifyManager.getCloudifyUrl());
 
 127     public void testGetCloudifyManagerNotFound() throws Exception {
 
 128         CloudifyManager cloudifyManager = client.getCloudifyManager(UUID.randomUUID().toString());
 
 129         assertNull(cloudifyManager);
 
 134     public void testGetCloudSiteByClliAndAicVersionHappyPath() throws Exception {
 
 135         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "2.5");
 
 136         assertNotNull(cloudSite);
 
 140     public void testGetCloudSiteByClliAndAicVersionNotFound() throws Exception {
 
 141         CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "232496239746328");
 
 142         assertNull(cloudSite);
 
 146     public void testGetServiceByID() throws Exception {
 
 147         Service serviceByID = client.getServiceByID("5df8b6de-2083-11e7-93ae-92361f002671");
 
 148         assertNotNull(serviceByID);
 
 149         assertEquals("MSOTADevInfra_vSAMP10a_Service", serviceByID.getModelName());
 
 150         assertEquals("NA", serviceByID.getServiceType());
 
 151         assertEquals("NA", serviceByID.getServiceRole());
 
 155     public void testGetServiceByIDNotFound() throws Exception {
 
 156         Service serviceByID = client.getServiceByID(UUID.randomUUID().toString());
 
 157         assertNull(serviceByID);
 
 161     public void testGetVfModuleByModelUUID() throws Exception {
 
 162         VfModule vfModule = client.getVfModuleByModelUUID("20c4431c-246d-11e7-93ae-92361f002671");
 
 163         assertNotNull(vfModule);
 
 164         assertNotNull(vfModule.getVfModuleCustomization());
 
 165         assertEquals("78ca26d0-246d-11e7-93ae-92361f002671", vfModule.getModelInvariantUUID());
 
 166         assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
 
 170     public void testGetVfModuleByModelUUIDNotFound() throws Exception {
 
 171         VfModule vfModule = client.getVfModuleByModelUUID(UUID.randomUUID().toString());
 
 172         assertNull(vfModule);
 
 176     public void testGetVnfResourceByModelUUID() throws Exception {
 
 177         VnfResource vnfResource = client.getVnfResourceByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
 
 178         assertNotNull(vnfResource);
 
 179         assertEquals("vSAMP10a", vnfResource.getModelName());
 
 183     public void testGetVnfResourceByModelUUIDNotFound() throws Exception {
 
 184         VnfResource vnfResource = client.getVnfResourceByModelUUID(UUID.randomUUID().toString());
 
 185         assertNull(vnfResource);
 
 189     public void testGetVnfResourceCustomizationByModelCustomizationUUID() {
 
 190         VnfResourceCustomization vnfResourceCustomization =
 
 191                 client.getVnfResourceCustomizationByModelCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002671");
 
 192         assertNotNull(vnfResourceCustomization);
 
 193         assertEquals("vSAMP", vnfResourceCustomization.getNfRole());
 
 194         assertNotNull(vnfResourceCustomization.getModelCustomizationUUID());
 
 195         assertNotNull(vnfResourceCustomization.getVnfResources());
 
 196         assertNotNull(vnfResourceCustomization.getVfModuleCustomizations());
 
 197         assertEquals("vSAMP10a", vnfResourceCustomization.getVnfResources().getModelName());
 
 198         assertTrue("skip post instantiation configuration", vnfResourceCustomization.isSkipPostInstConf());
 
 202     public void testGetVnfResourceCustomizationByModelCustomizationUUINotFound() {
 
 203         VnfResourceCustomization vnfResourceCustomization =
 
 204                 client.getVnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
 
 205         assertNull(vnfResourceCustomization);
 
 209     public void testGetInstanceGroupByModelUUID() {
 
 210         InstanceGroup instanceGroup = client.getInstanceGroupByModelUUID("0c8692ef-b9c0-435d-a738-edf31e71f38b");
 
 211         assertNotNull(instanceGroup);
 
 212         assertEquals("network_collection_resource_1806..NetworkCollection..0", instanceGroup.getModelName());
 
 213         assertEquals("org.openecomp.resource.cr.NetworkCollectionResource1806",
 
 214                 instanceGroup.getToscaNodeType().toString());
 
 218     public void testGetVfModuleCustomizationByModelCuztomizationUUID() {
 
 219         VfModuleCustomization vfModuleCustomization =
 
 220                 client.getVfModuleCustomizationByModelCuztomizationUUID("cb82ffd8-252a-11e7-93ae-92361f002671");
 
 221         assertNotNull(vfModuleCustomization);
 
 222         assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
 
 223         assertEquals("base", vfModuleCustomization.getLabel());
 
 227     public void testGetVfModuleCustomizationByModelCuztomizationUUIDNotFound() {
 
 228         VfModuleCustomization vfModuleCustomization =
 
 229                 client.getVfModuleCustomizationByModelCuztomizationUUID(UUID.randomUUID().toString());
 
 230         assertNull(vfModuleCustomization);
 
 234     public void testGetNetworkResourceCustomizationByModelCustomizationUUID() {
 
 235         NetworkResourceCustomization networkResourceCustomization =
 
 236                 client.getNetworkResourceCustomizationByModelCustomizationUUID("3bdbb104-476c-483e-9f8b-c095b3d308ac");
 
 237         assertNotNull(networkResourceCustomization);
 
 238         assertNotNull(networkResourceCustomization.getModelCustomizationUUID());
 
 239         assertEquals("CONTRAIL30_GNDIRECT 9", networkResourceCustomization.getModelInstanceName());
 
 240         assertNotNull(networkResourceCustomization.getNetworkResource());
 
 244     public void testGetNetworkResourceCustomizationByModelCustomizationUUIDNotFound() {
 
 245         NetworkResourceCustomization networkResourceCustomization =
 
 246                 client.getNetworkResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
 
 247         assertNull(networkResourceCustomization);
 
 251     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID() {
 
 252         VfModuleCustomization vfModuleCustomization =
 
 253                 client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
 
 254                         "cb82ffd8-252a-11e7-93ae-92361f002672", "20c4431c-246d-11e7-93ae-92361f002672");
 
 255         assertNotNull(vfModuleCustomization);
 
 256         assertNotNull(vfModuleCustomization.getModelCustomizationUUID());
 
 257         assertNotNull(vfModuleCustomization.getVfModule());
 
 258         assertEquals("base", vfModuleCustomization.getLabel());
 
 262     public void testGgetVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUIDNotFound() {
 
 263         VfModuleCustomization vfModuleCustomization =
 
 264                 client.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
 
 265                         "cb82ffd8-252a-11e7-93ae-92361f002672", UUID.randomUUID().toString());
 
 266         assertNull(vfModuleCustomization);
 
 270     public void testGetFirstByServiceModelUUIDAndAction() {
 
 271         ServiceRecipe serviceRecipe =
 
 272                 client.getFirstByServiceModelUUIDAndAction("4694a55f-58b3-4f17-92a5-796d6f5ffd0d", "createInstance");
 
 273         assertNotNull(serviceRecipe);
 
 274         assertNotNull(serviceRecipe.getServiceModelUUID());
 
 275         assertNotNull(serviceRecipe.getAction());
 
 276         assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri());
 
 277         assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
 
 281     public void testGetFirstByServiceModelUUIDAndActionNotFound() {
 
 282         ServiceRecipe serviceRecipe = client.getFirstByServiceModelUUIDAndAction("5df8b6de-2083-11e7-93ae-92361f002671",
 
 283                 UUID.randomUUID().toString());
 
 284         assertNull(serviceRecipe);
 
 288     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersion() {
 
 289         VnfResource vnfResource = client
 
 290                 .getFirstVnfResourceByModelInvariantUUIDAndModelVersion("2fff5b20-214b-11e7-93ae-92361f002671", "2.0");
 
 291         assertNotNull(vnfResource);
 
 292         assertNotNull(vnfResource.getModelInvariantId());
 
 293         assertNotNull(vnfResource.getModelVersion());
 
 294         assertNotNull(vnfResource.getHeatTemplates());
 
 295         assertEquals("vSAMP10a", vnfResource.getModelName());
 
 299     public void testGetFirstVnfResourceByModelInvariantUUIDAndModelVersionNotFound() {
 
 300         VnfResource vnfResource = client.getFirstVnfResourceByModelInvariantUUIDAndModelVersion(
 
 301                 "2fff5b20-214b-11e7-93ae-92361f002671", UUID.randomUUID().toString());
 
 302         assertNull(vnfResource);
 
 306     public void testGetFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources() {
 
 307         VnfResource vnfr = new VnfResource();
 
 308         vnfr.setModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
 
 309         VnfResourceCustomization firstVnfResourceCustomizationByModelInstanceNameAndVnfResources =
 
 310                 client.getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources("vSAMP10a 1", vnfr);
 
 311         assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources);
 
 312         assertEquals("vSAMP", firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getNfRole());
 
 313         assertEquals("vSAMP10a 1",
 
 314                 firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getModelInstanceName());
 
 315         assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVnfResources());
 
 316         assertNotNull(firstVnfResourceCustomizationByModelInstanceNameAndVnfResources.getVfModuleCustomizations());
 
 320     public void testGetFirstVnfRecipeByNfRoleAndAction() {
 
 321         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction("GR-API-DEFAULT", "createInstance");
 
 322         assertNotNull(vnfRecipe);
 
 323         assertNotNull(vnfRecipe.getNfRole());
 
 324         assertNotNull(vnfRecipe.getAction());
 
 325         assertEquals("Gr api recipe to create vnf", vnfRecipe.getDescription());
 
 326         assertEquals("/mso/async/services/WorkflowActionBB", vnfRecipe.getOrchestrationUri());
 
 330     public void testGetFirstVnfRecipeByNfRoleAndActionNotFound() {
 
 331         VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction(UUID.randomUUID().toString(), "createInstance");
 
 332         assertNull(vnfRecipe);
 
 336     public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction() {
 
 337         VnfComponentsRecipe vnfComponentsRecipe =
 
 338                 client.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(
 
 339                         "20c4431c-246d-11e7-93ae-92361f002671", "volumeGroup", "createInstance");
 
 340         assertNotNull(vnfComponentsRecipe);
 
 341         assertNotNull(vnfComponentsRecipe.getAction());
 
 342         assertNotNull(vnfComponentsRecipe.getVfModuleModelUUID());
 
 343         assertNotNull(vnfComponentsRecipe.getVnfComponentType());
 
 344         assertEquals("Gr api recipe to create volume-group", vnfComponentsRecipe.getDescription());
 
 345         assertEquals("/mso/async/services/WorkflowActionBB", vnfComponentsRecipe.getOrchestrationUri());
 
 351     public void testGetFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndActionNotFound() {
 
 352         VnfComponentsRecipe vnfComponentsRecipe =
 
 353                 client.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(
 
 354                         UUID.randomUUID().toString(), "volumeGroup", "createInstance");
 
 355         assertNull(vnfComponentsRecipe);
 
 359     public void testGetFirstVnfComponentsRecipeByVnfComponentTypeAndAction() {
 
 360         VnfComponentsRecipe vnfComponentsRecipe =
 
 361                 client.getFirstVnfComponentsRecipeByVnfComponentTypeAndAction("volumeGroup", "createInstance");
 
 362         assertNotNull(vnfComponentsRecipe);
 
 363         assertNotNull(vnfComponentsRecipe.getAction());
 
 364         assertNotNull(vnfComponentsRecipe.getVnfComponentType());
 
 365         assertEquals("VID_DEFAULT recipe t", vnfComponentsRecipe.getDescription());
 
 366         assertEquals("/mso/async/services/CreateVfModuleVolumeInfraV1", vnfComponentsRecipe.getOrchestrationUri());
 
 370     public void testGetServiceByModelVersionAndModelInvariantUUID() {
 
 372                 client.getServiceByModelVersionAndModelInvariantUUID("2.0", "9647dfc4-2083-11e7-93ae-92361f002671");
 
 373         assertNotNull(service);
 
 374         assertNotNull(service.getModelVersion());
 
 375         assertNotNull(service.getModelInvariantUUID());
 
 376         assertEquals("MSOTADevInfra_vSAMP10a_Service", service.getModelName());
 
 377         assertEquals("NA", service.getServiceRole());
 
 381     public void testGetServiceByModelVersionAndModelInvariantUUIDNotFound() {
 
 382         Service service = client.getServiceByModelVersionAndModelInvariantUUID("2.0", UUID.randomUUID().toString());
 
 387     public void testGetVfModuleByModelInvariantUUIDAndModelVersion() {
 
 389                 client.getVfModuleByModelInvariantUUIDAndModelVersion("78ca26d0-246d-11e7-93ae-92361f002671", "2");
 
 390         assertNotNull(vfModule);
 
 391         assertNotNull(vfModule.getModelVersion());
 
 392         assertNotNull(vfModule.getModelInvariantUUID());
 
 393         assertEquals("vSAMP10aDEV::base::module-0", vfModule.getModelName());
 
 394         assertEquals("vSAMP10a DEV Base", vfModule.getDescription());
 
 398     public void testGetVfModuleByModelInvariantUUIDAndModelVersionNotFound() {
 
 399         VfModule vfModule = client.getVfModuleByModelInvariantUUIDAndModelVersion(UUID.randomUUID().toString(), "2");
 
 400         assertNull(vfModule);
 
 404     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDesc() {
 
 405         List<Service> serviceList =
 
 406                 client.getServiceByModelInvariantUUIDOrderByModelVersionDesc("9647dfc4-2083-11e7-93ae-92361f002671");
 
 407         assertFalse(serviceList.isEmpty());
 
 408         assertEquals(2, serviceList.size());
 
 409         Service service = serviceList.get(0);
 
 410         assertEquals("2.0", service.getModelVersion());
 
 414     public void testGetServiceByModelInvariantUUIDOrderByModelVersionDescNotFound() {
 
 415         List<Service> serviceList =
 
 416                 client.getServiceByModelInvariantUUIDOrderByModelVersionDesc(UUID.randomUUID().toString());
 
 417         assertTrue(serviceList.isEmpty());
 
 421     public void testGetVfModuleByModelInvariantUUIDOrderByModelVersionDesc() {
 
 422         List<VfModule> moduleList =
 
 423                 client.getVfModuleByModelInvariantUUIDOrderByModelVersionDesc("78ca26d0-246d-11e7-93ae-92361f002671");
 
 424         assertFalse(moduleList.isEmpty());
 
 425         assertEquals(2, moduleList.size());
 
 426         VfModule module = moduleList.get(0);
 
 427         assertEquals("vSAMP10a DEV Base", module.getDescription());
 
 431     public void testCloudSiteClient() {
 
 432         CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger(
 
 433                 "http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
 
 434         CloudSite cloudSite = new CloudSite();
 
 435         cloudSite.setId("MTN6");
 
 436         cloudSite.setClli("TESTCLLI");
 
 437         cloudSite.setRegionId("regionId");
 
 438         cloudSite.setCloudVersion("VERSION");
 
 439         cloudSite.setPlatform("PLATFORM");
 
 441         CloudIdentity cloudIdentity = new CloudIdentity();
 
 442         cloudIdentity.setId("RANDOMID");
 
 443         cloudIdentity.setIdentityUrl("URL");
 
 444         cloudIdentity.setMsoId("MSO_ID");
 
 445         cloudIdentity.setMsoPass("MSO_PASS");
 
 446         cloudIdentity.setAdminTenant("ADMIN_TENANT");
 
 447         cloudIdentity.setMemberRole("ROLE");
 
 448         cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
 
 449         cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
 
 450         cloudSite.setIdentityService(cloudIdentity);
 
 451         localClient.postCloudSite(cloudSite);
 
 452         CloudSite getCloudSite = this.client.getCloudSite("MTN6");
 
 453         assertNotNull(getCloudSite);
 
 454         assertNotNull(getCloudSite.getIdentityService());
 
 455         assertEquals("TESTCLLI", getCloudSite.getClli());
 
 456         assertEquals("regionId", getCloudSite.getRegionId());
 
 457         assertEquals("RANDOMID", getCloudSite.getIdentityServiceId());
 
 459         getCloudSite.setClli("clli2");
 
 460         getCloudSite.setRegionId("region2");
 
 462         CloudSite updatedCloudSite = this.client.updateCloudSite(getCloudSite);
 
 463         assertNotNull(updatedCloudSite);
 
 464         assertNotNull(updatedCloudSite.getIdentityService());
 
 465         assertEquals("clli2", updatedCloudSite.getClli());
 
 466         assertEquals("region2", updatedCloudSite.getRegionId());
 
 468         this.client.deleteCloudSite(getCloudSite.getId());
 
 469         getCloudSite = this.client.getCloudSite("MTN6");
 
 470         assertNull(getCloudSite);
 
 474     public void testGetHomingInstance() {
 
 475         HomingInstance homingInstance = client.getHomingInstance("5df8b6de-2083-11e7-93ae-92361f232671");
 
 476         assertNotNull(homingInstance);
 
 477         assertNotNull(homingInstance.getCloudOwner());
 
 478         assertNotNull(homingInstance.getCloudRegionId());
 
 479         assertNotNull(homingInstance.getOofDirectives());
 
 483     public void testPostHomingInstance() {
 
 484         CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger(
 
 485                 "http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
 
 486         HomingInstance homingInstance = new HomingInstance();
 
 487         homingInstance.setServiceInstanceId("5df8d6be-2083-11e7-93ae-92361f232671");
 
 488         homingInstance.setCloudOwner("CloudOwner-1");
 
 489         homingInstance.setCloudRegionId("CloudRegionOne");
 
 490         homingInstance.setOofDirectives("{\n" + "\"directives\": [\n" + "{\n" + "\"directives\": [\n" + "{\n"
 
 491                 + "\"attributes\": [\n" + "{\n" + "\"attribute_value\": \"onap.hpa.flavor31\",\n"
 
 492                 + "\"attribute_name\": \"firewall_flavor_name\"\n" + "}\n" + "],\n"
 
 493                 + "\"type\": \"flavor_directives\"\n" + "}\n" + "],\n" + "\"type\": \"vnfc\",\n" + "\"id\": \"vfw\"\n"
 
 494                 + "},\n" + "{\n" + "\"directives\": [\n" + "{\n" + "\"attributes\": [\n" + "{\n"
 
 495                 + "\"attribute_value\": \"onap.hpa.flavor32\",\n" + "\"attribute_name\": \"packetgen_flavor_name\"\n"
 
 496                 + "}\n" + "],\n" + "\"type\": \"flavor_directives\"\n" + "}\n" + "],\n" + "\"type\": \"vnfc\",\n"
 
 497                 + "\"id\": \"vgenerator\"\n" + "},\n" + "{\n" + "\"directives\": [\n" + "{\n" + "\"attributes\": [\n"
 
 498                 + "{\n" + "\"attribute_value\": \"onap.hpa.flavor31\",\n" + "\"attribute_name\": \"sink_flavor_name\"\n"
 
 499                 + "}\n" + "],\n" + "\"type\": \"flavor_directives\"\n" + "}\n" + "],\n" + "\"type\": \"vnfc\",\n"
 
 500                 + "\"id\": \"vsink\"\n" + "}\n" + "]\n" + "}");
 
 501         localClient.postHomingInstance(homingInstance);
 
 502         HomingInstance getHomingInstance = this.client.getHomingInstance("5df8d6be-2083-11e7-93ae-92361f232671");
 
 503         assertNotNull(getHomingInstance);
 
 504         assertNotNull(getHomingInstance.getCloudRegionId());
 
 505         assertNotNull(getHomingInstance.getCloudOwner());
 
 506         assertEquals("CloudOwner-1", getHomingInstance.getCloudOwner());
 
 507         assertEquals("CloudRegionOne", getHomingInstance.getCloudRegionId());
 
 511     public void testGetServiceByModelName() {
 
 512         Service service = client.getServiceByModelName("MSOTADevInfra_Test_Service");
 
 513         assertNotNull(service);
 
 514         assertNotNull(service.getModelVersion());
 
 515         assertNotNull(service.getModelInvariantUUID());
 
 516         assertEquals("MSOTADevInfra_Test_Service", service.getModelName());
 
 517         assertEquals("NA", service.getServiceRole());
 
 521     public void testGetServiceByModelNameNotFound() {
 
 522         Service service = client.getServiceByModelName("Not_Found");
 
 527     public void testGetServiceByModelUUID() {
 
 528         Service service = client.getServiceByModelUUID("5df8b6de-2083-11e7-93ae-92361f002679");
 
 529         assertNotNull(service);
 
 530         assertNotNull(service.getModelVersion());
 
 531         assertNotNull(service.getModelInvariantUUID());
 
 532         assertEquals("5df8b6de-2083-11e7-93ae-92361f002679", service.getModelUUID());
 
 533         assertEquals("NA", service.getServiceRole());
 
 537     public void testGetServiceByModelUUIDNotFound() {
 
 538         Service service = client.getServiceByModelUUID("Not_Found");
 
 543     public void testGetNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner() {
 
 544         NorthBoundRequest northBoundRequest = new NorthBoundRequest();
 
 545         northBoundRequest.setAction("createService");
 
 546         northBoundRequest.setRequestScope("service");
 
 547         northBoundRequest.setIsAlacarte(true);
 
 548         northBoundRequest.setCloudOwner("my-custom-cloud-owner");
 
 549         client.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner("createService", "service", true,
 
 550                 "my-custom-cloud-owner");
 
 551         assertNotNull(northBoundRequest);
 
 552         assertEquals("createService", northBoundRequest.getAction());
 
 553         assertEquals("service", northBoundRequest.getRequestScope());
 
 554         assertEquals(true, northBoundRequest.getIsAlacarte());
 
 555         assertEquals("my-custom-cloud-owner", northBoundRequest.getCloudOwner());
 
 559     public void testFindServiceRecipeByActionAndServiceModelUUID() {
 
 560         ServiceRecipe serviceRecipe = client.findServiceRecipeByActionAndServiceModelUUID("createInstance",
 
 561                 "4694a55f-58b3-4f17-92a5-796d6f5ffd0d");
 
 562         assertNotNull(serviceRecipe);
 
 563         assertNotNull(serviceRecipe.getServiceModelUUID());
 
 564         assertNotNull(serviceRecipe.getAction());
 
 565         assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri());
 
 566         assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
 
 570     public void testFindServiceRecipeByActionAndServiceModelUUIDNotFound() {
 
 571         ServiceRecipe serviceRecipe =
 
 572                 client.findServiceRecipeByActionAndServiceModelUUID("not_found", "5df8b6de-2083-11e7-93ae-test");
 
 573         assertNull(serviceRecipe);
 
 577     public void testFindExternalToInternalServiceByServiceName() {
 
 578         ExternalServiceToInternalService externalServiceToInternalService =
 
 579                 client.findExternalToInternalServiceByServiceName("MySpecialServiceName");
 
 580         assertNotNull(externalServiceToInternalService);
 
 581         assertNotNull(externalServiceToInternalService.getServiceName());
 
 582         assertNotNull(externalServiceToInternalService.getServiceModelUUID());
 
 583         assertEquals("MySpecialServiceName", externalServiceToInternalService.getServiceName());
 
 587     public void testFindExternalToInternalServiceByServiceNameNotFound() {
 
 588         ExternalServiceToInternalService externalServiceToInternalService =
 
 589                 client.findExternalToInternalServiceByServiceName("Not_Found");
 
 590         assertNull(externalServiceToInternalService);
 
 594     public void getPnfResourceByModelUUID_validUuid_expectedOutput() {
 
 595         PnfResource pnfResource = client.getPnfResourceByModelUUID("ff2ae348-214a-11e7-93ae-92361f002680");
 
 596         assertNotNull(pnfResource);
 
 597         assertEquals("PNFResource modelUUID", "ff2ae348-214a-11e7-93ae-92361f002680", pnfResource.getModelUUID());
 
 598         assertEquals("PNFResource modelInvariantUUID", "2fff5b20-214b-11e7-93ae-92361f002680",
 
 599                 pnfResource.getModelInvariantUUID());
 
 600         assertEquals("PNFResource modelVersion", "1.0", pnfResource.getModelVersion());
 
 601         assertEquals("PNFResource orchestration mode", "", pnfResource.getOrchestrationMode());
 
 605     public void getPnfResourceByModelUUID_invalidUuid_NullOutput() {
 
 606         PnfResource pnfResource = client.getPnfResourceByModelUUID(UUID.randomUUID().toString());
 
 607         assertNull(pnfResource);
 
 611     public void getPnfResourceCustomizationByModelCustomizationUUID_validUuid_expectedOutput() {
 
 612         PnfResourceCustomization pnfResourceCustomization =
 
 613                 client.getPnfResourceCustomizationByModelCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002680");
 
 614         assertEquals("modelInstanceName", "PNF routing", pnfResourceCustomization.getModelInstanceName());
 
 615         assertEquals("blueprintName", "test_configuration_restconf", pnfResourceCustomization.getBlueprintName());
 
 616         assertEquals("blueprintVersion", "1.0.0", pnfResourceCustomization.getBlueprintVersion());
 
 617         assertTrue("skip post instantiation configuration", pnfResourceCustomization.isSkipPostInstConf());
 
 618         PnfResource pnfResource = pnfResourceCustomization.getPnfResources();
 
 619         assertNotNull(pnfResource);
 
 620         assertEquals("PNFResource modelUUID", "ff2ae348-214a-11e7-93ae-92361f002680", pnfResource.getModelUUID());
 
 621         assertEquals("PNFResource modelInvariantUUID", "2fff5b20-214b-11e7-93ae-92361f002680",
 
 622                 pnfResource.getModelInvariantUUID());
 
 623         assertEquals("PNFResource modelVersion", "1.0", pnfResource.getModelVersion());
 
 624         assertEquals("PNFResource orchestration mode", "", pnfResource.getOrchestrationMode());
 
 628     public void getPnfResourceCustomizationByModelCustomizationUUID_invalidUuid_nullOutput() {
 
 629         PnfResourceCustomization pnfResourceCustomization =
 
 630                 client.getPnfResourceCustomizationByModelCustomizationUUID(UUID.randomUUID().toString());
 
 631         assertNull(pnfResourceCustomization);
 
 635     public void getPnfResourceCustomizationFromJoinTable_validServiceUuid_expectedOutput() {
 
 636         List<PnfResourceCustomization> pnfResourceCustomizationList =
 
 637                 client.getPnfResourceCustomizationByModelUuid("5df8b6de-2083-11e7-93ae-92361f002676");
 
 638         assertEquals(1, pnfResourceCustomizationList.size());
 
 640         PnfResourceCustomization pnfResourceCustomization = pnfResourceCustomizationList.get(0);
 
 641         assertEquals("modelInstanceName", "PNF routing", pnfResourceCustomization.getModelInstanceName());
 
 642         assertEquals("blueprintName", "test_configuration_restconf", pnfResourceCustomization.getBlueprintName());
 
 643         assertEquals("blueprintVersion", "1.0.0", pnfResourceCustomization.getBlueprintVersion());
 
 644         PnfResource pnfResource = pnfResourceCustomization.getPnfResources();
 
 645         assertNotNull(pnfResource);
 
 647         assertEquals("PNFResource modelUUID", "ff2ae348-214a-11e7-93ae-92361f002680", pnfResource.getModelUUID());
 
 648         assertEquals("PNFResource modelInvariantUUID", "2fff5b20-214b-11e7-93ae-92361f002680",
 
 649                 pnfResource.getModelInvariantUUID());
 
 650         assertEquals("PNFResource modelVersion", "1.0", pnfResource.getModelVersion());
 
 651         assertEquals("PNFResource orchestration mode", "", pnfResource.getOrchestrationMode());
 
 655     public void getPnfResourceCustomizationFromJoinTable_invalidServiceUuid_nullOutput() {
 
 656         List<PnfResourceCustomization> pnfResourceCustomizationList =
 
 657                 client.getPnfResourceCustomizationByModelUuid(UUID.randomUUID().toString());
 
 658         assertEquals(0, pnfResourceCustomizationList.size());
 
 662     public void testGetServiceTopologyById() throws Exception {
 
 663         org.onap.so.rest.catalog.beans.Service serviceByID =
 
 664                 client.getServiceModelInformation("5df8b6de-2083-11e7-93ae-92361f002671", "2");
 
 665         assertNotNull(serviceByID);
 
 666         assertEquals("MSOTADevInfra_vSAMP10a_Service", serviceByID.getModelName());
 
 667         assertEquals("NA", serviceByID.getServiceType());
 
 668         assertEquals("NA", serviceByID.getServiceRole());
 
 672     public void testGetServices() throws Exception {
 
 673         List<org.onap.so.rest.catalog.beans.Service> services = client.getServices();
 
 674         assertEquals(false, services.isEmpty());
 
 678     public void testVnf() throws Exception {
 
 679         org.onap.so.rest.catalog.beans.Vnf vnf = client.getVnfModelInformation("5df8b6de-2083-11e7-93ae-92361f002671",
 
 680                 "68dc9a92-214c-11e7-93ae-92361f002671", "0");
 
 682         assertEquals("vSAMP10a", vnf.getModelName());
 
 683         assertEquals(false, vnf.getNfDataValid());
 
 684         assertEquals("vSAMP", vnf.getNfFunction());
 
 685         assertEquals("vSAMP", vnf.getNfNamingCode());
 
 686         assertEquals("vSAMP", vnf.getNfRole());
 
 687         assertEquals("vSAMP", vnf.getNfType());
 
 689         vnf.setNfDataValid(true);
 
 690         vnf.setNfFunction("nfFunction");
 
 691         vnf.setNfRole("nfRole");
 
 692         vnf.setNfType("nfType");
 
 693         vnf.setNfNamingCode("nfNamingCode");
 
 695         client.updateVnf("5df8b6de-2083-11e7-93ae-92361f002671", vnf);
 
 696         vnf = client.getVnfModelInformation("5df8b6de-2083-11e7-93ae-92361f002671",
 
 697                 "68dc9a92-214c-11e7-93ae-92361f002671", "0");
 
 698         assertEquals("vSAMP10a", vnf.getModelName());
 
 699         assertEquals(true, vnf.getNfDataValid());
 
 700         assertEquals("nfFunction", vnf.getNfFunction());
 
 701         assertEquals("nfNamingCode", vnf.getNfNamingCode());
 
 702         assertEquals("nfRole", vnf.getNfRole());
 
 703         assertEquals("nfType", vnf.getNfType());
 
 709     public void getWorkflowByArtifactUUID_validUuid_expectedOutput() {
 
 710         Workflow workflow = client.findWorkflowByArtifactUUID("5b0c4322-643d-4c9f-b184-4516049e99b1");
 
 711         assertEquals("artifactName", "testingWorkflow.bpmn", workflow.getArtifactName());
 
 715     public void getWorkflowByArtifactUUID_invalidUuid_nullOutput() {
 
 716         Workflow workflow = client.findWorkflowByArtifactUUID(UUID.randomUUID().toString());
 
 717         assertNull(workflow);
 
 721     public void getWorkflowByModelUUID_validUuid_expectedOutput() {
 
 722         List<Workflow> workflows = client.findWorkflowByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
 
 723         assertTrue(workflows != null);
 
 724         assertTrue(workflows.size() != 0);
 
 726         assertEquals("testingWorkflow.bpmn", workflows.get(0).getArtifactName());
 
 730     public void getWorkflowByModelUUID_invalidUuid_nullOutput() {
 
 731         Workflow workflow = client.findWorkflowByArtifactUUID(UUID.randomUUID().toString());
 
 732         assertNull(workflow);
 
 736     public void getWorkflowBySource_validSource_expectedOutput() {
 
 737         List<Workflow> workflows = client.findWorkflowBySource("sdc");
 
 738         assertTrue(workflows != null);
 
 739         assertTrue(workflows.size() != 0);
 
 741         assertEquals("testingWorkflow.bpmn", workflows.get(0).getArtifactName());
 
 745     public void getWorkflowBySource_invalidSource_nullOutput() {
 
 746         List<Workflow> workflow = client.findWorkflowBySource("abc");
 
 747         assertNull(workflow);
 
 751     public void getCloudSites() {
 
 752         List<CloudSite> cloudSites = client.getCloudSites();
 
 753         assertNotNull(cloudSites);
 
 754         assertNotEquals(0, cloudSites.size());