make sure tests cleanup EMs and EMFs

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1006038 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2010-10-08 21:46:25 +00:00
parent a0fad7795b
commit 044164b4ad
3 changed files with 142 additions and 128 deletions

View File

@ -81,7 +81,7 @@ public class TestContainerSpecCompatibilityOptions
assertEquals("JPA", spec.getName().toUpperCase());
assertEquals(spec.getVersion(), 1);
emf1.close();
closeEMF(emf1);
}
@ -136,7 +136,7 @@ public class TestContainerSpecCompatibilityOptions
em.close();
}
} finally {
oemf.close();
closeEMF(oemf);
}
}
@ -205,7 +205,7 @@ public class TestContainerSpecCompatibilityOptions
fail("OneToMany mapping failed with exception message: " + e.getMessage());
} finally {
em.close();
oemf.close();
closeEMF(oemf);
}
}

View File

@ -60,16 +60,19 @@ public class TestQuerySQLCache extends SingleEMFTestCase {
props.put("openjpa.jdbc.QuerySQLCache",
"org.apache.openjpa.persistence.compatible.TestQuerySQLCache.BadCacheMap");
OpenJPAEntityManagerFactorySPI emf1 = null;
try {
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
emf1 = (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
cast(Persistence.createEntityManagerFactory("test", props));
//
// EMF creation must throw an exception because the cache implementation class will not be found
//
assertFalse(false);
fail("EMF creation must throw an exception because the cache implementation class will not be found");
}
catch (Exception e) {
assertTrue(true);
} finally {
closeEMF(emf1);
}
}
@ -108,9 +111,10 @@ public class TestQuerySQLCache extends SingleEMFTestCase {
+ TblParent.class.getName() + ")");
props.put("openjpa.jdbc.QuerySQLCache", "true");
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.
OpenJPAEntityManagerFactorySPI emf1 = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.
cast(Persistence.createEntityManagerFactory("test", props));
EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
try {
EntityManagerImpl em = (EntityManagerImpl)emf1.createEntityManager();
em.getTransaction().begin();
@ -157,14 +161,17 @@ public class TestQuerySQLCache extends SingleEMFTestCase {
assertTrue(hasGrandChild);
}
assertTrue(hasChild);
}
em.close();
emf.close();
}
} finally {
closeEMF(emf1);
}
}
private void runMultiEMCaching(Map props) {
EntityManagerFactory emfac = Persistence.createEntityManagerFactory("test", props);
try {
EntityManager em = emfac.createEntityManager();
//
@ -219,6 +226,9 @@ public class TestQuerySQLCache extends SingleEMFTestCase {
em.flush();
em.getTransaction().commit();
em.close();
} finally {
closeEMF(emfac);
}
}

View File

@ -54,6 +54,7 @@ extends AbstractCachedEMFTestCase {
"org/apache/openjpa/persistence/compat/" +
"persistence_1_0.xml");
try {
Compatibility compat = emf.getConfiguration().getCompatibilityInstance();
assertTrue(compat.getFlushBeforeDetach());
assertTrue(compat.getCopyOnDetach());
@ -64,8 +65,9 @@ extends AbstractCachedEMFTestCase {
Specification spec = emf.getConfiguration().getSpecificationInstance();
assertEquals("JPA", spec.getName().toUpperCase());
assertEquals(spec.getVersion(), 1);
emf.close();
} finally {
closeEMF(emf);
}
}
/*
@ -79,6 +81,7 @@ extends AbstractCachedEMFTestCase {
"org/apache/openjpa/persistence/compat/" +
"persistence_2_0.xml");
try {
Compatibility compat = emf.getConfiguration().getCompatibilityInstance();
assertFalse(compat.getFlushBeforeDetach());
assertFalse(compat.getCopyOnDetach());
@ -89,8 +92,9 @@ extends AbstractCachedEMFTestCase {
Specification spec = emf.getConfiguration().getSpecificationInstance();
assertEquals("JPA", spec.getName().toUpperCase());
assertEquals(spec.getVersion(), 2);
emf.close();
} finally {
closeEMF(emf);
}
}
/*
@ -125,7 +129,7 @@ extends AbstractCachedEMFTestCase {
em.close();
}
} finally {
emf.close();
closeEMF(emf);
}
}
@ -194,7 +198,7 @@ extends AbstractCachedEMFTestCase {
fail("OneToMany mapping failed with exception message: " + e.getMessage());
} finally {
em.close();
emf.close();
closeEMF(emf);
}
}