From dc662be961c270ec186ab863c837e4279e1d0131 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Fri, 25 May 2012 20:28:30 +0000 Subject: [PATCH] OPENJPA-2095 - JUnit 4 treats Test*.class as test case. Otherwise the following exception will be observed. java.lang.IllegalArgumentException: Test class can only have one constructor at org.junit.runners.model.TestClass.(TestClass.java:32) at org.junit.runners.ParentRunner.(ParentRunner.java:54) Rename entity classes prefix Test* to avoid the problem. git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@1342800 13f79535-47bb-0310-9956-ffa450edef68 --- .../persistence/jdbc/TestTimestampPKDeletion.java | 12 ++++++------ ...alizer.java => EntityWithFailedExternalizer.java} | 8 +++----- .../kernel/TestBatchFlushWithMetadataException.java | 10 +++++----- ...thTimestampPK.java => EntityWithTimestampPK.java} | 6 +++--- 4 files changed, 17 insertions(+), 19 deletions(-) rename openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/{TestItemWithFailedExternalizer.java => EntityWithFailedExternalizer.java} (90%) rename openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/{TestEntityWithTimestampPK.java => EntityWithTimestampPK.java} (91%) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestTimestampPKDeletion.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestTimestampPKDeletion.java index 4fa5da24b..dcf309bd6 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestTimestampPKDeletion.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestTimestampPKDeletion.java @@ -24,17 +24,17 @@ import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import javax.persistence.Query; -import org.apache.openjpa.persistence.simple.TestEntityWithTimestampPK; +import org.apache.openjpa.persistence.simple.EntityWithTimestampPK; import org.apache.openjpa.persistence.test.SQLListenerTestCase; public class TestTimestampPKDeletion extends SQLListenerTestCase { public void setUp() { - setUp(TestEntityWithTimestampPK.class); + setUp(EntityWithTimestampPK.class); } public void testTimestampPKDeletion() { - TestEntityWithTimestampPK testEntity = new TestEntityWithTimestampPK("test"); + EntityWithTimestampPK testEntity = new EntityWithTimestampPK("test"); EntityManager em = emf.createEntityManager(); @@ -46,10 +46,10 @@ public class TestTimestampPKDeletion extends SQLListenerTestCase { em = emf.createEntityManager(); final EntityTransaction tx = em.getTransaction(); tx.begin(); - final Query q = em.createQuery("SELECT testEntity FROM TestEntityWithTimestampPK testEntity "); + final Query q = em.createQuery("SELECT testEntity FROM EntityWithTimestampPK testEntity "); - final List testEntities = q.getResultList(); - for (TestEntityWithTimestampPK t : testEntities) { + final List testEntities = q.getResultList(); + for (EntityWithTimestampPK t : testEntities) { em.remove(t); } tx.commit(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/TestItemWithFailedExternalizer.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java similarity index 90% rename from openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/TestItemWithFailedExternalizer.java rename to openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java index a7609cac6..f60b1b5c9 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/TestItemWithFailedExternalizer.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java @@ -23,11 +23,9 @@ import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.PersistenceException; -import javax.persistence.Table; @Entity -@Table(name="TestItemWithFailedExternalizer") -public class TestItemWithFailedExternalizer implements Serializable { +public class EntityWithFailedExternalizer implements Serializable { private static final long serialVersionUID = 1L; @@ -73,11 +71,11 @@ public class TestItemWithFailedExternalizer implements Serializable { } } - public TestItemWithFailedExternalizer() { + public EntityWithFailedExternalizer() { super(); } - public TestItemWithFailedExternalizer(int iref, String name, String data) { + public EntityWithFailedExternalizer(int iref, String name, String data) { super(); this.iref = iref; this.name = name; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java index ff613e4a7..d1064f83c 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java @@ -24,7 +24,7 @@ import javax.persistence.EntityTransaction; import org.apache.openjpa.persistence.PersistenceException; import org.apache.openjpa.persistence.RollbackException; -import org.apache.openjpa.persistence.jdbc.common.apps.TestItemWithFailedExternalizer; +import org.apache.openjpa.persistence.jdbc.common.apps.EntityWithFailedExternalizer; import org.apache.openjpa.persistence.test.SQLListenerTestCase; /* @@ -35,7 +35,7 @@ public class TestBatchFlushWithMetadataException extends SQLListenerTestCase { @Override public void setUp() throws Exception { - setUp(DROP_TABLES, TestItemWithFailedExternalizer.class); + setUp(DROP_TABLES, EntityWithFailedExternalizer.class); } public void testCreate(){ @@ -43,10 +43,10 @@ public class TestBatchFlushWithMetadataException extends SQLListenerTestCase { EntityTransaction tx = em.getTransaction(); tx.begin(); - TestItemWithFailedExternalizer item1 = new TestItemWithFailedExternalizer(1001, "MyName1", "description1"); - TestItemWithFailedExternalizer item2 = new TestItemWithFailedExternalizer(1002, "MyName2", "description2"); + EntityWithFailedExternalizer item1 = new EntityWithFailedExternalizer(1001, "MyName1", "description1"); + EntityWithFailedExternalizer item2 = new EntityWithFailedExternalizer(1002, "MyName2", "description2"); item1.getExt().throwEx=true; - TestItemWithFailedExternalizer item3 = new TestItemWithFailedExternalizer(1003, "MyName3", "description3"); + EntityWithFailedExternalizer item3 = new EntityWithFailedExternalizer(1003, "MyName3", "description3"); em.persist(item1); em.persist(item2); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityWithTimestampPK.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/EntityWithTimestampPK.java similarity index 91% rename from openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityWithTimestampPK.java rename to openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/EntityWithTimestampPK.java index e3bdf2818..2c2fc3af5 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityWithTimestampPK.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/EntityWithTimestampPK.java @@ -25,7 +25,7 @@ import javax.persistence.Entity; import javax.persistence.Id; @Entity -public class TestEntityWithTimestampPK { +public class EntityWithTimestampPK { @Id private Timestamp idTsp; @@ -36,13 +36,13 @@ public class TestEntityWithTimestampPK { return idTsp; } - public TestEntityWithTimestampPK(String desc) { + public EntityWithTimestampPK(String desc) { super(); this.idTsp = new Timestamp((new Date()).getTime()); this.description = desc; } - public TestEntityWithTimestampPK(){ + public EntityWithTimestampPK(){ }