make sure tests close EMs and streams

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1022222 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2010-10-13 18:15:04 +00:00
parent ff900d98fe
commit 71ae858f91
11 changed files with 41 additions and 11 deletions

View File

@ -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");

View File

@ -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() {

View File

@ -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();
}
/**

View File

@ -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() {

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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() {

View File

@ -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() {

View File

@ -69,6 +69,8 @@ public class TestMappedSuperClass extends SingleEMFTestCase {
rs = em.createQuery(query).getResultList();
} catch (ArgumentException e) {
// as expected
} finally {
em.close();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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;
}