use of org.candlepin.common.exceptions.ExceptionMessage in project candlepin by candlepin.
the class ValidationExceptionMapper method toResponse.
@Override
public Response toResponse(ValidationException exception) {
Map<String, String> map = VersionUtil.getVersionMap();
ResponseBuilder bldr = Response.status(Status.BAD_REQUEST).type(determineBestMediaType()).header(VersionUtil.VERSION_HEADER, map.get("version") + "-" + map.get("release"));
StringBuffer message = new StringBuffer();
if (ConstraintViolationException.class.isAssignableFrom(exception.getClass())) {
for (ConstraintViolation cv : ((ConstraintViolationException) exception).getConstraintViolations()) {
message.append(cv.getPropertyPath().toString());
message.append(": ");
message.append(cv.getMessage());
}
bldr.entity(new ExceptionMessage(message.toString()));
} else {
getDefaultBuilder(exception, Response.Status.BAD_REQUEST, determineBestMediaType());
}
return bldr.build();
}
use of org.candlepin.common.exceptions.ExceptionMessage in project candlepin by candlepin.
the class RuntimeExceptionMapperTest method candlepinException.
@Test
public void candlepinException() {
CandlepinException ce = mock(CandlepinException.class);
when(ce.httpReturnCode()).thenReturn(Status.CONFLICT);
ExceptionMessage em = new ExceptionMessage().setDisplayMessage("you screwed up");
when(ce.message()).thenReturn(em);
when(req.getHeader(HttpHeaderNames.ACCEPT)).thenReturn("application/json");
assertEquals("you screwed up", em.toString());
Response r = rem.toResponse(ce);
assertNotNull(r);
assertEquals(Status.CONFLICT.getStatusCode(), r.getStatus());
verifyMessage(r, "you screwed up");
}
use of org.candlepin.common.exceptions.ExceptionMessage in project candlepin by candlepin.
the class RuntimeExceptionMapperTest method candlepinExceptionWithChildNotCandleping.
@Test
public void candlepinExceptionWithChildNotCandleping() {
CandlepinException ce = mock(CandlepinException.class);
when(ce.httpReturnCode()).thenReturn(Status.CONFLICT);
when(ce.message()).thenReturn(new ExceptionMessage().setDisplayMessage("you screwed up"));
when(req.getHeader(HttpHeaderNames.ACCEPT)).thenReturn("application/json");
when(ce.getCause()).thenReturn(new ConflictException("you screwed up"));
Response r = rem.toResponse(ce);
assertNotNull(r);
assertEquals(Status.CONFLICT.getStatusCode(), r.getStatus());
verifyMessage(r, "you screwed up");
}
use of org.candlepin.common.exceptions.ExceptionMessage in project candlepin by candlepin.
the class TestExceptionMapperBase method verifyMessage.
protected void verifyMessage(Response r, String expectedmsg) {
ExceptionMessage em = (ExceptionMessage) r.getEntity();
assertNotNull(em);
assertThat(em.getDisplayMessage(), matchesRegex(expectedmsg));
}
use of org.candlepin.common.exceptions.ExceptionMessage in project candlepin by candlepin.
the class JaxRsExceptionResponseBuilderTest method candlepinParserError.
@Test
public void candlepinParserError() {
CandlepinParameterParseException parseEx = new CandlepinParameterParseException("paramName", "thisFormat");
RuntimeException ex = new RuntimeException(parseEx);
Response resp = exceptionBuilder.getResponse(ex);
ExceptionMessage e = (ExceptionMessage) resp.getEntity();
assertTrue(exceptionBuilder.canHandle(ex));
assertTrue(e.getDisplayMessage().contains("paramName"));
assertTrue(e.getDisplayMessage().contains("thisFormat"));
}
Aggregations