@Test public void testIdentityExceptionMappings() { CougarFault fault = new Fault(FaultCode.Client, "DSC-0033"); ResponseCode responseCode = ResponseCodeMapper.getResponseCodeFromHttpCode(HttpServletResponse.SC_BAD_REQUEST, fault); assertEquals(ResponseCode.BadRequest, responseCode); fault = new Fault(FaultCode.Client, "DSC-0034"); responseCode = ResponseCodeMapper.getResponseCodeFromHttpCode(HttpServletResponse.SC_BAD_REQUEST, fault); assertEquals(ResponseCode.BadRequest, responseCode); fault = new Fault(FaultCode.Client, "DSC-0035"); responseCode = ResponseCodeMapper.getResponseCodeFromHttpCode(HttpServletResponse.SC_BAD_REQUEST, fault); assertEquals(ResponseCode.BadRequest, responseCode); fault = new Fault(FaultCode.Client, "DSC-0036"); responseCode = ResponseCodeMapper.getResponseCodeFromHttpCode(HttpServletResponse.SC_BAD_REQUEST, fault); assertEquals(ResponseCode.BadRequest, responseCode); fault = new Fault(FaultCode.Client, "DSC-0037"); responseCode = ResponseCodeMapper.getResponseCodeFromHttpCode(HttpServletResponse.SC_FORBIDDEN, fault); assertEquals(ResponseCode.Forbidden, responseCode); fault = new Fault(FaultCode.Client, "DSC-0038"); responseCode = ResponseCodeMapper.getResponseCodeFromHttpCode(HttpServletResponse.SC_FORBIDDEN, fault); assertEquals(ResponseCode.Forbidden, responseCode); fault = new Fault(FaultCode.Client, "DSC-0039"); responseCode = ResponseCodeMapper.getResponseCodeFromHttpCode(HttpServletResponse.SC_BAD_REQUEST, fault); assertEquals(ResponseCode.BadRequest, responseCode); fault = new Fault(FaultCode.Client, "DSC-0040"); responseCode = ResponseCodeMapper.getResponseCodeFromHttpCode(HttpServletResponse.SC_FORBIDDEN, fault); assertEquals(ResponseCode.Forbidden, responseCode); }
public static ResponseCode getResponseCodeFromHttpCode(int httpResponseStatus, CougarFault fault) { if(httpResponseStatus == HttpServletResponse.SC_INTERNAL_SERVER_ERROR){ if(fault.getErrorCode().startsWith(COUGAR_FAULT_PREFIX)){ return ResponseCode.InternalError; } else{ return ResponseCode.BusinessException; } } for (Map.Entry<ResponseCode, Integer> entry : RESPONSE_CODES.entrySet()) { if (entry.getValue() == httpResponseStatus) { return entry.getKey(); } } return ResponseCode.InternalError; }
ResponseCodeMapper { public static ResponseCode getResponseCodeFromHttpCode(int httpResponseStatus, CougarFault fault) { if(httpResponseStatus == HttpServletResponse.SC_INTERNAL_SERVER_ERROR){ if(fault.getErrorCode().startsWith(COUGAR_FAULT_PREFIX)){ return ResponseCode.InternalError; } else{ return ResponseCode.BusinessException; } } for (Map.Entry<ResponseCode, Integer> entry : RESPONSE_CODES.entrySet()) { if (entry.getValue() == httpResponseStatus) { return entry.getKey(); } } return ResponseCode.InternalError; } }
ResponseCodeMapper { public static ResponseCode getResponseCodeFromHttpCode(int httpResponseStatus, CougarFault fault) { if(httpResponseStatus == HttpServletResponse.SC_INTERNAL_SERVER_ERROR){ if(fault.getErrorCode().startsWith(COUGAR_FAULT_PREFIX)){ return ResponseCode.InternalError; } else{ return ResponseCode.BusinessException; } } for (Map.Entry<ResponseCode, Integer> entry : RESPONSE_CODES.entrySet()) { if (entry.getValue() == httpResponseStatus) { return entry.getKey(); } } return ResponseCode.InternalError; }  }
ResponseCodeMapper { public static ResponseCode getResponseCodeFromHttpCode(int httpResponseStatus, CougarFault fault) { if(httpResponseStatus == HttpServletResponse.SC_INTERNAL_SERVER_ERROR){ if(fault.getErrorCode().startsWith(COUGAR_FAULT_PREFIX)){ return ResponseCode.InternalError; } else{ return ResponseCode.BusinessException; } } for (Map.Entry<ResponseCode, Integer> entry : RESPONSE_CODES.entrySet()) { if (entry.getValue() == httpResponseStatus) { return entry.getKey(); } } return ResponseCode.InternalError; }  static void setResponseStatus(HttpServletResponse response, ResponseCode code); static int getHttpResponseCode(ResponseCode code); static ResponseCode getResponseCodeFromHttpCode(int httpResponseStatus, CougarFault fault); }
ResponseCodeMapper { public static ResponseCode getResponseCodeFromHttpCode(int httpResponseStatus, CougarFault fault) { if(httpResponseStatus == HttpServletResponse.SC_INTERNAL_SERVER_ERROR){ if(fault.getErrorCode().startsWith(COUGAR_FAULT_PREFIX)){ return ResponseCode.InternalError; } else{ return ResponseCode.BusinessException; } } for (Map.Entry<ResponseCode, Integer> entry : RESPONSE_CODES.entrySet()) { if (entry.getValue() == httpResponseStatus) { return entry.getKey(); } } return ResponseCode.InternalError; }  static void setResponseStatus(HttpServletResponse response, ResponseCode code); static int getHttpResponseCode(ResponseCode code); static ResponseCode getResponseCodeFromHttpCode(int httpResponseStatus, CougarFault fault);  }