openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1535839 - in /openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test: java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java resources/META-INF/openjpa2018.xml
Date Fri, 25 Oct 2013 19:45:08 GMT
Author: struberg
Date: Fri Oct 25 19:45:08 2013
New Revision: 1535839

URL: http://svn.apache.org/r1535839
Log:
OPENJPA-2018 improve unit test setup

Removed:
    openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/resources/META-INF/openjpa2018.xml
Modified:
    openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java

Modified: openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java?rev=1535839&r1=1535838&r2=1535839&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java
(original)
+++ openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java
Fri Oct 25 19:45:08 2013
@@ -18,12 +18,8 @@
  */
 package org.apache.openjpa.openjpa2018;
 
-import junit.framework.TestCase;
-import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
 
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
 import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
@@ -33,87 +29,87 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
-public class OpenJPA2018Test extends TestCase {
-    private EntityManager em;
-    private EntityTransaction transaction;
-    private EntityManagerFactory factory;
+public class OpenJPA2018Test extends SingleEMTestCase
+{
 
     @Override
     public void setUp() {
-        factory = OpenJPAPersistence.createEntityManagerFactory("openjpa2018", "META-INF/openjpa2018.xml");
-        em = factory.createEntityManager();
-        transaction = em.getTransaction();
-        transaction.begin();
-    }
-
-    @Override
-    public void tearDown() {
-        transaction.rollback();
-        em.close();
-        factory.close();
+        super.setUp(User2018.class, CLEAR_TABLES);
     }
 
     public void testInCriteriaWithArray() {
-
-        User2018 user = new User2018();
-        em.persist(user);
-        em.flush();
-
-        CriteriaBuilder builder = em.getCriteriaBuilder();
-
-        CriteriaQuery<User2018> criteria = builder.createQuery(User2018.class);
-        Root<User2018> root = criteria.from(User2018.class);
-        criteria.where(root.get("id").in(builder.parameter(Long[].class)));
-
-        TypedQuery<User2018> query = em.createQuery(criteria);
-        for (ParameterExpression parameter : criteria.getParameters()) {
-            query.setParameter(parameter, new Long[] { user.id });
+        em.getTransaction().begin();
+        try {
+            User2018 user = new User2018();
+            em.persist(user);
+            em.flush();
+
+            CriteriaBuilder builder = em.getCriteriaBuilder();
+
+            CriteriaQuery<User2018> criteria = builder.createQuery(User2018.class);
+            Root<User2018> root = criteria.from(User2018.class);
+            criteria.where(root.get("id").in(builder.parameter(Long[].class)));
+
+            TypedQuery<User2018> query = em.createQuery(criteria);
+            for (ParameterExpression parameter : criteria.getParameters()) {
+                query.setParameter(parameter, new Long[] { user.id });
+            }
+
+            List<User2018> result = query.getResultList();
+            assertTrue(!result.isEmpty());
+        } finally {
+            em.getTransaction().commit();
         }
-
-        List<User2018> result = query.getResultList();
-        assertTrue(!result.isEmpty());
     }
 
     public void testInCriteriaWithCollection() {
-
-        User2018 user = new User2018();
-        em.persist(user);
-        em.flush();
-
-        CriteriaBuilder builder = em.getCriteriaBuilder();
-
-        CriteriaQuery<User2018> criteria = builder.createQuery(User2018.class);
-        Root<User2018> root = criteria.from(User2018.class);
-        criteria.where(root.get("id").in(builder.parameter(Collection.class)));
-
-        TypedQuery<User2018> query = em.createQuery(criteria);
-        for (ParameterExpression parameter : criteria.getParameters()) {
-            query.setParameter(parameter, Arrays.asList(user.id));
+        em.getTransaction().begin();
+        try {
+            User2018 user = new User2018();
+            em.persist(user);
+            em.flush();
+
+            CriteriaBuilder builder = em.getCriteriaBuilder();
+
+            CriteriaQuery<User2018> criteria = builder.createQuery(User2018.class);
+            Root<User2018> root = criteria.from(User2018.class);
+            criteria.where(root.get("id").in(builder.parameter(Collection.class)));
+
+            TypedQuery<User2018> query = em.createQuery(criteria);
+            for (ParameterExpression parameter : criteria.getParameters()) {
+                query.setParameter(parameter, Arrays.asList(user.id));
+            }
+
+            List<User2018> result = query.getResultList();
+            assertTrue(!result.isEmpty());
+        } finally {
+            em.getTransaction().commit();
         }
-
-        List<User2018> result = query.getResultList();
-        assertTrue(!result.isEmpty());
     }
 
     public void testId() {
-
-        User2018 user = new User2018();
-        em.persist(user);
-        em.flush();
-
-        CriteriaBuilder builder = em.getCriteriaBuilder();
-
-        CriteriaQuery<User2018> criteria = builder.createQuery(User2018.class);
-        Root<User2018> root = criteria.from(User2018.class);
-        criteria.where(builder.equal(root.get("id"), user.id));
-
-        TypedQuery<User2018> query = em.createQuery(criteria);
-        for (ParameterExpression parameter : criteria.getParameters()) {
-            query.setParameter(parameter, user.id);
+        em.getTransaction().begin();
+        try {
+            User2018 user = new User2018();
+            em.persist(user);
+            em.flush();
+
+            CriteriaBuilder builder = em.getCriteriaBuilder();
+
+            CriteriaQuery<User2018> criteria = builder.createQuery(User2018.class);
+            Root<User2018> root = criteria.from(User2018.class);
+            criteria.where(builder.equal(root.get("id"), user.id));
+
+            TypedQuery<User2018> query = em.createQuery(criteria);
+            for (ParameterExpression parameter : criteria.getParameters()) {
+                query.setParameter(parameter, user.id);
+            }
+
+            List<User2018> result = query.getResultList();
+            assertTrue(!result.isEmpty());
+        } finally {
+            em.getTransaction().commit();
         }
-
-        List<User2018> result = query.getResultList();
-        assertTrue(!result.isEmpty());
     }
 
 }



Mime
View raw message