Search in sources :

Example 1 with CollectionFactory

use of org.apache.tapestry5.commons.util.CollectionFactory in project tapestry-5 by apache.

the class EntityManagerSourceImplTest method multiple_persistence_units_include_unlisted_classes.

@Test
public void multiple_persistence_units_include_unlisted_classes() {
    Exception exception = null;
    try {
        new EntityManagerSourceImpl(LoggerFactory.getLogger(EntityManagerSourceImplTest.class), new ClasspathResource("multiple-persistence-units-include-unlisted-classes.xml"), null, CollectionFactory.<String, PersistenceUnitConfigurer>newMap());
        fail("Exception expected");
    } catch (Exception e) {
        exception = e;
    }
    assertNotNull(exception);
    assertEquals(exception.getMessage(), "Persistence units 'TestUnit, TestUnit2' are configured to include managed classes that have not been explicitly listed. This is forbidden when multiple persistence units are used in the same application. Please configure persistence units to exclude unlisted managed classes (e.g. by removing <exclude-unlisted-classes> element) and include them explicitly.");
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Test(org.testng.annotations.Test)

Example 2 with CollectionFactory

use of org.apache.tapestry5.commons.util.CollectionFactory in project tapestry-5 by apache.

the class EntityManagerSourceImplTest method create.

private EntityManagerSourceImpl create(final String persistenceUnitFile) {
    PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() {

        @Override
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public void configure(TapestryPersistenceUnitInfo unitInfo) {
            Map properties = new HashMap();
            properties.put("MYKEY", "MYVALUE");
            unitInfo.transactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL).persistenceProviderClassName("org.eclipse.persistence.jpa.PersistenceProvider").excludeUnlistedClasses(true).addProperty("javax.persistence.jdbc.user", "sa").addProperty("javax.persistence.jdbc.driver", "org.h2.Driver").addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:test").setEntityManagerProperties(properties);
        }
    };
    Map<String, PersistenceUnitConfigurer> configurerMap = CollectionFactory.<String, PersistenceUnitConfigurer>newMap();
    configurerMap.put("defaultpropertytest", configurer);
    EntityManagerSourceImpl emSource = new EntityManagerSourceImpl(LoggerFactory.getLogger(EntityManagerSourceImplTest.class), new ClasspathResource(persistenceUnitFile), null, configurerMap);
    return emSource;
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) HashMap(java.util.HashMap) PersistenceUnitConfigurer(org.apache.tapestry5.jpa.PersistenceUnitConfigurer) Map(java.util.Map) HashMap(java.util.HashMap) TapestryPersistenceUnitInfo(org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo)

Aggregations

ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PersistenceUnitConfigurer (org.apache.tapestry5.jpa.PersistenceUnitConfigurer)1 TapestryPersistenceUnitInfo (org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo)1 Test (org.testng.annotations.Test)1