Search in sources :

Example 16 with ErrorResponse

use of io.crnk.core.engine.error.ErrorResponse in project crnk-framework by crnk-project.

the class CrnkExceptionMapperTest method badRequest.

@Test
public void badRequest() {
    CrnkExceptionMapper mapper = new CrnkExceptionMapper();
    ErrorResponse response = mapper.toErrorResponse(new BadRequestException("testMessage"));
    assertThat(response.getHttpStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400);
    assertThat(mapper.accepts(response)).isTrue();
    CrnkMappableException exception = mapper.fromErrorResponse(response);
    assertThat(exception).isInstanceOf(BadRequestException.class);
    assertThat(exception.getMessage()).isEqualTo("testMessage");
}
Also used : CrnkExceptionMapper(io.crnk.core.engine.internal.exception.CrnkExceptionMapper) ErrorResponse(io.crnk.core.engine.error.ErrorResponse) Test(org.junit.Test)

Example 17 with ErrorResponse

use of io.crnk.core.engine.error.ErrorResponse in project crnk-framework by crnk-project.

the class CrnkExceptionMapperTest method shouldMapToErrorResponse.

@Test
public void shouldMapToErrorResponse() throws Exception {
    CrnkExceptionMapper mapper = new CrnkExceptionMapper();
    ErrorResponse response = mapper.toErrorResponse(new SampleCrnkException());
    assertThat(response.getHttpStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
    assertThat((Iterable<?>) response.getResponse().getEntity()).hasSize(1).extracting("title", "detail").containsExactly(tuple(TITLE1, DETAIL1));
}
Also used : CrnkExceptionMapper(io.crnk.core.engine.internal.exception.CrnkExceptionMapper) ErrorResponse(io.crnk.core.engine.error.ErrorResponse) Test(org.junit.Test)

Example 18 with ErrorResponse

use of io.crnk.core.engine.error.ErrorResponse in project crnk-framework by crnk-project.

the class CrnkExceptionMapperTest method internalServerError.

@Test
public void internalServerError() {
    CrnkExceptionMapper mapper = new CrnkExceptionMapper();
    ErrorResponse response = mapper.toErrorResponse(new InternalServerErrorException("testMessage"));
    assertThat(response.getHttpStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
    assertThat(mapper.accepts(response)).isTrue();
    CrnkMappableException exception = mapper.fromErrorResponse(response);
    assertThat(exception).isInstanceOf(InternalServerErrorException.class);
    assertThat(exception.getMessage()).isEqualTo("testMessage");
}
Also used : CrnkExceptionMapper(io.crnk.core.engine.internal.exception.CrnkExceptionMapper) ErrorResponse(io.crnk.core.engine.error.ErrorResponse) Test(org.junit.Test)

Aggregations

ErrorResponse (io.crnk.core.engine.error.ErrorResponse)18 Test (org.junit.Test)15 ErrorData (io.crnk.core.engine.document.ErrorData)10 ExceptionMapperRegistry (io.crnk.core.engine.internal.exception.ExceptionMapperRegistry)7 CrnkExceptionMapper (io.crnk.core.engine.internal.exception.CrnkExceptionMapper)6 ExceptionMapper (io.crnk.core.engine.error.ExceptionMapper)5 JsonApiExceptionMapper (io.crnk.core.engine.error.JsonApiExceptionMapper)4 Optional (io.crnk.core.utils.Optional)4 BadRequestException (io.crnk.core.exception.BadRequestException)3 Document (io.crnk.core.engine.document.Document)2 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ClientException (io.crnk.client.ClientException)1 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)1 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)1 PreconditionUtil (io.crnk.core.engine.internal.utils.PreconditionUtil)1