openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [openjpa] 04/04: test cleanup
Date Sat, 02 Feb 2019 11:09:49 GMT
This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit 25cde67172b9fb9f8e11a0db0cd77a05fe3a31ad
Author: Mark Struberg <struberg@apache.org>
AuthorDate: Sat Feb 2 12:08:57 2019 +0100

    test cleanup
    
    * remove unused methods
    * fix formatting
    * delete entries owt we will randomly blow up
---
 .../TestTemporalTypeQueryParameterBinding.java     | 278 ++++++++++-----------
 .../jpql/clauses/TestEJBQueryInterface.java        |   7 +-
 .../persistence/query/TestEJBQueryInterface.java   |   8 +-
 3 files changed, 139 insertions(+), 154 deletions(-)

diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestTemporalTypeQueryParameterBinding.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestTemporalTypeQueryParameterBinding.java
index 8dfe367..e6108d9 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestTemporalTypeQueryParameterBinding.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestTemporalTypeQueryParameterBinding.java
@@ -44,33 +44,32 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
  *
  */
 public class TestTemporalTypeQueryParameterBinding extends SingleEMFTestCase {
-	private static Calendar PARAM_CALENDAR = Calendar.getInstance();
-	private  static long T1 = PARAM_CALENDAR.getTimeInMillis();
-	private  static long T2 = T1 + 2000;
-	private  static long T3 = T1 + 3000;
-
-	private static Date     VALUE_DATE     = new Date(T1);
-	private static Time     VALUE_TIME     = new Time(T2);
-	private static Timestamp VALUE_TSTAMP   = new Timestamp(T3);
-
-
-	private static String JPQL_NAMED  =
-		"SELECT p FROM TimeKeeper p " +
-		"WHERE p.date=:d AND p.time=:t AND p.tstamp=:ts";
-	private static String JPQL_POSITIONAL  =
-		"SELECT p FROM TimeKeeper p " +
-		"WHERE p.date=?1 AND p.time=?2 AND p.tstamp=?3";
-
-	private EntityManager em;
-	@Override
-	public void setUp() throws Exception {
-		super.setUp(CLEAR_TABLES, TimeKeeper.class, TimeEntity.class);
-		em = emf.createEntityManager();
-
-		TimeKeeper pc = new TimeKeeper();
-		pc.setDate(VALUE_DATE);
-		pc.setTime(VALUE_TIME);
-		pc.setTstamp(VALUE_TSTAMP);
+    private static Calendar PARAM_CALENDAR = Calendar.getInstance();
+    private  static long T1 = PARAM_CALENDAR.getTimeInMillis();
+    private  static long T2 = T1 + 2000;
+    private  static long T3 = T1 + 3000;
+
+    private static Date     VALUE_DATE     = new Date(T1);
+    private static Time     VALUE_TIME     = new Time(T2);
+    private static Timestamp VALUE_TSTAMP   = new Timestamp(T3);
+
+
+    private static String JPQL_NAMED  =
+        "SELECT p FROM TimeKeeper p WHERE p.date=:d AND p.time=:t AND p.tstamp=:ts";
+    
+    private static String JPQL_POSITIONAL  =
+        "SELECT p FROM TimeKeeper p WHERE p.date=?1 AND p.time=?2 AND p.tstamp=?3";
+
+    private EntityManager em;
+    @Override
+    public void setUp() throws Exception {
+        super.setUp(CLEAR_TABLES, TimeKeeper.class, TimeEntity.class);
+        em = emf.createEntityManager();
+
+        TimeKeeper pc = new TimeKeeper();
+        pc.setDate(VALUE_DATE);
+        pc.setTime(VALUE_TIME);
+        pc.setTstamp(VALUE_TSTAMP);
 
         TimeEntity te = new TimeEntity();
         te.setName("name1");
@@ -78,112 +77,112 @@ public class TestTemporalTypeQueryParameterBinding extends SingleEMFTestCase
{
         te.setCal2Timestamp(PARAM_CALENDAR);
         te.setCal2Time(PARAM_CALENDAR);
         te.setCal2Date(PARAM_CALENDAR);
-		te.setUDate2SDate(VALUE_DATE);
-		te.setUDate2Time(VALUE_DATE);
-		te.setUDate2Timestamp(VALUE_DATE);
-
-		em.getTransaction().begin();
-		em.persist(pc);
-		em.persist(te);
-		em.getTransaction().commit();
-	}
-
-	public void testNamedParameterConvertedFromCalendarValue() {
-		Calendar c1 = Calendar.getInstance();
-		Calendar c2 = Calendar.getInstance();
-		Calendar c3 = Calendar.getInstance();
-		c1.setTimeInMillis(T1);
-		c2.setTimeInMillis(T2);
-		c3.setTimeInMillis(T3);
-
-		Query q = em.createQuery(JPQL_NAMED);
-		q.setParameter("d",  c1, TemporalType.DATE);
-		q.setParameter("t",  c2, TemporalType.TIME);
-		q.setParameter("ts", c3, TemporalType.TIMESTAMP);
-
-		assertEquals(1, q.getResultList().size());
-	}
-
-	public void testPositionalParameterConvertedFromCalendarValue() {
-		Calendar c1 = Calendar.getInstance();
-		Calendar c2 = Calendar.getInstance();
-		Calendar c3 = Calendar.getInstance();
-		c1.setTimeInMillis(T1);
-		c2.setTimeInMillis(T2);
-		c3.setTimeInMillis(T3);
-
-		Query q = em.createQuery(JPQL_POSITIONAL);
-		q.setParameter(1,  c1, TemporalType.DATE);
-		q.setParameter(2,  c2, TemporalType.TIME);
-		q.setParameter(3,  c3, TemporalType.TIMESTAMP);
-
-		assertEquals(1, q.getResultList().size());
-	}
-	public void testNamedParameterConvertedFromDateValue() {
-		Date d1 = new Date(T1);
-		Date d2 = new Date(T2);
-		Date d3 = new Date(T3);
-
-		Query q = em.createQuery(JPQL_NAMED);
-		q.setParameter("d",  d1, TemporalType.DATE);
-		q.setParameter("t",  d2, TemporalType.TIME);
-		q.setParameter("ts", d3, TemporalType.TIMESTAMP);
-
-		assertEquals(1, q.getResultList().size());
-	}
-
-	public void testPositionalParameterConvertedFromDateValue() {
-		Date d1 = new Date(T1);
-		Date d2 = new Date(T2);
-		Date d3 = new Date(T3);
-
-		Query q = em.createQuery(JPQL_POSITIONAL);
-		q.setParameter(1,  d1, TemporalType.DATE);
-		q.setParameter(2,  d2, TemporalType.TIME);
-		q.setParameter(3,  d3, TemporalType.TIMESTAMP);
-
-		assertEquals(1, q.getResultList().size());
-	}
-
-
-	public void testNamedParameterWithMismatchedValue() {
-		Date d1 = new Date(T1);
-		Date d2 = new Date(T2);
-		Date d3 = new Date(T3);
-
-		Query q = em.createQuery(JPQL_NAMED);
-		q.setParameter("d",  d1, TemporalType.TIME);
-		q.setParameter("ts",  d2, TemporalType.TIMESTAMP);
-
-		try {
-	        q.setParameter("t",  d3, TemporalType.DATE);
-			fail("Expeceted " + ArgumentException.class.getName());
-		} catch (IllegalArgumentException ex) {
-			// good
-		}
-	}
-
-	public void testPositionalParameterWithMismatchedValue() {
-		Date d1 = new Date(T1);
-		Date d2 = new Date(T2);
-		Date d3 = new Date(T3);
-
-		Query q = em.createQuery(JPQL_POSITIONAL);
-		q.setParameter(1,  d1, TemporalType.TIME);
-
-		try {
-	        q.setParameter(2,  d2, TemporalType.TIMESTAMP);
-			fail("Expeceted " + ArgumentException.class.getName());
-		} catch (IllegalArgumentException ex) {
-		    // expected.
-		}
+        te.setUDate2SDate(VALUE_DATE);
+        te.setUDate2Time(VALUE_DATE);
+        te.setUDate2Timestamp(VALUE_DATE);
+
+        em.getTransaction().begin();
+        em.persist(pc);
+        em.persist(te);
+        em.getTransaction().commit();
+    }
+
+    public void testNamedParameterConvertedFromCalendarValue() {
+        Calendar c1 = Calendar.getInstance();
+        Calendar c2 = Calendar.getInstance();
+        Calendar c3 = Calendar.getInstance();
+        c1.setTimeInMillis(T1);
+        c2.setTimeInMillis(T2);
+        c3.setTimeInMillis(T3);
+
+        Query q = em.createQuery(JPQL_NAMED);
+        q.setParameter("d",  c1, TemporalType.DATE);
+        q.setParameter("t",  c2, TemporalType.TIME);
+        q.setParameter("ts", c3, TemporalType.TIMESTAMP);
+
+        assertEquals(1, q.getResultList().size());
+    }
+
+    public void testPositionalParameterConvertedFromCalendarValue() {
+        Calendar c1 = Calendar.getInstance();
+        Calendar c2 = Calendar.getInstance();
+        Calendar c3 = Calendar.getInstance();
+        c1.setTimeInMillis(T1);
+        c2.setTimeInMillis(T2);
+        c3.setTimeInMillis(T3);
+
+        Query q = em.createQuery(JPQL_POSITIONAL);
+        q.setParameter(1,  c1, TemporalType.DATE);
+        q.setParameter(2,  c2, TemporalType.TIME);
+        q.setParameter(3,  c3, TemporalType.TIMESTAMP);
+
+        assertEquals(1, q.getResultList().size());
+    }
+    public void testNamedParameterConvertedFromDateValue() {
+        Date d1 = new Date(T1);
+        Date d2 = new Date(T2);
+        Date d3 = new Date(T3);
+
+        Query q = em.createQuery(JPQL_NAMED);
+        q.setParameter("d",  d1, TemporalType.DATE);
+        q.setParameter("t",  d2, TemporalType.TIME);
+        q.setParameter("ts", d3, TemporalType.TIMESTAMP);
+
+        assertEquals(1, q.getResultList().size());
+    }
+
+    public void testPositionalParameterConvertedFromDateValue() {
+        Date d1 = new Date(T1);
+        Date d2 = new Date(T2);
+        Date d3 = new Date(T3);
+
+        Query q = em.createQuery(JPQL_POSITIONAL);
+        q.setParameter(1,  d1, TemporalType.DATE);
+        q.setParameter(2,  d2, TemporalType.TIME);
+        q.setParameter(3,  d3, TemporalType.TIMESTAMP);
+
+        assertEquals(1, q.getResultList().size());
+    }
+
+
+    public void testNamedParameterWithMismatchedValue() {
+        Date d1 = new Date(T1);
+        Date d2 = new Date(T2);
+        Date d3 = new Date(T3);
+
+        Query q = em.createQuery(JPQL_NAMED);
+        q.setParameter("d",  d1, TemporalType.TIME);
+        q.setParameter("ts",  d2, TemporalType.TIMESTAMP);
+
+        try {
+            q.setParameter("t",  d3, TemporalType.DATE);
+            fail("Expeceted " + ArgumentException.class.getName());
+        } catch (IllegalArgumentException ex) {
+            // good
+        }
+    }
+
+    public void testPositionalParameterWithMismatchedValue() {
+        Date d1 = new Date(T1);
+        Date d2 = new Date(T2);
+        Date d3 = new Date(T3);
+
+        Query q = em.createQuery(JPQL_POSITIONAL);
+        q.setParameter(1,  d1, TemporalType.TIME);
+
+        try {
+            q.setParameter(2,  d2, TemporalType.TIMESTAMP);
+            fail("Expeceted " + ArgumentException.class.getName());
+        } catch (IllegalArgumentException ex) {
+            // expected.
+        }
         try {
             q.setParameter(3,  d3, TemporalType.DATE);
             fail("Expeceted " + ArgumentException.class.getName());
         } catch (IllegalArgumentException ex) {
             // expected.
         }
-	}
+    }
 
     public void testTemporalType() {
         EntityManager em = emf.createEntityManager();
@@ -239,31 +238,6 @@ public class TestTemporalTypeQueryParameterBinding extends SingleEMFTestCase
{
     }
 
 
-    void verifyParams(String jpql, Class<? extends Exception> error,
-        Object... params) {
-        EntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-		Query query = em.createNativeQuery(jpql);
-		for (int i=0; params != null && i<params.length; i=+2) {
-			try {
-				if (params[i] instanceof Number) {
-                    query.setParameter(((Number) params[i]).intValue(),
-                        params[i + 1]);
-                } else {
-                    query.setParameter(params[i].toString(), params[i+1]);
-				}
-				if (error != null)
-					fail("Expected " + error.getName());
-			} catch (Exception e) {
-				if (!error.isAssignableFrom(e.getClass())) {
-				    // let the test harness handle the exception
-                    throw new RuntimeException("An unexpected exception " +
-                            "occurred see initCause for details", e);
-				}
-			}
-		}
-		em.getTransaction().commit();
-	}
 
     void assertSetTemporalParameter(Query q, int pos, Date v, TemporalType temporalType)
{
         try {
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/clauses/TestEJBQueryInterface.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/clauses/TestEJBQueryInterface.java
index a4940ac..4b3a057 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/clauses/TestEJBQueryInterface.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/clauses/TestEJBQueryInterface.java
@@ -37,11 +37,16 @@ public class TestEJBQueryInterface extends AbstractTestCase {
 
     @Override
     public void setUp() {
-        deleteAll(Entity1.class);
 
         int instNum = 10;
 
         EntityManager em = currentEntityManager();
+
+        startTx(em);
+        deleteAll(Entity1.class, em);
+        deleteAll(Entity2.class, em);
+        endTx(em);
+
         startTx(em);
 
         //create and persist multiple entity1 instances
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestEJBQueryInterface.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestEJBQueryInterface.java
index 621a081..e90c22a 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestEJBQueryInterface.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestEJBQueryInterface.java
@@ -33,11 +33,17 @@ public class TestEJBQueryInterface extends BaseQueryTest {
 
     @Override
     public void setUp() throws Exception {
-        super.setUp(Entity1.class, Entity2.class, Order.class, OrderItem.class);
+        super.setUp(Entity1.class, Entity2.class, Order.class, OrderItem.class, "openjpa.Log",
"SQL=Trace");
 
         int instNum = 10;
 
         EntityManager em = currentEntityManager();
+
+        startTx(em);
+        deleteAll(Entity1.class, em);
+        deleteAll(Entity2.class, em);
+        endTx(em);
+
         startTx(em);
 
         //create and persist multiple entity1 instances


Mime
View raw message