diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestFKColumnNames.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestFKColumnNames.java index 60e6f1164..45a53bdaa 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestFKColumnNames.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestFKColumnNames.java @@ -24,19 +24,15 @@ import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.Persistence; -import junit.framework.TestCase; - import org.apache.openjpa.jdbc.meta.MappingRepository; import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase; /** * Testcase that verifies the names for Foreign Key columns is as expected. */ -public class TestFKColumnNames extends TestCase { +public class TestFKColumnNames extends AbstractPersistenceTestCase { - OpenJPAEntityManagerFactorySPI emf = - (OpenJPAEntityManagerFactorySPI) Persistence - .createEntityManagerFactory("test"); /** *

@@ -49,6 +45,9 @@ public class TestFKColumnNames extends TestCase { *

*/ public void testSQLKeywords() { + OpenJPAEntityManagerFactorySPI emf = + (OpenJPAEntityManagerFactorySPI) Persistence + .createEntityManagerFactory("test"); MappingRepository repos = (MappingRepository) emf.getConfiguration() .getMetaDataRepositoryInstance(); @@ -58,6 +57,7 @@ public class TestFKColumnNames extends TestCase { assertEquals("FROM_ID", repos.getMapping(Inner2.class, null, true) .getFieldMapping("from").getColumns()[0].getName()); + closeEMF(emf); } @Entity diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestMixedAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestMixedAccess.java index e9751414e..1c918b943 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestMixedAccess.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestMixedAccess.java @@ -27,28 +27,32 @@ import org.apache.openjpa.persistence.test.PersistenceTestCase; public class TestMixedAccess extends AbstractCachedEMFTestCase { public void testMixedAccessEntityError() { + EntityManagerFactory emf = null; try { - EntityManagerFactory emf = - createEMF(UnenhancedMixedAccess.class, "openjpa.RuntimeUnenhancedClasses", "supported"); + emf = createEMF(UnenhancedMixedAccess.class, "openjpa.RuntimeUnenhancedClasses", "supported"); emf.createEntityManager().close(); } catch (RuntimeException e) { String msg = e.getMessage(); if (!(msg.contains("UnenhancedMixedAccess.id") && msg.contains("UnenhancedMixedAccess.getStringField"))) throw e; + } finally { + closeEMF(emf); } } public void testInappropriateTransientError() { + EntityManagerFactory emf = null; try { - EntityManagerFactory emf = createEMF( - UnenhancedInappropriateTransient.class, "openjpa.RuntimeUnenhancedClasses", "supported"); + emf = createEMF(UnenhancedInappropriateTransient.class, "openjpa.RuntimeUnenhancedClasses", "supported"); emf.createEntityManager().close(); } catch (RuntimeException e) { String msg = e.getMessage(); if (!(msg.contains("UnenhancedInappropriateTransient.id") && msg.contains("UnenhancedInappropriateTransient.prePersist"))) throw e; - } + } finally { + closeEMF(emf); + } } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestMultiColumnVersion.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestMultiColumnVersion.java index 7c1e6cb94..8e55226bb 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestMultiColumnVersion.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestMultiColumnVersion.java @@ -63,6 +63,7 @@ public class TestMultiColumnVersion extends SingleEMFTestCase { em.merge(pc); em.getTransaction().commit(); assertVersionEquals(new Number[]{2,2, 2.0f}, em.getVersion(pc)); + em.close(); } public void testConcurrentOptimisticUpdateFailsForSingleTable() { @@ -84,6 +85,7 @@ public class TestMultiColumnVersion extends SingleEMFTestCase { pc1.setName("Updated in em1"); pc2.setName("Updated in em2"); em1.getTransaction().commit(); + em1.close(); try { em2.getTransaction().commit(); @@ -111,7 +113,9 @@ public class TestMultiColumnVersion extends SingleEMFTestCase { assertVersionEquals(em1.getVersion(pc1), em2.getVersion(pc2)); em1.getTransaction().commit(); + em1.close(); em2.getTransaction().commit(); + em2.close(); } public void testVersionOnPersistAndUpdateForMultiTable() { @@ -128,6 +132,7 @@ public class TestMultiColumnVersion extends SingleEMFTestCase { em.merge(pc); em.getTransaction().commit(); assertVersionEquals(new Number[]{2,2,2,2}, em.getVersion(pc)); + em.close(); } public void testConcurrentOptimisticUpdateFailsForMultiTable() { @@ -150,6 +155,7 @@ public class TestMultiColumnVersion extends SingleEMFTestCase { pc1.setName("Updated in em1"); pc2.setName("Updated in em2"); em1.getTransaction().commit(); + em1.close(); try { em2.getTransaction().commit(); @@ -178,7 +184,9 @@ public class TestMultiColumnVersion extends SingleEMFTestCase { assertVersionEquals(em1.getVersion(pc1), em2.getVersion(pc2)); em1.getTransaction().commit(); + em1.close(); em2.getTransaction().commit(); + em2.close(); } static void assertVersionEquals(Object expected, Object actual) { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java index 7d2a8d98a..75228f4b3 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java @@ -346,4 +346,5 @@ public class TestNonstandardMappingAnnotations } em.close(); - }} + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestPropertyAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestPropertyAccess.java index 44b9c6cd4..9be9314ea 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestPropertyAccess.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestPropertyAccess.java @@ -47,6 +47,7 @@ public class TestPropertyAccess assertNotNull(pa1_2); assertEquals(10, pa1_2.getId()); assertEquals("foo", pa1_2.getName()); + em.close(); } public void testPropertyAccessBasicMutation() { @@ -70,6 +71,7 @@ public class TestPropertyAccess PropertyAccess1 pa1_3 = em.find(PropertyAccess1.class, 10); assertNotSame(pa1_2, pa1_3); assertEquals("foobar", pa1_3.getName()); + em.close(); } public void testJPQL() {