Search in sources :

Example 1 with TransactionRollbackExceptionMapper

use of io.crnk.jpa.internal.TransactionRollbackExceptionMapper in project crnk-framework by crnk-project.

the class JpaExceptionMapperTests method testTransactionRollbackException.

@Test
public void testTransactionRollbackException() {
    javax.transaction.RollbackException exception = new javax.transaction.RollbackException() {

        public Throwable getCause() {
            return new BadRequestException("test");
        }
    };
    ExceptionMapperRegistry exceptionMapperRegistry = boot.getExceptionMapperRegistry();
    TransactionRollbackExceptionMapper mapper = (TransactionRollbackExceptionMapper) exceptionMapperRegistry.findMapperFor(exception.getClass()).get();
    ErrorResponse response = mapper.toErrorResponse(exception);
    ErrorData errorData = response.getErrors().iterator().next();
    Assert.assertEquals(Integer.toString(HttpStatus.BAD_REQUEST_400), errorData.getStatus());
    Assert.assertEquals("test", errorData.getDetail());
}
Also used : TransactionRollbackExceptionMapper(io.crnk.jpa.internal.TransactionRollbackExceptionMapper) BadRequestException(io.crnk.core.exception.BadRequestException) ExceptionMapperRegistry(io.crnk.core.engine.internal.exception.ExceptionMapperRegistry) 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 ExceptionMapperRegistry (io.crnk.core.engine.internal.exception.ExceptionMapperRegistry)1 BadRequestException (io.crnk.core.exception.BadRequestException)1 TransactionRollbackExceptionMapper (io.crnk.jpa.internal.TransactionRollbackExceptionMapper)1 Test (org.junit.Test)1