update MSO create service instance URL
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / rest / MsoRestClientNewTest.java
index 12fd4a5..0217204 100644 (file)
  */
 package org.onap.vid.mso.rest;
 
+import static org.apache.commons.io.IOUtils.toInputStream;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
 import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.xebialabs.restito.server.StubServer;
+import io.joshworks.restclient.http.HttpResponse;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.util.Properties;
 import java.util.UUID;
+import org.apache.commons.configuration.PropertiesConfiguration;
 import org.glassfish.grizzly.http.util.HttpStatus;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -45,6 +53,7 @@ import org.onap.vid.mso.MsoProperties;
 import org.onap.vid.mso.MsoResponseWrapper;
 import org.onap.vid.mso.MsoResponseWrapperInterface;
 import org.onap.vid.mso.RestObject;
+import org.onap.vid.utils.SystemPropertiesWrapper;
 import org.springframework.test.context.ContextConfiguration;
 
 @ContextConfiguration(classes = {SystemProperties.class})
@@ -52,7 +61,7 @@ public class MsoRestClientNewTest {
 
     private static StubServer server;
     private static StubServer securedServer;
-    private static Properties props = new Properties();
+    private static PropertiesConfiguration props = new PropertiesConfiguration();
     private static String msoCreateServiceInstanceJson;
     private static String msoScaleOutVfModule;
     private final static String CREATE_INSTANCE_RESPONSE_STR =
@@ -67,7 +76,7 @@ public class MsoRestClientNewTest {
 
 
     @BeforeClass
-    public static void start() throws IOException {
+    public static void start() throws Exception {
         server = new StubServer().run();
         securedServer = new StubServer().secured().run();
 
@@ -100,7 +109,7 @@ public class MsoRestClientNewTest {
 
     @Test
     public void testCreateSvcInstance() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_CONFIGURATIONS);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_CONFIGURATIONS);
         endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
                 server,
@@ -113,7 +122,7 @@ public class MsoRestClientNewTest {
 
     @Test
     public void testCreateVnf() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_VNF_INSTANCE);
         endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
                 server,
@@ -127,7 +136,7 @@ public class MsoRestClientNewTest {
 
     @Test
     public void testCreateNwInstance() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
         String nw_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
                 server,
@@ -140,7 +149,7 @@ public class MsoRestClientNewTest {
 
     @Test
     public void testCreateVolumeGroupInstance() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
         String vnf_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         vnf_endpoint = vnf_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
@@ -154,7 +163,7 @@ public class MsoRestClientNewTest {
 
     @Test
     public void testCreateVfModuleInstance() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
         String partial_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         String vf_module_endpoint =
                 partial_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
@@ -186,7 +195,7 @@ public class MsoRestClientNewTest {
     @Ignore
     @Test
     public void testDeleteSvcInstance() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE);
         endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
 
 
@@ -202,7 +211,7 @@ public class MsoRestClientNewTest {
     @Ignore
     @Test
     public void testDeleteVnf() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_VNF_INSTANCE);
         endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
 
         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
@@ -217,7 +226,7 @@ public class MsoRestClientNewTest {
     @Ignore
     @Test
     public void testDeleteVfModule() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
         String part_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         String vf_modules_endpoint = part_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
         String delete_vf_endpoint = vf_modules_endpoint + '/' + SAMPLE_VNF_MODULE_ID;
@@ -234,7 +243,7 @@ public class MsoRestClientNewTest {
     @Ignore
     @Test
     public void testDeleteVolumeGroupInstance() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
         String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         String vnf_endpoint = svc_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
         String delete_volume_group_endpoint = vnf_endpoint + "/" + SAMPLE_VNF_MODULE_ID;
@@ -251,7 +260,7 @@ public class MsoRestClientNewTest {
     @Ignore
     @Test
     public void testDeleteNwInstance() throws Exception {
-        String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
+        String endpoint = props.getString(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
         String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         String delete_nw_endpoint = svc_endpoint + "/" + SAMPLE_NETWORK_INSTANCE_ID;
 
@@ -266,7 +275,7 @@ public class MsoRestClientNewTest {
 
     @Test
     public void testGetOrchestrationRequest() {
-        String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
+        String p = props.getString(MsoProperties.MSO_REST_API_GET_ORC_REQ);
         String path = p + "/" + SAMPLE_REQUEST_ID;
 
         try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
@@ -280,7 +289,7 @@ public class MsoRestClientNewTest {
 
     @Test
     public void testGetManualTasksByRequestId() {
-        String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
+        String p = props.getString(MsoProperties.MSO_REST_API_GET_ORC_REQ);
         String path = p + "/" + UUID.randomUUID();
         String validResponse = "" 
             + "{ "
@@ -315,23 +324,6 @@ public class MsoRestClientNewTest {
         }
     }
 
-    @Test
-    public void testGetOrchestrationRequestsForDashboard() throws Exception {
-        MsoRestClientNew testSubject;
-        String t = "";
-        String sourceId = "";
-        String endpoint = "";
-        RestObject restObject = null;
-        MsoResponseWrapper result;
-
-        // default test
-        try {
-            testSubject = createTestSubject();
-            result = testSubject.getOrchestrationRequest(t, sourceId, endpoint, restObject, true);
-        } catch (Exception e) {
-        }
-    }
-
     @Test
     public void testCompleteManualTask() throws Exception {
         MsoRestClientNew testSubject;
@@ -367,7 +359,7 @@ public class MsoRestClientNewTest {
 
     @Test
     public void testSetConfigurationActiveStatus() throws Exception {
-        String endpoint = "/serviceInstances/v5/<service_instance_id>/configurations/<configuration_id>";
+        String endpoint = "/serviceInstances/v7/<service_instance_id>/configurations/<configuration_id>";
         endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         endpoint = endpoint.replace(MsoController.CONFIGURATION_ID, SAMPLE_CONFIGURATION_ID);
         endpoint = endpoint + "/activate";
@@ -412,25 +404,34 @@ public class MsoRestClientNewTest {
     }
 
     @Test
-    public void testSetServiceInstanceStatus() throws Exception {
-        MsoRestClientNew testSubject;
-        RequestDetails requestDetails = null;
+    public void testSetServiceInstanceStatus_givenValidResponse_responseIsPopulatedAccordingly() {
+        RequestDetails requestDetails = new RequestDetails();
         String t = "";
         String sourceId = "";
         String endpoint = "";
-        RestObject<String> restObject = null;
+        final SyncRestClient client = mock(SyncRestClient.class);
+        MsoRestClientNew testSubject = new MsoRestClientNew(client, "", null, new SystemPropertiesWrapper());
 
-        // default test
-        try {
-            testSubject = createTestSubject();
-            testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
-        } catch (Exception e) {
-        }
+        // setup
+        final HttpResponse<String> response = mock(HttpResponse.class);
+        final int expectedStatus = 202;
+        final String expectedResponse = "expected response";
+
+        when(client.post(eq(endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(response);
+        when(response.getStatus()).thenReturn(expectedStatus);
+        when(response.getBody()).thenReturn(expectedResponse);
+        when(response.getRawBody()).thenReturn(toInputStream(expectedResponse));
+
+        // test
+        MsoResponseWrapper responseWrapper = testSubject.setServiceInstanceStatus(requestDetails, endpoint);
+
+        assertThat(responseWrapper.getStatus(), is(expectedStatus));
+        assertThat(responseWrapper.getEntity(), is(expectedResponse));
     }
 
     @Test
     public void testRemoveRelationshipFromServiceInstance() throws Exception {
-        String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
+        String serviceEndpoint = props.getString(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE);
         String removeRelationshipsPath = serviceEndpoint + "/" + SERVICE_INSTANCE_ID + "/removeRelationships";
 
         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
@@ -458,7 +459,7 @@ public class MsoRestClientNewTest {
     }
     @Test
     public void testScaleOutVfModule() throws IOException {
-        String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
+        String serviceEndpoint = props.getString(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
         String partial_endpoint = serviceEndpoint.replaceFirst(SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
         String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
@@ -473,10 +474,10 @@ public class MsoRestClientNewTest {
 
     private MsoRestClientNew msoRestClient() {
         final WebConfig webConfig = new WebConfig();
-        return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl(),null);
+        return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl(), null, new SystemPropertiesWrapper());
     }
 
     private MsoRestClientNew createTestSubject() {
-        return new MsoRestClientNew(null, "",null);
+        return new MsoRestClientNew(null, "", null, new SystemPropertiesWrapper());
     }
 }