summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevan Goodwin <dgoodwin@redhat.com>2009-11-24 13:26:46 -0400
committerDevan Goodwin <dgoodwin@redhat.com>2009-11-24 13:26:46 -0400
commit1b4a97f23cee693d465a04737ed3913194476ffb (patch)
tree2126a5cf1cc67d0098b5f75328215dcd155d8c82
parent110e92e9df170964779d148eb9ac075ca4239a08 (diff)
downloadcandlepin-1b4a97f23cee693d465a04737ed3913194476ffb.tar.gz
candlepin-1b4a97f23cee693d465a04737ed3913194476ffb.tar.xz
candlepin-1b4a97f23cee693d465a04737ed3913194476ffb.zip
Cleanup test transaction management.
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/test/ModelTestFixture.java33
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/test/ProductTest.java27
2 files changed, 37 insertions, 23 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/ModelTestFixture.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/ModelTestFixture.java
new file mode 100644
index 0000000..4076555
--- /dev/null
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ModelTestFixture.java
@@ -0,0 +1,33 @@
+package org.fedoraproject.candlepin.model.test;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import org.fedoraproject.candlepin.util.EntityManagerUtil;
+import org.junit.Before;
+
+public class ModelTestFixture {
+
+ protected EntityManager em;
+
+ @Before
+ public void setUp() {
+ em = EntityManagerUtil.createEntityManager();
+ }
+
+ /**
+ * Begin a transaction, persist the given entity, and commit.
+ *
+ * @param storeMe Entity to persist.
+ */
+ protected void persistAndCommit(Object storeMe) {
+ EntityTransaction tx = null;
+ tx = em.getTransaction();
+ tx.begin();
+
+ em.persist(storeMe);
+ tx.commit();
+ }
+
+
+}
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/ProductTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/ProductTest.java
index 42bfc79..a492741 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/test/ProductTest.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ProductTest.java
@@ -4,29 +4,19 @@ import static org.junit.Assert.assertEquals;
import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceException;
import org.fedoraproject.candlepin.model.Product;
-import org.fedoraproject.candlepin.util.EntityManagerUtil;
-import org.junit.Before;
import org.junit.Test;
-public class ProductTest {
+public class ProductTest extends ModelTestFixture {
- private EntityManager em;
-
- @Before
- public void setUp() {
- em = EntityManagerUtil.createEntityManager();
- }
@Test
public void normalCreate() {
Product prod = new Product("myproductlabel", "My Product");
- storeObject(prod);
+ persistAndCommit(prod);
List<Product> results = em.createQuery("select p from Product as p")
.getResultList();
@@ -38,7 +28,7 @@ public class ProductTest {
Product prod = new Product();
prod.setLabel("someproductlabel");
- storeObject(prod);
+ persistAndCommit(prod);
}
@@ -47,17 +37,8 @@ public class ProductTest {
Product prod = new Product();
prod.setName("My Product Name");
- storeObject(prod);
+ persistAndCommit(prod);
}
- public void storeObject(Object storeMe) {
- EntityTransaction tx = null;
- tx = em.getTransaction();
- tx.begin();
-
- em.persist(storeMe);
- tx.commit();
- }
-
}