diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java index 87ff2564f..a2ecce259 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/openjpa2018/OpenJPA2018Test.java @@ -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() { + em.getTransaction().begin(); + try { + User2018 user = new User2018(); + em.persist(user); + em.flush(); - User2018 user = new User2018(); - em.persist(user); - em.flush(); + CriteriaBuilder builder = em.getCriteriaBuilder(); - CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaQuery criteria = builder.createQuery(User2018.class); + Root root = criteria.from(User2018.class); + criteria.where(root.get("id").in(builder.parameter(Long[].class))); - CriteriaQuery criteria = builder.createQuery(User2018.class); - Root root = criteria.from(User2018.class); - criteria.where(root.get("id").in(builder.parameter(Long[].class))); + TypedQuery query = em.createQuery(criteria); + for (ParameterExpression parameter : criteria.getParameters()) { + query.setParameter(parameter, new Long[] { user.id }); + } - TypedQuery query = em.createQuery(criteria); - for (ParameterExpression parameter : criteria.getParameters()) { - query.setParameter(parameter, new Long[] { user.id }); + List result = query.getResultList(); + assertTrue(!result.isEmpty()); + } finally { + em.getTransaction().commit(); } - - List result = query.getResultList(); - assertTrue(!result.isEmpty()); } public void testInCriteriaWithCollection() { + em.getTransaction().begin(); + try { + User2018 user = new User2018(); + em.persist(user); + em.flush(); - User2018 user = new User2018(); - em.persist(user); - em.flush(); + CriteriaBuilder builder = em.getCriteriaBuilder(); - CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaQuery criteria = builder.createQuery(User2018.class); + Root root = criteria.from(User2018.class); + criteria.where(root.get("id").in(builder.parameter(Collection.class))); - CriteriaQuery criteria = builder.createQuery(User2018.class); - Root root = criteria.from(User2018.class); - criteria.where(root.get("id").in(builder.parameter(Collection.class))); + TypedQuery query = em.createQuery(criteria); + for (ParameterExpression parameter : criteria.getParameters()) { + query.setParameter(parameter, Arrays.asList(user.id)); + } - TypedQuery query = em.createQuery(criteria); - for (ParameterExpression parameter : criteria.getParameters()) { - query.setParameter(parameter, Arrays.asList(user.id)); + List result = query.getResultList(); + assertTrue(!result.isEmpty()); + } finally { + em.getTransaction().commit(); } - - List result = query.getResultList(); - assertTrue(!result.isEmpty()); } public void testId() { + em.getTransaction().begin(); + try { + User2018 user = new User2018(); + em.persist(user); + em.flush(); - User2018 user = new User2018(); - em.persist(user); - em.flush(); + CriteriaBuilder builder = em.getCriteriaBuilder(); - CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaQuery criteria = builder.createQuery(User2018.class); + Root root = criteria.from(User2018.class); + criteria.where(builder.equal(root.get("id"), user.id)); - CriteriaQuery criteria = builder.createQuery(User2018.class); - Root root = criteria.from(User2018.class); - criteria.where(builder.equal(root.get("id"), user.id)); + TypedQuery query = em.createQuery(criteria); + for (ParameterExpression parameter : criteria.getParameters()) { + query.setParameter(parameter, user.id); + } - TypedQuery query = em.createQuery(criteria); - for (ParameterExpression parameter : criteria.getParameters()) { - query.setParameter(parameter, user.id); + List result = query.getResultList(); + assertTrue(!result.isEmpty()); + } finally { + em.getTransaction().commit(); } - - List result = query.getResultList(); - assertTrue(!result.isEmpty()); } } diff --git a/openjpa-persistence-jdbc/src/test/resources/META-INF/openjpa2018.xml b/openjpa-persistence-jdbc/src/test/resources/META-INF/openjpa2018.xml deleted file mode 100644 index 384801970..000000000 --- a/openjpa-persistence-jdbc/src/test/resources/META-INF/openjpa2018.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - org.apache.openjpa.persistence.PersistenceProviderImpl - org.apache.openjpa.openjpa2018.User2018 - - - - - - - -