update MSO configuration URL
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / MsoBusinessLogicImplTest.java
index 8308622..558dc26 100644 (file)
@@ -21,6 +21,7 @@
 
 package org.onap.vid.mso;
 
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 import static org.assertj.core.api.Assertions.tuple;
@@ -55,7 +56,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import io.joshworks.restclient.http.HttpResponse;
 import java.io.IOException;
 import java.net.URL;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -90,13 +90,13 @@ import org.onap.vid.mso.model.CloudConfiguration;
 import org.onap.vid.mso.model.ModelInfo;
 import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
 import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
-import org.onap.vid.mso.model.RequestInfo;
 import org.onap.vid.mso.model.RequestParameters;
 import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
 import org.onap.vid.mso.rest.Request;
 import org.onap.vid.mso.rest.RequestDetails;
 import org.onap.vid.mso.rest.RequestDetailsWrapper;
 import org.onap.vid.mso.rest.Task;
+import org.onap.vid.testUtils.TestUtils;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
 import org.springframework.test.context.ContextConfiguration;
@@ -109,6 +109,7 @@ import org.testng.annotations.Test;
 public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
 
     private static final ObjectMapper objectMapper = new ObjectMapper();
+    private static final String MY_PRETTY_URL = "my pretty url";
 
     @Mock
     private MsoInterface msoInterface;
@@ -137,7 +138,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
     public void shouldProperlyCreateConfigurationInstanceWithCorrectServiceInstanceId() throws Exception {
         // given
         String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
-        String endpointTemplate = String.format("/serviceInstances/v6/%s/configurations", serviceInstanceId);
+        String endpointTemplate = String.format("/serviceInstantiation/v7/serviceInstances/%s/configurations", serviceInstanceId);
         RequestDetailsWrapper requestDetailsWrapper = createRequestDetails();
         MsoResponseWrapper expectedResponse = createOkResponse();
         given(msoInterface.createConfigurationInstance(requestDetailsWrapper, endpointTemplate))
@@ -183,7 +184,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
     public void shouldProperlyCreateSvcInstanceWithProperParameters() {
 
         MsoResponseWrapper expectedResponse = createOkResponse();
-        String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
+        String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE);
         given(msoInterface.createSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
 
         MsoResponseWrapper response = msoBusinessLogic.createSvcInstance(msoRequest);
@@ -832,7 +833,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
     public void shouldProperlyGetActivateFabricConfigurationPathWithProperParameters() {
         // given
         String serviceInstanceId = "testServiceId";
-        String path = validateEndpointPath(MsoProperties.MSO_REST_API_SERVICE_INSTANCE_CREATE);
+        String path = validateEndpointPath(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE);
         path += "/" + serviceInstanceId + "/activateFabricConfiguration";
 
         // when
@@ -844,56 +845,22 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
 
     @Test
     public void shouldProperlyGetDeactivateAndCloudDeletePathWithProperParameters() {
-        // given
-        String serviceInstanceId = "testServiceId";
-        String vnfInstanceId = "testVnfInstanceId";
-        String vfModuleInstanceId = "testVfModuleInstanceId";
-        String path = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
-        path = path.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
-        path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
-        path += "/" + vfModuleInstanceId + "/deactivateAndCloudDelete";
 
         // when
-        String response = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
+        String response = msoBusinessLogic.getDeactivateAndCloudDeletePath("testServiceId", "testVnfInstanceId", "testVfModuleInstanceId");
 
         // then
-        assertThat(response).isEqualTo(path);
+        String expectedPath = "/serviceInstantiation/v7/serviceInstances/testServiceId/vnfs/testVnfInstanceId/"+
+            "vfModules/testVfModuleInstanceId/deactivateAndCloudDelete";
+        assertThat(response).isEqualTo(expectedPath);
     }
 
     @Test
-    public void shouldProperlyBuildRequestDetailsForSoftDeleteWithProperParameters() {
-        //  given
-        SoftDeleteRequest softDeleteRequest = new SoftDeleteRequest();
-        RequestDetails requestDetails = new RequestDetails();
-
-        String userId = "testUserID";
-        String tenantId = "testTenantId ";
-        String cloudRegionId = "testCloudId";
-
-
-        RequestInfo requestInfo = new RequestInfo();
-        requestInfo.setSource("VID");
-        requestInfo.setRequestorId(userId);
-        requestDetails.setRequestInfo(requestInfo);
-
-        CloudConfiguration cloudConfiguration = new CloudConfiguration();
-        cloudConfiguration.setTenantId(tenantId);
-        cloudConfiguration.setLcpCloudRegionId(cloudRegionId);
-        requestDetails.setCloudConfiguration(cloudConfiguration);
-
-        setModelInfoForRequestDetails(requestDetails);
-
-        setRequestParametersForRequestDetails(requestDetails);
-
-        softDeleteRequest.setLcpCloudRegionId(cloudRegionId);
-        softDeleteRequest.setTenantId(tenantId);
-        softDeleteRequest.setUserId(userId);
-
-        //  when
-        RequestDetails response = msoBusinessLogic.buildRequestDetailsForSoftDelete(softDeleteRequest);
-
-        //  then
-        assertThat(response).isEqualTo(requestDetails);
+    public void shouldProperlyBuildRequestDetailsForSoftDeleteWithProperParameters() throws IOException {
+        SoftDeleteRequest request = new SoftDeleteRequest("testTenantId", "testCloudId", "testUserID");
+        String expected = IOUtils.toString(this.getClass().getResource("/payload_jsons/vfModuleDeactivateAndCloudDelete.json"), "UTF-8");
+        final RequestDetails result = msoBusinessLogic.buildRequestDetailsForSoftDelete(request);
+        MatcherAssert.assertThat(result, jsonEquals(expected));
     }
 
     private void setRequestParametersForRequestDetails(RequestDetails requestDetails) {
@@ -1430,7 +1397,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
     private HttpResponse<String> mockForGetOrchestrationRequest() {
 
         HttpResponse<String> httpResponse = mock(HttpResponse.class);
-        HttpResponseWithRequestInfo<String> httpResponseWithRequestInfo = new HttpResponseWithRequestInfo<>(httpResponse, "my pretty url", HttpMethod.GET);
+        HttpResponseWithRequestInfo<String> httpResponseWithRequestInfo = new HttpResponseWithRequestInfo<>(httpResponse, MY_PRETTY_URL, HttpMethod.GET);
         when(msoInterface.getOrchestrationRequest(any(String.class),anyBoolean()))
             .thenReturn(httpResponseWithRequestInfo);
         return httpResponse;
@@ -1441,11 +1408,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
         HttpResponse<String> httpResponse = mockForGetOrchestrationRequest();
         when(httpResponse.getStatus()).thenReturn(statusCode);
         when(httpResponse.getBody()).thenReturn(body);
-        try {
-            when(httpResponse.getRawBody()).thenReturn(IOUtils.toInputStream(body, StandardCharsets.UTF_8.name()));
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        TestUtils.mockGetRawBodyWithStringBody(httpResponse, body);
         return httpResponse;
     }
 
@@ -1536,7 +1499,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
         final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
 
         assertMsoStatus(msoStatus, true);
-        assertMetadata(msoStatus, 200, startsWith(responseString.substring(0, 400)), "my pretty url", equalTo("OK"));
+        assertMetadata(msoStatus, 200, startsWith(responseString.substring(0, 400)), MY_PRETTY_URL, equalTo("OK"));
     }
 
     @Test
@@ -1552,7 +1515,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
 
         assertMsoStatus(msoStatus, true);
 
-        assertMetadata(msoStatus, 200, equalTo(responseString), "my pretty url", containsString("OK"));
+        assertMetadata(msoStatus, 200, equalTo(responseString), MY_PRETTY_URL, containsString("OK"));
     }
 
     @Test
@@ -1565,7 +1528,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
 
         assertMsoStatus(msoStatus, false);
 
-        assertMetadata(msoStatus, 200, equalTo(responseString), "my pretty url", containsString("JsonParseException: Unrecognized token"));
+        assertMetadata(msoStatus, 200, equalTo(responseString), MY_PRETTY_URL, containsString("JsonParseException: Unrecognized token"));
     }
 
     @Test
@@ -1573,7 +1536,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
         String responseString = "my raw data";
 
         when(msoInterface.getOrchestrationRequest(any(), eq(true))).thenThrow(
-            new ExceptionWithRequestInfo(HttpMethod.GET, "my pretty url", responseString, 406,
+            new ExceptionWithRequestInfo(HttpMethod.GET, MY_PRETTY_URL, responseString, 406,
                 new GenericUncheckedException(
                     new HttpException("Simulating as 406 was returned (200 or 202 expected)"))));
 
@@ -1581,7 +1544,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
 
         assertMsoStatus(msoStatus, false);
 
-        assertMetadata(msoStatus, 406, equalTo(responseString), "my pretty url", containsString("HttpException: Simulating as 406 was returned"));
+        assertMetadata(msoStatus, 406, equalTo(responseString), MY_PRETTY_URL, containsString("HttpException: Simulating as 406 was returned"));
     }