@Test public void toResponseValidationErrors() { RollbackExceptionMapper mapper = new RollbackExceptionMapper(); ConstraintViolation<?> cv = mock(ConstraintViolation.class); Path pp = mock(Path.class); when(cv.getPropertyPath()).thenReturn(pp); Set<ConstraintViolation<?>> violations = new HashSet<ConstraintViolation<?>>(); violations.add(cv); ConstraintViolationException cve = new ConstraintViolationException(violations); RollbackException e = new RollbackException(cve); Response r = mapper.toResponse(e); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus()); assertNotNull(r.getEntity()); List<StandardError> errors = (List<StandardError>) r.getEntity(); assertEquals(1, errors.size()); }
@Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; }
RollbackExceptionMapper implements ExceptionMapper<RollbackException> { @Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; } }
RollbackExceptionMapper implements ExceptionMapper<RollbackException> { @Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; }  }
RollbackExceptionMapper implements ExceptionMapper<RollbackException> { @Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; }  @Override Response toResponse(RollbackException exception); }
RollbackExceptionMapper implements ExceptionMapper<RollbackException> { @Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; }  @Override Response toResponse(RollbackException exception);  }