Search in sources :

Example 1 with PersistenceUnitInfoAdapter

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();
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PersistenceUnitInfoAdapter(org.hibernate.jpa.test.PersistenceUnitInfoAdapter)

Example 2 with PersistenceUnitInfoAdapter

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
    }
}
Also used : HibernateException(org.hibernate.HibernateException) PersistenceUnitInfoAdapter(org.hibernate.jpa.test.PersistenceUnitInfoAdapter) Test(org.junit.Test)

Example 3 with PersistenceUnitInfoAdapter

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));
    }
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) PersistenceUnitInfoAdapter(org.hibernate.jpa.test.PersistenceUnitInfoAdapter) Test(org.junit.Test)

Example 4 with PersistenceUnitInfoAdapter

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) HashMap(java.util.HashMap) EntityManagerFactory(javax.persistence.EntityManagerFactory) Map(java.util.Map) HashMap(java.util.HashMap) PersistenceUnitInfoAdapter(org.hibernate.jpa.test.PersistenceUnitInfoAdapter) Test(org.junit.Test)

Example 5 with PersistenceUnitInfoAdapter

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
    }
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder) PersistenceUnitInfoAdapter(org.hibernate.jpa.test.PersistenceUnitInfoAdapter) Test(org.junit.Test)

Aggregations

PersistenceUnitInfoAdapter (org.hibernate.jpa.test.PersistenceUnitInfoAdapter)6 Test (org.junit.Test)5 EntityManagerFactoryBuilderImpl (org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 EntityManager (javax.persistence.EntityManager)1 HibernateException (org.hibernate.HibernateException)1 EntityManagerFactoryBuilder (org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)1