mirror of https://github.com/apache/openjpa.git
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:
parent
ff900d98fe
commit
71ae858f91
|
@ -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");
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -69,6 +69,8 @@ public class TestMappedSuperClass extends SingleEMFTestCase {
|
|||
rs = em.createQuery(query).getResultList();
|
||||
} catch (ArgumentException e) {
|
||||
// as expected
|
||||
} finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue