diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common')
17 files changed, 227 insertions, 137 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/camundabeans/CamundaVIDRequest.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/camundabeans/CamundaVIDRequest.java index 3880bd43b1..4517811494 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/camundabeans/CamundaVIDRequest.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/camundabeans/CamundaVIDRequest.java @@ -116,6 +116,9 @@ public class CamundaVIDRequest { return serviceInput; } + @JsonProperty(CommonConstants.GENERATE_IDS) + private CamundaBooleanInput generateIds; + @JsonProperty(CommonConstants.CAMUNDA_SERVICE_INPUT) public void setServiceInput(CamundaInput serviceInput) { this.serviceInput = serviceInput; @@ -347,6 +350,11 @@ public class CamundaVIDRequest { return "CamundaRequest"; } + public CamundaBooleanInput getGenerateIds() { + return generateIds; + } - + public void setGenerateIds(CamundaBooleanInput generateIds) { + this.generateIds = generateIds; + } } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java index 5dd99f51cd..bc8af6e690 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java @@ -99,6 +99,7 @@ public class CamundaClient extends RequestClient { return response; } + @Override public HttpResponse post(RequestClientParameter parameterObject) throws IOException { HttpPost post = new HttpPost(url); logger.debug(CAMUNDA_URL_MESAGE + url); @@ -110,7 +111,7 @@ public class CamundaClient extends RequestClient { parameterObject.getVnfType(), parameterObject.getVfModuleType(), parameterObject.getNetworkType(), parameterObject.getRequestDetails(), parameterObject.getApiVersion(), parameterObject.isaLaCarte(), parameterObject.getRequestUri(), parameterObject.getRecipeParamXsd(), - parameterObject.getInstanceGroupId()); + parameterObject.getInstanceGroupId(), parameterObject.isGenerateIdsOnly()); StringEntity input = new StringEntity(jsonReq); input.setContentType(CommonConstants.CONTENT_TYPE_JSON); @@ -169,7 +170,7 @@ public class CamundaClient extends RequestClient { String serviceInstanceId, String pnfCorrelationId, String vnfId, String vfModuleId, String volumeGroupId, String networkId, String configurationId, String serviceType, String vnfType, String vfModuleType, String networkType, String requestDetails, String apiVersion, boolean aLaCarte, String requestUri, - String paramXsd, String instanceGroupId) { + String paramXsd, String instanceGroupId, boolean generateIdsOnly) { String jsonReq = null; try { @@ -196,6 +197,8 @@ public class CamundaClient extends RequestClient { CamundaInput requestUriInput = new CamundaInput(); CamundaInput recipeParamsInput = new CamundaInput(); CamundaInput instanceGroupIdInput = new CamundaInput(); + CamundaBooleanInput generateIds = new CamundaBooleanInput(); + requestIdInput.setValue(StringUtils.defaultString(requestId)); isBaseVfModuleInput.setValue(isBaseVfModule); @@ -217,6 +220,7 @@ public class CamundaClient extends RequestClient { requestUriInput.setValue(StringUtils.defaultString(requestUri)); recipeParamsInput.setValue(paramXsd); instanceGroupIdInput.setValue(StringUtils.defaultString(instanceGroupId)); + generateIds.setValue(generateIdsOnly); serviceInput.setValue(requestDetails); camundaRequest.setServiceInput(serviceInput); @@ -242,6 +246,7 @@ public class CamundaClient extends RequestClient { camundaRequest.setRequestUri(requestUriInput); camundaRequest.setRecipeParams(recipeParamsInput); camundaRequest.setInstanceGroupId(instanceGroupIdInput); + camundaRequest.setGenerateIds(generateIds); ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true); diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java index e48c98a395..6d2bbfc613 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java @@ -81,6 +81,7 @@ public final class CommonConstants { public static final String X_LATEST_VERSION = "X-LatestVersion"; public static final String INSTANCE_GROUP_ID = "instanceGroupId"; public static final String INSTANCE_GROUP_INSTANCE_ID = "instanceGroupInstanceId"; + public static final String GENERATE_IDS = "generateIdsOnly"; private CommonConstants() { // prevent creating an instance of this class diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientParameter.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientParameter.java index 20c512af37..3cf3907424 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientParameter.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientParameter.java @@ -44,6 +44,7 @@ public class RequestClientParameter { private String recipeParamXsd; private String requestUri; private String instanceGroupId; + private boolean generateIdsOnly; private RequestClientParameter(Builder builder) { requestId = builder.requestId; @@ -67,7 +68,7 @@ public class RequestClientParameter { aLaCarte = builder.aLaCarte; requestUri = builder.requestUri; instanceGroupId = builder.instanceGroupId; - + generateIdsOnly = builder.generateIdsOnly; } public String getRequestId() { @@ -154,6 +155,14 @@ public class RequestClientParameter { return instanceGroupId; } + public boolean isGenerateIdsOnly() { + return generateIdsOnly; + } + + public void setGenerateIdsOnly(boolean generateIdsOnly) { + this.generateIdsOnly = generateIdsOnly; + } + public static class Builder { private String requestId; private boolean isBaseVfModule = false; @@ -176,6 +185,7 @@ public class RequestClientParameter { private String recipeParamXsd; private String requestUri; private String instanceGroupId; + private boolean generateIdsOnly; public Builder setRequestId(String requestId) { this.requestId = requestId; @@ -282,11 +292,14 @@ public class RequestClientParameter { return this; } + public Builder setGenerateIds(boolean generateIdsOnly) { + this.generateIdsOnly = generateIdsOnly; + return this; + } + public RequestClientParameter build() { return new RequestClientParameter(this); } } - - } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/ResponseHandler.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/ResponseHandler.java index 095182fe98..bedce185c5 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/ResponseHandler.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/ResponseHandler.java @@ -98,8 +98,9 @@ public class ResponseHandler { if (response != null) { responseBody = response.getResponse(); } else { - ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_ERROR_FROM_BPEL_SERVER, - ErrorCode.BusinessProcesssError).targetEntity("Camunda").targetServiceName("parseCamunda").build(); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_ERROR_FROM_BPEL_SERVER, ErrorCode.BusinessProcessError) + .targetEntity("Camunda").targetServiceName("parseCamunda").build(); BPMNFailureException bpmnFailureException = new BPMNFailureException.Builder(String.valueOf(status), status, ErrorNumbers.ERROR_FROM_BPEL) .errorInfo(errorLoggerInfo).build(); @@ -123,8 +124,9 @@ public class ResponseHandler { ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); } if (status != HttpStatus.SC_ACCEPTED) { - ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_ERROR_FROM_BPEL_SERVER, - ErrorCode.BusinessProcesssError).targetEntity("BPEL").targetServiceName("parseBpel").build(); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_ERROR_FROM_BPEL_SERVER, ErrorCode.BusinessProcessError) + .targetEntity("BPEL").targetServiceName("parseBpel").build(); throw new BPMNFailureException.Builder(String.valueOf(status), status, ErrorNumbers.ERROR_FROM_BPEL) .errorInfo(errorLoggerInfo).build(); @@ -149,9 +151,9 @@ public class ResponseHandler { .build(); } if (status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_ACCEPTED) { - ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_ERROR_FROM_BPEL_SERVER, - ErrorCode.BusinessProcesssError).targetEntity("CAMUNDATASK").targetServiceName("parseCamundaTask") - .build(); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_ERROR_FROM_BPEL_SERVER, ErrorCode.BusinessProcessError) + .targetEntity("CAMUNDATASK").targetServiceName("parseCamundaTask").build(); throw new BPMNFailureException.Builder(String.valueOf(status), status, ErrorNumbers.ERROR_FROM_BPEL) .errorInfo(errorLoggerInfo).build(); diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java index 2fd426dec2..b81ee58aa4 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java @@ -23,6 +23,7 @@ import java.io.IOException; import javax.annotation.Priority; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.core.UriInfo; import javax.ws.rs.ext.Provider; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.apihandler.common.ErrorNumbers; @@ -52,15 +53,20 @@ public class RequestIdFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext context) throws IOException { String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID); + UriInfo uriInfo = context.getUriInfo(); + String requestURI = uriInfo.getPath(); - logger.info("Checking if requestId: {} already exists in requestDb InfraActiveRequests table", requestId); - InfraActiveRequests infraActiveRequests = infraActiveRequestsClient.getInfraActiveRequestbyRequestId(requestId); + if (!requestURI.contains("orchestrationRequests")) { + logger.info("Checking if requestId: {} already exists in requestDb InfraActiveRequests table", requestId); + InfraActiveRequests infraActiveRequests = + infraActiveRequestsClient.getInfraActiveRequestbyRequestId(requestId); - if (infraActiveRequests != null) { - logger.error( - "RequestId: {} already exists in RequestDB InfraActiveRequests table, throwing DuplicateRequestIdException", - requestId); - throw new DuplicateRequestIdException(createRequestError(requestId, "InfraActiveRequests")); + if (infraActiveRequests != null) { + logger.error( + "RequestId: {} already exists in RequestDB InfraActiveRequests table, throwing DuplicateRequestIdException", + requestId); + throw new DuplicateRequestIdException(createRequestError(requestId, "InfraActiveRequests")); + } } } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Action.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Action.java index 6957e1fe73..6869a3a213 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Action.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Action.java @@ -29,6 +29,7 @@ public enum Action implements Actions { deleteInstance, configureInstance, replaceInstance, + replaceInstanceRetainAssignments, activateInstance, deactivateInstance, enablePort, @@ -46,5 +47,6 @@ public enum Action implements Actions { scaleOut, recreateInstance, addMembers, - removeMembers + removeMembers, + forCustomWorkflow } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Actions.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Actions.java index 5dbe44f58b..5ae0cea549 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Actions.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Actions.java @@ -20,6 +20,8 @@ package org.onap.so.apihandlerinfra; -public interface Actions { +import java.io.Serializable; + +public interface Actions extends Serializable { } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiException.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiException.java index c7f6459482..ab2ce10690 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiException.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiException.java @@ -29,7 +29,7 @@ public abstract class ApiException extends Exception { * */ private static final long serialVersionUID = 683162058616691134L; - private int httpResponseCode; + private int httpResponseCode = 500; private String messageID; private ErrorLoggerInfo errorLoggerInfo; @@ -49,6 +49,15 @@ public abstract class ApiException extends Exception { super(message, cause); } + public ApiException(String message, int httpResponseCode) { + super(message); + this.httpResponseCode = httpResponseCode; + } + + public ApiException(String message) { + super(message); + } + public String getMessageID() { return messageID; } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapper.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapper.java index 66b86a6961..62f39d9148 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapper.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapper.java @@ -70,73 +70,34 @@ public class ApiExceptionMapper implements ExceptionMapper<ApiException> { @Override public Response toResponse(ApiException exception) { - - return Response.status(exception.getHttpResponseCode()).entity(buildErrorString(exception)).build(); + logger.error("Error During API Call", exception); + 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) { diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java index 42198e2d0c..cbbfa16eaa 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java @@ -22,7 +22,7 @@ package org.onap.so.apihandlerinfra.exceptions; public class DuplicateRequestException extends ApiException { - private static final String duplicateFailMessage = "Error: Locked instance - This %s (%s) " + private static final String DUPLICATE_FAIL_MESSAGE = "Error: Locked instance - This %s (%s) " + "already has a request being worked with a status of %s (RequestId - %s). The existing request must finish or be cleaned up before proceeding."; private DuplicateRequestException(Builder builder) { @@ -36,7 +36,7 @@ public class DuplicateRequestException extends ApiException { public Builder(String requestScope, String instance, String requestStatus, String requestID, int httpResponseCode, String messageID) { - super(String.format(duplicateFailMessage, requestScope, instance, requestStatus, requestID), + super(String.format(DUPLICATE_FAIL_MESSAGE, requestScope, instance, requestStatus, requestID), httpResponseCode, messageID); } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RequestDbFailureException.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RequestDbFailureException.java index 577a14674b..a8f868da05 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RequestDbFailureException.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RequestDbFailureException.java @@ -22,7 +22,7 @@ package org.onap.so.apihandlerinfra.exceptions; public class RequestDbFailureException extends ApiException { - private static final String requestDbFailMessage = "Unable to %s due to error contacting requestDb: %s"; + private static final String REQUEST_DB_FAIL_MESSAGE = "Unable to %s due to error contacting requestDb: %s"; private RequestDbFailureException(Builder builder) { super(builder); @@ -32,7 +32,7 @@ public class RequestDbFailureException extends ApiException { public Builder(String action, String error, int httpResponseCode, String messageID) { - super(requestDbFailMessage.format(requestDbFailMessage, action, error), httpResponseCode, messageID); + super(REQUEST_DB_FAIL_MESSAGE.format(REQUEST_DB_FAIL_MESSAGE, action, error), httpResponseCode, messageID); } public RequestDbFailureException build() { diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ValidateException.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ValidateException.java index 372ed30d8e..ae8256e64f 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ValidateException.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ValidateException.java @@ -28,6 +28,11 @@ public class ValidateException extends ApiException { } + public ValidateException(String errorMessage, int httpResponseCode) { + super(errorMessage, httpResponseCode); + } + + public static class Builder extends ApiException.Builder<Builder> { public Builder(String message, int httpResponseCode, String messageID) { diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java index 36d004e87d..94c62a9689 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java @@ -47,11 +47,11 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.mock.env.MockEnvironment; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.databind.JsonMappingException; - /** * This class implements test methods of Camunda Beans. * @@ -164,10 +164,10 @@ public class CamundaClientTest { String testResult = testClient.wrapVIDRequest(requestId, isBaseVfModule, recipeTimeout, requestAction, serviceInstanceId, pnfCorrelationId, vnfId, vfModuleId, volumeGroupId, networkId, configurationId, serviceType, vnfType, vfModuleType, networkType, requestDetails, apiVersion, aLaCarte, requestUri, "", - instanceGroupId); + instanceGroupId, false); String expected = inputStream("/WrappedVIDRequest.json"); - assertEquals(expected, testResult); + JSONAssert.assertEquals(expected, testResult, false); } @Test diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java index 8716047603..1aa6c3c5d9 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java @@ -23,9 +23,13 @@ package org.onap.so.apihandler.filters; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import java.io.IOException; +import java.net.URI; import java.util.Collections; import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.UriInfo; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -53,6 +57,9 @@ public class RequestIdFilterTest { @Mock private RequestsDbClient requestsDbClient; + @Mock + private UriInfo uriInfo; + @InjectMocks @Spy private RequestIdFilter requestIdFilter; @@ -70,7 +77,6 @@ public class RequestIdFilterTest { 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; } @@ -87,12 +93,35 @@ public class RequestIdFilterTest { doReturn(infraActiveRequests).when(requestsDbClient).getInfraActiveRequestbyRequestId(requestId); doReturn(error).when(requestIdFilter).createRequestError(REQUEST_ID, "InfraActiveRequests"); + doReturn("/onap/so/infra/serviceInstantiation/v7/serviceInstances").when(uriInfo).getPath(); + doReturn(uriInfo).when(mockContext).getUriInfo(); thrown.expect(DuplicateRequestIdException.class); thrown.expectMessage("HTTP 400 Bad Request"); + + requestIdFilter.filter(mockContext); } + + @Test + public void filterTestInfraSkipRequestIdLookup() throws IOException { + String requestId = REQUEST_ID; + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId); + + // ExpectedRecord InfraActiveRequests + InfraActiveRequests infraActiveRequests = new InfraActiveRequests(); + infraActiveRequests.setRequestId(REQUEST_ID); + + doReturn("onap/so/infra/orchestrationRequests/v7/" + REQUEST_ID).when(uriInfo).getPath(); + doReturn(uriInfo).when(mockContext).getUriInfo(); + + verify(requestsDbClient, never()).getInfraActiveRequestbyRequestId(REQUEST_ID); + + requestIdFilter.filter(mockContext); + } + + @Test public void createRequestErrorTest() throws IOException { RequestError requestError = getRequestError(); diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java index 2922aaa896..1a846da65a 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java @@ -73,26 +73,6 @@ public class ApiExceptionMapperTest { @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 = @@ -138,38 +118,4 @@ public class ApiExceptionMapperTest { 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)); - } } diff --git a/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json b/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json index b9d0a8c3c6..3353f8c7ce 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json +++ b/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json @@ -1 +1,102 @@ -{"variables":{"bpmnRequest":{"value":"{requestDetails: }","type":"String"},"requestId":{"value":"f7ce78bb-423b-11e7-93f8-0050569a796","type":"String"},"mso-request-id":{"value":"f7ce78bb-423b-11e7-93f8-0050569a796","type":"String"},"isBaseVfModule":{"value":true,"type":"Boolean"},"recipeTimeout":{"value":10000,"type":"Integer"},"requestAction":{"value":"createInstance","type":"String"},"serviceInstanceId":{"value":"12345679","type":"String"},"pnfCorrelationId":{"value":"12345679","type":"String"},"vnfId":{"value":"234567891","type":"String"},"vfModuleId":{"value":"345678912","type":"String"},"volumeGroupId":{"value":"456789123","type":"String"},"networkId":{"value":"567891234","type":"String"},"configurationId":{"value":"678912345","type":"String"},"serviceType":{"value":"testService","type":"String"},"vnfType":{"value":"testVnf","type":"String"},"vfModuleType":{"value":"vfModuleType","type":"String"},"networkType":{"value":"networkType","type":"String"},"recipeParams":{"value":"","type":"String"},"host":{"value":null,"type":"String"},"apiVersion":{"value":"6","type":"String"},"aLaCarte":{"value":true,"type":"Boolean"},"requestUri":{"value":"v7/serviceInstances/assign","type":"String"},"instanceGroupId":{"value":"ff305d54-75b4-431b-adb2-eb6b9e5ff000","type":"String"}}}
\ No newline at end of file +{ + "variables": { + "bpmnRequest": { + "value": "{requestDetails: }", + "type": "String" + }, + "requestId": { + "value": "f7ce78bb-423b-11e7-93f8-0050569a796", + "type": "String" + }, + "mso-request-id": { + "value": "f7ce78bb-423b-11e7-93f8-0050569a796", + "type": "String" + }, + "isBaseVfModule": { + "value": true, + "type": "Boolean" + }, + "recipeTimeout": { + "value": 10000, + "type": "Integer" + }, + "requestAction": { + "value": "createInstance", + "type": "String" + }, + "serviceInstanceId": { + "value": "12345679", + "type": "String" + }, + "pnfCorrelationId": { + "value": "12345679", + "type": "String" + }, + "vnfId": { + "value": "234567891", + "type": "String" + }, + "vfModuleId": { + "value": "345678912", + "type": "String" + }, + "volumeGroupId": { + "value": "456789123", + "type": "String" + }, + "networkId": { + "value": "567891234", + "type": "String" + }, + "configurationId": { + "value": "678912345", + "type": "String" + }, + "serviceType": { + "value": "testService", + "type": "String" + }, + "vnfType": { + "value": "testVnf", + "type": "String" + }, + "vfModuleType": { + "value": "vfModuleType", + "type": "String" + }, + "networkType": { + "value": "networkType", + "type": "String" + }, + "recipeParams": { + "value": "", + "type": "String" + }, + "host": { + "value": null, + "type": "String" + }, + "apiVersion": { + "value": "6", + "type": "String" + }, + "aLaCarte": { + "value": true, + "type": "Boolean" + }, + "requestUri": { + "value": "v7/serviceInstances/assign", + "type": "String" + }, + "instanceGroupId": { + "value": "ff305d54-75b4-431b-adb2-eb6b9e5ff000", + "type": "String" + }, + "generateIdsOnly": { + "value": false, + "type": "Boolean" + } + } +} + + |