Merge "add junit coverage"
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / ServiceInstancesTest.java
index db6273d..9f74278 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
@@ -28,20 +28,14 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.onap.so.logger.HttpHeadersConstants.ONAP_REQUEST_ID;
+import static org.onap.logging.filter.base.Constants.HttpHeaders.CLIENT_ID;
+import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID;
+import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID;
 import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID;
-import static org.onap.so.logger.MdcConstants.CLIENT_ID;
-import static org.onap.so.logger.MdcConstants.ENDTIME;
-import static org.onap.so.logger.MdcConstants.INVOCATION_ID;
-import static org.onap.so.logger.MdcConstants.PARTNERNAME;
-import static org.onap.so.logger.MdcConstants.RESPONSECODE;
-import static org.onap.so.logger.MdcConstants.RESPONSEDESC;
-import static org.onap.so.logger.MdcConstants.SERVICE_NAME;
-import static org.onap.so.logger.MdcConstants.STATUSCODE;
-import static org.onap.so.logger.HttpHeadersConstants.TRANSACTION_ID;
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
@@ -57,12 +51,17 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.apihandlerinfra.exceptions.ContactCamundaException;
+import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException;
 import org.onap.so.db.catalog.beans.Service;
 import org.onap.so.db.catalog.beans.ServiceRecipe;
 import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.logger.HttpHeadersConstants;
 import org.onap.so.serviceinstancebeans.CloudConfiguration;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.ModelType;
+import org.onap.so.serviceinstancebeans.RequestDetails;
 import org.onap.so.serviceinstancebeans.RequestError;
+import org.onap.so.serviceinstancebeans.RequestInfo;
 import org.onap.so.serviceinstancebeans.RequestParameters;
 import org.onap.so.serviceinstancebeans.RequestReferences;
 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
@@ -75,24 +74,23 @@ import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.util.UriComponentsBuilder;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.tomakehurst.wiremock.http.Fault;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-
 
 public class ServiceInstancesTest extends BaseTest {
 
     private final ObjectMapper mapper = new ObjectMapper();
-    private ObjectMapper errorMapper = new ObjectMapper();
 
     @Autowired
     private ServiceInstances servInstances;
 
+    @Autowired
+    private RequestHandlerUtils requestHandlerUtils;
+
     @Value("${wiremock.server.port}")
     private String wiremockPort;
 
@@ -107,12 +105,10 @@ public class ServiceInstancesTest extends BaseTest {
     @Before
     public void beforeClass() {
         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-        errorMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-        errorMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
         // set headers
         headers = new HttpHeaders();
         headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name");
-        headers.set(HttpHeadersConstants.TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
+        headers.set(TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
         headers.set(ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
         headers.set(ONAPLogConstants.MDCs.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
         headers.set(CLIENT_ID, "VID");
@@ -123,7 +119,7 @@ public class ServiceInstancesTest extends BaseTest {
         } catch (MalformedURLException e) {
             e.printStackTrace();
         }
-        wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests.*")).willReturn(aResponse()
+        wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/")).willReturn(aResponse()
                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
         Mockito.doReturn(null).when(requestsDbClient).getInfraActiveRequestbyRequestId(Mockito.any());
     }
@@ -216,35 +212,6 @@ public class ServiceInstancesTest extends BaseTest {
         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
-
-
-
-        for (ILoggingEvent logEvent : TestAppender.events)
-            if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging")
-                    && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")) {
-                Map<String, String> mdc = logEvent.getMDCPropertyMap();
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
-                assertNotNull(mdc.get(INVOCATION_ID));
-                assertEquals("UNKNOWN", mdc.get(PARTNERNAME));
-                assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances", mdc.get(SERVICE_NAME));
-                assertEquals("INPROGRESS", mdc.get(STATUSCODE));
-            } else if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging")
-                    && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("EXIT")) {
-                Map<String, String> mdc = logEvent.getMDCPropertyMap();
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
-                assertNotNull(mdc.get(ENDTIME));
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
-                assertNotNull(mdc.get(INVOCATION_ID));
-                assertEquals("202", mdc.get(RESPONSECODE));
-                assertEquals("UNKNOWN", mdc.get(PARTNERNAME));
-                assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances", mdc.get(SERVICE_NAME));
-                assertEquals("COMPLETE", mdc.get(STATUSCODE));
-                assertNotNull(mdc.get(RESPONSEDESC));
-                assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
-                assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
-                assertEquals("5.0.0", response.getHeaders().get("X-LatestVersion").get(0));
-            }
     }
 
     @Test
@@ -276,14 +243,13 @@ public class ServiceInstancesTest extends BaseTest {
         requestReferences.setInstanceId("1882939");
         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
         expectedResponse.setRequestReferences(requestReferences);
-        uri = servInstanceUriPrev7 + "v5";
+        uri = servInstanceuri + "v5";
         ResponseEntity<String> response =
                 sendRequest(inputStream("/ServiceInstancePrev7.json"), uri, HttpMethod.POST, headers);
 
         // then
-        assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+        assertEquals(404, response.getStatusCode().value());
         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
-        assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
     }
 
     @Test
@@ -887,7 +853,7 @@ public class ServiceInstancesTest extends BaseTest {
         ResponseEntity<String> response =
                 sendRequest(inputStream("/VnfWithServiceRelatedInstanceFail.json"), uri, HttpMethod.POST);
 
-        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+        assertEquals(404, response.getStatusCode().value());
     }
 
     @Test
@@ -896,7 +862,7 @@ public class ServiceInstancesTest extends BaseTest {
         ResponseEntity<String> response = sendRequest(inputStream("/NoVnfResource.json"), uri, HttpMethod.POST);
 
         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals("No valid vnfResource is specified", realResponse.getServiceException().getText());
     }
 
@@ -938,6 +904,45 @@ public class ServiceInstancesTest extends BaseTest {
         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
     }
 
+    @Test
+    public void replaceVnfInstanceNoCloudConfig() throws IOException {
+        wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/v1/getInfraActiveRequests.*"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBodyFile("infra/VnfLookup.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
+        wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
+        wireMockServer.stubFor(get(urlMatching(
+                ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002671"))
+                        .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                .withBody(getWiremockResponseForCatalogdb(
+                                        "vnfResourceCustomization_ReplaceVnf_Response.json"))
+                                .withStatus(org.apache.http.HttpStatus.SC_OK)));
+        wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/1/vnfResources"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBody(getWiremockResponseForCatalogdb("vnfResources_ReplaceVnf_Response.json"))
+                        .withStatus(org.apache.http.HttpStatus.SC_OK)));
+        wireMockServer.stubFor(get(urlMatching(
+                ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=replaceInstance"))
+                        .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                .withBody(getWiremockResponseForCatalogdb("vnfRecipeReplaceInstance_Response.json"))
+                                .withStatus(org.apache.http.HttpStatus.SC_OK)));
+        // expected response
+        ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
+        RequestReferences requestReferences = new RequestReferences();
+        requestReferences.setInstanceId("1882939");
+        requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
+        expectedResponse.setRequestReferences(requestReferences);
+        uri = servInstanceuri + "v7"
+                + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
+        ResponseEntity<String> response =
+                sendRequest(inputStream("/ReplaceVnfNoCloudConfig.json"), uri, HttpMethod.POST, headers);
+
+        assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+        ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
+        assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
+    }
+
     @Test
     public void replaceVnfRecreateInstance() throws IOException {
         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/RecreateInfraVce"))
@@ -1329,7 +1334,7 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals("No valid vfModuleCustomization is specified", realResponse.getServiceException().getText());
     }
 
@@ -1369,6 +1374,44 @@ public class ServiceInstancesTest extends BaseTest {
         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
     }
 
+    @Test
+    public void replaceVfModuleInstanceNoCloudConfigurationTest() throws IOException {
+        wireMockServer.stubFor(
+                get(urlPathEqualTo("/aai/v19/network/generic-vnfs/generic-vnf/ff305d54-75b4-431b-adb2-eb6b9e5ff000"))
+                        .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                .withBodyFile("infra/Vnf.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
+        wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
+        wireMockServer
+                .stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]"
+                        + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
+                                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                        .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
+                                        .withStatus(org.apache.http.HttpStatus.SC_OK)));
+        wireMockServer.stubFor(get(urlMatching(
+                ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
+                        + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=replaceInstance"))
+                                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                        .withBody(getWiremockResponseForCatalogdb(
+                                                "vnfComponentRecipeDeleteVfModule_Response.json"))
+                                        .withStatus(org.apache.http.HttpStatus.SC_OK)));
+        // expected response
+        ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
+        RequestReferences requestReferences = new RequestReferences();
+        requestReferences.setInstanceId("1882939");
+        requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
+        expectedResponse.setRequestReferences(requestReferences);
+        uri = servInstanceuri + "v7"
+                + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
+        ResponseEntity<String> response =
+                sendRequest(inputStream("/ReplaceVfModuleNoCloudConfig.json"), uri, HttpMethod.POST, headers);
+
+        assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+        ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
+        assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
+    }
+
     @Test
     public void updateVfModuleInstance() throws IOException {
         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
@@ -1420,7 +1463,6 @@ public class ServiceInstancesTest extends BaseTest {
     public void createVfModuleNoModelType() throws IOException {
         InfraActiveRequests expectedRecord = new InfraActiveRequests();
         expectedRecord.setRequestStatus("FAILED");
-        expectedRecord.setAction("createInstance");
         expectedRecord.setStatusMessage("Error parsing request: No valid modelType is specified");
         expectedRecord.setProgress(100L);
         expectedRecord.setSource("VID");
@@ -2133,7 +2175,7 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals("Request Failed due to BPEL error with HTTP Status = 202{\"instanceId\": \"1882939\"}",
                 realResponse.getServiceException().getText());
     }
@@ -2168,7 +2210,7 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals("Exception caught mapping Camunda JSON response to object",
                 realResponse.getServiceException().getText());
     }
@@ -2201,7 +2243,7 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertTrue(realResponse.getServiceException().getText()
                 .contains("<aetgt:ErrorMessage>Exception in create execution list 500"));
     }
@@ -2239,14 +2281,12 @@ public class ServiceInstancesTest extends BaseTest {
         requestReferences.setInstanceId("1882939");
         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
         expectedResponse.setRequestReferences(requestReferences);
-        uri = servInstanceUriPrev7 + "v5";
+        uri = servInstanceuri + "v5";
         ResponseEntity<String> response =
                 sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST, headers);
 
         // then
-        assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
-        ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
-        assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
+        assertEquals(404, response.getStatusCode().value());
     }
 
     @Test
@@ -2257,7 +2297,7 @@ public class ServiceInstancesTest extends BaseTest {
         RequestParameters requestParameters = request.getRequestDetails().getRequestParameters();
         String userParamsTxt = inputStream("/userParams.txt");
 
-        List<Map<String, Object>> userParams = servInstances.configureUserParams(requestParameters);
+        List<Map<String, Object>> userParams = requestHandlerUtils.configureUserParams(requestParameters);
         System.out.println(userParams);
         assertTrue(userParams.size() > 0);
         assertTrue(userParams.get(0).containsKey("name"));
@@ -2271,7 +2311,7 @@ public class ServiceInstancesTest extends BaseTest {
         ServiceInstancesRequest request =
                 mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
         CloudConfiguration cloudConfig =
-                servInstances.configureCloudConfig(request.getRequestDetails().getRequestParameters());
+                requestHandlerUtils.configureCloudConfig(request.getRequestDetails().getRequestParameters());
 
         assertEquals("mdt25b", cloudConfig.getLcpCloudRegionId());
         assertEquals("aefb697db6524ddebfe4915591b0a347", cloudConfig.getTenantId());
@@ -2284,7 +2324,7 @@ public class ServiceInstancesTest extends BaseTest {
                 mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
         ServiceInstancesRequest expected =
                 mapper.readValue(inputStream("/LegacyMacroServiceInstance.json"), ServiceInstancesRequest.class);
-        servInstances.mapToLegacyRequest(request.getRequestDetails());
+        requestHandlerUtils.mapToLegacyRequest(request.getRequestDetails());
         System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request));
         assertThat(request, sameBeanAs(expected));
     }
@@ -2371,7 +2411,7 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals("Exception caught mapping Camunda JSON response to object",
                 realResponse.getServiceException().getText());
     }
@@ -2387,9 +2427,9 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(
-                "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error",
+                "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
     }
 
@@ -2410,7 +2450,7 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(
                 "Error: Locked instance - This service (testService9) already has a request being worked with a status of UNLOCKED (RequestId - f0a35706-efc4-4e27-80ea-a995d7a2a40f). The existing request must finish or be cleaned up before proceeding.",
                 realResponse.getServiceException().getText());
@@ -2432,9 +2472,9 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(
-                "Unable to get process-instance history from Camunda for requestId: f0a35706-efc4-4e27-80ea-a995d7a2a40f due to error: org.springframework.web.client.HttpServerErrorException: 500 Server Error",
+                "Unable to get process-instance history from Camunda for requestId: f0a35706-efc4-4e27-80ea-a995d7a2a40f due to error: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
     }
 
@@ -2449,9 +2489,9 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(
-                "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error",
+                "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
     }
 
@@ -2481,9 +2521,9 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(
-                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error",
+                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
     }
 
@@ -2501,9 +2541,9 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(
-                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error",
+                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
     }
 
@@ -2518,9 +2558,9 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST, headers);
 
         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(
-                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error",
+                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
     }
 
@@ -2563,15 +2603,6 @@ public class ServiceInstancesTest extends BaseTest {
         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
         assertEquals(response.getHeaders().get(TRANSACTION_ID).get(0), "32807a28-1a14-4b88-b7b3-2950918aa76d");
-
-        for (ILoggingEvent logEvent : TestAppender.events) {
-            if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging")
-                    && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")) {
-                Map<String, String> mdc = logEvent.getMDCPropertyMap();
-                assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
-                assertEquals("VID", mdc.get(PARTNERNAME));
-            }
-        }
     }
 
     @Test
@@ -2623,7 +2654,7 @@ public class ServiceInstancesTest extends BaseTest {
         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE);
         // then
         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-RequestID header is specified");
     }
 
@@ -2636,7 +2667,7 @@ public class ServiceInstancesTest extends BaseTest {
         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noPartnerHeaders);
         // then
         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-PartnerName header is specified");
     }
 
@@ -2655,7 +2686,7 @@ public class ServiceInstancesTest extends BaseTest {
 
         // then
         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(realResponse.getServiceException().getText(), "No valid X-RequestorID header is specified");
     }
 
@@ -2743,10 +2774,202 @@ public class ServiceInstancesTest extends BaseTest {
         ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers);
 
         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
-        RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals(realResponse.getServiceException().getText(),
                 "No valid modelCustomizationId for networkResourceCustomization lookup is specified");
     }
 
+    @Test
+    public void setServiceTypeTestALaCarte() throws JsonProcessingException {
+        String requestScope = ModelType.service.toString();
+        Boolean aLaCarteFlag = true;
+        ServiceInstancesRequest sir = new ServiceInstancesRequest();
+        RequestDetails requestDetails = new RequestDetails();
+        RequestInfo requestInfo = new RequestInfo();
+        requestInfo.setSource("VID");
+        requestDetails.setRequestInfo(requestInfo);
+        sir.setRequestDetails(requestDetails);
+        Service defaultService = new Service();
+        defaultService.setServiceType("testServiceTypeALaCarte");
+
+        wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
+
+        String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
+        assertEquals(serviceType, "testServiceTypeALaCarte");
+    }
+
+    @Test
+    public void setServiceTypeTest() throws JsonProcessingException {
+        String requestScope = ModelType.service.toString();
+        Boolean aLaCarteFlag = false;
+        ServiceInstancesRequest sir = new ServiceInstancesRequest();
+        RequestDetails requestDetails = new RequestDetails();
+        RequestInfo requestInfo = new RequestInfo();
+        ModelInfo modelInfo = new ModelInfo();
+        modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a");
+        requestInfo.setSource("VID");
+        requestDetails.setModelInfo(modelInfo);
+        requestDetails.setRequestInfo(requestInfo);
+        sir.setRequestDetails(requestDetails);
+        Service defaultService = new Service();
+        defaultService.setServiceType("testServiceType");
+
+        wireMockServer.stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
+
+        String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
+        assertEquals(serviceType, "testServiceType");
+    }
+
+    @Test
+    public void setServiceTypeTestDefault() throws JsonProcessingException {
+        String requestScope = ModelType.service.toString();
+        Boolean aLaCarteFlag = false;
+        ServiceInstancesRequest sir = new ServiceInstancesRequest();
+        RequestDetails requestDetails = new RequestDetails();
+        RequestInfo requestInfo = new RequestInfo();
+        ModelInfo modelInfo = new ModelInfo();
+        modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a");
+        requestInfo.setSource("VID");
+        requestDetails.setModelInfo(modelInfo);
+        requestDetails.setRequestInfo(requestInfo);
+        sir.setRequestDetails(requestDetails);
+        Service defaultService = new Service();
+        defaultService.setServiceType("testServiceType");
+
+        wireMockServer.stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withStatus(HttpStatus.SC_NOT_FOUND)));
+        wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
+
+        String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
+        assertEquals(serviceType, "testServiceType");
+    }
+
+    @Test
+    public void setServiceTypeTestNetwork() throws JsonProcessingException {
+        String requestScope = ModelType.network.toString();
+        Boolean aLaCarteFlag = null;
+        ServiceInstancesRequest sir = new ServiceInstancesRequest();
+        RequestDetails requestDetails = new RequestDetails();
+        RequestInfo requestInfo = new RequestInfo();
+        ModelInfo modelInfo = new ModelInfo();
+        modelInfo.setModelName("networkModelName");
+        requestInfo.setSource("VID");
+        requestDetails.setModelInfo(modelInfo);
+        requestDetails.setRequestInfo(requestInfo);
+        sir.setRequestDetails(requestDetails);
+
+        String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
+        assertEquals(serviceType, "networkModelName");
+    }
+
+    @Test
+    public void setServiceInstanceIdInstanceGroupTest() throws JsonParseException, JsonMappingException, IOException {
+        String requestScope = "instanceGroup";
+        ServiceInstancesRequest sir =
+                mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class);
+        assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc",
+                requestHandlerUtils.setServiceInstanceId(requestScope, sir));
+    }
+
+    @Test
+    public void setServiceInstanceIdTest() {
+        String requestScope = "vnf";
+        ServiceInstancesRequest sir = new ServiceInstancesRequest();
+        sir.setServiceInstanceId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
+        assertEquals("f0a35706-efc4-4e27-80ea-a995d7a2a40f",
+                requestHandlerUtils.setServiceInstanceId(requestScope, sir));
+    }
+
+    @Test
+    public void setServiceInstanceIdReturnNullTest() {
+        String requestScope = "vnf";
+        ServiceInstancesRequest sir = new ServiceInstancesRequest();
+        assertNull(requestHandlerUtils.setServiceInstanceId(requestScope, sir));
+    }
+
+    @Test
+    public void camundaHistoryCheckTest() throws ContactCamundaException, RequestDbFailureException {
+        wireMockServer.stubFor(get(
+                ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
+                        .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                .withBodyFile("Camunda/HistoryCheckResponse.json")
+                                .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+        InfraActiveRequests duplicateRecord = new InfraActiveRequests();
+        duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
+        boolean inProgress = false;
+        inProgress = requestHandlerUtils.camundaHistoryCheck(duplicateRecord, null);
+        assertTrue(inProgress);
+    }
+
+    @Test
+    public void camundaHistoryCheckNoneFoundTest() throws ContactCamundaException, RequestDbFailureException {
+        wireMockServer.stubFor(get(
+                ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
+                        .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                .withBody("[]").withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+        InfraActiveRequests duplicateRecord = new InfraActiveRequests();
+        duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
+        boolean inProgress = false;
+        inProgress = requestHandlerUtils.camundaHistoryCheck(duplicateRecord, null);
+        assertFalse(inProgress);
+    }
+
+    @Test
+    public void camundaHistoryCheckNotInProgressTest() throws ContactCamundaException, RequestDbFailureException {
+        wireMockServer.stubFor(get(
+                ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
+                        .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                .withBodyFile("Camunda/HistoryCheckResponseCompleted.json")
+                                .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+        InfraActiveRequests duplicateRecord = new InfraActiveRequests();
+        duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
+        boolean inProgress = false;
+        inProgress = requestHandlerUtils.camundaHistoryCheck(duplicateRecord, null);
+        assertFalse(inProgress);
+    }
+
+    @Test
+    public void handleReplaceInstance_Test() throws JsonParseException, JsonMappingException, IOException {
+        String replaceVfModule = inputStream("/ReplaceVfModule.json");
+        ObjectMapper mapper = new ObjectMapper();
+        ServiceInstancesRequest sir = mapper.readValue(replaceVfModule, ServiceInstancesRequest.class);
+        Actions action = servInstances.handleReplaceInstance(Action.replaceInstance, sir);
+        assertEquals(Action.replaceInstance, action);
+    }
+
+    @Test
+    public void handleReplaceInstance_retainAssignments_Test()
+            throws JsonParseException, JsonMappingException, IOException {
+        String replaceVfModule = inputStream("/ReplaceVfModuleRetainAssignments.json");
+        ObjectMapper mapper = new ObjectMapper();
+        ServiceInstancesRequest sir = mapper.readValue(replaceVfModule, ServiceInstancesRequest.class);
+        Actions action = servInstances.handleReplaceInstance(Action.replaceInstance, sir);
+        assertEquals(Action.replaceInstanceRetainAssignments, action);
+    }
+
+    @Test
+    public void getCloudConfigurationAAIEntityNotFoundTest() throws IOException {
+        RequestError expectedResponse =
+                mapper.readValue(inputStream("/AAIEntityNotFoundResponse.json"), RequestError.class);
+        uri = servInstanceuri + "v7"
+                + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
+        ResponseEntity<String> response =
+                sendRequest(inputStream("/ReplaceVfModuleNoCloudConfig.json"), uri, HttpMethod.POST, headers);
+
+        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
+        assertThat(expectedResponse, sameBeanAs(realResponse));
+    }
 
 }
+