Search in sources :

Example 1 with WebApplicationExceptionMapper

use of io.crnk.rs.internal.WebApplicationExceptionMapper in project crnk-framework by crnk-project.

the class WebApplicationExceptionMapperTest method test.

@Test
public void test() {
    WebApplicationExceptionMapper mapper = new WebApplicationExceptionMapper();
    WebApplicationException exception = new WebApplicationException("hi");
    ErrorResponse response = mapper.toErrorResponse(exception);
    Iterable<ErrorData> errors = response.getErrors();
    Iterator<ErrorData> iterator = errors.iterator();
    ErrorData data = iterator.next();
    Assert.assertFalse(iterator.hasNext());
    Assert.assertEquals("500", data.getStatus());
    Assert.assertEquals("hi", data.getCode());
    Assert.assertTrue(mapper.accepts(response));
    WebApplicationException fromErrorResponse = mapper.fromErrorResponse(response);
    Assert.assertEquals("hi", fromErrorResponse.getMessage());
}
Also used : WebApplicationExceptionMapper(io.crnk.rs.internal.WebApplicationExceptionMapper) WebApplicationException(javax.ws.rs.WebApplicationException) ErrorData(io.crnk.core.engine.document.ErrorData) ErrorResponse(io.crnk.core.engine.error.ErrorResponse) Test(org.junit.Test)

Aggregations

ErrorData (io.crnk.core.engine.document.ErrorData)1 ErrorResponse (io.crnk.core.engine.error.ErrorResponse)1 WebApplicationExceptionMapper (io.crnk.rs.internal.WebApplicationExceptionMapper)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Test (org.junit.Test)1