update MSO create service instance URL
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / rest / MsoRestClientNewTest.java
index bfc82ce..0217204 100644 (file)
@@ -2,15 +2,15 @@
  * ============LICENSE_START=======================================================
  * VID
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018 Nokia. All rights reserved.
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- *
+ * 
  *      http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  */
 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.UUID;
+import org.apache.commons.configuration.PropertiesConfiguration;
 import org.glassfish.grizzly.http.util.HttpStatus;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -28,31 +47,21 @@ import org.junit.Ignore;
 import org.junit.Test;
 import org.onap.portalsdk.core.util.SystemProperties;
 import org.onap.vid.client.SyncRestClient;
-import org.onap.vid.controllers.MsoController;
-import org.onap.vid.mso.MsoInterface;
+import org.onap.vid.controller.MsoController;
+import org.onap.vid.controller.WebConfig;
 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;
 
-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 static org.onap.vid.controllers.MsoController.SVC_INSTANCE_ID;
-import static org.onap.vid.controllers.MsoController.VNF_INSTANCE_ID;
-
 @ContextConfiguration(classes = {SystemProperties.class})
 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(
@@ -279,50 +288,39 @@ public class MsoRestClientNewTest {
     }
 
     @Test
-    public void testGetManualTasks() {
-        String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
+    public void testGetManualTasksByRequestId() {
+        String p = props.getString(MsoProperties.MSO_REST_API_GET_ORC_REQ);
         String path = p + "/" + UUID.randomUUID();
+        String validResponse = "" 
+            + "{ "
+            + "  \"taskList\": [ "
+            + "    { "
+            + "      \"taskId\": \"daf4dd84-b77a-42da-a051-3239b7a9392c\", "
+            + "      \"type\": \"fallout\", "
+            + "      \"nfRole\": \"vEsmeralda\", "
+            + "      \"subscriptionServiceType\": \"Emanuel\", "
+            + "      \"originalRequestId\": \"d352c70d-5ef8-4977-9ea8-4c8cbe860422\", "
+            + "      \"originalRequestorId\": \"ss835w\", "
+            + "      \"errorSource\": \"A&AI\", "
+            + "      \"errorCode\": \"404\", "
+            + "      \"errorMessage\": \"Failed in A&AI 404\", "
+            + "      \"validResponses\": [ "
+            + "        \"rollback\", "
+            + "        \"abort\", "
+            + "        \"skip\", "
+            + "        \"resume\", "
+            + "        \"retry\" "
+            + "      ] "
+            + "    } "
+            + "  ] "
+            + "}";
 
         try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
             server,
             path,
             HttpStatus.OK_200,
-            CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
-            closure.executeGet(msoRestClient()::getManualTasks);
-        }
-    }
-
-    @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.getOrchestrationRequestsForDashboard(t, sourceId, endpoint, restObject);
-        } catch (Exception e) {
-        }
-    }
-
-    @Test
-    public void testGetManualTasksByRequestId() throws Exception {
-        MsoRestClientNew testSubject;
-        String t = "";
-        String sourceId = "";
-        String endpoint = "";
-        RestObject restObject = null;
-        MsoResponseWrapper result;
-
-        // default test
-        try {
-            testSubject = createTestSubject();
-            result = testSubject.getManualTasksByRequestId(t, sourceId, endpoint, restObject);
-        } catch (Exception e) {
+            validResponse,validResponse)) {
+            closure.executeGet(endpoint -> msoRestClient().getManualTasksByRequestId(null, null, endpoint, null));
         }
     }
 
@@ -361,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";
@@ -406,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(
@@ -452,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(
@@ -466,10 +473,11 @@ public class MsoRestClientNewTest {
     }
 
     private MsoRestClientNew msoRestClient() {
-        return new MsoRestClientNew(new SyncRestClient(MsoInterface.objectMapper()), baseUrl());
+        final WebConfig webConfig = new WebConfig();
+        return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl(), null, new SystemPropertiesWrapper());
     }
 
     private MsoRestClientNew createTestSubject() {
-        return new MsoRestClientNew(null, "");
+        return new MsoRestClientNew(null, "", null, new SystemPropertiesWrapper());
     }
-}
\ No newline at end of file
+}