Removed the table names from the persistence unit description.
authorErik Brakkee <erik@brakkee.org>
Mon, 5 Jul 2010 14:36:13 +0000 (14:36 +0000)
committerErik Brakkee <erik@brakkee.org>
Mon, 5 Jul 2010 14:36:13 +0000 (14:36 +0000)
The JPA providers no drop the tables themselves.
This is also more robust.
The databasetester should now be created through the dbutils instead of
through the JPA support.

security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/JpaUserAdministrationTest.java
security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/JpaUserSetTest.java
security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/SecurityPersistenceUnit.java
test/enterprise/src/main/java/org/wamblee/support/persistence/DatabaseUtils.java
test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java
test/enterprise/src/main/java/org/wamblee/support/persistence/PersistenceUnitDescription.java
test/enterprise/src/test/java/org/wamblee/support/persistence/DatabaseUtilsLeakTest.java
test/enterprise/src/test/java/org/wamblee/support/persistence/DatabaseUtilsTestBase.java
test/enterprise/src/test/java/org/wamblee/support/persistence/MyEntityExampleTestBase.java
test/enterprise/src/test/java/org/wamblee/support/persistence/MyPersistenceUnit.java

index c5bd6dbb3332d1f427bd4328151f609d1dbf91b8..2a0048e92037fa0d001da4546ec33f52d8f9b40f 100644 (file)
@@ -72,7 +72,7 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
 
         for (final Method method : methods) {
             if (method.getName().startsWith("test")) {
-                userAdminTester.getJpaTester().getDbUtils().cleanDatabase();
+                userAdminTester.getJpaTester().getDbUtils().cleanDatabase(new SecurityTables());
                 clearUserCache();
                 userAdminTester.getJpaTester().getDbUtils().executeInTransaction(
                     new JdbcUnitOfWork<Void>() {
index f55048d6f1397ce0d6ca1e02ef128b2b8844939f..e5430fb6bd9d066f31e67f77fe5906ee34143b22 100644 (file)
@@ -230,7 +230,7 @@ public class JpaUserSetTest extends InMemoryUserSetTest {
      * 
      */
     public void testVerifyAddRemove() throws Exception {
-        jpaTester.getDbUtils().cleanDatabase(); // super class setup always creates one group. 
+        jpaTester.getDbUtils().cleanDatabase(new SecurityTables()); // super class setup always creates one group. 
         
         GroupSet groups = getGroups();
         assertEquals(0, groups.size());
index ce82c9ecc49062c3a9b45a45b4efe5dbe8e3e91d..d41500ac0cbccf481ea61264ad01216857202bc2 100644 (file)
@@ -1,18 +1,10 @@
 package org.wamblee.security.authentication.jpa;
 
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.filter.ITableFilterSimple;
 import org.wamblee.support.persistence.PersistenceUnitDescription;
 
 public class SecurityPersistenceUnit extends PersistenceUnitDescription {
 
     public SecurityPersistenceUnit() { 
-        super("jdbc/security", "securitytest", new ITableFilterSimple() {
-            
-            @Override
-            public boolean accept(String aTableName) throws DataSetException {
-                return aTableName.startsWith("SEC_");
-            }
-        });
+        super("jdbc/security", "securitytest");
     }
 }
index 23938768223259fe70ae76d100388cad789cb0ad..b57cd46184e3c4293da6ca5e25c01f6aec8957cd 100644 (file)
@@ -65,7 +65,6 @@ public class DatabaseUtils {
      */
     private static final String SCHEMA_PATTERN = "%";
     private DataSource dataSource;
-    private ITableFilterSimple tables;
 
     private IDatabaseTester dbtester;
     /**
@@ -77,12 +76,10 @@ public class DatabaseUtils {
     /**
      * Constructs the database utils. 
      * Before use, {@link #start()} must be called. 
-     * @param aDataSource Datasource. 
-     * @param aTables Tables to work with. 
+     * @param aDataSource Datasource.  
      */
-    public DatabaseUtils(DataSource aDataSource, ITableFilterSimple aTables) {
+    public DatabaseUtils(DataSource aDataSource) {
         dataSource = aDataSource;
-        tables = aTables;
         dbtester = new DataSourceDatabaseTester(dataSource);
         connections = new ArrayList<IDatabaseConnection>(); 
     }
@@ -111,8 +108,8 @@ public class DatabaseUtils {
         connections.clear();
     }
 
-    public IDatabaseTester createDbTester() throws Exception {
-        return createDbTester(getTableNames(tables));
+    public IDatabaseTester createDbTester(ITableFilterSimple aTables) throws Exception {
+        return createDbTester(getTableNames(aTables));
     }
 
     public IDatabaseTester createDbTester(String[] aTables) throws Exception {
@@ -122,10 +119,6 @@ public class DatabaseUtils {
         return dbtester;
     }
 
-    public void cleanDatabase() throws Exception {
-        cleanDatabase(tables);
-    }
-
     public void executeOnTables(ITableFilterSimple aTables,
         final TableSetOperation aOperation) throws Exception {
         final String[] tableNames = getTableNames(aTables);
@@ -170,11 +163,7 @@ public class DatabaseUtils {
             connection.close();
         }
     }
-
-    public String[] getTableNames() throws Exception {
-        return getTableNames(tables);
-    }
-
+    
     /**
      * @throws SQLException
      */
@@ -201,14 +190,6 @@ public class DatabaseUtils {
         }
     }
 
-    public void emptyTables() throws Exception {
-        executeOnTables(tables, new TableSetOperation() {
-            public void execute(String aTable) throws Exception {
-                emptyTable(aTable);
-            }
-        });
-    }
-
     /**
      * @return
      * @throws SQLException
@@ -230,10 +211,6 @@ public class DatabaseUtils {
         executeSql("delete from " + aTable);
     }
 
-    public void dropTables() throws Exception {
-        dropTables(tables);
-    }
-
     public void dropTables(ITableFilterSimple aTables) throws Exception {
         final String[] tableNames = getTableNames(aTables);
         String[] sortedTables = executeInTransaction(new JdbcUnitOfWork<String[]>() {
index 19f7f187d5838f5ef1272db9d67d8934d3a1bb48..e74003f126276fc162cfd0085639c873724111cc 100644 (file)
@@ -94,18 +94,12 @@ public class JpaTester {
             throw new RuntimeException("JNDI problem", e);
         }
 
-        dbUtils = new DatabaseUtils(dataSource, persistenceUnit.getTables());
+        dbUtils = new DatabaseUtils(dataSource);
         dbUtils.start();
-        dbUtils.dropTables();
         dbUtils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables());
 
         jpaBuilder = new JpaBuilder(db.getJdbcUrl(), db.getUsername(), db.getPassword(), persistenceUnit);
         jpaBuilder.start();
-
-        // db tester should be created after Jpa builder because jpa builder
-        // creates the
-        // tables that the tester looks at when it is initialized.
-        dbTester = dbUtils.createDbTester();
     }
 
     /**
@@ -131,10 +125,6 @@ public class JpaTester {
         return dataSource;
     }
 
-    public IDatabaseTester getDbTester() {
-        return dbTester;
-    }
-
     public DatabaseUtils getDbUtils() {
         return dbUtils;
     }
index 4cd06d049a6d49a4e3f4e6c2ba4e98249f3506de..c97667b678642cbe6e2f6b73dcc561a07f2f6c0c 100644 (file)
@@ -15,7 +15,6 @@
  */ 
 package org.wamblee.support.persistence;
 
-import org.dbunit.dataset.filter.ITableFilterSimple;
 
 /**
  * Describes a persistence unit. 
@@ -26,19 +25,15 @@ public class PersistenceUnitDescription {
 
     private String jndiName;
     private String unitName;
-    private ITableFilterSimple tables;
 
     /**
      * Constructs the description. 
      * @param aJndiName Jndi name. 
      * @param aUnitName Persistence unit name. 
-     * @param aTables Tables to delete.
      */
-    public PersistenceUnitDescription(String aJndiName, String aUnitName,
-        ITableFilterSimple aTables) {
+    public PersistenceUnitDescription(String aJndiName, String aUnitName) {
         jndiName = aJndiName;
         unitName = aUnitName;
-        tables = aTables;
     }
 
     /**
@@ -54,12 +49,4 @@ public class PersistenceUnitDescription {
     public String getUnitName() {
         return unitName;
     }
-
-    /**
-     * Tables to delete. 
-     * @return Tables. 
-     */
-    public ITableFilterSimple getTables() {
-        return tables;
-    }
 }
index 75cabee6da1e6ecd82a9456c36b5c4f0761c98bf..b7770b0a53ff6d6ecaa4578fc8d5e3cbc8874432 100644 (file)
@@ -1,15 +1,13 @@
 package org.wamblee.support.persistence;
 
+import static junit.framework.Assert.*;
+
 import javax.sql.DataSource;
 
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.filter.ITableFilterSimple;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import static junit.framework.TestCase.*;
-
 public class DatabaseUtilsLeakTest {
 
     private Database db;
@@ -20,12 +18,7 @@ public class DatabaseUtilsLeakTest {
         db = DatabaseBuilder.getDatabase();
         DataSource ds = db.start(); 
         
-        dbutils = new DatabaseUtils(ds, new ITableFilterSimple() {
-            @Override
-            public boolean accept(String aTableName) throws DataSetException {
-                return false; 
-            }
-        });
+        dbutils = new DatabaseUtils(ds);
     }
     
     @After
@@ -36,7 +29,7 @@ public class DatabaseUtilsLeakTest {
     @Test
     public void testLeak() throws Exception {
         assertEquals(0, db.getActiveConnections()); 
-        dbutils.dropTables();
+        dbutils.dropTables(new MyTables());
         assertEquals(0, db.getActiveConnections());
     }
     
index 1092149ec7f7ef265806bc27001ca613d530d1be..7974529753c03f6c1e32685150c839004a701053 100644 (file)
@@ -47,15 +47,15 @@ public class DatabaseUtilsTestBase {
 
         persistenceUnit = new MyPersistenceUnit();
 
-        dbutils = new DatabaseUtils(dataSource, persistenceUnit.getTables());
-        dbutils.dropTables();
+        dbutils = new DatabaseUtils(dataSource);
+        dbutils.dropTables(new MyTables());
         dbutils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables());
 
         builder = new JpaBuilder(db.getJdbcUrl(), db.getUsername(), db.getPassword(), persistenceUnit);
         builder.start();
 
         assertEquals(0, db.getActiveConnections());
-        dbtester = dbutils.createDbTester();
+        dbtester = dbutils.createDbTester(new MyTables());
     }
 
     @After
@@ -69,14 +69,14 @@ public class DatabaseUtilsTestBase {
 
     @Test
     public void testTablesCorrect() throws Exception {
-        String[] tables = dbutils.getTableNames();
+        String[] tables = dbutils.getTableNames(new MyTables());
         assertEquals(1, tables.length);
         assertEquals("XYZ_MYENTITY", tables[0]);
     }
 
     @Test
     public void testDeleteTables() throws Exception {
-        String[] tables = dbutils.getTableNames();
+        String[] tables = dbutils.getTableNames(new MyTables());
         assertEquals(1, tables.length);
         assertEquals("XYZ_MYENTITY", tables[0]);
 
@@ -94,14 +94,14 @@ public class DatabaseUtilsTestBase {
         assertEquals(1, table.getRowCount());
 
         // Clean the database
-        dbutils.cleanDatabase();
+        dbutils.cleanDatabase(new MyTables());
         table = dbtester.getDataSet().getTable("XYZ_MYENTITY");
         assertEquals(0, table.getRowCount());
 
         // Now drop the database
-        dbutils.dropTables();
+        dbutils.dropTables(new MyTables());
         dbutils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables());
-        tables = dbutils.getTableNames();
+        tables = dbutils.getTableNames(new MyTables());
         assertEquals(0, tables.length);
     }
 
index f6da97e80a108f55089240054a89ede85cdf4f18..c3771775363558a507f74f3a4f318946e332e615 100644 (file)
@@ -61,7 +61,7 @@ public class MyEntityExampleTestBase {
         // but we don't need it. We can use datbase utils if we want to execute
         // straight JDBC calls.
         builder = jpaTester.getJpaBuilder();
-        dbtester = jpaTester.getDbTester();
+        dbtester = jpaTester.getDbUtils().createDbTester(new MyTables());
         dbutils = jpaTester.getDbUtils();
         dbutils.start();
     }
index 7a09d245a0feb29b2fb77c2942bc1b30dc87c5c4..5b1b278b20788afc33498dbad98426db80b1a130 100644 (file)
@@ -25,6 +25,6 @@ public class MyPersistenceUnit extends PersistenceUnitDescription {
     private static final String PERSISTENCE_UNIT_NAME = "org.wamblee.jee.support-test";
 
     public MyPersistenceUnit() {
-        super(JNDI_NAME, PERSISTENCE_UNIT_NAME, new MyTables());
+        super(JNDI_NAME, PERSISTENCE_UNIT_NAME);
     }
 }