[SO] Pending Create changes for SO-API and BPMN-INFRA to support CNF's through ASD
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / ServiceInstancesTest.java
index 4951053..cb48d00 100644 (file)
@@ -1,8 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ *  Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +13,8 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
 
@@ -26,17 +26,17 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get;
 import static com.github.tomakehurst.wiremock.client.WireMock.post;
 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
+import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_PARTNER_NAME;
 import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID;
-import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID;
 import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID;
-import static org.onap.logging.filter.base.Constants.HttpHeaders.CLIENT_ID;
+import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID;
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
@@ -81,12 +81,10 @@ 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;
@@ -99,6 +97,8 @@ public class ServiceInstancesTest extends BaseTest {
 
     private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/";
     private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/";
+    private final String orchestration_path = "/onap/so/infra";
+
     private String uri;
     private URL selfLink;
     private URL initialUrl;
@@ -108,23 +108,21 @@ 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(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");
+        headers.set(ONAP_PARTNER_NAME, "VID");
         headers.set(REQUESTOR_ID, "xxxxxx");
         try { // generate one-time port number to avoid RANDOM port number later.
-            initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH));
+            initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH, orchestration_path));
             initialPort = initialUrl.getPort();
         } 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());
     }
@@ -217,37 +215,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.SOAuditLogContainerFilter")
-                    && 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(ONAPLogConstants.MDCs.INVOCATION_ID));
-                assertEquals("UNKNOWN", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
-                assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",
-                        mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
-                assertEquals("INPROGRESS", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
-            } else if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter")
-                    && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("EXIT")) {
-                Map<String, String> mdc = logEvent.getMDCPropertyMap();
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP));
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
-                assertEquals("202", mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE));
-                assertEquals("UNKNOWN", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
-                assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",
-                        mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
-                assertEquals("COMPLETE", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
-                assertNotNull(mdc.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION));
-                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
@@ -400,15 +367,6 @@ public class ServiceInstancesTest extends BaseTest {
                                 .withStatus(HttpStatus.SC_NOT_FOUND)));
 
         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
-
-        for (ILoggingEvent logEvent : TestAppender.events) {
-            if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.SOAuditLogContainerFilter")
-                    && 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));
-                assertNotNull(mdc.get("PartnerName"));
-            }
-        }
     }
 
     @Test
@@ -486,6 +444,10 @@ public class ServiceInstancesTest extends BaseTest {
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
 
+        wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
+
         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
@@ -528,6 +490,10 @@ public class ServiceInstancesTest extends BaseTest {
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
 
+        wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
+
         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
@@ -569,6 +535,10 @@ public class ServiceInstancesTest extends BaseTest {
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
 
+        wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
+
         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
@@ -907,7 +877,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());
     }
 
@@ -949,6 +919,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"))
@@ -1122,6 +1131,34 @@ public class ServiceInstancesTest extends BaseTest {
         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
     }
 
+    @Test
+    public void createCnfInstanceNoALaCarte() throws IOException {
+
+        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(".*/service/5df8b6de-2083-11e7-93ae-92361f002672"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBody(getWiremockResponseForCatalogdb("serviceCnf_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/ff305d54-75b4-431b-adb2-eb6b9e5ff000/cnfs";
+        ResponseEntity<String> response =
+                sendRequest(inputStream("/CnfWithServiceRelatedInstance.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"));
+        assertTrue(response.getBody().contains("1882939"));
+    }
+
     @Test
     public void createVfModuleInstance() throws IOException {
         wireMockServer.stubFor(get(urlMatching(
@@ -1340,7 +1377,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());
     }
 
@@ -1380,6 +1417,44 @@ public class ServiceInstancesTest extends BaseTest {
         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
     }
 
+    @Test
+    public void replaceVfModuleInstanceNoCloudConfigurationTest() throws IOException {
+        wireMockServer.stubFor(
+                get(urlPathMatching("/aai/v\\d+/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"))
@@ -1451,6 +1526,8 @@ public class ServiceInstancesTest extends BaseTest {
                 sendRequest(inputStream("/VfModuleNoModelType.json"), uri, HttpMethod.POST, headers);
         // ActualRecord
         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+        assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d",
+                response.getHeaders().get(ONAPLogConstants.Headers.REQUEST_ID).get(0));
     }
 
     @Test
@@ -1907,6 +1984,10 @@ public class ServiceInstancesTest extends BaseTest {
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
 
+        wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
+
         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
@@ -2082,6 +2163,10 @@ public class ServiceInstancesTest extends BaseTest {
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
 
+        wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
+                .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                        .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
+
         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
@@ -2143,7 +2228,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());
     }
@@ -2162,7 +2247,6 @@ public class ServiceInstancesTest extends BaseTest {
 
         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
-                        .withBodyFile("Camunda/UnauthorizedResponse.json")
                         .withStatus(org.apache.http.HttpStatus.SC_UNAUTHORIZED)));
 
         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
@@ -2178,8 +2262,8 @@ 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);
-        assertEquals("Exception caught mapping Camunda JSON response to object",
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
+        assertEquals("Request Failed due to BPEL error with HTTP Status = 401 UNAUTHORIZED",
                 realResponse.getServiceException().getText());
     }
 
@@ -2211,7 +2295,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"));
     }
@@ -2378,8 +2462,8 @@ public class ServiceInstancesTest extends BaseTest {
         ResponseEntity<String> response =
                 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);
+        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+        RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
         assertEquals("Exception caught mapping Camunda JSON response to object",
                 realResponse.getServiceException().getText());
     }
@@ -2395,9 +2479,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$InternalServerError: 500 Server Error",
+                "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error: [no body]",
                 realResponse.getServiceException().getText());
     }
 
@@ -2408,7 +2492,7 @@ public class ServiceInstancesTest extends BaseTest {
                         .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json")
                         .withStatus(HttpStatus.SC_ACCEPTED)));
         wireMockServer.stubFor(get(
-                ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
+                ("/sobpmnengine/history/process-instance?processInstanceBusinessKey=f0a35706-efc4-4e27-80ea-a995d7a2a40f&active=true&maxResults=1"))
                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                                 .withBodyFile("Camunda/HistoryCheckResponse.json")
                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
@@ -2418,7 +2502,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());
@@ -2431,7 +2515,7 @@ public class ServiceInstancesTest extends BaseTest {
                         .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json")
                         .withStatus(HttpStatus.SC_ACCEPTED)));
         wireMockServer.stubFor(get(
-                ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
+                ("/sobpmnengine/history/process-instance?processInstanceBusinessKey=f0a35706-efc4-4e27-80ea-a995d7a2a40f&active=true&maxResults=1"))
                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                                 .withStatus(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR)));
 
@@ -2440,9 +2524,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$InternalServerError: 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: [no body]",
                 realResponse.getServiceException().getText());
     }
 
@@ -2457,9 +2541,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$InternalServerError: 500 Server Error",
+                "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error: [no body]",
                 realResponse.getServiceException().getText());
     }
 
@@ -2489,9 +2573,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$InternalServerError: 500 Server Error",
+                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error: [no body]",
                 realResponse.getServiceException().getText());
     }
 
@@ -2509,9 +2593,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$InternalServerError: 500 Server Error",
+                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error: [no body]",
                 realResponse.getServiceException().getText());
     }
 
@@ -2526,9 +2610,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$InternalServerError: 500 Server Error",
+                "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error: [no body]",
                 realResponse.getServiceException().getText());
     }
 
@@ -2571,15 +2655,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.SOAuditLogContainerFilter")
-                    && 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(ONAPLogConstants.MDCs.PARTNER_NAME));
-            }
-        }
     }
 
     @Test
@@ -2631,7 +2706,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");
     }
 
@@ -2644,7 +2719,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");
     }
 
@@ -2663,7 +2738,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");
     }
 
@@ -2751,7 +2826,7 @@ 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");
     }
@@ -2874,7 +2949,7 @@ public class ServiceInstancesTest extends BaseTest {
     @Test
     public void camundaHistoryCheckTest() throws ContactCamundaException, RequestDbFailureException {
         wireMockServer.stubFor(get(
-                ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
+                ("/sobpmnengine/history/process-instance?processInstanceBusinessKey=f0a35706-efc4-4e27-80ea-a995d7a2a40f&active=true&maxResults=1"))
                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                                 .withBodyFile("Camunda/HistoryCheckResponse.json")
                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
@@ -2889,7 +2964,7 @@ public class ServiceInstancesTest extends BaseTest {
     @Test
     public void camundaHistoryCheckNoneFoundTest() throws ContactCamundaException, RequestDbFailureException {
         wireMockServer.stubFor(get(
-                ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
+                ("/sobpmnengine/history/process-instance?processInstanceBusinessKey=f0a35706-efc4-4e27-80ea-a995d7a2a40f&active=true&maxResults=1"))
                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                                 .withBody("[]").withStatus(org.apache.http.HttpStatus.SC_OK)));
 
@@ -2900,21 +2975,6 @@ public class ServiceInstancesTest extends BaseTest {
         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");
@@ -2933,5 +2993,20 @@ public class ServiceInstancesTest extends BaseTest {
         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));
+    }
+
 }