From 8a17669161ffc168b4656b259b05911df1194f94 Mon Sep 17 00:00:00 2001 From: Donald Woods Date: Fri, 8 Oct 2010 21:23:20 +0000 Subject: [PATCH] minor testcase helper tweaks git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1006029 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/AbstractPersistenceTestCase.java | 22 +++++++++++++++++++ .../persistence/test/SingleEMTestCase.java | 19 ++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java index 5e5221977..cefe92409 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java @@ -46,6 +46,7 @@ import org.apache.openjpa.kernel.Broker; import org.apache.openjpa.meta.ClassMetaData; import org.apache.openjpa.persistence.JPAFacadeHelper; import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.OpenJPAPersistence; /** * Base class for Persistence TestCases. This class contains utility methods but does not maintain an EntityManager or @@ -119,6 +120,27 @@ public abstract class AbstractPersistenceTestCase extends TestCase { return oemf; } + /** + * Create an entity manager factory for persistence unit pu. Put {@link #CLEAR_TABLES} in this list to + * tell the test framework to delete all table contents before running the tests. + * + * @param props + * list of persistent types used in testing and/or configuration values in the form + * key,value,key,value... + */ + protected OpenJPAEntityManagerFactorySPI createNamedOpenJPAEMF(final String pu, + String res, Map props) { + OpenJPAEntityManagerFactorySPI oemf = null; + Map config = new HashMap(System.getProperties()); + config.putAll(props); + oemf = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(pu, res, props); + if (oemf == null) { + throw new NullPointerException("Expected an OpenJPA entity manager factory " + + "for the persistence unit named: \"" + pu + "\""); + } + return oemf; + } + protected Map getPropertiesMap(Object... props) { Map map = new HashMap(); map.put("openjpa.DynamicEnhancementAgent", "false"); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java index 74b621388..4963e0027 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java @@ -106,16 +106,21 @@ public abstract class SingleEMTestCase * @return false if the EntityManager was already closed. */ protected boolean close() { + boolean brc = false; if (em == null) - return false; + return brc; - rollback(); + try { + rollback(); - if (!em.isOpen()) - return false; - - em.close(); - return !em.isOpen(); + if (!em.isOpen()) + return brc; + } finally { + em.close(); + brc = em.isOpen(); + em = null; + } + return !brc; } /**