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");
}
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));
}
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");
}
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");
}
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));
}
Aggregations