Search in sources :

Example 1 with CrnkExceptionMapper

use of io.crnk.core.engine.internal.exception.CrnkExceptionMapper in project crnk-framework by crnk-project.

the class CrnkExceptionMapperTest method forbidden.

@Test
public void forbidden() {
    CrnkExceptionMapper mapper = new CrnkExceptionMapper();
    ErrorResponse response = mapper.toErrorResponse(new ForbiddenException("testMessage"));
    assertThat(response.getHttpStatus()).isEqualTo(HttpStatus.FORBIDDEN_403);
    assertThat(mapper.accepts(response)).isTrue();
    CrnkMappableException exception = mapper.fromErrorResponse(response);
    assertThat(exception).isInstanceOf(ForbiddenException.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 2 with CrnkExceptionMapper

use of io.crnk.core.engine.internal.exception.CrnkExceptionMapper in project crnk-framework by crnk-project.

the class CrnkExceptionMapperTest method invalidExceptionNotManagedByMapper.

@Test(expected = IllegalStateException.class)
public void invalidExceptionNotManagedByMapper() {
    CrnkExceptionMapper mapper = new CrnkExceptionMapper();
    mapper.fromErrorResponse(new ErrorResponse(null, 123));
}
Also used : CrnkExceptionMapper(io.crnk.core.engine.internal.exception.CrnkExceptionMapper) ErrorResponse(io.crnk.core.engine.error.ErrorResponse) Test(org.junit.Test)

Example 3 with CrnkExceptionMapper

use of io.crnk.core.engine.internal.exception.CrnkExceptionMapper in project crnk-framework by crnk-project.

the class CrnkExceptionMapperTest method notAuthorized.

@Test
public void notAuthorized() {
    CrnkExceptionMapper mapper = new CrnkExceptionMapper();
    ErrorResponse response = mapper.toErrorResponse(new UnauthorizedException("testMessage"));
    assertThat(response.getHttpStatus()).isEqualTo(HttpStatus.UNAUTHORIZED_401);
    assertThat(mapper.accepts(response)).isTrue();
    CrnkMappableException exception = mapper.fromErrorResponse(response);
    assertThat(exception).isInstanceOf(UnauthorizedException.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 4 with CrnkExceptionMapper

use of io.crnk.core.engine.internal.exception.CrnkExceptionMapper 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 5 with CrnkExceptionMapper

use of io.crnk.core.engine.internal.exception.CrnkExceptionMapper 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)

Aggregations

ErrorResponse (io.crnk.core.engine.error.ErrorResponse)6 CrnkExceptionMapper (io.crnk.core.engine.internal.exception.CrnkExceptionMapper)6 Test (org.junit.Test)6