private static Response.Status getStatus(UserException uex) { List<String> contextList = uex.getContextStrings(); for (String context : contextList) { if (context.startsWith(RESPONSE_STATUS)) { try { String status = context.substring(RESPONSE_STATUS.length() + 1); return Response.Status.valueOf(status); } catch (Exception e) { // should not happen unless someone is passing an invalid status. In that case, ignore the context } } } if (uex.getErrorType() == ErrorType.CONCURRENT_MODIFICATION) { return CONFLICT; } return BAD_REQUEST; }
/** * Allows test to set the Druid failure response. * * @param json inbound test */ public static void setFailure(String json) { @SuppressWarnings("unchecked") Map<String, String> failure = (Map<String, String>) new JsonSlurper().parseText(json); //extract only status code and description from expected response string statusCode = Status.valueOf(failure.get("status")); jsonResponse = failure.get("description"); }
/** * Allows test to set the Druid failure response. * * @param json inbound test */ public static void setFailure(String json) { @SuppressWarnings("unchecked") Map<String, String> failure = (Map<String, String>) new JsonSlurper().parseText(json); //extract only status code and description from expected response string statusCode = Status.valueOf(failure.get("status")); jsonResponse = failure.get("description"); }