Refactor write behind testcase to use static EMFs.

modified:   openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/writebehind/AbstractWriteBehindTestCase.java

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@802261 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2009-08-07 22:45:35 +00:00
parent 3b327b5fbb
commit 1b769e629c
1 changed files with 20 additions and 17 deletions

View File

@ -25,12 +25,13 @@ import org.apache.openjpa.jdbc.writebehind.entities.AbstractSimpleEntity;
import org.apache.openjpa.jdbc.writebehind.entities.SimpleNonGeneratedIdEntity; import org.apache.openjpa.jdbc.writebehind.entities.SimpleNonGeneratedIdEntity;
import org.apache.openjpa.jdbc.writebehind.entities.SimpleTableGeneratedIdEntity; import org.apache.openjpa.jdbc.writebehind.entities.SimpleTableGeneratedIdEntity;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.test.SingleEMTestCase; import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
import org.apache.openjpa.persistence.test.PersistenceTestCase;
import org.apache.openjpa.writebehind.WriteBehindCache; import org.apache.openjpa.writebehind.WriteBehindCache;
import org.apache.openjpa.writebehind.WriteBehindCacheManager; import org.apache.openjpa.writebehind.WriteBehindCacheManager;
import org.apache.openjpa.writebehind.WriteBehindCallback; import org.apache.openjpa.writebehind.WriteBehindCallback;
public abstract class AbstractWriteBehindTestCase extends SingleEMTestCase { public abstract class AbstractWriteBehindTestCase extends PersistenceTestCase {
protected static Object[] writeBehindProps = protected static Object[] writeBehindProps =
new Object[] { new Object[] {
"openjpa.DataCache", "true", "openjpa.DataCache", "true",
@ -47,17 +48,27 @@ public abstract class AbstractWriteBehindTestCase extends SingleEMTestCase {
SimpleNonGeneratedIdEntity.class, SimpleTableGeneratedIdEntity.class, SimpleNonGeneratedIdEntity.class, SimpleTableGeneratedIdEntity.class,
AbstractSimpleEntity.class }; AbstractSimpleEntity.class };
protected EntityManagerFactory _validatorEMF = null; protected static OpenJPAEntityManagerFactorySPI _validatorEMF = null;
protected static OpenJPAEntityManagerFactorySPI emf = null;
protected OpenJPAEntityManagerSPI em = null;
public void setUp() { public void setUp() throws Exception {
super.setUp();
if(emf == null) { if(emf == null) {
super.setUp(writeBehindProps); emf = createEMF(writeBehindProps);
} }
if(_validatorEMF == null) { if(_validatorEMF == null) {
_validatorEMF = createEMF(validatorProps); _validatorEMF = createEMF(validatorProps);
} }
em = emf.createEntityManager();
} }
public void tearDown() throws Exception {
em.close();
super.tearDown();
}
public static Object[] getDefaultWriteBehindProperties() { public static Object[] getDefaultWriteBehindProperties() {
return writeBehindProps; return writeBehindProps;
} }
@ -66,10 +77,8 @@ public abstract class AbstractWriteBehindTestCase extends SingleEMTestCase {
return getWBCacheManager(emf); return getWBCacheManager(emf);
} }
protected WriteBehindCacheManager getWBCacheManager( protected WriteBehindCacheManager getWBCacheManager(OpenJPAEntityManagerFactorySPI factory) {
OpenJPAEntityManagerFactorySPI factory) { WriteBehindCacheManager wbcm = factory.getConfiguration().getWriteBehindCacheManagerInstance();
WriteBehindCacheManager wbcm =
factory.getConfiguration().getWriteBehindCacheManagerInstance();
return wbcm; return wbcm;
} }
@ -91,8 +100,7 @@ public abstract class AbstractWriteBehindTestCase extends SingleEMTestCase {
return factory.getConfiguration().getWriteBehindCallbackInstance(); return factory.getConfiguration().getWriteBehindCallbackInstance();
} }
protected WriteBehindCache getWBCache( protected WriteBehindCache getWBCache(OpenJPAEntityManagerFactorySPI factory, String name) {
OpenJPAEntityManagerFactorySPI factory, String name) {
WriteBehindCache wbc = null; WriteBehindCache wbc = null;
if (StringUtils.isEmpty(name)) { if (StringUtils.isEmpty(name)) {
wbc = getWBCacheManager(factory).getSystemWriteBehindCache(); wbc = getWBCacheManager(factory).getSystemWriteBehindCache();
@ -101,13 +109,8 @@ public abstract class AbstractWriteBehindTestCase extends SingleEMTestCase {
} }
return wbc; return wbc;
} }
protected EntityManagerFactory getValidatorEMF() { protected EntityManagerFactory getValidatorEMF() {
return _validatorEMF; return _validatorEMF;
} }
public void tearDown() throws Exception {
// intentionally skip super.tearDown()
}
} }