mirror of https://github.com/apache/openjpa.git
OPENJPA-1153: Speed tests up by using only needed entities rather than all entities from persistence.xml
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@814295 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
558446dfe9
commit
e9b5c53fd0
|
@ -67,6 +67,7 @@ import java.util.ListIterator;
|
|||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.management.IntrospectionException;
|
||||
import javax.persistence.EntityManager;
|
||||
|
@ -93,6 +94,7 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase {
|
|||
private Map<Map,OpenJPAEntityManagerFactory> emfs =
|
||||
new HashMap<Map,OpenJPAEntityManagerFactory>();
|
||||
private OpenJPAEntityManager currentEntityManager;
|
||||
private Object[] props;
|
||||
|
||||
protected enum Platform {
|
||||
EMPRESS,
|
||||
|
@ -118,6 +120,18 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase {
|
|||
persistenceXmlResource = computePersistenceXmlResource(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the given persistent types during the test.
|
||||
*
|
||||
* @param props
|
||||
* list of persistent types used in testing and/or configuration values in the form
|
||||
* key,value,key,value...
|
||||
*/
|
||||
protected void setUp(Object... props) throws Exception {
|
||||
super.setUp();
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
super.tearDown();
|
||||
|
@ -194,11 +208,25 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase {
|
|||
addProperties(map);
|
||||
|
||||
OpenJPAEntityManagerFactory emf = emfs.get(map);
|
||||
if (emf == null) {
|
||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
||||
"TestConv", persistenceXmlResource, map);
|
||||
emfs.put(map, emf);
|
||||
if (emf != null) {
|
||||
return emf;
|
||||
}
|
||||
|
||||
if (props != null) {
|
||||
// Join properties passed in setUp (usually entities) with the given map and use them to create EMF.
|
||||
Object[] propsAndMap = new Object[props.length + map.size() * 2];
|
||||
System.arraycopy(props, 0, propsAndMap, 0, props.length);
|
||||
int i = props.length;
|
||||
for (Object o : map.entrySet()) {
|
||||
Entry mapEntry = (Entry) o;
|
||||
propsAndMap[i++] = mapEntry.getKey();
|
||||
propsAndMap[i++] = mapEntry.getValue();
|
||||
}
|
||||
emf = createEMF(propsAndMap);
|
||||
} else {
|
||||
emf = OpenJPAPersistence.createEntityManagerFactory("TestConv", persistenceXmlResource, map);
|
||||
}
|
||||
emfs.put(map, emf);
|
||||
return emf;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ public class TestCalendarFields extends BaseKernelTest {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
deleteAll(CalendarFields.class);
|
||||
public void setUp() throws Exception {
|
||||
super.setUp(CalendarFields.class);
|
||||
}
|
||||
|
||||
public void testFieldDefaultTimeZone() {
|
||||
|
@ -67,7 +67,7 @@ public class TestCalendarFields extends BaseKernelTest {
|
|||
endEm(pm);
|
||||
|
||||
pm = getPM();
|
||||
cal = (CalendarFields) pm.find(CalendarFields.class, id);
|
||||
cal = pm.find(CalendarFields.class, id);
|
||||
assertEquals(TimeZone.getTimeZone("Asia/Singapore"),
|
||||
cal.getSingapore().getTimeZone());
|
||||
endEm(pm);
|
||||
|
@ -90,9 +90,9 @@ public class TestCalendarFields extends BaseKernelTest {
|
|||
endEm(pm);
|
||||
|
||||
pm = getPM();
|
||||
c2 = (CalendarFields) pm.find(CalendarFields.class, id2);
|
||||
c2 = pm.find(CalendarFields.class, id2);
|
||||
assertTimeZonesEquals(c1, c2);
|
||||
assertTimeZonesEquals(c1, (CalendarFields) pm.detachCopy(c2));
|
||||
assertTimeZonesEquals(c1, pm.detachCopy(c2));
|
||||
endEm(pm);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ public class TestCheckConsistency extends BaseKernelTest {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
deleteAll(RuntimeTest1.class);
|
||||
public void setUp() throws Exception {
|
||||
super.setUp(RuntimeTest1.class);
|
||||
|
||||
RuntimeTest1 pc = new RuntimeTest1();
|
||||
pc.setIntField(1);
|
||||
|
@ -61,7 +61,7 @@ public class TestCheckConsistency extends BaseKernelTest {
|
|||
pm.validateChanges(); // no-op outside trans
|
||||
startTx(pm);
|
||||
|
||||
RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
|
||||
RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
|
||||
pc.setIntField1(100);
|
||||
|
||||
RuntimeTest1 npc = new RuntimeTest1();
|
||||
|
@ -89,7 +89,7 @@ public class TestCheckConsistency extends BaseKernelTest {
|
|||
pm.validateChanges(); // no-op outside trans
|
||||
startTx(pm);
|
||||
|
||||
RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
|
||||
RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
|
||||
pc.setIntField1(100);
|
||||
|
||||
RuntimeTest1 npc = new RuntimeTest1();
|
||||
|
@ -112,7 +112,7 @@ public class TestCheckConsistency extends BaseKernelTest {
|
|||
pm = getPM();
|
||||
try {
|
||||
RuntimeTest1 temp =
|
||||
(RuntimeTest1) pm.find(RuntimeTest1.class, noid);
|
||||
pm.find(RuntimeTest1.class, noid);
|
||||
fail("Object should not exist." + temp.getIntField() + "::" +
|
||||
temp.getIntField1());
|
||||
} catch (Exception jonfe) {
|
||||
|
@ -176,7 +176,7 @@ try {
|
|||
startTx(pm);
|
||||
boolean hasConn = hasConnection(pm);
|
||||
|
||||
RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
|
||||
RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
|
||||
pc.setIntField1(100);
|
||||
|
||||
RuntimeTest1 npc = new RuntimeTest1();
|
||||
|
@ -212,7 +212,7 @@ try {
|
|||
startTx(pm);
|
||||
boolean hasConn = hasConnection(pm);
|
||||
|
||||
RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
|
||||
RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
|
||||
pc.setIntField1(100);
|
||||
|
||||
RuntimeTest1 npc = new RuntimeTest1();
|
||||
|
@ -238,7 +238,7 @@ try {
|
|||
pm = getPM();
|
||||
try {
|
||||
RuntimeTest1 temp =
|
||||
(RuntimeTest1) pm.find(RuntimeTest1.class, noid);
|
||||
pm.find(RuntimeTest1.class, noid);
|
||||
|
||||
fail("Object should not exist." + temp.getIntField() + "::" +
|
||||
temp.getIntField1());
|
||||
|
|
|
@ -41,8 +41,8 @@ public class TestClassStringConstructor extends BaseKernelTest {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
deleteAll(AppIdClassString.class);
|
||||
public void setUp() throws Exception {
|
||||
super.setUp(AppIdClassString.class);
|
||||
}
|
||||
|
||||
public void testConstructor() {
|
||||
|
|
|
@ -60,7 +60,7 @@ public class TestDateQueries extends BaseKernelTest {
|
|||
|
||||
public void setUp()
|
||||
throws Exception {
|
||||
super.setUp();
|
||||
super.setUp(AllFieldTypesTest.class);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MMMMM dd, yyyy",
|
||||
Locale.US);
|
||||
|
@ -69,9 +69,6 @@ public class TestDateQueries extends BaseKernelTest {
|
|||
_after = sdf.parse("April 27, 1978");
|
||||
_pm = getPM();
|
||||
|
||||
// delete all existing instances
|
||||
deleteAll(AllFieldTypesTest.class);
|
||||
|
||||
// create some instances to query on
|
||||
startTx(_pm);
|
||||
AllFieldTypesTest test = new AllFieldTypesTest();
|
||||
|
|
|
@ -52,8 +52,8 @@ public class TestExtents extends BaseKernelTest {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
deleteAll(RuntimeTest1.class);
|
||||
public void setUp() throws Exception {
|
||||
super.setUp(RuntimeTest1.class, RuntimeTest2.class);
|
||||
|
||||
OpenJPAEntityManager pm = getPM();
|
||||
startTx(pm);
|
||||
|
@ -101,7 +101,7 @@ public class TestExtents extends BaseKernelTest {
|
|||
|
||||
public void testExtent4() {
|
||||
OpenJPAEntityManager pm = getPM();
|
||||
Extent ext = (Extent) pm.createExtent(RuntimeTest1.class, true);
|
||||
Extent ext = pm.createExtent(RuntimeTest1.class, true);
|
||||
|
||||
List all = new LinkedList();
|
||||
for (Iterator i = ext.iterator(); i.hasNext();)
|
||||
|
|
|
@ -54,8 +54,8 @@ public class TestExtents2 extends BaseKernelTest {
|
|||
public TestExtents2() {
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
deleteAll(RuntimeTest1.class);
|
||||
public void setUp() throws Exception {
|
||||
super.setUp(RuntimeTest1.class, RuntimeTest2.class, RuntimeTest3.class);
|
||||
|
||||
RuntimeTest1 test1 = new RuntimeTest1();
|
||||
test1.setIntField(1);
|
||||
|
@ -170,7 +170,7 @@ public class TestExtents2 extends BaseKernelTest {
|
|||
startTx(pm);
|
||||
try {
|
||||
RuntimeTest2 test2 =
|
||||
(RuntimeTest2) pm.find(RuntimeTest2.class, _oid2);
|
||||
pm.find(RuntimeTest2.class, _oid2);
|
||||
pm.remove(test2);
|
||||
RuntimeTest1 test1 = new RuntimeTest1();
|
||||
pm.persist(test1);
|
||||
|
|
Loading…
Reference in New Issue