use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class InterceptorTest method testConfiguredInterceptor.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test Interceptor settings
@Test
public void testConfiguredInterceptor() {
Map settings = basicSettings();
settings.put(org.hibernate.cfg.AvailableSettings.INTERCEPTOR, ExceptionInterceptor.class.getName());
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName("Laptop");
try {
em.getTransaction().begin();
em.persist(i);
em.getTransaction().commit();
fail("No interceptor");
} catch (IllegalStateException e) {
assertEquals(ExceptionInterceptor.EXCEPTION_MESSAGE, e.getMessage());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
emf.close();
}
}
use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class InterceptorTest method testDeprecatedConfiguredInterceptor.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test deprecated Interceptor settings
@Test
public void testDeprecatedConfiguredInterceptor() {
Map settings = basicSettings();
settings.put(AvailableSettings.INTERCEPTOR, ExceptionInterceptor.class.getName());
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName("Laptop");
try {
em.getTransaction().begin();
em.persist(i);
em.getTransaction().commit();
fail("No interceptor");
} catch (IllegalStateException e) {
assertEquals(ExceptionInterceptor.EXCEPTION_MESSAGE, e.getMessage());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
emf.close();
}
}
use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class PersisterClassProviderTest method testPersisterClassProvider.
@Test
@SuppressWarnings("unchecked")
public void testPersisterClassProvider() {
Map settings = SettingsGenerator.generateSettings(PersisterClassResolverInitiator.IMPL_NAME, GoofyPersisterClassProvider.class, AvailableSettings.LOADED_CLASSES, Arrays.asList(Bell.class));
try {
EntityManagerFactory entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
entityManagerFactory.close();
} catch (PersistenceException e) {
Assert.assertNotNull(e.getCause());
Assert.assertNotNull(e.getCause().getCause());
Assert.assertEquals(GoofyException.class, e.getCause().getCause().getClass());
}
}
use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class ColumnWithExplicitReferenceToPrimaryTableTest method testColumnAnnotationWithExplicitReferenceToPrimaryTable.
@Test
@TestForIssue(jiraKey = "HHH-8539")
public void testColumnAnnotationWithExplicitReferenceToPrimaryTable() {
final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {
@Override
public List<String> getManagedClassNames() {
return Arrays.asList(AnEntity.class.getName());
}
};
final Map settings = new HashMap();
settings.put(AvailableSettings.HBM2DDL_AUTO, "create-drop");
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(pu, settings).build();
emf.close();
}
use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class TransactionCommitFailureTest method testConfiguredInterceptor.
@Test
public void testConfiguredInterceptor() {
Map settings = basicSettings();
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
transactionFailureTrigger.set(true);
em.getTransaction().commit();
} catch (RollbackException e) {
assertEquals(COMMIT_FAILURE, e.getCause().getMessage());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
emf.close();
}
}
Aggregations