From b24ea518738adbf00e7e7cc7eb5ee2f3491462ac Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Wed, 6 Jan 2010 18:49:52 +0000 Subject: [PATCH] HHH-4688 Make sure @OrderBy works for @ElementCollection. move test case git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18427 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../collectionelement/OrderByTest.java | 63 +++++++++++++++++++ .../collectionelement}/Products.java | 2 +- .../collectionelement}/Widgets.java | 2 +- .../hibernate/ejb/test/ops/OrderByTest.java | 61 ------------------ 4 files changed, 65 insertions(+), 63 deletions(-) create mode 100644 annotations/src/test/java/org/hibernate/test/annotations/collectionelement/OrderByTest.java rename {entitymanager/src/test/java/org/hibernate/ejb/test/ops => annotations/src/test/java/org/hibernate/test/annotations/collectionelement}/Products.java (91%) rename {entitymanager/src/test/java/org/hibernate/ejb/test/ops => annotations/src/test/java/org/hibernate/test/annotations/collectionelement}/Widgets.java (87%) delete mode 100644 entitymanager/src/test/java/org/hibernate/ejb/test/ops/OrderByTest.java diff --git a/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/OrderByTest.java b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/OrderByTest.java new file mode 100644 index 0000000000..e1100ca5e5 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/OrderByTest.java @@ -0,0 +1,63 @@ +package org.hibernate.test.annotations.collectionelement; + +import junit.framework.Assert; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.test.annotations.TestCase; + +import javax.persistence.EntityManager; +import java.util.HashSet; +import java.util.Iterator; + +public class OrderByTest extends TestCase { + + /** + * Test @OrderBy on the Widgets.name field. + * + */ + public void testOrderByName() throws Exception { + Session s = openSession(); + Transaction tx = s.beginTransaction(); + + Products p = new Products(); + HashSet set = new HashSet(); + + Widgets widget = new Widgets(); + widget.setName("hammer"); + set.add(widget); + s.persist(widget); + + widget = new Widgets(); + widget.setName("axel"); + set.add(widget); + s.persist(widget); + + widget = new Widgets(); + widget.setName("screwdriver"); + set.add(widget); + s.persist(widget); + + p.setWidgets(set); + s.persist(p); + tx.commit(); + + tx = s.beginTransaction(); + s.clear(); + p = (Products) s.get(Products.class,p.getId()); + Assert.assertTrue("has three Widgets", p.getWidgets().size() == 3); + Iterator iter = p.getWidgets().iterator(); + Assert.assertEquals( "axel", ((Widgets)iter.next()).getName() ); + Assert.assertEquals( "hammer", ((Widgets)iter.next()).getName() ); + Assert.assertEquals( "screwdriver", ((Widgets)iter.next()).getName() ); + tx.commit(); + s.close(); + } + + protected Class[] getMappings() { + return new Class[] { + Products.class, + Widgets.class + }; + } + +} diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Products.java b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Products.java similarity index 91% rename from entitymanager/src/test/java/org/hibernate/ejb/test/ops/Products.java rename to annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Products.java index 29a8a415fe..212755d8b9 100644 --- a/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Products.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Products.java @@ -1,4 +1,4 @@ -package org.hibernate.ejb.test.ops; +package org.hibernate.test.annotations.collectionelement; import javax.persistence.ElementCollection; import javax.persistence.Entity; diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Widgets.java b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Widgets.java similarity index 87% rename from entitymanager/src/test/java/org/hibernate/ejb/test/ops/Widgets.java rename to annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Widgets.java index 6f415009d2..d27ed8d15d 100644 --- a/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Widgets.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Widgets.java @@ -1,4 +1,4 @@ -package org.hibernate.ejb.test.ops; +package org.hibernate.test.annotations.collectionelement; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/ops/OrderByTest.java b/entitymanager/src/test/java/org/hibernate/ejb/test/ops/OrderByTest.java deleted file mode 100644 index c7bed8ec68..0000000000 --- a/entitymanager/src/test/java/org/hibernate/ejb/test/ops/OrderByTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.hibernate.ejb.test.ops; - -import org.hibernate.ejb.test.TestCase; - -import javax.persistence.EntityManager; -import java.util.HashSet; -import java.util.Iterator; - -public class OrderByTest extends TestCase { - - public Class[] getAnnotatedClasses() { - return new Class[]{ - Products.class, - Widgets.class - }; - } - - /** - * Test @OrderBy on the Widgets.name field. - * - */ - public void testOrderByName() throws Exception { - EntityManager em = getOrCreateEntityManager(); - em.getTransaction().begin(); - - Products p = new Products(); - HashSet set = new HashSet(); - - Widgets widget = new Widgets(); - widget.setName("hammer"); - set.add(widget); - em.persist(widget); - - widget = new Widgets(); - widget.setName("axel"); - set.add(widget); - em.persist(widget); - - widget = new Widgets(); - widget.setName("screwdriver"); - set.add(widget); - em.persist(widget); - - p.setWidgets(set); - em.persist(p); - em.getTransaction().commit(); - - em.getTransaction().begin(); - em.clear(); - p = em.find(Products.class,p.getId()); - assertTrue("has three Widgets", p.getWidgets().size() == 3); - Iterator iter = p.getWidgets().iterator(); - assertEquals( "axel", ((Widgets)iter.next()).getName() ); - assertEquals( "hammer", ((Widgets)iter.next()).getName() ); - assertEquals( "screwdriver", ((Widgets)iter.next()).getName() ); - em.getTransaction().commit(); - em.close(); - } - - -}