Search in sources :

Example 1 with JsonProcessingExceptionMapper

use of org.graylog2.shared.rest.exceptionmappers.JsonProcessingExceptionMapper in project graylog2-server by Graylog2.

the class JsonProcessingExceptionMapperTest method testToResponse.

@Test
public void testToResponse() throws Exception {
    final ExceptionMapper<JsonProcessingException> mapper = new JsonProcessingExceptionMapper();
    final JsonParser jsonParser = new JsonFactory().createParser("");
    final JsonMappingException exception = new JsonMappingException(jsonParser, "Boom!", new RuntimeException("rootCause"));
    final Response response = mapper.toResponse(exception);
    assertEquals(response.getStatusInfo(), Response.Status.BAD_REQUEST);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
    assertTrue(response.hasEntity());
    assertTrue(response.getEntity() instanceof ApiError);
    final ApiError responseEntity = (ApiError) response.getEntity();
    assertTrue(responseEntity.getMessage().startsWith("Boom!"));
}
Also used : JsonProcessingExceptionMapper(org.graylog2.shared.rest.exceptionmappers.JsonProcessingExceptionMapper) Response(javax.ws.rs.core.Response) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ApiError(org.graylog2.plugin.rest.ApiError) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.junit.Test)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Response (javax.ws.rs.core.Response)1 ApiError (org.graylog2.plugin.rest.ApiError)1 JsonProcessingExceptionMapper (org.graylog2.shared.rest.exceptionmappers.JsonProcessingExceptionMapper)1 Test (org.junit.Test)1