hibernate support for jpa testing.
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 4 Apr 2010 14:28:51 +0000 (14:28 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 4 Apr 2010 14:28:51 +0000 (14:28 +0000)
trunk/support/test/hibernate/pom.xml [new file with mode: 0644]
trunk/support/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateJpaCustomizer.java [new file with mode: 0644]
trunk/support/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateTables.java [new file with mode: 0644]
trunk/support/test/hibernate/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer [moved from trunk/support/test/enterprise/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer with 51% similarity]
trunk/support/test/hibernate/src/test/java/org/wamblee/support/persistence/hibernate/DatabaseUtilsTest.java [new file with mode: 0644]
trunk/support/test/hibernate/src/test/java/org/wamblee/support/persistence/hibernate/MyEntityExampleTest.java [new file with mode: 0644]

diff --git a/trunk/support/test/hibernate/pom.xml b/trunk/support/test/hibernate/pom.xml
new file mode 100644 (file)
index 0000000..45457e1
--- /dev/null
@@ -0,0 +1,50 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <parent>
+    <groupId>org.wamblee</groupId>
+    <artifactId>wamblee-utils</artifactId>
+    <version>0.2-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.wamblee</groupId>
+  <artifactId>wamblee-support-test-hibernate</artifactId>
+  <packaging>jar</packaging>
+  <name>wamblee.org support general library</name>
+  <url>http://wamblee.org</url>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-support-test-enterprise</artifactId>
+      <version>0.2-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-support-test-enterprise</artifactId>
+      <version>0.2-SNAPSHOT</version>
+      <type>test-jar</type>
+    </dependency>
+
+    <dependency>
+      <groupId>org.dbunit</groupId>
+      <artifactId>dbunit</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.persistence</groupId>
+      <artifactId>persistence-api</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-hibernate-jpa</artifactId>
+      <version>0.2-SNAPSHOT</version>
+    </dependency>
+
+  </dependencies>
+
+</project>
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 (file)
index 0000000..fa4def8
--- /dev/null
@@ -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<String, String> 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 (file)
index 0000000..4b2c8a0
--- /dev/null
@@ -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<String> TABLES = Arrays.asList(new String[] { "" } );
+       
+       public boolean accept(String aTableName) throws DataSetException {
+               return TABLES.contains(aTableName);
+       }
+
+}
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 (file)
index 0000000..68edf22
--- /dev/null
@@ -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 (file)
index 0000000..537cb54
--- /dev/null
@@ -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
+}