From: erik Date: Sun, 4 Apr 2010 14:28:51 +0000 (+0000) Subject: hibernate support for jpa testing. X-Git-Tag: wamblee-utils-0.2@603~31 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=9b2fcad10bb4b09c928ace3779dd9f87fc1eb91c;p=utils hibernate support for jpa testing. --- diff --git a/trunk/support/test/hibernate/pom.xml b/trunk/support/test/hibernate/pom.xml new file mode 100644 index 00000000..45457e1b --- /dev/null +++ b/trunk/support/test/hibernate/pom.xml @@ -0,0 +1,50 @@ + + + + org.wamblee + wamblee-utils + 0.2-SNAPSHOT + + + 4.0.0 + org.wamblee + wamblee-support-test-hibernate + jar + wamblee.org support general library + http://wamblee.org + + + + org.wamblee + wamblee-support-test-enterprise + 0.2-SNAPSHOT + + + + org.wamblee + wamblee-support-test-enterprise + 0.2-SNAPSHOT + test-jar + + + + org.dbunit + dbunit + + + + javax.persistence + persistence-api + + + + org.wamblee + wamblee-hibernate-jpa + 0.2-SNAPSHOT + + + + + diff --git a/trunk/support/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateJpaCustomizer.java b/trunk/support/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateJpaCustomizer.java new file mode 100644 index 00000000..fa4def8f --- /dev/null +++ b/trunk/support/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateJpaCustomizer.java @@ -0,0 +1,31 @@ +package org.wamblee.support.persistence.hibernate; + +import java.util.Map; + +import org.dbunit.dataset.filter.ITableFilterSimple; +import org.wamblee.support.persistence.JpaCustomizer; +import org.wamblee.support.persistence.PersistenceUnitDescription; + +public class HibernateJpaCustomizer implements JpaCustomizer { + + public HibernateJpaCustomizer() { + // Empty + } + + @Override + public void customize(PersistenceUnitDescription aPersistenceUnit, Map aJpaProperties) { + // Hibernate: Override transaction type and datasource + aJpaProperties.put("javax.persistence.transactionType", "RESOURCE_LOCAL"); + aJpaProperties.put("javax.persistence.jtaDataSource", null); + aJpaProperties.put("javax.persistence.nonJtaDataSource", aPersistenceUnit.getJndiName()); + + // Hibernate schema generation + aJpaProperties.put("hibernate.hbm2ddl.auto", "create"); + } + + @Override + public ITableFilterSimple getJpaTables() { + return new HibernateTables(); + } + +} diff --git a/trunk/support/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateTables.java b/trunk/support/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateTables.java new file mode 100644 index 00000000..4b2c8a09 --- /dev/null +++ b/trunk/support/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateTables.java @@ -0,0 +1,20 @@ +package org.wamblee.support.persistence.hibernate; + +import java.util.Arrays; +import java.util.List; + +import org.dbunit.dataset.DataSetException; +import org.dbunit.dataset.filter.ITableFilterSimple; + +/** + * Toplink-specific tables. + */ +public class HibernateTables implements ITableFilterSimple { + + private static final List TABLES = Arrays.asList(new String[] { "" } ); + + public boolean accept(String aTableName) throws DataSetException { + return TABLES.contains(aTableName); + } + +} diff --git a/trunk/support/test/enterprise/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer b/trunk/support/test/hibernate/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer similarity index 51% rename from trunk/support/test/enterprise/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer rename to trunk/support/test/hibernate/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer index adb67544..d057634d 100644 --- a/trunk/support/test/enterprise/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer +++ b/trunk/support/test/hibernate/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer @@ -1,2 +1 @@ -org.wamblee.support.persistence.toplink.ToplinkJpaCustomizer org.wamblee.support.persistence.hibernate.HibernateJpaCustomizer diff --git a/trunk/support/test/hibernate/src/test/java/org/wamblee/support/persistence/hibernate/DatabaseUtilsTest.java b/trunk/support/test/hibernate/src/test/java/org/wamblee/support/persistence/hibernate/DatabaseUtilsTest.java new file mode 100644 index 00000000..68edf22a --- /dev/null +++ b/trunk/support/test/hibernate/src/test/java/org/wamblee/support/persistence/hibernate/DatabaseUtilsTest.java @@ -0,0 +1,23 @@ +package org.wamblee.support.persistence.hibernate; + +import static junit.framework.Assert.assertEquals; + +import javax.persistence.EntityManager; +import javax.sql.DataSource; + +import org.dbunit.IDatabaseTester; +import org.dbunit.dataset.ITable; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.wamblee.support.persistence.Database; +import org.wamblee.support.persistence.DatabaseBuilder; +import org.wamblee.support.persistence.DatabaseUtils; +import org.wamblee.support.persistence.DatabaseUtilsTestBase; +import org.wamblee.support.persistence.JpaBuilder; +import org.wamblee.support.persistence.PersistenceUnitDescription; +import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork; + +public class DatabaseUtilsTest extends DatabaseUtilsTestBase { + // Empty, all tests inherited +} diff --git a/trunk/support/test/hibernate/src/test/java/org/wamblee/support/persistence/hibernate/MyEntityExampleTest.java b/trunk/support/test/hibernate/src/test/java/org/wamblee/support/persistence/hibernate/MyEntityExampleTest.java new file mode 100644 index 00000000..537cb549 --- /dev/null +++ b/trunk/support/test/hibernate/src/test/java/org/wamblee/support/persistence/hibernate/MyEntityExampleTest.java @@ -0,0 +1,29 @@ +package org.wamblee.support.persistence.hibernate; + +import javax.persistence.EntityManager; +import javax.persistence.Persistence; +import javax.sql.DataSource; + +import org.dbunit.DataSourceDatabaseTester; +import org.dbunit.DatabaseTestCase; +import org.dbunit.IDatabaseTester; +import org.dbunit.dataset.ITable; +import org.dbunit.dataset.filter.ITableFilterSimple; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.wamblee.support.persistence.DatabaseUtils; +import org.wamblee.support.persistence.JpaBuilder; +import org.wamblee.support.persistence.JpaTester; +import org.wamblee.support.persistence.MyEntityExampleTestBase; +import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork; + +import static junit.framework.Assert.*; + + +/** + * This class shows an example of how to test an entity using jpa. + */ +public class MyEntityExampleTest extends MyEntityExampleTestBase { + // Empty, all tests are inherited +}