cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgen...@apache.org
Subject svn commit: r823188 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/OrderingTest.java
Date Thu, 08 Oct 2009 14:30:59 GMT
Author: mgentry
Date: Thu Oct  8 14:30:59 2009
New Revision: 823188

URL: http://svn.apache.org/viewvc?rev=823188&view=rev
Log:
Beefier test case incorporating tests for CAY-1283 (enums for Ordering class).

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/OrderingTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/OrderingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/OrderingTest.java?rev=823188&r1=823187&r2=823188&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/OrderingTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/OrderingTest.java
Thu Oct  8 14:30:59 2009
@@ -38,33 +38,107 @@
         assertEquals(pathSpec, ord.getSortSpec().getOperand(0));
     }
 
+    @Deprecated
     public void testPathSpec2() throws Exception {
         String pathSpec = "a.b.c";
         Ordering ord = new Ordering(pathSpec, false);
         assertEquals(pathSpec, ord.getSortSpec().getOperand(0));
     }
 
+    public void testPathSpec3() throws Exception {
+        String pathSpec = "a.b.c";
+        Ordering ord = new Ordering(pathSpec, SortOrder.DESCENDING);
+        assertEquals(pathSpec, ord.getSortSpec().getOperand(0));
+    }
+
+    @Deprecated
     public void testAsending1() throws Exception {
         Ordering ord = new Ordering();
         ord.setAscending(Ordering.DESC);
         assertEquals(Ordering.DESC, ord.isAscending());
     }
 
+    @Deprecated
+    public void testAsending2() throws Exception {
+        Ordering ord = new Ordering("K", Ordering.DESC);
+        assertEquals(Ordering.DESC, ord.isAscending());
+    }
+
+    public void testAscending1() throws Exception {
+        Ordering ord = new Ordering();
+        ord.setAscending();
+        assertTrue(ord.isAscending());
+        assertFalse(ord.isDescending());
+    }
+
+    public void testAscending2() throws Exception {
+        Ordering ord = new Ordering();
+        ord.setSortOrder(SortOrder.ASCENDING);
+        assertTrue(ord.isAscending());
+        assertFalse(ord.isDescending());
+    }
+
+    public void testAscending3() throws Exception {
+        Ordering ord = new Ordering();
+        ord.setSortOrder(SortOrder.ASCENDING_INSENSITIVE);
+        assertTrue(ord.isAscending());
+        assertFalse(ord.isDescending());
+    }
+
+    public void testDescending1() throws Exception {
+        Ordering ord = new Ordering();
+        ord.setDescending();
+        assertFalse(ord.isAscending());
+        assertTrue(ord.isDescending());
+    }
+
+    public void testDescending2() throws Exception {
+        Ordering ord = new Ordering();
+        ord.setSortOrder(SortOrder.DESCENDING);
+        assertFalse(ord.isAscending());
+        assertTrue(ord.isDescending());
+    }
+
+    public void testDescending3() throws Exception {
+        Ordering ord = new Ordering();
+        ord.setSortOrder(SortOrder.DESCENDING_INSENSITIVE);
+        assertFalse(ord.isAscending());
+        assertTrue(ord.isDescending());
+    }
+
+    @Deprecated
     public void testCaseInsensitive1() throws Exception {
         Ordering ord = new Ordering("M", Ordering.ASC, true);
         assertTrue(ord.isCaseInsensitive());
     }
 
+    @Deprecated
     public void testCaseInsensitive2() throws Exception {
         Ordering ord = new Ordering("N", Ordering.ASC, false);
         assertFalse(ord.isCaseInsensitive());
     }
 
-    public void testAsending2() throws Exception {
-        Ordering ord = new Ordering("K", Ordering.DESC);
-        assertEquals(Ordering.DESC, ord.isAscending());
+    public void testCaseInsensitive3() throws Exception {
+        Ordering ord = new Ordering("M", SortOrder.ASCENDING_INSENSITIVE);
+        assertTrue(ord.isCaseInsensitive());
     }
 
+    public void testCaseInsensitive4() throws Exception {
+        Ordering ord = new Ordering("N", SortOrder.ASCENDING);
+        assertFalse(ord.isCaseInsensitive());
+    }
+
+    public void testCaseInsensitive5() throws Exception {
+        Ordering ord = new Ordering("M", SortOrder.DESCENDING_INSENSITIVE);
+        assertTrue(ord.isCaseInsensitive());
+    }
+
+    public void testCaseInsensitive6() throws Exception {
+        Ordering ord = new Ordering("N", SortOrder.DESCENDING);
+        assertFalse(ord.isCaseInsensitive());
+    }
+
+    @Deprecated
     public void testCompare1() throws Exception {
         Painting p1 = new Painting();
         p1.setEstimatedPrice(new BigDecimal(1000.00));
@@ -81,6 +155,7 @@
         assertTrue(ordering.compare(p2, p3) == 0);
     }
 
+    @Deprecated
     public void testCompare2() throws Exception {
         // compare on non-persistent property
         TestBean t1 = new TestBean(1000);
@@ -93,7 +168,36 @@
         assertTrue(ordering.compare(t2, t3) == 0);
     }
 
-    public void testOrderList() throws Exception {
+    public void testCompare3() throws Exception {
+        Painting p1 = new Painting();
+        p1.setEstimatedPrice(new BigDecimal(1000.00));
+
+        Painting p2 = new Painting();
+        p2.setEstimatedPrice(new BigDecimal(2000.00));
+
+        Painting p3 = new Painting();
+        p3.setEstimatedPrice(new BigDecimal(2000.00));
+
+        Ordering ordering = new Ordering("estimatedPrice", SortOrder.ASCENDING);
+        assertTrue(ordering.compare(p1, p2) < 0);
+        assertTrue(ordering.compare(p2, p1) > 0);
+        assertTrue(ordering.compare(p2, p3) == 0);
+    }
+
+    public void testCompare4() throws Exception {
+        // compare on non-persistent property
+        TestBean t1 = new TestBean(1000);
+        TestBean t2 = new TestBean(2000);
+        TestBean t3 = new TestBean(2000);
+
+        Ordering ordering = new Ordering("integer", SortOrder.ASCENDING);
+        assertTrue(ordering.compare(t1, t2) < 0);
+        assertTrue(ordering.compare(t2, t1) > 0);
+        assertTrue(ordering.compare(t2, t3) == 0);
+    }
+
+    @Deprecated
+    public void testOrderList1() throws Exception {
         // compare on non-persistent property
         List list = new ArrayList(3);
 
@@ -107,7 +211,22 @@
         assertEquals(5, ((TestBean) list.get(2)).getInteger().intValue());
     }
 
-    public void testOrderListWithMultipleOrderings() throws Exception {
+    public void testOrderList2() throws Exception {
+        // compare on non-persistent property
+        List list = new ArrayList(3);
+
+        list.add(new TestBean(5));
+        list.add(new TestBean(2));
+        list.add(new TestBean(3));
+
+        new Ordering("integer", SortOrder.ASCENDING).orderList(list);
+        assertEquals(2, ((TestBean) list.get(0)).getInteger().intValue());
+        assertEquals(3, ((TestBean) list.get(1)).getInteger().intValue());
+        assertEquals(5, ((TestBean) list.get(2)).getInteger().intValue());
+    }
+
+    @Deprecated
+    public void testOrderListWithMultipleOrderings1() throws Exception {
         // compare on non-persistent property
         List list = new ArrayList(6);
 
@@ -133,4 +252,31 @@
         assertEquals(list.get(1), orderedList.get(4));
         assertEquals(list.get(0), orderedList.get(5));
     }
+
+    public void testOrderListWithMultipleOrderings2() throws Exception {
+        // compare on non-persistent property
+        List list = new ArrayList(6);
+
+        list.add(new TestBean("c", 1));
+        list.add(new TestBean("c", 30));
+        list.add(new TestBean("a", 5));
+        list.add(new TestBean("b", 1));
+        list.add(new TestBean("b", 2));
+        list.add(new TestBean("b", 5));
+
+        List orderings = new ArrayList(2);
+        orderings.add(new Ordering("string", SortOrder.ASCENDING));
+        orderings.add(new Ordering("integer", SortOrder.DESCENDING));
+
+        // clone list and then order
+        List orderedList = new ArrayList(list);
+        Ordering.orderList(orderedList, orderings);
+
+        assertEquals(list.get(2), orderedList.get(0));
+        assertEquals(list.get(5), orderedList.get(1));
+        assertEquals(list.get(4), orderedList.get(2));
+        assertEquals(list.get(3), orderedList.get(3));
+        assertEquals(list.get(1), orderedList.get(4));
+        assertEquals(list.get(0), orderedList.get(5));
+    }
 }



Mime
View raw message