diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestBooleanId.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestBooleanId.java index 2213e34d2..7b2d1f7fb 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestBooleanId.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestBooleanId.java @@ -33,6 +33,7 @@ public class TestBooleanId extends SQLListenerTestCase { private BooleanIdEntity se; private CompoundBooleanIdEntity ce; + @Override public void setUp() throws Exception { super.setUp(BooleanIdEntity.class, CompoundBooleanIdEntity.class, @@ -40,6 +41,12 @@ public class TestBooleanId extends SQLListenerTestCase { assertTrue(emf != null); } + @Override + public void tearDown() throws Exception { + closeEM(em); + super.tearDown(); + } + public void testSimpleBooleanIdEntity() { se = new BooleanIdEntity(true,"name"); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestStringId.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestStringId.java index 6ab295b1f..253b2f8e1 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestStringId.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestStringId.java @@ -26,14 +26,18 @@ import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase; public class TestStringId extends AbstractPersistenceTestCase { private static EntityManagerFactory _emf; - public void setUp() { + @Override + public void setUp() throws Exception { + super.setUp(); _emf = createEMF(StringIdEntity.class); cleanup(); } + @Override public void tearDown() { - _emf.close(); + closeEMF(_emf); + _emf = null; } private void cleanup() { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java index a344238f2..6d2365a34 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java @@ -624,6 +624,7 @@ public class TestDefaultInheritanceStrategy verifyInheritanceFinderResult(em, BaseClass6.class, 479, 302); verifyInheritanceFinderResult(em, SubclassI.class, 109); verifyInheritanceFinderResult(em, SubclassJ.class, 238); + em.close(); } /** diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java index 5a5cf11f8..17a5869d3 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java @@ -57,6 +57,7 @@ public class TestFindAbstractClass query = "select c from AbstractBase c"; rs = em.createQuery(query).getResultList(); assertTrue(rs.get(0) instanceof ConcreteSubclass); + em.close(); } public void testFind() { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestJoinTableStrategy.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestJoinTableStrategy.java index 6aab95077..7fdb76957 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestJoinTableStrategy.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestJoinTableStrategy.java @@ -73,11 +73,6 @@ public class TestJoinTableStrategy extends SingleEMFTestCase { em.close(); } - @Override - public void tearDown() { - // problem deleting table in MySQL - } - public void testFindEntity() { EntityManager em1 = emf.createEntityManager(); Manager m = em1.find(Manager.class, 1); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMappedSuperclass.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMappedSuperclass.java index 6e5df22af..194b2b1e7 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMappedSuperclass.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMappedSuperclass.java @@ -72,6 +72,7 @@ public class TestMappedSuperclass extends SingleEMFTestCase { em.getTransaction().begin(); em.persist(sd); em.getTransaction().commit(); + em.close(); } /** @@ -104,5 +105,6 @@ public class TestMappedSuperclass extends SingleEMFTestCase { em.getTransaction().begin(); em.merge(sd); em.getTransaction().commit(); + em.close(); } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java index d17515446..44d169006 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java @@ -66,6 +66,7 @@ public class TestAbstractJoinedAppId assertTrue(rs.size() > 0); for (int i = 0; i < rs.size(); i++) assertTrue(rs.get(i) instanceof Subclass); + em.close(); } public void testTraverseRelation() { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java index 99c67b476..d8172676c 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java @@ -171,6 +171,7 @@ public class TestInheritanceTypeJoinedQuery extends SQLListenerTestCase { Object obj = rs.get(i); assertTrue((obj instanceof ParttimeEmployee) || (obj instanceof FulltimeEmployee)); } + em.close(); } public void testInheritanceTypeJoinedQuery() { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java index 3524bf68b..7a757b221 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java @@ -69,6 +69,8 @@ public class TestMappedSuperClass extends SingleEMFTestCase { rs = em.createQuery(query).getResultList(); } catch (ArgumentException e) { // as expected + } finally { + em.close(); } } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java index f6f14aa77..fa5559b39 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java @@ -132,6 +132,7 @@ public class TestTablePerClassInheritanceWithAbstractRoot extends .getTranslations().contains(translation)); } em.getTransaction().rollback(); + em.close(); } @@ -145,8 +146,10 @@ public class TestTablePerClassInheritanceWithAbstractRoot extends */ public int count(Class c) { OpenJPAEntityManager em = emf.createEntityManager(); - return ((Number) em.createQuery("SELECT COUNT(p) FROM " + + Number n = ((Number) em.createQuery("SELECT COUNT(p) FROM " + c.getSimpleName() + " p").getSingleResult()).intValue(); + closeEM(em); + return n.intValue(); } /** @@ -215,6 +218,8 @@ public class TestTablePerClassInheritanceWithAbstractRoot extends } catch(ArgumentException e) { // as expected //System.out.println("e.getMessages()"); + } finally { + em.close(); } } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/serializable/TestSerialization.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/serializable/TestSerialization.java index 279922f0c..40f29a4aa 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/serializable/TestSerialization.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/serializable/TestSerialization.java @@ -20,6 +20,7 @@ package org.apache.openjpa.persistence.inheritance.serializable; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -71,6 +72,7 @@ public class TestSerialization extends SingleEMFTestCase { emp = em.find(Employee.class, id); assertEquals(deserialized, emp); + em.close(); } /** @@ -78,19 +80,28 @@ public class TestSerialization extends SingleEMFTestCase { */ private Object serializeObject(Object orig) { Object deserialized = null; + ObjectOutputStream oos = null; + ObjectInputStream ois = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); + oos = new ObjectOutputStream(baos); oos.writeObject(orig); ByteArrayInputStream bais = new ByteArrayInputStream(baos .toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); + ois = new ObjectInputStream(bais); - deserialized = ois.readObject(); + deserialized = ois.readObject(); } catch (Exception e) { fail(e.toString()); + } finally { + try { + oos.close(); + ois.close(); + } catch (IOException e) { + // ignore + } } return deserialized; }