make sure tests close EMs and EMFs

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1022228 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2010-10-13 18:35:46 +00:00
parent 71ae858f91
commit 1a3d16a013
5 changed files with 27 additions and 12 deletions

View File

@ -24,19 +24,15 @@ import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Persistence;
import junit.framework.TestCase;
import org.apache.openjpa.jdbc.meta.MappingRepository;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
/**
* Testcase that verifies the names for Foreign Key columns is as expected.
*/
public class TestFKColumnNames extends TestCase {
public class TestFKColumnNames extends AbstractPersistenceTestCase {
OpenJPAEntityManagerFactorySPI emf =
(OpenJPAEntityManagerFactorySPI) Persistence
.createEntityManagerFactory("test");
/**
* <P>
@ -49,6 +45,9 @@ public class TestFKColumnNames extends TestCase {
* </P>
*/
public void testSQLKeywords() {
OpenJPAEntityManagerFactorySPI emf =
(OpenJPAEntityManagerFactorySPI) Persistence
.createEntityManagerFactory("test");
MappingRepository repos =
(MappingRepository) emf.getConfiguration()
.getMetaDataRepositoryInstance();
@ -58,6 +57,7 @@ public class TestFKColumnNames extends TestCase {
assertEquals("FROM_ID", repos.getMapping(Inner2.class, null, true)
.getFieldMapping("from").getColumns()[0].getName());
closeEMF(emf);
}
@Entity

View File

@ -27,28 +27,32 @@ import org.apache.openjpa.persistence.test.PersistenceTestCase;
public class TestMixedAccess extends AbstractCachedEMFTestCase {
public void testMixedAccessEntityError() {
EntityManagerFactory emf = null;
try {
EntityManagerFactory emf =
createEMF(UnenhancedMixedAccess.class, "openjpa.RuntimeUnenhancedClasses", "supported");
emf = createEMF(UnenhancedMixedAccess.class, "openjpa.RuntimeUnenhancedClasses", "supported");
emf.createEntityManager().close();
} catch (RuntimeException e) {
String msg = e.getMessage();
if (!(msg.contains("UnenhancedMixedAccess.id") &&
msg.contains("UnenhancedMixedAccess.getStringField")))
throw e;
} finally {
closeEMF(emf);
}
}
public void testInappropriateTransientError() {
EntityManagerFactory emf = null;
try {
EntityManagerFactory emf = createEMF(
UnenhancedInappropriateTransient.class, "openjpa.RuntimeUnenhancedClasses", "supported");
emf = createEMF(UnenhancedInappropriateTransient.class, "openjpa.RuntimeUnenhancedClasses", "supported");
emf.createEntityManager().close();
} catch (RuntimeException e) {
String msg = e.getMessage();
if (!(msg.contains("UnenhancedInappropriateTransient.id") &&
msg.contains("UnenhancedInappropriateTransient.prePersist")))
throw e;
}
} finally {
closeEMF(emf);
}
}
}

View File

@ -63,6 +63,7 @@ public class TestMultiColumnVersion extends SingleEMFTestCase {
em.merge(pc);
em.getTransaction().commit();
assertVersionEquals(new Number[]{2,2, 2.0f}, em.getVersion(pc));
em.close();
}
public void testConcurrentOptimisticUpdateFailsForSingleTable() {
@ -84,6 +85,7 @@ public class TestMultiColumnVersion extends SingleEMFTestCase {
pc1.setName("Updated in em1");
pc2.setName("Updated in em2");
em1.getTransaction().commit();
em1.close();
try {
em2.getTransaction().commit();
@ -111,7 +113,9 @@ public class TestMultiColumnVersion extends SingleEMFTestCase {
assertVersionEquals(em1.getVersion(pc1), em2.getVersion(pc2));
em1.getTransaction().commit();
em1.close();
em2.getTransaction().commit();
em2.close();
}
public void testVersionOnPersistAndUpdateForMultiTable() {
@ -128,6 +132,7 @@ public class TestMultiColumnVersion extends SingleEMFTestCase {
em.merge(pc);
em.getTransaction().commit();
assertVersionEquals(new Number[]{2,2,2,2}, em.getVersion(pc));
em.close();
}
public void testConcurrentOptimisticUpdateFailsForMultiTable() {
@ -150,6 +155,7 @@ public class TestMultiColumnVersion extends SingleEMFTestCase {
pc1.setName("Updated in em1");
pc2.setName("Updated in em2");
em1.getTransaction().commit();
em1.close();
try {
em2.getTransaction().commit();
@ -178,7 +184,9 @@ public class TestMultiColumnVersion extends SingleEMFTestCase {
assertVersionEquals(em1.getVersion(pc1), em2.getVersion(pc2));
em1.getTransaction().commit();
em1.close();
em2.getTransaction().commit();
em2.close();
}
static void assertVersionEquals(Object expected, Object actual) {

View File

@ -346,4 +346,5 @@ public class TestNonstandardMappingAnnotations
}
em.close();
}}
}
}

View File

@ -47,6 +47,7 @@ public class TestPropertyAccess
assertNotNull(pa1_2);
assertEquals(10, pa1_2.getId());
assertEquals("foo", pa1_2.getName());
em.close();
}
public void testPropertyAccessBasicMutation() {
@ -70,6 +71,7 @@ public class TestPropertyAccess
PropertyAccess1 pa1_3 = em.find(PropertyAccess1.class, 10);
assertNotSame(pa1_2, pa1_3);
assertEquals("foobar", pa1_3.getName());
em.close();
}
public void testJPQL() {