From c95593d8e255e351127a24efcde2bc33fb0b055a Mon Sep 17 00:00:00 2001 From: Milosz Tylenda Date: Sat, 17 Oct 2009 14:49:54 +0000 Subject: [PATCH] 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@826264 13f79535-47bb-0310-9956-ffa450edef68 --- .../kernel/TestEJBGetObjectByIdValue.java | 15 +++++----- .../persistence/kernel/TestEJBInterfaces.java | 28 +++++++++---------- .../persistence/kernel/TestEJBLocales.java | 6 ++-- .../persistence/kernel/TestEJBNullValues.java | 4 +-- .../persistence/kernel/TestEJBState.java | 6 ++-- ...joWithoutAnnotationsCannotBePersisted.java | 14 +++++----- 6 files changed, 35 insertions(+), 38 deletions(-) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBGetObjectByIdValue.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBGetObjectByIdValue.java index a807c6ce1..778a37c16 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBGetObjectByIdValue.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBGetObjectByIdValue.java @@ -23,19 +23,18 @@ import javax.persistence.EntityManager; import org.apache.openjpa.persistence.kernel.common.apps.AImplB; import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1; +import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest2; +import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest3; import org.apache.openjpa.persistence.common.utils.AbstractTestCase; public class TestEJBGetObjectByIdValue extends AbstractTestCase { - private Object[] oids; - public TestEJBGetObjectByIdValue(String name) { super(name, "kernelcactusapp"); } public void setUp() throws Exception { - deleteAll(RuntimeTest1.class); - deleteAll(AImplB.class); + super.setUp(RuntimeTest1.class, RuntimeTest2.class, RuntimeTest3.class, AImplB.class); EntityManager em = currentEntityManager(); startTx(em); @@ -56,12 +55,12 @@ public class TestEJBGetObjectByIdValue extends AbstractTestCase { endEm(em); em = currentEntityManager(); - pc = (RuntimeTest1) em.find(RuntimeTest1.class, 1); + pc = em.find(RuntimeTest1.class, 1); assertEquals("foo", pc.getStringField()); em.close(); em = currentEntityManager(); - pc = (RuntimeTest1) em.find(RuntimeTest1.class, pc.getIntField()); + pc = em.find(RuntimeTest1.class, pc.getIntField()); assertEquals("foo", pc.getStringField()); endEm(em); } @@ -78,12 +77,12 @@ public class TestEJBGetObjectByIdValue extends AbstractTestCase { endEm(em); em = currentEntityManager(); - pc = (AImplB) em.find(AImplB.class, oid); + pc = em.find(AImplB.class, oid); assertEquals("foo", pc.getName()); endEm(em); em = currentEntityManager(); - pc = (AImplB) em.find(AImplB.class, oid.toString()); + pc = em.find(AImplB.class, oid.toString()); assertEquals("foo", pc.getName()); endEm(em); } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBInterfaces.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBInterfaces.java index e58b29863..eaea742b1 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBInterfaces.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBInterfaces.java @@ -24,6 +24,7 @@ import javax.persistence.EntityManager; import org.apache.openjpa.persistence.kernel.common.apps.InterfaceHolder; import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl1; import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl2; +import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl3; import org.apache.openjpa.persistence.common.utils.AbstractTestCase; /** @@ -37,16 +38,14 @@ public class TestEJBInterfaces extends AbstractTestCase { super(name, "kernelcactusapp"); } + @Override + public void setUp() throws Exception { + super.setUp(InterfaceTestImpl1.class, InterfaceTestImpl2.class, InterfaceTestImpl3.class, + InterfaceHolder.class); + } + @SuppressWarnings("unchecked") public void testInterfaceField() { - try { - deleteAll(InterfaceTestImpl1.class); - deleteAll(InterfaceTestImpl2.class); - deleteAll(InterfaceHolder.class); - } - catch (Exception e) { - } - EntityManager em2 = currentEntityManager(); startTx(em2); @@ -65,8 +64,7 @@ public class TestEJBInterfaces extends AbstractTestCase { em = currentEntityManager(); startTx(em); - InterfaceHolder hold = - (InterfaceHolder) em.find(InterfaceHolder.class, 1); + InterfaceHolder hold = em.find(InterfaceHolder.class, 1); assertNotNull(hold.getIntf()); assertEquals("intf-1-field", hold.getIntf().getStringField()); endTx(em); @@ -74,7 +72,7 @@ public class TestEJBInterfaces extends AbstractTestCase { em = currentEntityManager(); startTx(em); - hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); + hold = em.find(InterfaceHolder.class, 1); hold.setIntf(null); assertNull(hold.getIntf()); endTx(em); @@ -82,14 +80,14 @@ public class TestEJBInterfaces extends AbstractTestCase { em = currentEntityManager(); startTx(em); - hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); + hold = em.find(InterfaceHolder.class, 1); assertNull(hold.getIntf()); endTx(em); endEm(em); em = currentEntityManager(); startTx(em); - hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); + hold = em.find(InterfaceHolder.class, 1); hold.setIntf(new InterfaceTestImpl2("intf-2-field")); assertEquals("intf-2-field", hold.getIntf().getStringField()); endTx(em); @@ -97,7 +95,7 @@ public class TestEJBInterfaces extends AbstractTestCase { em = currentEntityManager(); startTx(em); - hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); + hold = em.find(InterfaceHolder.class, 1); assertNotNull(hold.getIntf()); assertEquals("intf-2-field", hold.getIntf().getStringField()); endTx(em); @@ -105,7 +103,7 @@ public class TestEJBInterfaces extends AbstractTestCase { em = currentEntityManager(); startTx(em); - hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); + hold = em.find(InterfaceHolder.class, 1); hold.getIntfs().add(new InterfaceTestImpl1("intf-1-set")); endTx(em); endEm(em); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLocales.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLocales.java index 478c0414a..a973c1f80 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLocales.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLocales.java @@ -25,6 +25,8 @@ import javax.persistence.EntityManager; import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1; +import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest2; +import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest3; import org.apache.openjpa.persistence.common.utils.AbstractTestCase; public class TestEJBLocales extends AbstractTestCase { @@ -33,8 +35,8 @@ public class TestEJBLocales extends AbstractTestCase { super(name, "kernelcactusapp"); } - public void setUp() { - deleteAll(RuntimeTest1.class); + public void setUp() throws Exception { + super.setUp(RuntimeTest1.class, RuntimeTest2.class, RuntimeTest3.class); } public void testLocales() { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNullValues.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNullValues.java index aff968bca..04c834a39 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNullValues.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNullValues.java @@ -30,8 +30,8 @@ public class TestEJBNullValues extends AbstractTestCase { super(name, "kernelcactusapp"); } - public void setUp() { - deleteAll(Inner.class); + public void setUp() throws Exception { + super.setUp(Inner.class); } public void testException() { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBState.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBState.java index 747d17baa..406cf9d13 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBState.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBState.java @@ -27,14 +27,12 @@ import org.apache.openjpa.persistence.common.utils.AbstractTestCase; public class TestEJBState extends AbstractTestCase { - private static final int INSERT_COUNT = 20; - public TestEJBState(String name) { super(name, "kernelcactusapp"); } - public void setUp() { - deleteAll(AllFieldsTypeTest.class); + public void setUp() throws Exception { + super.setUp(AllFieldsTypeTest.class); } public void testBigDecimalsLoseTrailingZeros() { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPojoWithoutAnnotationsCannotBePersisted.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPojoWithoutAnnotationsCannotBePersisted.java index 34d9d5e3c..66993880c 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPojoWithoutAnnotationsCannotBePersisted.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPojoWithoutAnnotationsCannotBePersisted.java @@ -20,14 +20,13 @@ package org.apache.openjpa.persistence.kernel; import javax.persistence.EntityManager; - -import org.apache.openjpa.persistence.kernel.common.apps.UnAnnotPojo; import org.apache.openjpa.persistence.common.utils.AbstractTestCase; -/* - * @author Afam Okeke - * Ensures that pojo that is not persistent capable cannot be persisted. - */ +import org.apache.openjpa.persistence.kernel.common.apps.UnAnnotPojo; +/** + * Ensures that pojo that is not persistent capable cannot be persisted. + * @author Afam Okeke + */ public class TestPojoWithoutAnnotationsCannotBePersisted extends AbstractTestCase { @@ -37,7 +36,8 @@ public class TestPojoWithoutAnnotationsCannotBePersisted super(name, "kernelcactusapp"); } - public void setUp() { + public void setUp() throws Exception { + super.setUp(new Object[] {}); pojo = new UnAnnotPojo(); pojo.setName("failure"); pojo.setNum(0);