From ba40eeb0df65eba18fa150c8736f6cc084508d4b Mon Sep 17 00:00:00 2001 From: "Plummer, Brittany" Date: Wed, 20 Nov 2019 20:56:44 -0500 Subject: vnf and vf module replace requests to make Added cloudConfiguration when not sent in replace request Added robot test for vfModule request with no cloud config Started adding unit tests for ServiceInstances Added unit tests for BpmnRequestBuilder changes Added ServiceInstances tests to test replace without CloudConfig Removed unused wiremock stubbings from test Added check for replaceInstanceRetainAssignments action Added action to common package to fix failing robot tests Removed new test, updated existing vfModule replace Added jackson annotations to RequestError object Fixed failing unit tests apih common Issue-ID: SO-2523 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I9470a0a9c7e356ef98ceb7269e066e79e0afb074 --- .../java/org/onap/so/apihandlerinfra/Action.java | 1 + .../exceptions/ApiExceptionMapper.java | 61 ++++------------------ 2 files changed, 12 insertions(+), 50 deletions(-) (limited to 'mso-api-handlers/mso-api-handler-common/src/main/java/org') 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..0653513184 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, 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 6a56b58f04..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 @@ -71,72 +71,33 @@ public class ApiExceptionMapper implements ExceptionMapper { @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 variables = exception.getVariables(); - ErrorLoggerInfo errorLoggerInfo = exception.getErrorLoggerInfo(); - - if (errorText.length() > 1999) { errorText = errorText.substring(0, 1999); } - - - - List typeList = Optional.ofNullable(headers.getAcceptableMediaTypes()).orElse(new ArrayList<>()); - List 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 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 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) { -- cgit 1.2.3-korg