use of org.hibernate.jpa.test.PersistenceUnitInfoAdapter in project hibernate-orm by hibernate.
the class ConfigurationTest method buildMetadata.
@SuppressWarnings("unchecked")
private MetadataImplementor buildMetadata(SharedCacheMode mode) {
Map settings = new HashMap();
settings.put(AvailableSettings.SHARED_CACHE_MODE, mode);
settings.put(Environment.CACHE_REGION_FACTORY, CustomRegionFactory.class.getName());
settings.put(AvailableSettings.LOADED_CLASSES, Arrays.asList(ExplicitlyCacheableEntity.class, ExplicitlyNonCacheableEntity.class, NoCacheableAnnotationEntity.class));
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter();
final EntityManagerFactoryBuilderImpl emfb = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(adapter, settings);
emf = emfb.build();
return emfb.getMetadata();
}
use of org.hibernate.jpa.test.PersistenceUnitInfoAdapter in project hibernate-orm by hibernate.
the class ConfigurationObjectSettingTest method testContainerBootstrapValidationFactory.
@Test
public void testContainerBootstrapValidationFactory() {
final Object token = new Object();
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter();
try {
Bootstrap.getEntityManagerFactoryBuilder(adapter, Collections.singletonMap(AvailableSettings.VALIDATION_FACTORY, token));
fail("Was expecting error as token did not implement ValidatorFactory");
} catch (HibernateException e) {
// probably the condition we want but unfortunately the exception is not specific
// and the pertinent info is in a cause
}
}
use of org.hibernate.jpa.test.PersistenceUnitInfoAdapter in project hibernate-orm by hibernate.
the class ConfigurationObjectSettingTest method testContainerBootstrapValidationMode.
@Test
public void testContainerBootstrapValidationMode() {
// first, via the integration vars
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
{
// as object
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(empty, Collections.singletonMap(AvailableSettings.VALIDATION_MODE, ValidationMode.CALLBACK));
assertEquals(ValidationMode.CALLBACK, builder.getConfigurationValues().get(AvailableSettings.VALIDATION_MODE));
}
{
// as string
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(empty, Collections.singletonMap(AvailableSettings.VALIDATION_MODE, ValidationMode.CALLBACK.name()));
assertEquals(ValidationMode.CALLBACK.name(), builder.getConfigurationValues().get(AvailableSettings.VALIDATION_MODE));
}
// next, via the PUI
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter() {
@Override
public ValidationMode getValidationMode() {
return ValidationMode.CALLBACK;
}
};
{
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(adapter, null);
assertEquals(ValidationMode.CALLBACK, builder.getConfigurationValues().get(AvailableSettings.VALIDATION_MODE));
}
// via both, integration vars should take precedence
{
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(adapter, Collections.singletonMap(AvailableSettings.VALIDATION_MODE, ValidationMode.NONE));
assertEquals(ValidationMode.NONE, builder.getConfigurationValues().get(AvailableSettings.VALIDATION_MODE));
}
}
use of org.hibernate.jpa.test.PersistenceUnitInfoAdapter in project hibernate-orm by hibernate.
the class IdentifierGeneratorStrategyProviderTest method testIdentifierGeneratorStrategyProvider.
@Test
@SuppressWarnings("unchecked")
public void testIdentifierGeneratorStrategyProvider() {
Map settings = new HashMap();
settings.put(AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER, FunkyIdentifierGeneratorProvider.class.getName());
settings.put(AvailableSettings.LOADED_CLASSES, Collections.singletonList(Cable.class));
final EntityManagerFactory entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitInfoAdapter(), settings).build();
final EntityManager entityManager = entityManagerFactory.createEntityManager();
try {
entityManager.persist(new Cable());
entityManager.flush();
Assert.fail("FunkyException should have been thrown when the id is generated");
} catch (FunkyException e) {
entityManager.close();
entityManagerFactory.close();
}
}
use of org.hibernate.jpa.test.PersistenceUnitInfoAdapter in project hibernate-orm by hibernate.
the class SessionFactoryObserverTest method testSessionFactoryObserverProperty.
@Test
public void testSessionFactoryObserverProperty() {
EntityManagerFactoryBuilder builder = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitInfoAdapter(), Collections.singletonMap(AvailableSettings.SESSION_FACTORY_OBSERVER, GoofySessionFactoryObserver.class.getName()));
try {
final EntityManagerFactory entityManagerFactory = builder.build();
entityManagerFactory.close();
Assert.fail("GoofyException should have been thrown");
} catch (GoofyException e) {
// success
}
}
Aggregations