diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java index 0a153dd92..db7e35c3d 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java @@ -78,6 +78,7 @@ public class TestAutoIncrement extends SingleEMFTestCase { em.getTransaction().commit(); assertEquals(1, Math.abs(pc1.getId() - pc2.getId())); + em.close(); } public void testAutoIncrementIdentityWithNativeSequence() { @@ -90,6 +91,7 @@ public class TestAutoIncrement extends SingleEMFTestCase { em.getTransaction().commit(); assertEquals(1, Math.abs(pc1.getId() - pc2.getId())); + em.close(); } /** @@ -108,6 +110,7 @@ public class TestAutoIncrement extends SingleEMFTestCase { // Sequence probably exists. em.getTransaction().rollback(); } + closeEM(em); closeEMF(factorySPI); } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java index 07b005b01..734718dc6 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java @@ -129,16 +129,23 @@ public class TestFlushBeforeDetach extends SQLListenerTestCase { */ private Object serializeObject(Object orig) throws Exception { Object deserialized = null; + ObjectOutputStream oos = null; + ObjectInputStream ois = null; - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(orig); + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + oos = new ObjectOutputStream(baos); + oos.writeObject(orig); - ByteArrayInputStream bais = - new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); + ByteArrayInputStream bais = + new ByteArrayInputStream(baos.toByteArray()); + ois = new ObjectInputStream(bais); - deserialized = ois.readObject(); - return deserialized; + deserialized = ois.readObject(); + return deserialized; + } finally { + oos.close(); + ois.close(); + } } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java index 2931c26c1..3fc2008c4 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java @@ -59,6 +59,7 @@ public class TestMissingMetaData extends TestCase { public void tearDown() { emf.close(); + emf = null; } public static void main(String[] args) { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java index 631c2cdf4..51442185d 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java @@ -34,6 +34,7 @@ import org.apache.openjpa.persistence.AutoClearType; import org.apache.openjpa.persistence.OpenJPAEntityManager; import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; import org.apache.openjpa.persistence.OpenJPAPersistence; +import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase; /** * This test case tests the getProperties() and getSupportedProperties() methods @@ -43,16 +44,16 @@ import org.apache.openjpa.persistence.OpenJPAPersistence; * @author Pinaki Poddar * */ -public class TestPropertiesMethods extends TestCase { +public class TestPropertiesMethods extends AbstractPersistenceTestCase { private static final String UNIT_NAME = "test"; - private static OpenJPAEntityManagerFactory emf; + private OpenJPAEntityManagerFactory emf; private OpenJPAEntityManager em; @SuppressWarnings("unchecked") public void setUp() throws Exception { - if (emf == null) { - Map config = new HashMap(); - config.putAll(System.getProperties()); + super.setUp(); + Map config = new HashMap(); + config.putAll(System.getProperties()); /* numeric */ config.put("openjpa.DataCacheTimeout", 300); /* num enum */ config.put("openjpa.AutoClear", 0); @@ -64,12 +65,19 @@ public class TestPropertiesMethods extends TestCase { /* equiv key */ //config.put("javax.persistence.jdbc.url", "jdbc:derby:target/database/test;create=true"); /* prime use */ //config.put("openjpa.ConnectionUserName", "root"); - emf = OpenJPAPersistence.cast(Persistence.createEntityManagerFactory(UNIT_NAME, config)); - assertNotNull(emf); - } + emf = OpenJPAPersistence.cast(Persistence.createEntityManagerFactory(UNIT_NAME, config)); + assertNotNull(emf); em = OpenJPAPersistence.cast(emf.createEntityManager()); } + @Override + public void tearDown() { + closeEM(em); + em = null; + closeEMF(emf); + emf = null; + } + // public void testProperties() { // print("EMF Properties", emf.getProperties()); // print("EMF Supported Properties", emf.getSupportedProperties()); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestSerializedFactory.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestSerializedFactory.java index 3ade10d22..fea9933c0 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestSerializedFactory.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestSerializedFactory.java @@ -82,6 +82,8 @@ public class TestSerializedFactory extends SingleEMFTestCase { emf2.close(); assertFalse("The entity manager factory is not closed", emf2.isOpen()); + emf2 = null; + oos.close(); } public static void main(String[] args) { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java index 11b8a9a6b..cebb5c1bf 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java @@ -62,6 +62,7 @@ public class TestValidationFactory extends SingleEMFTestCase { assertEquals("Default ValidationFactory", null, conf.getValidationFactoryInstance()); + closeEMF(emf); } /** @@ -91,6 +92,7 @@ public class TestValidationFactory extends SingleEMFTestCase { assertEquals("ValidationFactory", this.getClass(), conf.getValidationFactoryInstance()); + closeEMF(emf); } /** @@ -120,6 +122,7 @@ public class TestValidationFactory extends SingleEMFTestCase { assertEquals("ValidationFactory", this.getClass(), conf.getValidationFactoryInstance()); + closeEMF(emf); } /** @@ -159,6 +162,7 @@ public class TestValidationFactory extends SingleEMFTestCase { getLog().trace("testValidationFactory4() - caught expected " + "PersistenceException", e); } + closeEMF(emf); } }