import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 import org.apache.commons.lang3.builder.ToStringBuilder;
-import com.fasterxml.jackson.annotation.JsonRootName;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
+import com.fasterxml.jackson.annotation.JsonTypeName;
 
 
 /**
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {"policyException", "serviceException"})
 @XmlRootElement(name = "requestError")
-@JsonRootName(value = "requestError")
+@JsonTypeName("requestError")
+@JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME)
+@JsonInclude(Include.NON_NULL)
 public class RequestError {
 
     protected PolicyException policyException;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlType;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.fasterxml.jackson.annotation.JsonRootName;
 
 
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "serviceException")
 @JsonRootName(value = "serviceException")
+@JsonInclude(Include.NON_EMPTY)
 public class ServiceException extends ExceptionType {
 
 
 
     deleteInstance,
     configureInstance,
     replaceInstance,
+    replaceInstanceRetainAssignments,
     activateInstance,
     deactivateInstance,
     enablePort,
 
     @Override
     public Response toResponse(ApiException exception) {
         logger.error("Error During API Call", exception);
-        return Response.status(exception.getHttpResponseCode()).entity(buildErrorString(exception)).build();
+        return Response.status(exception.getHttpResponseCode()).entity(buildError(exception)).build();
     }
 
-    protected String buildErrorString(ApiException exception) {
+    protected RequestError buildError(ApiException exception) {
         String errorText = exception.getMessage();
         String messageId = exception.getMessageID();
         List<String> variables = exception.getVariables();
-        ErrorLoggerInfo errorLoggerInfo = exception.getErrorLoggerInfo();
-
-
 
         if (errorText.length() > 1999) {
             errorText = errorText.substring(0, 1999);
         }
-
-
-
-        List<MediaType> typeList = Optional.ofNullable(headers.getAcceptableMediaTypes()).orElse(new ArrayList<>());
-        List<String> typeListString = typeList.stream().map(item -> item.toString()).collect(Collectors.toList());
-        MediaType type;
-        if (typeListString.stream().anyMatch(item -> item.contains(MediaType.APPLICATION_XML))) {
-            type = MediaType.APPLICATION_XML_TYPE;
-        } else if (typeListString.stream().anyMatch(item -> typeListString.contains(MediaType.APPLICATION_JSON))) {
-            type = MediaType.APPLICATION_JSON_TYPE;
-        } else {
-            type = MediaType.APPLICATION_JSON_TYPE;
-        }
-
-        return buildServiceErrorResponse(errorText, messageId, variables, type);
+        return buildServiceErrorResponse(errorText, messageId, variables);
 
     }
 
-    protected String buildServiceErrorResponse(String errorText, String messageId, List<String> variables,
-            MediaType type) {
-        RequestError re = new RequestError();
-        ServiceException se = new ServiceException();
-        se.setMessageId(messageId);
-        se.setText(errorText);
+    protected RequestError buildServiceErrorResponse(String errorText, String messageId, List<String> variables) {
+        RequestError requestError = new RequestError();
+        ServiceException serviceException = new ServiceException();
+        serviceException.setMessageId(messageId);
+        serviceException.setText(errorText);
         if (variables != null) {
             for (String variable : variables) {
-                se.getVariables().add(variable);
+                serviceException.getVariables().add(variable);
             }
         }
-        re.setServiceException(se);
-        String requestErrorStr;
-
-        ObjectMapper mapper = createObjectMapper();
-
-        mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
-        mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
-        try {
-            if (MediaType.APPLICATION_JSON_TYPE.equals(type)) {
-                requestErrorStr = mapper.writeValueAsString(re);
-            } else {
-                StringWriter sw = new StringWriter();
-                this.getMarshaller().marshal(re, sw);
-                requestErrorStr = sw.toString();
-            }
-        } catch (JsonProcessingException | JAXBException e) {
-            String errorMsg =
-                    "Exception in buildServiceErrorResponse writing exceptionType to string " + e.getMessage();
-            logger.error("BuildServiceErrorResponse", e);
-            return errorMsg;
-        }
-
-        return requestErrorStr;
+        requestError.setServiceException(serviceException);
+        return requestError;
     }
 
     protected void writeErrorLog(Exception e, String errorText, ErrorLoggerInfo errorLogInfo) {
 
         serviceException.setMessageId("SVC0002");
         serviceException.setText(
                 "RequestId: 32807a28-1a14-4b88-b7b3-2950918aa769 already exists in the RequestDB InfraActiveRequests table");
-        serviceException.setVariables(Collections.emptyList());
         requestError.setServiceException(serviceException);
         return requestError;
     }
 
     @InjectMocks
     ApiExceptionMapper mapper = new ApiExceptionMapper();
 
-
-    @Before
-    public void setUp() {
-        when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_JSON_TYPE));
-    }
-
-    @Test
-    public void testObjectMapperError() throws JsonProcessingException {
-        ObjectMapper mockedMapper = Mockito.mock(ObjectMapper.class);
-        Mockito.when(mockedMapper.writeValueAsString(anyObject())).thenThrow(JsonProcessingException.class);
-        ValidateException validateException = new ValidateException.Builder("Test", 0, null).build();
-        ApiExceptionMapper mockedException = Mockito.spy(mapper);
-        Mockito.doReturn(mockedMapper).when(mockedException).createObjectMapper();
-        Response resp = mockedException.toResponse((ApiException) validateException);
-
-        /// assertEquals(resp.getStatus(), HttpStatus.SC_BAD_REQUEST);
-        assertThat(resp.getEntity().toString(),
-                startsWith("Exception in buildServiceErrorResponse writing exceptionType to string"));
-    }
-
     @Test
     public void testValidateResponse() {
         ValidateException validateException =
 
         assertEquals(resp.getStatus(), HttpStatus.SC_BAD_GATEWAY);
     }
-
-    @Test
-    public void verifyXMLPath() throws JAXBException {
-        when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_XML_TYPE));
-        BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,
-                ErrorNumbers.SVC_BAD_PARAMETER).build();
-        ApiExceptionMapper mapperSpy = Mockito.spy(mapper);
-        doReturn(marshaller).when(mapperSpy).getMarshaller();
-        Response resp = mapperSpy.toResponse((ApiException) bpmnException);
-        verify(marshaller, times(1)).marshal(any(Object.class), any(Writer.class));
-    }
-
-    @Test
-    public void verifyMediaType() {
-        ApiExceptionMapper mapperSpy = Mockito.spy(mapper);
-        BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,
-                ErrorNumbers.SVC_BAD_PARAMETER).build();
-        when(headers.getAcceptableMediaTypes())
-                .thenReturn(Arrays.asList(MediaType.APPLICATION_XML_TYPE.withCharset("UTF-8")));
-        mapperSpy.toResponse(bpmnException);
-        verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class),
-                ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_XML_TYPE));
-        when(headers.getAcceptableMediaTypes())
-                .thenReturn(Arrays.asList(MediaType.APPLICATION_JSON_TYPE.withCharset("UTF-8")));
-        mapperSpy = Mockito.spy(mapper);
-        mapperSpy.toResponse(bpmnException);
-        verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class),
-                ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_JSON_TYPE));
-        when(headers.getAcceptableMediaTypes()).thenReturn(null);
-        mapperSpy = Mockito.spy(mapper);
-        mapperSpy.toResponse(bpmnException);
-        verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class),
-                ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_JSON_TYPE));
-    }
 }
 
             }
             re.setServiceException(se);
         }
-
-        String requestErrorStr = null;
-
-        try {
-            ObjectMapper mapper = new ObjectMapper();
-            mapper.setSerializationInclusion(Include.NON_DEFAULT);
-            requestErrorStr = mapper.writeValueAsString(re);
-        } catch (Exception e) {
-            logger.error("Exception in buildServiceErrorResponse writing exceptionType to string ", e);
-        }
-
-        return builder.buildResponse(httpResponseCode, null, requestErrorStr, version);
+        return builder.buildResponse(httpResponseCode, null, re, version);
     }
 
 
 
 import org.onap.so.apihandlerinfra.exceptions.ApiException;
 import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException;
 import org.onap.so.apihandlerinfra.exceptions.ValidateException;
+import org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder;
+import org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException;
 import org.onap.so.apihandlerinfra.infra.rest.handler.AbstractRestHandler;
 import org.onap.so.apihandlerinfra.infra.rest.validators.RequestValidatorListenerRunner;
 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
 import org.onap.so.exceptions.ValidationException;
 import org.onap.so.logger.ErrorCode;
 import org.onap.so.logger.MessageEnum;
+import org.onap.so.serviceinstancebeans.CloudConfiguration;
 import org.onap.so.serviceinstancebeans.ModelInfo;
 import org.onap.so.serviceinstancebeans.ModelType;
 import org.onap.so.serviceinstancebeans.RequestDetails;
     @Autowired
     private RequestValidatorListenerRunner requestValidatorListenerRunner;
 
+    @Autowired
+    private BpmnRequestBuilder bpmnRequestBuilder;
+
     @POST
     @Path("/{version:[vV][5-7]}/serviceInstances")
     @Consumes(MediaType.APPLICATION_JSON)
         if (sir.getRequestDetails().getRequestParameters() != null) {
             aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
         }
+
         requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId,
                 currentActiveReq);
+        if ((action == Action.replaceInstance || action == Action.replaceInstanceRetainAssignments)
+                && (requestScope.equals(ModelType.vnf.toString()) || requestScope.equals(ModelType.vfModule.toString()))
+                && sir.getRequestDetails().getCloudConfiguration() == null) {
+            CloudConfiguration cloudConfiguration =
+                    getCloudConfigurationOnReplace(requestScope, instanceIdMap, currentActiveReq);
+            sir.getRequestDetails().setCloudConfiguration(cloudConfiguration);
+            setCloudConfigurationCurrentActiveRequest(cloudConfiguration, currentActiveReq);
+        }
         requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
 
+
         int requestVersion = Integer.parseInt(version.substring(1));
         String instanceName = null;
         if (sir.getRequestDetails().getRequestInfo() != null) {
                     ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
         }
 
-        if (!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance) {
+        if (!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance
+                && !(requestScope.equalsIgnoreCase(ModelType.vnf.name())
+                        && (action == Action.replaceInstance || action == Action.replaceInstanceRetainAssignments))) {
             aLaCarte = true;
         } else if (aLaCarte == null) {
             aLaCarte = false;
         String serviceInstanceId;
         Boolean aLaCarte = null;
         String apiVersion = version.substring(1);
-        boolean inProgress = false;
         ServiceInstancesRequest sir;
 
         sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
         if (sir.getRequestDetails().getRequestParameters() != null) {
             aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
         }
+
         requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId,
                 currentActiveReq);
         requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
                 requestScope);
     }
 
+    protected CloudConfiguration getCloudConfigurationOnReplace(String requestScope,
+            HashMap<String, String> instanceIdMap, InfraActiveRequests currentActiveReq) throws ApiException {
+        logger.debug("Replace request is missing cloudConfiguration, autofilling from create.");
+        CloudConfiguration cloudConfiguration = null;
+        if (requestScope.equals(ModelType.vfModule.toString())) {
+            cloudConfiguration = bpmnRequestBuilder.getCloudConfigurationVfModuleReplace(
+                    instanceIdMap.get("vnfInstanceId"), instanceIdMap.get("vfModuleInstanceId"));
+        } else {
+            cloudConfiguration = bpmnRequestBuilder.mapCloudConfigurationVnf(instanceIdMap.get("vnfInstanceId"));
+        }
+
+        if (cloudConfiguration == null) {
+            String errorMessage = "CloudConfiguration not found during autofill for replace request.";
+            logger.error(errorMessage);
+            updateStatus(currentActiveReq, Status.FAILED, errorMessage);
+            throw new CloudConfigurationNotFoundException(
+                    "CloudConfiguration not found during autofill for replace request.");
+        }
+        return cloudConfiguration;
+    }
+
+    protected void setCloudConfigurationCurrentActiveRequest(CloudConfiguration cloudConfiguration,
+            InfraActiveRequests currentActiveRequest) {
+        if (cloudConfiguration.getLcpCloudRegionId() != null) {
+            currentActiveRequest.setAicCloudRegion(cloudConfiguration.getLcpCloudRegionId());
+        }
+
+        if (cloudConfiguration.getTenantId() != null) {
+            currentActiveRequest.setTenantId(cloudConfiguration.getTenantId());
+        }
+    }
 }
 
         return createServiceInstancesRequest(vnf, vfModule, modelType);
     }
 
+    public CloudConfiguration getCloudConfigurationVfModuleReplace(String vnfId, String vfModuleId)
+            throws AAIEntityNotFound {
+        GenericVnf vnf = aaiDataRet.getGenericVnf(vnfId);
+        if (vnf == null) {
+            throw new AAIEntityNotFound(GENERIC_VNF_NOT_FOUND_IN_INVENTORY_VNF_ID + vnfId);
+        }
+
+        return mapCloudConfiguration(vnf, vfModuleId);
+    }
+
     public ServiceInstancesRequest buildVolumeGroupDeleteRequest(String vnfId, String volumeGroupId)
             throws AAIEntityNotFound {
         GenericVnf vnf = aaiDataRet.getGenericVnf(vnfId);
         }
         requestDetails.setModelInfo(mapVfModuleModelInformation(vfModule, modelType));
 
-        requestDetails.setCloudConfiguration(mapCloudConfiguration(vnf, vfModule));
+        requestDetails.setCloudConfiguration(mapCloudConfiguration(vnf, vfModule.getVfModuleId()));
         requestDetails.setRequestParameters(createRequestParameters());
         return requestDetails;
     }
         return modelInfo;
     }
 
-    public CloudConfiguration mapCloudConfiguration(GenericVnf vnf, VfModule vfModule) {
+    public CloudConfiguration mapCloudConfiguration(GenericVnf vnf, String vfModuleId) {
         CloudConfiguration cloudConfig = new CloudConfiguration();
         AAIResultWrapper wrapper = new AAIResultWrapper(vnf);
         Optional<org.onap.so.client.aai.entities.Relationships> relationshipsOpt = wrapper.getRelationships();
         }
 
         if (tenantId == null || cloudOwner == null || lcpRegionId == null) {
-            Map<String, String[]> filters = createQueryRequest("vfModuleId", vfModule.getVfModuleId());
+            Map<String, String[]> filters = createQueryRequest("vfModuleId", vfModuleId);
             Optional<ServiceInstancesRequest> request = findServiceInstanceRequest(filters);
             if (request.isPresent()) {
                 if (request.get().getRequestDetails() != null
         return cloudConfig;
     }
 
+    public CloudConfiguration mapCloudConfigurationVnf(String vnfId) {
+        CloudConfiguration cloudConfig = new CloudConfiguration();
+        String tenantId = null;
+        String cloudOwner = null;
+        String lcpRegionId = null;
+
+        Map<String, String[]> filters = createQueryRequest("vnfId", vnfId);
+        Optional<ServiceInstancesRequest> request = findServiceInstanceRequest(filters);
+        if (request.isPresent()) {
+            if (request.get().getRequestDetails() != null
+                    && request.get().getRequestDetails().getCloudConfiguration() != null) {
+                if (request.get().getRequestDetails().getCloudConfiguration().getTenantId() != null) {
+                    tenantId = request.get().getRequestDetails().getCloudConfiguration().getTenantId();
+                }
+                if (request.get().getRequestDetails().getCloudConfiguration().getCloudOwner() != null) {
+                    cloudOwner = request.get().getRequestDetails().getCloudConfiguration().getCloudOwner();
+                }
+                if (request.get().getRequestDetails().getCloudConfiguration().getLcpCloudRegionId() != null) {
+                    lcpRegionId = request.get().getRequestDetails().getCloudConfiguration().getLcpCloudRegionId();
+                }
+            }
+        } else {
+            throw new CloudConfigurationNotFoundException(CLOUD_CONFIGURATION_COULD_NOT_BE_FOUND);
+        }
+        cloudConfig.setTenantId(tenantId);
+        cloudConfig.setCloudOwner(cloudOwner);
+        cloudConfig.setLcpCloudRegionId(lcpRegionId);
+        return cloudConfig;
+    }
+
     public Optional<ServiceInstancesRequest> findServiceInstanceRequest(Map<String, String[]> filters) {
         List<InfraActiveRequests> completeRequests = infraActiveRequestsClient.getRequest(filters);
         InfraActiveRequests foundRequest = completeRequests.get(0);
 
 
 package org.onap.so.apihandlerinfra.infra.rest.exception;
 
-public class AAIEntityNotFound extends Exception {
+import org.onap.so.apihandlerinfra.exceptions.ApiException;
+
+public class AAIEntityNotFound extends ApiException {
 
     public AAIEntityNotFound(String errorMessage) {
         super(errorMessage);
 
                                 || action == Action.updateInstance)) {
                     throw new ValidationException("cloudConfiguration");
                 }
-                if ((requestScope.equalsIgnoreCase(ModelType.vnf.name())
-                        || requestScope.equalsIgnoreCase(ModelType.vfModule.name()))
-                        && action == Action.replaceInstance) {
-                    throw new ValidationException("cloudConfiguration");
-                }
                 if (requestScope.equalsIgnoreCase(ModelType.configuration.name())
                         && (action == Action.enablePort || action == Action.disablePort
                                 || action == Action.activateInstance || action == Action.deactivateInstance)) {
 
                 restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
 
         ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
                 restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
 
         ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
 
 
         ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
 
                         mapper.readValue(inputStream("/CloudConfiguration/CloudConfigurationNetwork.json"),
                                 ServiceInstancesRequest.class),
                         instanceIdMapTest, Action.createInstance, 5},
-                {"No valid cloudConfiguration is specified",
-                        mapper.readValue(inputStream("/CloudConfiguration/CloudConfigurationVnf.json"),
-                                ServiceInstancesRequest.class),
-                        instanceIdMapTest, Action.replaceInstance, 5},
                 {"No valid cloudConfiguration is specified",
                         mapper.readValue(inputStream("/CloudConfiguration/CloudConfigurationConfig.json"),
                                 ServiceInstancesRequest.class),
 
     public void testUnlockOrchestrationRequest() throws Exception {
         setupTestUnlockOrchestrationRequest("0017f68c-eb2d-45bb-b7c7-ec31b37dc349", "UNLOCKED");
         ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
         String requestJSON =
                 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
         HttpHeaders headers = new HttpHeaders();
     public void testUnlockOrchestrationRequest_invalid_Json() throws Exception {
         setupTestUnlockOrchestrationRequest_invalid_Json();
         ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
         String requestJSON =
                 new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
         HttpHeaders headers = new HttpHeaders();
         actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
 
         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
-        assertThat(actualRequestError, sameBeanAs(expectedRequestError));
+        assertThat(expectedRequestError, sameBeanAs(actualRequestError));
     }
 
     @Test
 
 public class ServiceInstancesTest extends BaseTest {
 
     private final ObjectMapper mapper = new ObjectMapper();
-    private ObjectMapper errorMapper = new ObjectMapper();
 
     @Autowired
     private ServiceInstances servInstances;
     @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");
         } 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());
     }
         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());
     }
 
         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"))
                 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());
     }
 
         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
     }
 
+    @Test
+    public void replaceVfModuleInstanceNoCloudConfigurationTest() throws IOException {
+        wireMockServer.stubFor(
+                get(urlPathEqualTo("/aai/v17/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"))
                 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());
     }
                 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());
     }
                 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"));
     }
                 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());
     }
                 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$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
                 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());
                 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$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
                 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$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
                 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$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
                 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$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
                 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$InternalServerError: 500 Server Error",
                 realResponse.getServiceException().getText());
         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");
     }
 
         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");
     }
 
 
         // 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");
     }
 
         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");
     }
         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));
+    }
+
 }
 
 
--- /dev/null
+package org.onap.so.apihandlerinfra;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import java.util.HashMap;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.apihandlerinfra.exceptions.ApiException;
+import org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder;
+import org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException;
+import org.onap.so.apihandlerinfra.vnfbeans.ModelType;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.serviceinstancebeans.CloudConfiguration;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ServiceInstancesUnitTest {
+
+    @Mock
+    private BpmnRequestBuilder bpmnRequestBuilder;
+
+    @Spy
+    @InjectMocks
+    private ServiceInstances serviceInstances;
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+
+    @Test
+    public void getCloudConfigurationOnReplaceVnfTest() throws ApiException {
+        CloudConfiguration cloudConfiguration = new CloudConfiguration();
+        cloudConfiguration.setTenantId("tenantId");
+        cloudConfiguration.setLcpCloudRegionId("lcpCloudRegionId");
+        String requestScope = ModelType.vnf.toString();
+        HashMap<String, String> instanceIdMap = new HashMap<>();
+        instanceIdMap.put("vnfInstanceId", "17c10d8e-48f4-4ee6-b162-a801943df6d6");
+        InfraActiveRequests currentActiveRequest = new InfraActiveRequests();
+
+        doReturn(cloudConfiguration).when(bpmnRequestBuilder)
+                .mapCloudConfigurationVnf("17c10d8e-48f4-4ee6-b162-a801943df6d6");
+        CloudConfiguration result =
+                serviceInstances.getCloudConfigurationOnReplace(requestScope, instanceIdMap, currentActiveRequest);
+
+        assertEquals(cloudConfiguration, result);
+    }
+
+    @Test
+    public void getCloudConfigurationOnReplaceVfModuleTest() throws ApiException {
+        CloudConfiguration cloudConfiguration = new CloudConfiguration();
+        cloudConfiguration.setTenantId("tenantId");
+        cloudConfiguration.setLcpCloudRegionId("lcpCloudRegionId");
+        String requestScope = ModelType.vfModule.toString();
+        HashMap<String, String> instanceIdMap = new HashMap<>();
+        instanceIdMap.put("vnfInstanceId", "17c10d8e-48f4-4ee6-b162-a801943df6d6");
+        instanceIdMap.put("vfModuleInstanceId", "17c10d8e-48f4-4ee6-b162-a801943df6d8");
+        InfraActiveRequests currentActiveRequest = new InfraActiveRequests();
+
+        doReturn(cloudConfiguration).when(bpmnRequestBuilder).getCloudConfigurationVfModuleReplace(
+                "17c10d8e-48f4-4ee6-b162-a801943df6d6", "17c10d8e-48f4-4ee6-b162-a801943df6d8");
+        CloudConfiguration result =
+                serviceInstances.getCloudConfigurationOnReplace(requestScope, instanceIdMap, currentActiveRequest);
+
+        assertEquals(cloudConfiguration, result);
+    }
+
+    @Test
+    public void getCloudConfigurationReturnsNullTest() throws ApiException {
+        String requestScope = ModelType.vfModule.toString();
+        HashMap<String, String> instanceIdMap = new HashMap<>();
+        instanceIdMap.put("vnfInstanceId", "17c10d8e-48f4-4ee6-b162-a801943df6d6");
+        instanceIdMap.put("vfModuleInstanceId", "17c10d8e-48f4-4ee6-b162-a801943df6d8");
+        InfraActiveRequests currentActiveRequest = new InfraActiveRequests();
+
+        doReturn(null).when(bpmnRequestBuilder).getCloudConfigurationVfModuleReplace(
+                "17c10d8e-48f4-4ee6-b162-a801943df6d6", "17c10d8e-48f4-4ee6-b162-a801943df6d8");
+        thrown.expect(CloudConfigurationNotFoundException.class);
+        thrown.expectMessage("CloudConfiguration not found during autofill for replace request.");
+
+        serviceInstances.getCloudConfigurationOnReplace(requestScope, instanceIdMap, currentActiveRequest);
+    }
+
+    @Test
+    public void setCloudConfigurationCurrentActiveRequestTest() {
+        CloudConfiguration cloudConfiguration = new CloudConfiguration();
+        cloudConfiguration.setTenantId("tenantId");
+        cloudConfiguration.setLcpCloudRegionId("lcpCloudRegionId");
+
+        InfraActiveRequests currentActiveRequest = new InfraActiveRequests();
+        serviceInstances.setCloudConfigurationCurrentActiveRequest(cloudConfiguration, currentActiveRequest);
+
+        assertEquals("tenantId", currentActiveRequest.getTenantId());
+        assertEquals("lcpCloudRegionId", currentActiveRequest.getAicCloudRegion());
+    }
+}
 
 
 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Optional;
 import org.junit.Before;
 import org.junit.Rule;
 import org.onap.so.client.aai.entities.AAIResultWrapper;
 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
+import org.onap.so.constants.Status;
 import org.onap.so.db.request.client.RequestsDbClient;
+import org.onap.so.serviceinstancebeans.CloudConfiguration;
 import org.onap.so.serviceinstancebeans.ModelType;
+import org.onap.so.serviceinstancebeans.RequestDetails;
 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
         assertThat(actualRequest, sameBeanAs(expectedRequest));
     }
 
+    @Test
+    public void test_getCloudConfigurationVfModuleReplace() throws Exception {
+        String vnfId = "vnfId";
+        String vfModuleId = "vfModuleId";
+
+        GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class);
+
+        doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class,
+                AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId));
+
+        CloudConfiguration result = reqBuilder.getCloudConfigurationVfModuleReplace(vnfId, vfModuleId);
+        assertEquals("0422ffb57ba042c0800a29dc85ca70f8", result.getTenantId());
+        assertEquals("cloudOwner", result.getCloudOwner());
+        assertEquals("regionOne", result.getLcpCloudRegionId());
+    }
+
+    @Test
+    public void test_mapCloudConfigurationVnf() throws Exception {
+        String vnfId = "6fb01019-c3c4-41fe-b307-d1c56850b687";
+        Map<String, String[]> filters = new HashMap<>();
+        filters.put("vnfId", new String[] {"EQ", vnfId});
+        filters.put("requestStatus", new String[] {"EQ", Status.COMPLETE.toString()});
+        filters.put("action", new String[] {"EQ", "createInstance"});
+
+        ServiceInstancesRequest serviceRequest = new ServiceInstancesRequest();
+        CloudConfiguration cloudConfiguration = new CloudConfiguration();
+        RequestDetails requestDetails = new RequestDetails();
+        cloudConfiguration.setCloudOwner("cloudOwner");
+        cloudConfiguration.setTenantId("tenantId");
+        cloudConfiguration.setLcpCloudRegionId("lcpCloudRegionId");
+        requestDetails.setCloudConfiguration(cloudConfiguration);
+        serviceRequest.setRequestDetails(requestDetails);
+
+        doReturn(filters).when(reqBuilder).createQueryRequest("vnfId", vnfId);
+        doReturn(Optional.of(serviceRequest)).when(reqBuilder).findServiceInstanceRequest(filters);
+
+
+        CloudConfiguration result = reqBuilder.mapCloudConfigurationVnf(vnfId);
+        assertEquals("tenantId", result.getTenantId());
+        assertEquals("cloudOwner", result.getCloudOwner());
+        assertEquals("lcpCloudRegionId", result.getLcpCloudRegionId());
+    }
+
 }
 
 
--- /dev/null
+{
+    "requestError": {
+        "serviceException": {
+            "messageId": "SVC0001",
+            "text": "Generic Vnf Not Found In Inventory, VnfId: ff305d54-75b4-431b-adb2-eb6b9e5ff000"
+        }
+    }
+}
 
--- /dev/null
+{
+    "requestDetails": {
+        "requestInfo": { 
+            "source": "VID", 
+            "requestorId": "xxxxxx",
+            "instanceName": "testService60"
+        },
+        "requestParameters": {
+            "aLaCarte": true, 
+            "autoBuildVfModules": false,
+            "subscriptionServiceType": "test"
+        },
+        "modelInfo":{
+            "modelInvariantId": "f7ce78bb-423b-11e7-93f8-0050569a7968",
+            "modelVersion":"2", 
+            "modelVersionId":"78ca26d0-246d-11e7-93ae-92361f002671", 
+            "modelType":"vfModule",
+            "modelName":"serviceModel",
+            "modelCustomizationId": "a7f1d08e-b02d-11e6-80f5-76304dec7eb7"
+        },
+         "subscriberInfo": {
+              "globalSubscriberId": "MSO_1610_dev", 
+              "subscriberName": "MSO_1610_dev"
+        }
+    }
+}
+    
+    
 
--- /dev/null
+{
+    "vnfInstanceId": "ff305d54-75b4-431b-adb2-eb6b9e5ff000",
+    "requestDetails": {
+        "modelInfo": {
+            "modelType": "vnf",
+            "modelInvariantId": "ff5256d2-5a33-55df-13ab-12abad84e7ff",
+            "modelName": "vSAMP12..base..module-0",
+            "modelVersion": "1",
+            "modelVersionId": "1",
+            "modelCustomizationId": "68dc9a92-214c-11e7-93ae-92361f002671"
+        },
+        "requestInfo": {
+            "instanceName": "VNFTEST-10",
+            "source": "VID",
+            "suppressRollback": true,
+            "requestorId": "xxxxxx",
+            "productFamilyId": "FamilyID"
+        },
+        "relatedInstanceList": [
+        {
+            "relatedInstance": {
+               "instanceId": "f7ce78bb-423b-11e7-93f8-0050569a7968", 
+               "modelInfo": {   
+                  "modelType": "service",
+                  "modelInvariantId": "ff3514e3-5a33-55df-13ab-12abad84e7ff",
+                  "modelVersionId": "fe6985cd-ea33-3346-ac12-ab121484a3fe",
+                  "modelName": "vSAMP12",
+                  "modelVersion": "1.0"
+               }
+            }
+         },
+         {
+            "relatedInstance": {
+               "instanceId": "ff305d54-75b4-431b-adb2-eb6b9e5ff000",
+                "instanceDirection": "source",
+               "modelInfo": {   
+                  "modelType": "vnf",
+                  "modelInvariantId": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
+                  "modelVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
+                  "modelName": "vSAMP12",
+                  "modelVersion": "1.0",
+                  "modelCustomizationId": "b0ed83ec-b7b4-4c70-91c2-63feeaf8609b"
+               }
+            }
+         }
+         ],
+        "requestParameters": {
+            "aLaCarte": true,
+            "userParams": []
+        },
+        "platform": {
+            "platformName": "platformName"
+        },
+        "lineOfBusiness": {
+            "lineOfBusinessName": "lobName"
+        }
+    }
+}
 
--- /dev/null
+[ 
+   { 
+      "requestId":"b15f30dc-56b1-4a1a-aaf1-156c0d685142",
+      "action":"createInstance",
+      "requestStatus":"COMPLETE",
+      "statusMessage":"ALaCarte-Vnf-createInstance request was executed correctly.",
+      "flowStatus":"Successfully completed all Building Blocks",
+      "progress":100,
+      "startTime":"2019-11-11T19:28:56.000+0000",
+      "endTime":"2019-11-11T19:29:15.000+0000",
+      "source":"VID",
+      "vnfId":"5b20c24e-cabb-4725-8f88-57ca99a8ffe1",
+      "vnfName":"Robot_VNF_For_Volume_Group",
+      "vnfType":"Vf zrdm5bpxmc02092017-Service/Vf zrdm5bpxmc02092017-VF 0",
+      "tenantId":"0422ffb57ba042c0800a29dc85ca70f8",
+      "requestBody":"{\"requestDetails\": {\"relatedInstanceList\": [{\"relatedInstance\": {\"instanceId\": \"f5435110-b276-4920-9261-a18a5582d357\", \"modelInfo\": {\"modelVersionId\": \"bad955c3-29b2-4a27-932e-28e942cc6480\", \"modelVersion\": \"1\", \"modelName\": \"Vf zrdm5bpxmc02092017-Service\", \"modelInvariantId\": \"b16a9398-ffa3-4041-b78c-2956b8ad9c7b\", \"modelType\": \"service\"}}}], \"requestParameters\": {\"userParams\": [], \"enforceValidNfValues\": false, \"testApi\": \"GR_API\"}, \"lineOfBusiness\": {\"lineOfBusinessName\": \"vSAMP12_14-2XXX-Aug18-9001 - LOB\"}, \"requestInfo\": {\"source\": \"VID\", \"requestorId\": \"az2016\", \"instanceName\": \"Robot_VNF_For_Volume_Group\", \"suppressRollback\": false, \"productFamilyId\": \"06f76284-8710-11e6-ae22-56b6b6499611\"}, \"platform\": {\"platformName\": \"vSAMP12_14-2XXX-Aug18-9001 - Platform\"}, \"modelInfo\": {\"modelName\": \"Vf zrdm5bpxmc02092017-VF\", \"modelVersion\": \"1\", \"modelInvariantId\": \"23122c9b-dd7f-483f-bf0a-e069303db2f7\", \"modelType\": \"vnf\", \"modelCustomizationName\": \"Vf zrdm5bpxmc02092017-VF 0\", \"modelVersionId\": \"d326f424-2312-4dd6-b7fe-364fadbd1ef5\", \"modelCustomizationId\": \"96c23a4a-6887-4b2c-9cce-1e4ea35eaade\"}, \"cloudConfiguration\": {\"cloudOwner\": \"cloudOwner\", \"tenantId\": \"0422ffb57ba042c0800a29dc85ca70f8\", \"lcpCloudRegionId\": \"regionOne\"}}}",
+      "lastModifiedBy":"CamundaBPMN",
+      "modifyTime":"2019-11-11T19:29:15.000+0000",
+      "aicCloudRegion":"regionOne",
+      "serviceInstanceId":"f5435110-b276-4920-9261-a18a5582d357",
+      "requestScope":"vnf",
+      "requestAction":"createInstance",
+      "requestorId":"az2016",
+      "requestUrl":"http://192.168.99.100:9100/onap/so/infra/serviceInstantiation/v7/serviceInstances/f5435110-b276-4920-9261-a18a5582d357/vnfs",
+      "cloudApiRequests":[ 
+
+      ],
+      "requestURI":"b15f30dc-56b1-4a1a-aaf1-156c0d685142"
+   }
+]