use of io.crnk.jpa.internal.PersistenceRollbackExceptionMapper in project crnk-framework by crnk-project.
the class JpaExceptionMapperTests method testPersistenceRollbackException.
@Test
public void testPersistenceRollbackException() {
javax.persistence.RollbackException exception = new javax.persistence.RollbackException(new BadRequestException("test"));
ExceptionMapperRegistry exceptionMapperRegistry = boot.getExceptionMapperRegistry();
PersistenceRollbackExceptionMapper mapper = (PersistenceRollbackExceptionMapper) exceptionMapperRegistry.findMapperFor(javax.persistence.RollbackException.class).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());
}
use of io.crnk.jpa.internal.PersistenceRollbackExceptionMapper in project crnk-framework by crnk-project.
the class JpaModule method setupModule.
@Override
public void setupModule(ModuleContext context) {
this.context = context;
Set<Class> jpaTypes = new HashSet<>();
if (config != null) {
for (JpaRepositoryConfig<?> config : config.getRepositories()) {
jpaTypes.add(config.getEntityClass());
}
}
jpaMetaProvider = new JpaMetaProvider(jpaTypes);
jpaMetaLookup = new MetaLookup();
jpaMetaLookup.addProvider(jpaMetaProvider);
jpaMetaLookup.setModuleContext(context);
jpaMetaLookup.initialize();
if (config != null) {
initQueryFactory();
}
context.addResourceInformationBuilder(getResourceInformationProvider(context.getPropertiesProvider()));
context.addExceptionMapper(new OptimisticLockExceptionMapper());
context.addExceptionMapper(new PersistenceExceptionMapper(context));
context.addExceptionMapper(new PersistenceRollbackExceptionMapper(context));
addHibernateConstraintViolationExceptionMapper();
addTransactionRollbackExceptionMapper();
context.addRepositoryDecoratorFactory(new JpaRepositoryDecoratorFactory());
if (em != null) {
metaEnricher = new JpaMetaEnricher();
// enrich resource meta model with JPA information where incomplete
MetaModuleExtension metaModuleExtension = new MetaModuleExtension();
metaModuleExtension.addProvider(metaEnricher.getProvider());
context.addExtension(metaModuleExtension);
setupTransactionMgmt();
}
}
Aggregations