openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r524228 [1/2] - in /incubator/openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/pe...
Date Fri, 30 Mar 2007 18:45:17 GMT
Author: awhite
Date: Fri Mar 30 11:45:15 2007
New Revision: 524228

URL: http://svn.apache.org/viewvc?view=rev&rev=524228
Log:
Bring some consistency to test case structure.  Now all persistent test cases
extend SingleEMFTestCase or SingleEMTestCase as appropriate.  These base test
cases contain utilties for initializing the EMF on setup and deleting any
inserted database records and closing the EMF on teardown.


Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java   (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java   (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java
      - copied, changed from r523359, incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMTest.java
Removed:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTest.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMTest.java
Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestExceptionsFromCallbacks.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestArrayFieldsInDataCache.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestAttachWithNoChanges.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachmentOneMany.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestGetReferenceAndImplicitDetachment.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestGenerationType.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLDateId.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/CompanyModelTest.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryIdOfRelationDoesNotJoin.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestCascadingOneManyWithForeignKey.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestManyOneAsId.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMultipleSameTypedEmbeddedWithEagerRelations.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMethodsThrowAfterClose.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java Fri Mar 30 11:45:15 2007
@@ -577,7 +577,8 @@
     /**
      * Returns the alias for the described type, or <code>null</code> if none
      * has been set.
-     *  #see	setTypeAlias
+     * 
+     * @see #setTypeAlias
      */
     public String getTypeAlias() {
         if (_alias == null)

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestExceptionsFromCallbacks.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestExceptionsFromCallbacks.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestExceptionsFromCallbacks.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestExceptionsFromCallbacks.java Fri Mar 30 11:45:15 2007
@@ -7,47 +7,20 @@
 import javax.persistence.Persistence;
 import javax.persistence.RollbackException;
 
+import junit.framework.TestCase;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.apache.openjpa.persistence.callbacks.ExceptionsFromCallbacksEntity.CallbackTestException;
-
-import junit.framework.TestCase;
-
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Tests against JPA section 3.5's description of callback exception handling.
  */
 public class TestExceptionsFromCallbacks
-    extends TestCase {
-
-    private OpenJPAEntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        String types = ExceptionsFromCallbacksEntity.class.getName();
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        emf = (OpenJPAEntityManagerFactory) Persistence.
-            createEntityManagerFactory("test", props);
-        deleteAll();
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            deleteAll();
-            emf.close();
-        } catch (Exception e) {
-        }
-    }
-    
-    private void deleteAll() {
-        EntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        em.createQuery("delete from ExceptionsFromCallbacksEntity").
-            executeUpdate();
-        em.getTransaction().commit();
-        em.close();
+        setUp(ExceptionsFromCallbacksEntity.class);
     }
 
     public void testPrePersistException() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestArrayFieldsInDataCache.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestArrayFieldsInDataCache.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestArrayFieldsInDataCache.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestArrayFieldsInDataCache.java Fri Mar 30 11:45:15 2007
@@ -4,15 +4,15 @@
 import java.util.Arrays;
 import javax.persistence.EntityManager;
 
-import org.apache.openjpa.persistence.test.SingleEMTest;
-import org.apache.openjpa.persistence.simple.AllFieldTypes;
-import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.apache.openjpa.datacache.DataCache;
 import org.apache.openjpa.kernel.PCData;
 import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.simple.AllFieldTypes;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 public class TestArrayFieldsInDataCache
-    extends SingleEMTest {
+    extends SingleEMFTestCase {
 
     private static final String[] STRINGS = new String[]{ "a", "b", "c" };
     private static final int[] INTS = new int[]{ 1, 2, 3 };
@@ -20,25 +20,10 @@
     private Object jpaOid;
     private Object internalOid;
 
-    public TestArrayFieldsInDataCache() {
-        super(AllFieldTypes.class);
-    }
-
-    @Override
-    protected void setEMFProps(Map props) {
-        super.setEMFProps(props);
-        props.put("openjpa.DataCache", "true");
-        props.put("openjpa.RemoteCommitProvider", "sjvm");
-    }
-
-    @Override
-    protected boolean clearDatabaseInSetUp() {
-        return true;
-    }
-
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
+    public void setUp() {
+        setUp("openjpa.DataCache", "true", 
+            "openjpa.RemoteCommitProvider", "sjvm", 
+            AllFieldTypes.class);
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -70,7 +55,7 @@
             cachedFieldData.getClass().getComponentType());
 
         // make sure that the returned results are correct
-        em = emf.createEntityManager();
+        EntityManager em = emf.createEntityManager();
         AllFieldTypes aft = em.find(AllFieldTypes.class, jpaOid);
         assertTrue(Arrays.equals(STRINGS, aft.getArrayOfStrings()));
         assertNotSame(STRINGS, aft.getArrayOfStrings());
@@ -90,10 +75,10 @@
         assertEquals(int.class, cachedFieldData.getClass().getComponentType());
 
         // make sure that the returned results are correct
-        em = emf.createEntityManager();
+        EntityManager em = emf.createEntityManager();
         AllFieldTypes aft = em.find(AllFieldTypes.class, jpaOid);
         assertTrue(Arrays.equals(INTS, aft.getArrayOfInts()));
         assertNotSame(INTS, aft.getArrayOfInts());
         em.close();
     }
-}
\ No newline at end of file
+}

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java Fri Mar 30 11:45:15 2007
@@ -7,34 +7,19 @@
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.apache.openjpa.persistence.simple.AllFieldTypes;
-import org.apache.openjpa.persistence.test.SingleEMFTest;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 public class TestBulkJPQLAndDataCache
-    extends SingleEMFTest {
+    extends SingleEMFTestCase {
 
     private Object oid;
 
-    public TestBulkJPQLAndDataCache() {
-        super(AllFieldTypes.class, CascadeParent.class, CascadeChild.class);
-    }
-
-    @Override
-    protected boolean clearDatabaseInSetUp() {
-        return true;
-    }
-
-    protected void setEMFProps(Map props) {
-        super.setEMFProps(props);
-        props.put("openjpa.DataCache", "true");
-        props.put("openjpa.RemoteCommitProvider", "sjvm");
-    }
-
-    @Override
     public void setUp() throws Exception {
-        super.setUp();
+        setUp("openjpa.DataCache", "true",
+            "openjpa.RemoteCommitProvider", "sjvm",
+            AllFieldTypes.class, CascadeParent.class, CascadeChild.class);
 
-        OpenJPAEntityManager em =
-            OpenJPAPersistence.cast(emf.createEntityManager());
+        OpenJPAEntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         AllFieldTypes pc = new AllFieldTypes();
         pc.setStringField("DeleteMe");
@@ -44,28 +29,8 @@
         em.close();
     }
 
-    public void tearDown() 
-        throws Exception {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("DELETE FROM AllFieldTypes").executeUpdate();
-            em.createQuery("DELETE FROM CascadeParent").executeUpdate();
-            em.createQuery("DELETE FROM CascadeChild").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-        } catch (Exception e) {
-        }
-
-        super.tearDown();
-    }
-
     public void testBulkDelete() {
-        OpenJPAEntityManager em =
-            OpenJPAPersistence.cast(emf.createEntityManager());
-
+        OpenJPAEntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         List result = em.createQuery("SELECT o FROM AllFieldTypes o")
             .getResultList();
@@ -74,7 +39,7 @@
         em.getTransaction().commit();
         em.close();
 
-        em = OpenJPAPersistence.cast(emf.createEntityManager());
+        em = emf.createEntityManager();
 
         // this assumes that we invalidate the cache, rather than update it
         // according to the bulk rule.
@@ -86,8 +51,7 @@
     }
 
     public void testBulkUpdate() {
-        OpenJPAEntityManager em =
-            OpenJPAPersistence.cast(emf.createEntityManager());
+        OpenJPAEntityManager em = emf.createEntityManager();
 
         em.getTransaction().begin();
         List result = em.createQuery("SELECT o FROM AllFieldTypes o "
@@ -98,7 +62,7 @@
         em.getTransaction().commit();
         em.close();
 
-        em = OpenJPAPersistence.cast(emf.createEntityManager());
+        em = emf.createEntityManager();
 
         // this assumes that we invalidate the cache, rather than update it
         // according to the bulk rule.

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java Fri Mar 30 11:45:15 2007
@@ -15,60 +15,34 @@
  */
 package org.apache.openjpa.persistence.datacache;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 import javax.persistence.RollbackException;
 import javax.persistence.LockModeType;
+import javax.sql.DataSource;
 
-import junit.framework.TestCase;
-import java.util.HashMap;
-import java.util.Map;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import javax.sql.DataSource;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 public class TestDataCacheOptimisticLockRecovery
-    extends TestCase {
+    extends SingleEMFTestCase {
 
-    private EntityManagerFactory emf;
     private int pk;
 
     public void setUp() {
-        Map options = new HashMap(System.getProperties());
-
-        // turn on caching
-        options.put("openjpa.DataCache", "true");
-        options.put("openjpa.RemoteCommitProvider", "sjvm");
-
-        // ensure that OpenJPA knows about our type, so that 
-        // auto-schema-creation works
-        options.put("openjpa.MetaDataFactory",
-            "jpa(Types=" + OptimisticLockInstance.class.getName() + ")");
-
-        emf = Persistence.createEntityManagerFactory("test", options);
+        setUp("openjpa.DataCache", "true",
+            "openjpa.RemoteCommitProvider", "sjvm",
+            OptimisticLockInstance.class);
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        em.createQuery("delete from OptimisticLockInstance").executeUpdate();
-
         OptimisticLockInstance oli = new OptimisticLockInstance("foo");
-        try {
-            em.persist(oli);
-            em.getTransaction().commit();
-        } finally {
-            if (em.getTransaction().isActive())
-                em.getTransaction().rollback();
-        }
+        em.persist(oli);
+        em.getTransaction().commit();
         pk = oli.getPK();
         em.close();
-    }
-
-    public void tearDown() {
-        emf.close();
     }
 
     public void testOptimisticLockRecovery() 

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestAttachWithNoChanges.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestAttachWithNoChanges.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestAttachWithNoChanges.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestAttachWithNoChanges.java Fri Mar 30 11:45:15 2007
@@ -15,15 +15,11 @@
  */
 package org.apache.openjpa.persistence.detachment;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
 import javax.persistence.OptimisticLockException;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test that attaching an instance without having changed it still overwrites
@@ -32,37 +28,13 @@
  * @author Abe White
  */
 public class TestAttachWithNoChanges
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        String types = DetachmentOneManyParent.class.getName() + ";"
-            + DetachmentOneManyChild.class.getName(); 
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(DetachmentOneManyParent.class, DetachmentOneManyChild.class);
     }
 
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from DetachmentOneManyChild").
-                executeUpdate();
-            em.createQuery("delete from DetachmentOneManyParent").
-                executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
-    }
-    
     public void testAttachWithNoChangesChecksVersion() {
-try {
         DetachmentOneManyChild e = new DetachmentOneManyChild();
         DetachmentOneManyParent p = new DetachmentOneManyParent();
         e.setName("orig");
@@ -91,10 +63,6 @@
                 em.getTransaction().rollback();
             em.close();
         }
-} catch (RuntimeException re) {
-re.printStackTrace();
-throw re;
-}
     }
 
     public static void main(String[] args) {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachmentOneMany.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachmentOneMany.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachmentOneMany.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachmentOneMany.java Fri Mar 30 11:45:15 2007
@@ -15,16 +15,12 @@
  */
 package org.apache.openjpa.persistence.detachment;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
-import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
-import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.apache.openjpa.kernel.AutoDetach;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Tests detachment for bidirectional one-many relationship
@@ -32,37 +28,12 @@
  * @author David Ezzio
  */
 public class TestDetachmentOneMany
-    extends TestCase {
-
-    private OpenJPAEntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
-    @SuppressWarnings("unchecked")
     public void setUp() {
-        String types = DetachmentOneManyParent.class.getName() + ";"
-            + DetachmentOneManyChild.class.getName(); 
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        emf = (OpenJPAEntityManagerFactory) Persistence.
-            createEntityManagerFactory("test", props);
+        setUp(DetachmentOneManyParent.class, DetachmentOneManyChild.class);
     }
 
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from DetachmentOneManyChild").
-                executeUpdate();
-            em.createQuery("delete from DetachmentOneManyParent").
-                executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
-    }
-    
     public void testDetachment() {
         long id = createParentAndChildren();
     
@@ -72,6 +43,7 @@
             id);
         assertNotNull(parent);
         assertFalse("The parent was not detached", em.contains(parent));
+        em.close();
     }
 
     public void testFetchWithDetach() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestGetReferenceAndImplicitDetachment.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestGetReferenceAndImplicitDetachment.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestGetReferenceAndImplicitDetachment.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestGetReferenceAndImplicitDetachment.java Fri Mar 30 11:45:15 2007
@@ -1,54 +1,19 @@
 package org.apache.openjpa.persistence.detachment;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import javax.persistence.EntityManager;
-import javax.persistence.Persistence;
 import javax.persistence.RollbackException;
 
+import junit.framework.TestCase;
 import org.apache.openjpa.enhance.PersistenceCapable;
-import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
-
-import junit.framework.TestCase;
-
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 public class TestGetReferenceAndImplicitDetachment
-    extends TestCase {
-
-    private OpenJPAEntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        String types = DetachmentOneManyParent.class.getName() + ";"
-            + DetachmentOneManyChild.class.getName(); 
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        props.put("openjpa.DetachState", "fgs");
-        emf = (OpenJPAEntityManagerFactory) Persistence.
-            createEntityManagerFactory("test", props);
-        deleteAll();
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            deleteAll();
-            emf.close();
-        } catch (Exception e) {
-        }
-    }
-    
-    private void deleteAll() {
-        EntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        em.createQuery("delete from DetachmentOneManyChild").
-            executeUpdate();
-        em.createQuery("delete from DetachmentOneManyParent").
-            executeUpdate();
-        em.getTransaction().commit();
-        em.close();
+        setUp("openjpa.DetachState", "fgs",
+            DetachmentOneManyParent.class, DetachmentOneManyChild.class);
     }
 
     public void testNonexistentGetReferenceDetachmentInTxWithCommit() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestGenerationType.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestGenerationType.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestGenerationType.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestGenerationType.java Fri Mar 30 11:45:15 2007
@@ -15,20 +15,16 @@
  */
 package org.apache.openjpa.persistence.identity;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
 import javax.persistence.Query;
 
 import junit.framework.TestCase;
 import junit.textui.TestRunner;
-
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
-import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Simple test case to test the GenerationType for @Id...
@@ -36,16 +32,11 @@
  * @author Kevin Sutter
  */
 public class TestGenerationType
-    extends TestCase {
-
-    private OpenJPAEntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory",
-            "jpa(Types=" + IdentityGenerationType.class.getName() + ")");
-        emf = (OpenJPAEntityManagerFactory) Persistence.
-            createEntityManagerFactory("test", props);
+        setUp(IdentityGenerationType.class);
+
         /*
          * If the DBDictionary doesn't support AutoAssign(ment) of column
          * values, then null out the emf instance to prevent the rest of
@@ -56,20 +47,6 @@
             emf = null;
         }
 
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from IdentityGenerationType").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
     }
 
     public void testCreateEntityManager() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLDateId.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLDateId.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLDateId.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLDateId.java Fri Mar 30 11:45:15 2007
@@ -16,14 +16,10 @@
 package org.apache.openjpa.persistence.identity;
 
 import java.sql.Date;
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test that entities can use SQL dates as identity values.
@@ -31,29 +27,10 @@
  * @author Abe White
  */
 public class TestSQLDateId
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        String types = SQLDateIdEntity.class.getName();
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from SQLDateIdEntity").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
+        setUp(SQLDateIdEntity.class);
     }
 
     public void testPersist() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java Fri Mar 30 11:45:15 2007
@@ -15,14 +15,10 @@
  */
 package org.apache.openjpa.persistence.inheritance;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test that you can find a concrete subclass record when passing in its
@@ -31,16 +27,10 @@
  * @author Abe White
  */
 public class TestFindAbstractClass
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        String types = AbstractBase.class.getName() + ";"
-            + ConcreteSubclass.class.getName();
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(AbstractBase.class, ConcreteSubclass.class);
 
         ConcreteSubclass e = new ConcreteSubclass();
         e.setId("id");
@@ -51,20 +41,6 @@
         em.persist(e);
         em.getTransaction().commit();
         em.close();
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from ConcreteSubclass").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
     }
 
     public void testFind() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java Fri Mar 30 11:45:15 2007
@@ -15,14 +15,10 @@
  */
 package org.apache.openjpa.persistence.inheritance;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Perform basic operations on an inheritance hierarchy involving multiple
@@ -31,31 +27,11 @@
  * @author Abe White
  */
 public class TestMultipleMappedSuperclassHierarchy
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        String types = MappedSuperclassBase.class.getName() + ";"
-            + MappedSuperclassL2.class.getName() + ";"
-            + EntityL3.class.getName();
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from EntityL3").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
+        setUp(MappedSuperclassBase.class, MappedSuperclassL2.class,
+            EntityL3.class);
     }
 
     public void testPersist() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java Fri Mar 30 11:45:15 2007
@@ -15,14 +15,10 @@
  */
 package org.apache.openjpa.persistence.inheritance;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test that sibling classes with a shared id value declared in their 
@@ -31,18 +27,11 @@
  * @author Abe White
  */
 public class TestSharedMappedSuperclassIdValue
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        String types = MappedSuperclassBase.class.getName() + ";"
-            + MappedSuperclassL2.class.getName() + ";"
-            + EntityL3.class.getName() + ";"
-            + EntityL3Sibling.class.getName();
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(MappedSuperclassBase.class, MappedSuperclassL2.class,
+            EntityL3.class, EntityL3Sibling.class);
 
         EntityL3 ent = new EntityL3();
         ent.setId(1);
@@ -59,22 +48,6 @@
         em.persist(sib);
         em.getTransaction().commit();
         em.close();
-
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from EntityL3").executeUpdate();
-            em.createQuery("delete from EntityL3Sibling").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
     }
 
     public void testFind() {
@@ -107,7 +80,6 @@
 
         em.close();
     }
-
 
     public static void main(String[] args) {
         TestRunner.run(TestSharedMappedSuperclassIdValue.class);

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/CompanyModelTest.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/CompanyModelTest.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/CompanyModelTest.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/CompanyModelTest.java Fri Mar 30 11:45:15 2007
@@ -28,12 +28,13 @@
  *  
  * @author  Marc Prud'hommeaux
  */
-public abstract class CompanyModelTest extends SingleEMTest {
-    private static Map<Class,Class> factoryClasses;
+public abstract class CompanyModelTest 
+    extends SingleEMTestCase {
 
-    private final Map<Class,Class> impls;
+    private static Map<Class,Class> factoryClasses;
+    private Map<Class,Class> impls;
 
-    public CompanyModelTest() {
+    public void setUp() {
         // make a map of the implementations based on the class names in
         // the current package of the test subclass
         impls = new HashMap<Class,Class>();
@@ -48,7 +49,8 @@
         impls.put(IPartTimeEmployee.class, localClass("PartTimeEmployee"));
         impls.put(IProduct.class, localClass("Product"));
 
-        classes = (Class[]) impls.values().toArray(new Class[impls.size()]);
+        setUp(impls.values().toArray(new Class[impls.size()]));
+        checkModel();
     }
 
     private Class localClass(String name) {
@@ -60,16 +62,6 @@
         }
     }
 
-    public void setUp() throws Exception {
-        super.setUp();
-        try {
-            checkModel();
-        } catch (Exception e) {
-            closeEMF();
-            throw e;
-        }
-    }
-
     /** 
      * Runs through basic queries against all of the properties of all
      * of the known persistent classes. We're just checking here to
@@ -174,7 +166,7 @@
             verifyModel();
         } catch (AssertionFailedError e) {
             // clear all existing instances
-            delete(impls.values().toArray(new Class[0]));
+            clear(emf, impls.values().toArray(new Class[impls.size()]));
 
             // since the factory method needs to be static, we need to store
             // the classes statically

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java Fri Mar 30 11:45:15 2007
@@ -15,16 +15,12 @@
  */
 package org.apache.openjpa.persistence.query;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 import javax.persistence.Query;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.simple.NamedEntity;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test that we can query by an entity's abstract schema name.
@@ -32,15 +28,10 @@
  * @author Abe White
  */
 public class TestAbstractSchemaName
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
-            + NamedEntity.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(NamedEntity.class);
 
         NamedEntity e = new NamedEntity();
         e.setName("e"); 
@@ -50,21 +41,6 @@
         em.persist(e);
         em.getTransaction().commit();
         em.close();
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from named").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
     }
 
     public void testQuery() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java Fri Mar 30 11:45:15 2007
@@ -15,33 +15,18 @@
  */
 package org.apache.openjpa.persistence.query;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import javax.persistence.FlushModeType;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 
 import org.apache.openjpa.persistence.OpenJPAQuery;
 import org.apache.openjpa.persistence.simple.AllFieldTypes;
-
-import junit.framework.TestCase;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 public class TestInMemoryQueryMatchEscapes
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        Map options = new HashMap(System.getProperties());
-
-        // ensure that OpenJPA knows about our type, so that 
-        // auto-schema-creation works
-        options.put("openjpa.MetaDataFactory",
-            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
-
-        emf = Persistence.createEntityManagerFactory("test", options);
+        setUp(AllFieldTypes.class);
     }
     
     public void testDatabaseEscape() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java Fri Mar 30 11:45:15 2007
@@ -15,17 +15,13 @@
  */
 package org.apache.openjpa.persistence.query;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 import javax.persistence.Query;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test that we can exclude subclass instances from query results.
@@ -33,16 +29,10 @@
  * @author Abe White
  */
 public class TestQueryExcludingSubclasses
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
-            + ManyOneEntity.class.getName() + ";"
-            + ManyOneEntitySub.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(ManyOneEntity.class, ManyOneEntitySub.class);
 
         ManyOneEntity e1 = new ManyOneEntity();
         e1.setName("e1"); 
@@ -69,21 +59,6 @@
         em.close();
     }
 
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from ManyOneEntity").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
     public void testQuery() {
         EntityManager em = emf.createEntityManager();
         Query q = em.createQuery("select e from ManyOneEntity e "
@@ -114,7 +89,6 @@
         }
         em.close();
     }
-
 
     public static void main(String[] args) {
         TestRunner.run(TestQueryExcludingSubclasses.class);

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryIdOfRelationDoesNotJoin.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryIdOfRelationDoesNotJoin.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryIdOfRelationDoesNotJoin.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryIdOfRelationDoesNotJoin.java Fri Mar 30 11:45:15 2007
@@ -15,16 +15,12 @@
  */
 package org.apache.openjpa.persistence.query;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 import javax.persistence.Query;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test that querying the id of a related many-one (or one-one) does not create
@@ -33,17 +29,12 @@
  * @author Abe White
  */
 public class TestQueryIdOfRelationDoesNotJoin
-    extends TestCase {
+    extends SingleEMFTestCase {
 
-    private EntityManagerFactory emf;
     private long e3Id;
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types="
-                + ManyOneEntity.class.getName() + ";"
-                + ManyOneEntitySub.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(ManyOneEntity.class, ManyOneEntitySub.class);
 
         ManyOneEntity e1 = new ManyOneEntity();
         e1.setName("e1");
@@ -65,21 +56,6 @@
         em.remove(e3);
         em.getTransaction().commit();
         em.close();
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from ManyOneEntity").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
     }
 
     public void testQuery() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java Fri Mar 30 11:45:15 2007
@@ -15,28 +15,19 @@
  */
 package org.apache.openjpa.persistence.query;
 
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 import javax.persistence.Query;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
-public class TestResultSetMapping extends TestCase {
-
-    private EntityManagerFactory emf;
+public class TestResultSetMapping 
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        Map props = new HashMap();
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + 
-            org.apache.openjpa.persistence.query.SimpleEntity.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(SimpleEntity.class);
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -45,21 +36,6 @@
         em.close();
     }
 
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from simple").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
     public void testSimpleQuery() {
         EntityManager em = emf.createEntityManager();
         Query q = em.createNamedQuery("findSimpleEntitites");
@@ -74,4 +50,4 @@
     public static void main(String[] args) {
         TestRunner.run(TestResultSetMapping.class);
     }
-}
\ No newline at end of file
+}

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestCascadingOneManyWithForeignKey.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestCascadingOneManyWithForeignKey.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestCascadingOneManyWithForeignKey.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestCascadingOneManyWithForeignKey.java Fri Mar 30 11:45:15 2007
@@ -15,17 +15,13 @@
  */
 package org.apache.openjpa.persistence.relations;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
-import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Tests a cascading one-many backed by a foreign key.
@@ -33,33 +29,10 @@
  * @author Abe White
  */
 public class TestCascadingOneManyWithForeignKey
-    extends TestCase {
-
-    private OpenJPAEntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        String types = CascadingOneManyParent.class.getName() + ";"
-            + CascadingOneManyChild.class.getName(); 
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
-        emf = (OpenJPAEntityManagerFactory) Persistence.
-            createEntityManagerFactory("test", props);
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from CascadingOneManyChild").executeUpdate();
-            em.createQuery("delete from CascadingOneManyParent").
-                executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
+        setUp(CascadingOneManyParent.class, CascadingOneManyChild.class);
     }
 
     public void testPersist() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java Fri Mar 30 11:45:15 2007
@@ -15,15 +15,10 @@
  */
 package org.apache.openjpa.persistence.relations;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
-import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test ordering a one-many field on the primary key of the related entity.
@@ -31,17 +26,12 @@
  * @author Abe White
  */
 public class TestIdOrderedOneMany
-    extends TestCase {
+    extends SingleEMFTestCase {
 
-    private EntityManagerFactory emf;
     private long id;
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
-            + IdOrderedOneManyParent.class.getName() + ";"
-            + IdOrderedOneManyChild.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(IdOrderedOneManyParent.class, IdOrderedOneManyChild.class);
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -69,22 +59,6 @@
         em.getTransaction().commit();
         id = parent.getId();
         em.close();
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from IdOrderedOneManyChild").executeUpdate();
-            em.createQuery("delete from IdOrderedOneManyParent").
-                executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
     }
 
     public void testExplicitOrdering() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestManyOneAsId.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestManyOneAsId.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestManyOneAsId.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestManyOneAsId.java Fri Mar 30 11:45:15 2007
@@ -15,16 +15,12 @@
  */
 package org.apache.openjpa.persistence.relations;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 import javax.persistence.Query;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Perform basic operations on an entity with a many-one relation as its id
@@ -33,22 +29,16 @@
  * @author Abe White
  */
 public class TestManyOneAsId
-    extends TestCase {
+    extends SingleEMFTestCase {
 
-    private EntityManagerFactory emf;
     private long id;
     private long dsid;
     private long cid;
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
-            + BasicEntity.class.getName() + ";"
-            + DataStoreBasicEntity.class.getName() + ";"
-            + ManyOneIdOwner.class.getName() + ";"
-            + DataStoreManyOneIdOwner.class.getName() + ";"
-            + ManyOneCompoundIdOwner.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(BasicEntity.class, DataStoreBasicEntity.class,
+            ManyOneIdOwner.class, DataStoreManyOneIdOwner.class,
+            ManyOneCompoundIdOwner.class);
 
         BasicEntity id1 = new BasicEntity();
         id1.setName("id1");
@@ -106,26 +96,6 @@
         cid = cparent.getLongId();
         assertCompoundRelations(oem, cparent);
         em.close();
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from ManyOneIdOwner").executeUpdate();
-            em.createQuery("delete from DataStoreManyOneIdOwner").
-                executeUpdate();
-            em.createQuery("delete from ManyOneCompoundIdOwner").
-                executeUpdate();
-            em.createQuery("delete from BasicEntity").executeUpdate();
-            em.createQuery("delete from DataStoreBasicEntity").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
     }
 
     private void assertRelations(EntityManager em, ManyOneIdOwner parent) {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMultipleSameTypedEmbeddedWithEagerRelations.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMultipleSameTypedEmbeddedWithEagerRelations.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMultipleSameTypedEmbeddedWithEagerRelations.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMultipleSameTypedEmbeddedWithEagerRelations.java Fri Mar 30 11:45:15 2007
@@ -15,16 +15,12 @@
  */
 package org.apache.openjpa.persistence.relations;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 import javax.persistence.Query;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test that querying and retrieving entities with multiple same-typed embedded
@@ -33,16 +29,10 @@
  * @author Abe White
  */
 public class TestMultipleSameTypedEmbeddedWithEagerRelations
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
-            + EmbeddableWithRelation.class.getName() + ";"
-            + MultipleSameTypedEmbedded.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(EmbeddableWithRelation.class, MultipleSameTypedEmbedded.class);
 
         EmbeddableWithRelation embed1 = new EmbeddableWithRelation();
         embed1.setName("embed1");
@@ -67,22 +57,6 @@
         em.persist(m2);
         em.getTransaction().commit();
         em.close();
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from MultipleSameTypedEmbedded").
-                executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
     }
 
     public void testQuery() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java Fri Mar 30 11:45:15 2007
@@ -15,14 +15,10 @@
  */
 package org.apache.openjpa.persistence.relations;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Perform basic operations on an entity with interface relations that use
@@ -31,30 +27,10 @@
  * @author Abe White
  */
 public class TestTargetedIFaceRelations
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
-            + TargetedIFaceRelationParent.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from TargetedIFaceRelationParent").
-                executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
+        setUp(TargetedIFaceRelationParent.class);
     }
 
     public void testPersist() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java Fri Mar 30 11:45:15 2007
@@ -1,15 +1,30 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.openjpa.persistence.simple;
 
 import javax.persistence.Query;
 import javax.persistence.EntityManager;
 
-import org.apache.openjpa.persistence.test.PersistenceTestCase;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 public class TestCaseInsensitiveKeywordsInJPQL
-    extends PersistenceTestCase {
+    extends SingleEMFTestCase {
 
-    public Class[] getEntityTypes() {
-        return new Class[] { AllFieldTypes.class };
+    public void setUp() {
+        setUp(AllFieldTypes.class);
     }
 
     public void testCaseInsensitiveBooleans() {
@@ -38,4 +53,4 @@
         
         em.getTransaction().rollback();
     }
-}
\ No newline at end of file
+}

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java Fri Mar 30 11:45:15 2007
@@ -15,14 +15,10 @@
  */
 package org.apache.openjpa.persistence.simple;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
 
 /**
  * Test case to ensure that the proper JPA clear semantics are processed.
@@ -30,71 +26,46 @@
  * @author Kevin Sutter
  */
 public class TestEntityManagerClear
-    extends TestCase {
-
-    private EntityManagerFactory emf;
-    private EntityManager em;
+    extends SingleEMTestCase {
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory",
-            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
+        setUp(AllFieldTypes.class);
     }
 
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from AllFieldTypes").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
-    }
     public void testClear() {
-        try {
-            // Create EntityManager and Start a transaction (1)
-            em = emf.createEntityManager();
-            em.getTransaction().begin();
-
-            // Insert a new object and flush
-            AllFieldTypes testObject1 = new AllFieldTypes();
-            testObject1.setStringField("my test object1");
-            em.persist(testObject1);
-            em.flush();
-
-            // Clear the PC for new object 2
-            AllFieldTypes testObject2 = new AllFieldTypes();
-            testObject1.setStringField("my test object2");
-            em.persist(testObject2);
-            em.clear();
-
-            // Commit the transaction (only object 1 should be in database)
-            em.getTransaction().commit();
-
-            // Start a new transaction
-            em.getTransaction().begin();
-
-            // Attempt retrieve of Object1 from previous PC (should exist)
-            assertEquals(1, em.createQuery
-                    ("select x from AllFieldTypes x where x.stringField = 'my test object1'").
-                    getResultList().size());
-
-            // Attempt retrieve of Object2 from previous PC (should not exist)
-            assertEquals(0, em.createQuery
-                    ("select x from AllFieldTypes x where x.stringField = 'my test object2'").
-                    getResultList().size());
-
-            // Rollback the transaction and close everything
-            em.getTransaction().rollback();
-            em.close();
-        } catch (Exception ex) {
-            fail("Unexpected Exception ex = " + ex);
-        }
+        // Create EntityManager and Start a transaction (1)
+        begin();
+
+        // Insert a new object and flush
+        AllFieldTypes testObject1 = new AllFieldTypes();
+        testObject1.setStringField("my test object1");
+        persist(testObject1);
+        em.flush();
+
+        // Clear the PC for new object 2
+        AllFieldTypes testObject2 = new AllFieldTypes();
+        testObject1.setStringField("my test object2");
+        persist(testObject2);
+        em.clear();
+
+        // Commit the transaction (only object 1 should be in database)
+        commit();
+
+        // Start a new transaction
+        begin();
+
+        // Attempt retrieve of Object1 from previous PC (should exist)
+        assertEquals(1, query("select x from AllFieldTypes x "
+            + "where x.stringField = 'my test object1'").
+                getResultList().size());
+
+        // Attempt retrieve of Object2 from previous PC (should not exist)
+        assertEquals(0, query("select x from AllFieldTypes x "
+            + "where x.stringField = 'my test object2'").
+                getResultList().size());
+
+        // Rollback the transaction and close everything
+        rollback();
     }
 
     public static void main(String[] args) {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMethodsThrowAfterClose.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMethodsThrowAfterClose.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMethodsThrowAfterClose.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMethodsThrowAfterClose.java Fri Mar 30 11:45:15 2007
@@ -15,16 +15,12 @@
  */
 package org.apache.openjpa.persistence.simple;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
 import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
 
 /**
  * Negative test case to verify that EntityManager throws required exceptions
@@ -33,34 +29,15 @@
  * @author Craig Russell
  */
 public class TestEntityManagerMethodsThrowAfterClose
-    extends TestCase {
+    extends SingleEMTestCase {
 
-    private EntityManagerFactory emf;
-    private EntityManager em;
     private AllFieldTypes aft = new AllFieldTypes();
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory",
-            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
-        em = emf.createEntityManager();
-        em.close();
+        setUp(AllFieldTypes.class);
+        close();
     }
 
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from AllFieldTypes").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
-    }
     public void testPersistAfterClose() {
         try {
             em.persist(aft);

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java Fri Mar 30 11:45:15 2007
@@ -15,16 +15,12 @@
  */
 package org.apache.openjpa.persistence.simple;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
 
-import junit.framework.TestCase;
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Simple test case to get an EntityManager and perform some basic operations.
@@ -32,29 +28,10 @@
  * @author Marc Prud'hommeaux
  */
 public class TestPersistence
-    extends TestCase {
-
-    private EntityManagerFactory emf;
+    extends SingleEMFTestCase {
 
     public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory",
-            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from AllFieldTypes").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
+        setUp(AllFieldTypes.class);
     }
 
     public void testCreateEntityManager() {

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java Fri Mar 30 11:45:15 2007
@@ -1,20 +1,19 @@
 package org.apache.openjpa.persistence.simple;
 
-import org.apache.openjpa.persistence.OpenJPAPersistence;
-import org.apache.openjpa.persistence.test.PersistenceTestCase;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 public class TestTableNamesDefaultToEntityNames
-    extends PersistenceTestCase {
+    extends SingleEMFTestCase {
 
-    @Override
-    protected Class[] getEntityTypes() {
-        return new Class[] { NamedEntity.class };
+    public void setUp() {
+        setUp(NamedEntity.class);
     }
 
     public void testEntityNames() {
         ClassMapping cm = (ClassMapping) OpenJPAPersistence.getMetaData(
-            getEntityManagerFactory(), NamedEntity.class);
+            emf, NamedEntity.class);
         assertEquals("named", cm.getTable().getName());
     }
 }

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java?view=diff&rev=524228&r1=524227&r2=524228
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java Fri Mar 30 11:45:15 2007
@@ -1,39 +1,150 @@
 package org.apache.openjpa.persistence.test;
 
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
 
 import junit.framework.TestCase;
+import org.apache.openjpa.kernel.AbstractBrokerFactory;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
 
+/**
+ * Base test class providing persistence utilities.
+ */
 public abstract class PersistenceTestCase
     extends TestCase {
 
-    protected OpenJPAEntityManagerFactory emf;
-
-    protected Class[] getEntityTypes() {
-        return new Class[0];
-    }
+    /**
+     * Marker object you an pass to {@link #setUp} to indicate that the
+     * database tables should be cleared.
+     */
+    protected static final Object CLEAR_TABLES = new Object();
+
+    /**
+     * Create an entity manager factory.
+     *
+     * @param props list of persistent types used in testing and/or 
+     * configuration values in the form key,value,key,value...
+     */
+    protected OpenJPAEntityManagerFactory createEMF(Object... props) {
+        Map map = new HashMap(System.getProperties());
+        List<Class> types = new ArrayList<Class>();
+        boolean prop = false;
+        for (int i = 0; i < props.length; i++) {
+            if (prop) {
+                map.put(props[i - 1], props[i]);
+                prop = false;
+            } else if (props[i] == CLEAR_TABLES) {
+                map.put("openjpa.jdbc.SynchronizeMappings",
+                    "buildSchema(ForeignKeys=true," 
+                    + "SchemaAction='add,deleteTableContents')");
+            } else if (props[i] instanceof Class)
+                types.add((Class) props[i]);
+            else
+                prop = true;
+        }
 
-    public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        Class[] types = getEntityTypes();
-        if (types != null && types.length > 0) {
+        if (!types.isEmpty()) {
             StringBuffer buf = new StringBuffer();
-            for (int i = 0; i < types.length; i++) {
-                buf.append(types[i].getName());
-                if (i != types.length - 1)
-                    buf.append(",");
+            for (Class c : types) {
+                if (buf.length() > 0)
+                    buf.append(";");
+                buf.append(c.getName());
             }
-            props.put("openjpa.MetaDataFactory",
+            map.put("openjpa.MetaDataFactory",
                 "jpa(Types=" + buf.toString() + ")");
         }
-        emf = (OpenJPAEntityManagerFactory)
-            Persistence.createEntityManagerFactory("test", props);
+
+        return (OpenJPAEntityManagerFactory) Persistence.
+            createEntityManagerFactory("test", map);
+    }
+
+    /**
+     * Safely close the given factory.
+     */
+    protected boolean closeEMF(EntityManagerFactory emf) {
+        if (emf == null)
+            return false;
+        if (!emf.isOpen())
+            return false;
+
+        for (Iterator iter = ((AbstractBrokerFactory) OpenJPAPersistence
+            .toBrokerFactory(emf)).getOpenBrokers().iterator();
+            iter.hasNext(); ) {
+            Broker b = (Broker) iter.next();
+            if (b != null && !b.isClosed()) {
+                EntityManager em = OpenJPAPersistence.toEntityManager(b);
+                if (em.getTransaction().isActive())
+                    em.getTransaction().rollback();
+                em.close();
+            }
+        }
+
+        emf.close();
+        return !emf.isOpen();
+    }
+
+    /**
+     * Delete all instances of the given types using bulk delete queries.
+     */
+    protected void clear(EntityManagerFactory emf, Class... types) {
+        if (emf == null || types.length == 0)
+            return;
+
+        List<ClassMetaData> metas = new ArrayList<ClassMetaData>(types.length);
+        for (Class c : types) {
+            ClassMetaData meta = OpenJPAPersistence.getMetaData(emf, c);
+            if (meta != null)
+                metas.add(meta);
+        }
+        clear(emf, metas.toArray(new ClassMetaData[metas.size()]));
+    }
+
+    /**
+     * Delete all instances of the persistent types registered with the given
+     * factory using bulk delete queries.
+     */
+    protected void clear(EntityManagerFactory emf) {
+        if (emf == null)
+            return;
+        clear(emf, ((OpenJPAEntityManagerFactory) emf).getConfiguration().
+            getMetaDataRepositoryInstance().getMetaDatas());
+    }
+
+    /**
+     * Delete all instances of the given types using bulk delete queries.
+     */
+    private void clear(EntityManagerFactory emf, ClassMetaData... types) {
+        if (emf == null || types.length == 0)
+            return;
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        for (ClassMetaData meta : types) {
+            if (!meta.isMapped() || meta.isEmbeddedOnly() 
+                || Modifier.isAbstract(meta.getDescribedType().getModifiers()))
+                continue;
+            em.createQuery("DELETE FROM " + meta.getTypeAlias() + " o").
+                executeUpdate();
+        }
+        em.getTransaction().commit();
+        em.close();
     }
 
-    public OpenJPAEntityManagerFactory getEntityManagerFactory() {
-        return emf;
+    /**
+     * Return the entity name for the given type.   
+     */
+    protected String entityName(EntityManagerFactory emf, Class c) {
+        ClassMetaData meta = OpenJPAPersistence.getMetaData(emf, c);
+        return (meta == null) ? null : meta.getTypeAlias();
     }
 }



Mime
View raw message