summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevan Goodwin <dgoodwin@redhat.com>2009-11-25 16:13:36 -0400
committerDevan Goodwin <dgoodwin@redhat.com>2009-11-25 16:13:36 -0400
commitde2aeeae880b9fd5bd1dfb6600bc23d6530f68d4 (patch)
tree75ec1053695a76535b62ceb982be2bab910a5977
parentd2335372b366d7fb0837983f6705fd9f4156f337 (diff)
downloadcandlepin-de2aeeae880b9fd5bd1dfb6600bc23d6530f68d4.tar.gz
candlepin-de2aeeae880b9fd5bd1dfb6600bc23d6530f68d4.tar.xz
candlepin-de2aeeae880b9fd5bd1dfb6600bc23d6530f68d4.zip
Test Product hierarchy cascading.
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/test/ProductTest.java35
1 files changed, 30 insertions, 5 deletions
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 2341f5b..f1799aa 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/test/ProductTest.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ProductTest.java
@@ -1,6 +1,6 @@
package org.fedoraproject.candlepin.model.test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import java.util.List;
@@ -71,8 +71,6 @@ public class ProductTest extends ModelTestFixture {
parent.addChildProduct(child1);
parent.addChildProduct(child2);
- em.persist(child1);
- em.persist(child2);
em.persist(parent);
em.getTransaction().commit();
@@ -92,8 +90,6 @@ public class ProductTest extends ModelTestFixture {
Product child1 = new Product("child-product1", "Child Product 1");
Product parent2 = new Product("parent-product2", "Parent Product 2");
- List objects = em.createQuery("from Product p").getResultList();
-
parent1.addChildProduct(child1);
parent2.addChildProduct(child1); // should cause the failure
@@ -102,5 +98,34 @@ public class ProductTest extends ModelTestFixture {
em.persist(parent2);
em.getTransaction().commit();
}
+
+ @Test
+ public void testCascading() {
+ em.getTransaction().begin();
+
+ Product parent1 = new Product("parent-product1", "Parent Product 1");
+ Product child1 = new Product("child-product1", "Child Product 1");
+ parent1.addChildProduct(child1);
+ em.persist(parent1);
+ em.getTransaction().commit();
+
+ EntityManager em2 = EntityManagerUtil.createEntityManager();
+ Product result = (Product)em2.createQuery(
+ "select p from Product as p where name = :name")
+ .setParameter("name", child1.getName())
+ .getSingleResult();
+ assertNotNull(result);
+
+ em.getTransaction().begin();
+ em.remove(parent1);
+ em.getTransaction().commit();
+
+ em2 = EntityManagerUtil.createEntityManager();
+ List<Product> results = em2.createQuery(
+ "select p from Product as p where name = :name")
+ .setParameter("name", child1.getName())
+ .getResultList();
+ assertEquals(0, results.size());
+ }
}