update MSO create service instance URL
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / MsoBusinessLogicImplTest.java
index c9f576d..94a7cf9 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;
@@ -42,7 +43,6 @@ import static org.mockito.ArgumentMatchers.isA;
 import static org.mockito.BDDMockito.given;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.onap.vid.controller.MsoController.CONFIGURATION_ID;
 import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
@@ -72,7 +72,6 @@ import org.hamcrest.MatcherAssert;
 import org.jetbrains.annotations.NotNull;
 import org.mockito.ArgumentMatcher;
 import org.mockito.Mock;
-import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.mockito.hamcrest.MockitoHamcrest;
 import org.onap.portalsdk.core.util.SystemProperties;
@@ -91,7 +90,6 @@ 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;
@@ -186,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);
@@ -835,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
@@ -847,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) {
@@ -1612,68 +1576,5 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
         org.junit.Assert.assertThat(metadata.getRawData(), rawData);
         org.junit.Assert.assertThat(metadata.getDescription(), descriptionMatcher);
     }
-
-    @Test(dataProvider = "unAssignOrDeleteParams")
-    public void deleteSvcInstance_verifyEndPointPathConstructing(String status) {
-        Mockito.reset(msoInterface);
-        String endpoint = validateEndpointPath(MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE);
-        RequestDetails requestDetails = new RequestDetails();
-
-
-        msoBusinessLogic.deleteSvcInstance(requestDetails, "tempId", status);
-
-        verify(msoInterface).deleteSvcInstance(requestDetails, endpoint + "/tempId");
-    }
-
-    @DataProvider
-    public Object[][] unAssignOrDeleteParams() {
-        return new Object[][]{
-            {"Active"},
-            {"unexpected-status"},
-        };
-    }
-
-    @Test(dataProvider = "unAssignStatus")
-    public void deleteSvcInstance_verifyEndPointPathConstructing_unAssignFeatureOn(String status) {
-        Mockito.reset(msoInterface);
-        String endpoint = validateEndpointPath(MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE);
-        RequestDetails requestDetails = new RequestDetails();
-
-        msoBusinessLogic.deleteSvcInstance(requestDetails, "tempId", status);
-
-        verify(msoInterface).unassignSvcInstance(requestDetails, endpoint + "/tempId/unassign");
-    }
-
-    @DataProvider
-    public Object[][] unAssignStatus() {
-        return new Object[][]{
-            {"Created"},
-            {"Pendingdelete"},
-            {"pending-Delete"},
-            {"Assigned"}
-        };
-    }
-
-    @Test
-    public void deleteVnf_verifyEndPointPathConstructing() {
-        String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
-        RequestDetails requestDetails = new RequestDetails();
-
-        String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, "serviceInstanceTempId");
-
-        msoBusinessLogic.deleteVnf(requestDetails, "serviceInstanceTempId", "vnfInstanceTempId");
-        verify(msoInterface).deleteVnf(requestDetails, vnf_endpoint + "/vnfInstanceTempId");
-    }
-
-    @Test
-    public void deleteVfModule_verifyEndPointPathConstructing() {
-        String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
-        RequestDetails requestDetails = new RequestDetails();
-
-        String vf__modules_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, "serviceInstanceTempId").replaceFirst(VNF_INSTANCE_ID, "vnfInstanceTempId");
-
-        msoBusinessLogic.deleteVfModule(requestDetails, "serviceInstanceTempId", "vnfInstanceTempId", "vfModuleTempId");
-        verify(msoInterface).deleteVfModule(requestDetails, vf__modules_endpoint + "/vfModuleTempId");
-    }
 }