Merge 'origin/casablanca' into master
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / db / catalog / client / CatalogDbClientTest.java
index 4ec5839..4479e1b 100644 (file)
 
 package org.onap.so.db.catalog.client;
 
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import java.util.UUID;
+
+import javax.ws.rs.core.UriBuilder;
+
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.onap.so.adapters.catalogdb.CatalogDBApplication;
+import org.onap.so.db.catalog.beans.AuthenticationType;
+import org.onap.so.db.catalog.beans.CloudIdentity;
 import org.onap.so.db.catalog.beans.CloudSite;
 import org.onap.so.db.catalog.beans.CloudifyManager;
+import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
+import org.onap.so.db.catalog.beans.HomingInstance;
 import org.onap.so.db.catalog.beans.InstanceGroup;
 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
+import org.onap.so.db.catalog.beans.ServerType;
 import org.onap.so.db.catalog.beans.Service;
 import org.onap.so.db.catalog.beans.ServiceRecipe;
 import org.onap.so.db.catalog.beans.VfModule;
@@ -38,28 +51,49 @@ import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
 import org.onap.so.db.catalog.beans.VnfRecipe;
 import org.onap.so.db.catalog.beans.VnfResource;
 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
+import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
+import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
+import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.context.embedded.LocalServerPort;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import java.util.List;
-import java.util.UUID;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
 public class CatalogDbClientTest {
     public static final String MTN13 = "mtn13";
+    
     @LocalServerPort
     private int port;
+
+    @Value("${mso.db.auth}")
+    private String msoAdaptersAuth;
+       
     @Autowired
     CatalogDbClientPortChanger client;
 
     @Before
-    public void initialize() {
-        client.wiremockPort = String.valueOf(port);
+    public void initialize(){
+        client.wiremockPort= String.valueOf(port);
+    }
+
+    @Test
+    public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(){
+        RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", "*", "*", "*", "*");
+        Assert.assertEquals("Rollback", rainyDayHandlerStatus.getPolicy());
+    }
+
+    @Test
+    public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStepRecordNotFound(){
+        RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(UUID.randomUUID().toString(), "*", "*", "*", "*");
+        Assert.assertNull(rainyDayHandlerStatus);
     }
 
     @Test
@@ -363,4 +397,185 @@ public class CatalogDbClientTest {
         VfModule module = moduleList.get(0);
         Assert.assertEquals("vSAMP10a DEV Base",module.getDescription());
     }
+
+    @Test
+    public void testPostCloudSite() {
+        CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger("http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
+        CloudSite cloudSite = new CloudSite();
+        cloudSite.setId("MTN6");
+        cloudSite.setClli("TESTCLLI");
+        cloudSite.setRegionId("regionId");
+        cloudSite.setCloudVersion("VERSION");
+        cloudSite.setPlatform("PLATFORM");
+
+        CloudIdentity cloudIdentity = new CloudIdentity();
+        cloudIdentity.setId("RANDOMID");
+        cloudIdentity.setIdentityUrl("URL");
+        cloudIdentity.setMsoId("MSO_ID");
+        cloudIdentity.setMsoPass("MSO_PASS");
+        cloudIdentity.setAdminTenant("ADMIN_TENANT");
+        cloudIdentity.setMemberRole("ROLE");
+        cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
+        cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
+        cloudSite.setIdentityService(cloudIdentity);
+        localClient.postCloudSite(cloudSite);
+        CloudSite getCloudSite = this.client.getCloudSite("MTN6");
+        Assert.assertNotNull(getCloudSite);
+        Assert.assertNotNull(getCloudSite.getIdentityService());
+        Assert.assertEquals("TESTCLLI", getCloudSite.getClli());
+        Assert.assertEquals("regionId", getCloudSite.getRegionId());
+        Assert.assertEquals("RANDOMID", getCloudSite.getIdentityServiceId());
+    }
+
+    @Test
+    public void testGetHomingInstance() {
+        HomingInstance homingInstance = client.getHomingInstance("5df8b6de-2083-11e7-93ae-92361f232671");
+        Assert.assertNotNull(homingInstance);
+        Assert.assertNotNull(homingInstance.getCloudOwner());
+        Assert.assertNotNull(homingInstance.getCloudRegionId());
+        Assert.assertNotNull(homingInstance.getOofDirectives());
+    }
+
+    @Test
+    public void testPostHomingInstance() {
+        CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger("http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
+        HomingInstance homingInstance = new HomingInstance();
+        homingInstance.setServiceInstanceId("5df8d6be-2083-11e7-93ae-92361f232671");
+        homingInstance.setCloudOwner("CloudOwner-1");
+        homingInstance.setCloudRegionId("CloudRegionOne");
+        homingInstance.setOofDirectives("{\n" +
+                "\"directives\": [\n" +
+                "{\n" +
+                "\"directives\": [\n" +
+                "{\n" +
+                "\"attributes\": [\n" +
+                "{\n" +
+                "\"attribute_value\": \"onap.hpa.flavor31\",\n" +
+                "\"attribute_name\": \"firewall_flavor_name\"\n" +
+                "}\n" +
+                "],\n" +
+                "\"type\": \"flavor_directives\"\n" +
+                "}\n" +
+                "],\n" +
+                "\"type\": \"vnfc\",\n" +
+                "\"id\": \"vfw\"\n" +
+                "},\n" +
+                "{\n" +
+                "\"directives\": [\n" +
+                "{\n" +
+                "\"attributes\": [\n" +
+                "{\n" +
+                "\"attribute_value\": \"onap.hpa.flavor32\",\n" +
+                "\"attribute_name\": \"packetgen_flavor_name\"\n" +
+                "}\n" +
+                "],\n" +
+                "\"type\": \"flavor_directives\"\n" +
+                "}\n" +
+                "],\n" +
+                "\"type\": \"vnfc\",\n" +
+                "\"id\": \"vgenerator\"\n" +
+                "},\n" +
+                "{\n" +
+                "\"directives\": [\n" +
+                "{\n" +
+                "\"attributes\": [\n" +
+                "{\n" +
+                "\"attribute_value\": \"onap.hpa.flavor31\",\n" +
+                "\"attribute_name\": \"sink_flavor_name\"\n" +
+                "}\n" +
+                "],\n" +
+                "\"type\": \"flavor_directives\"\n" +
+                "}\n" +
+                "],\n" +
+                "\"type\": \"vnfc\",\n" +
+                "\"id\": \"vsink\"\n" +
+                "}\n" +
+                "]\n" +
+                "}");
+        localClient.postHomingInstance(homingInstance);
+        HomingInstance getHomingInstance = this.client.getHomingInstance("5df8d6be-2083-11e7-93ae-92361f232671");
+        Assert.assertNotNull(getHomingInstance);
+        Assert.assertNotNull(getHomingInstance.getCloudRegionId());
+        Assert.assertNotNull(getHomingInstance.getCloudOwner());
+        Assert.assertEquals("CloudOwner-1", getHomingInstance.getCloudOwner());
+        Assert.assertEquals("CloudRegionOne", getHomingInstance.getCloudRegionId());
+    }
+
+   @Test
+    public void testGetServiceByModelName() {
+        Service service = client.getServiceByModelName("MSOTADevInfra_Test_Service");
+        Assert.assertNotNull(service);
+        Assert.assertNotNull(service.getModelVersion());
+        Assert.assertNotNull(service.getModelInvariantUUID());
+        Assert.assertEquals("MSOTADevInfra_Test_Service", service.getModelName());
+        Assert.assertEquals("NA", service.getServiceRole());
+    }
+
+    @Test
+    public void testGetServiceByModelNameNotFound() {
+        Service service = client.getServiceByModelName("Not_Found");
+        Assert.assertNull(service);
+    }
+
+    @Test
+    public void testGetServiceByModelUUID() {
+        Service service = client.getServiceByModelUUID("5df8b6de-2083-11e7-93ae-92361f002679");
+        Assert.assertNotNull(service);
+        Assert.assertNotNull(service.getModelVersion());
+        Assert.assertNotNull(service.getModelInvariantUUID());
+        Assert.assertEquals("5df8b6de-2083-11e7-93ae-92361f002679", service.getModelUUID());
+        Assert.assertEquals("NA", service.getServiceRole());
+    }
+
+    @Test
+    public void testGetServiceByModelUUIDNotFound() {
+        Service service = client.getServiceByModelUUID("Not_Found");
+        Assert.assertNull(service);
+    }
+
+    @Test
+    public void testGetNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(){
+       NorthBoundRequest northBoundRequest = new NorthBoundRequest();
+       northBoundRequest.setAction("createService");
+       northBoundRequest.setRequestScope("service");
+       northBoundRequest.setIsAlacarte(true);
+       northBoundRequest.setCloudOwner("my-custom-cloud-owner");
+       client.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner("createService", "service", true, "my-custom-cloud-owner");
+       Assert.assertNotNull(northBoundRequest);
+       Assert.assertEquals("createService",northBoundRequest.getAction());
+       Assert.assertEquals("service",northBoundRequest.getRequestScope());
+       Assert.assertEquals(true,northBoundRequest.getIsAlacarte() );
+       Assert.assertEquals("my-custom-cloud-owner", northBoundRequest.getCloudOwner());
+    }
+   
+    @Test
+    public void testFindServiceRecipeByActionAndServiceModelUUID() {
+        ServiceRecipe serviceRecipe = client.findServiceRecipeByActionAndServiceModelUUID("createInstance","4694a55f-58b3-4f17-92a5-796d6f5ffd0d" );
+        Assert.assertNotNull(serviceRecipe);
+        Assert.assertNotNull(serviceRecipe.getServiceModelUUID());
+        Assert.assertNotNull(serviceRecipe.getAction());
+        Assert.assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri());
+        Assert.assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription());
+    }
+
+    @Test
+    public void testFindServiceRecipeByActionAndServiceModelUUIDNotFound() {
+        ServiceRecipe serviceRecipe = client.findServiceRecipeByActionAndServiceModelUUID("not_found","5df8b6de-2083-11e7-93ae-test" );
+        Assert.assertNull(serviceRecipe);
+    }
+
+    @Test
+    public void testFindExternalToInternalServiceByServiceName() {
+        ExternalServiceToInternalService externalServiceToInternalService = client.findExternalToInternalServiceByServiceName("MySpecialServiceName");
+        Assert.assertNotNull(externalServiceToInternalService);
+        Assert.assertNotNull(externalServiceToInternalService.getServiceName());
+        Assert.assertNotNull(externalServiceToInternalService.getServiceModelUUID());
+        Assert.assertEquals("MySpecialServiceName", externalServiceToInternalService.getServiceName());
+    }
+
+    @Test
+    public void testFindExternalToInternalServiceByServiceNameNotFound() {
+        ExternalServiceToInternalService externalServiceToInternalService = client.findExternalToInternalServiceByServiceName("Not_Found");
+        Assert.assertNull(externalServiceToInternalService);
+    }
 }