db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r521067 - in /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker: FunctionTest.java PaginationTest.java
Date Thu, 22 Mar 2007 01:21:18 GMT
Author: arminw
Date: Wed Mar 21 18:21:17 2007
New Revision: 521067

URL: http://svn.apache.org/viewvc?view=rev&rev=521067
Log:
update, fix tests

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PaginationTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java?view=diff&rev=521067&r1=521066&r2=521067
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java Wed Mar
21 18:21:17 2007
@@ -26,6 +26,7 @@
 import org.apache.ojb.broker.query.QueryFactory;
 import org.apache.ojb.broker.query.ReportQueryByCriteria;
 import org.apache.ojb.broker.util.AttributeTokenizer;
+import org.apache.ojb.broker.platforms.PlatformOracleImpl;
 import org.apache.commons.lang.builder.EqualsBuilder;
 
 /**
@@ -184,8 +185,13 @@
         assertEquals(1, size);
     }
 
-    public void testReportQuery_3()
+    public void testReportQuery_3() throws Exception
     {
+        if(broker.serviceConnectionManager().getSupportedPlatform() instanceof PlatformOracleImpl)
+        {
+            ojbSkipTestMessage("Seems that Oracle jdbc-driver doesn't support CURDATE() function");
+            return;
+        }
         String name = "testReportQuery_3_" + System.currentTimeMillis();
         Key key = createTestObject(name);
         broker.clearCache();
@@ -193,14 +199,12 @@
         Integer pk = ((Many) key.getCurdate().getSum().get(0)).getSum();
         Criteria crit = new Criteria().addEqualTo("curdate.sum.sum", pk).addEqualTo("name",
name);
         ReportQueryByCriteria q = QueryFactory.newReportQuery(Key.class, crit);
-        q.setAttributes(new String[]{"name", "sum(curdate.sum.fkOne)", "curdate()"});
+        q.setAttributes(new String[]{"name", "sum(curdate.sum.fkOne)", "CURDATE()"});
         q.addGroupBy("name");
 
-//        Criteria crit = new Criteria();
-//        ReportQueryByCriteria q = QueryFactory.newReportQuery(Key.class, crit);
-//        q.setAttributes(new String[]{"name", "sum(curdate.sum.fkOne)", "curdate()"});
-//        q.addGroupBy("name");
-//        q.setEndAtIndex(1);
+//        System.out.println("## n: " + broker.serviceConnectionManager().getConnection().getMetaData().getNumericFunctions());
+//        System.out.println("## s: " + broker.serviceConnectionManager().getConnection().getMetaData().getStringFunctions());
+//        System.out.println("## d: " + broker.serviceConnectionManager().getConnection().getMetaData().getTimeDateFunctions());
 
         Iterator it = broker.getReportQueryIteratorByQuery(q);
         int size = 0;
@@ -211,10 +215,10 @@
             assertNotNull(arr[1]);
             assertNotNull(arr[2]);
             ++size;
-            System.out.println();
-            System.out.print("arr[0]=" +arr[0]);
-            System.out.print(" arr[1]=" +arr[1]);
-            System.out.print(" arr[2]=" +arr[2]);
+//            System.out.println();
+//            System.out.print("arr[0]=" +arr[0]);
+//            System.out.print(" arr[1]=" +arr[1]);
+//            System.out.print(" arr[2]=" +arr[2]);
 
         }
         assertEquals(1, size);

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PaginationTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PaginationTest.java?view=diff&rev=521067&r1=521066&r2=521067
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PaginationTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PaginationTest.java Wed
Mar 21 18:21:17 2007
@@ -123,28 +123,40 @@
     public void testLimit_1()
     {
         String appendix = "_testLimit_1_" + System.currentTimeMillis();
-        performLimit(appendix, 1, 1, 10);
+        performLimit(appendix, 1, 1, 10, false);
     }
 
     public void testLimit_3()
     {
         String appendix = "_testLimit_3_" + System.currentTimeMillis();
-        performLimit(appendix, 3, 3, 30);
+        performLimit(appendix, 3, 3, 30, false);
     }
 
     public void testLimit_2()
     {
         String appendix = "_testLimit_2_" + System.currentTimeMillis();
-        performLimit(appendix, 9, 9, 90);
+        performLimit(appendix, 9, 9, 90, false);
     }
 
     public void testLimit_4()
     {
         String appendix = "_testLimit_4_" + System.currentTimeMillis();
-        performLimit(appendix, 10, 9, 90);
+        performLimit(appendix, 10, 9, 90, false);
     }
 
-    public void performLimit(String appendix, int limit, int expectedSize, int voteLessOrEqual)
+    public void testLimit_5()
+    {
+        String appendix = "_testLimit_5_" + System.currentTimeMillis();
+        performLimit(appendix, 9, 9, 90, true);
+    }
+
+    public void testLimit_6()
+    {
+        String appendix = "_testLimit_6_" + System.currentTimeMillis();
+        performLimit(appendix, 10, 9, 90, true);
+    }
+
+    public void performLimit(String appendix, int limit, int expectedSize, int voteLessOrEqual,
boolean distinct)
     {
         insertTestData(appendix);
 
@@ -163,6 +175,7 @@
         // because else it will end in multiple limit queries (one for each extent)
         // thus the result will be pagination_size * extents
         query.setWithExtents(false);
+        query.setDistinct(distinct);
 
         // check result without limit
         Collection result = broker.getCollectionByQuery(query);
@@ -186,6 +199,7 @@
         // because else it will end in multiple limit queries (one for each extent)
         // thus the result will be pagination_size * extents
         query.setWithExtents(false);
+        query.setDistinct(distinct);
         // query with limit
         query.setEndAtIndex(limit);
         result = broker.getCollectionByQuery(query);
@@ -211,7 +225,7 @@
         int expectedSize = 1;
         int voteGreaterEquals = 10;
         int voteLessEquals = 10;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
     }
 
     public void testLimitOffset_2()
@@ -222,7 +236,7 @@
         int expectedSize = 1;
         int voteGreaterEquals = 40;
         int voteLessEquals = 40;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
     }
 
     public void testLimitOffset_3()
@@ -233,7 +247,7 @@
         int expectedSize = 8;
         int voteGreaterEquals = 10;
         int voteLessEquals = 80;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
     }
 
     public void testLimitOffset_4()
@@ -244,7 +258,7 @@
         int expectedSize = 9;
         int voteGreaterEquals = 10;
         int voteLessEquals = 90;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
     }
 
     public void testLimitOffset_5()
@@ -255,7 +269,7 @@
         int expectedSize = 9;
         int voteGreaterEquals = 10;
         int voteLessEquals = 90;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
     }
 
     public void testLimitOffset_6()
@@ -266,7 +280,7 @@
         int expectedSize = 1;
         int voteGreaterEquals = 90;
         int voteLessEquals = 90;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
     }
 
     public void testLimitOffset_7()
@@ -277,7 +291,7 @@
         int expectedSize = 4;
         int voteGreaterEquals = 40;
         int voteLessEquals = 70;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
     }
 
     public void testLimitOffset_8()
@@ -289,7 +303,7 @@
         int expectedSize = 7;
         int voteGreaterEquals = 30;
         int voteLessEquals = 90;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
     }
 
     public void testLimitOffset_9()
@@ -301,12 +315,36 @@
         int expectedSize = 1;
         int voteGreaterEquals = 90;
         int voteLessEquals = 90;
-        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals);
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
false);
+    }
+
+    public void testLimitOffset_10()
+    {
+        String appendix = "_testLimitOffset_10_" + System.currentTimeMillis();
+        int start = 3;
+        // don't specify end
+        int end = Query.NO_END_AT_INDEX;
+        int expectedSize = 7;
+        int voteGreaterEquals = 30;
+        int voteLessEquals = 90;
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
true);
+    }
+
+    public void testLimitOffset_11()
+    {
+        String appendix = "_testLimitOffset_11_" + System.currentTimeMillis();
+        int start = 9;
+        // don't specify end
+        int end = Query.NO_END_AT_INDEX;
+        int expectedSize = 1;
+        int voteGreaterEquals = 90;
+        int voteLessEquals = 90;
+        performLimitOffest(appendix, start, end, expectedSize, voteGreaterEquals, voteLessEquals,
true);
     }
 
     public void performLimitOffest(String appendix, int start, int end,
                                    int expectedSize,
-                                   int voteGreaterEquals, int voteLessEquals)
+                                   int voteGreaterEquals, int voteLessEquals, boolean distinct)
     {
         insertTestData(appendix);
 
@@ -325,6 +363,7 @@
         // because else it will end in multiple limit queries (one for each extent)
         // thus the result will be pagination_size * extents
         query.setWithExtents(false);
+        query.setDistinct(distinct);
 
         // check result without limit
         Collection result = broker.getCollectionByQuery(query);
@@ -348,6 +387,7 @@
         // because else it will end in multiple limit queries (one for each extent)
         // thus the result will be pagination_size * extents
         query.setWithExtents(false);
+        query.setDistinct(distinct);
         query.setStartAtIndex(start);
         query.setEndAtIndex(end);
         result = broker.getCollectionByQuery(query);
@@ -482,6 +522,7 @@
             // expect PagingIterator instance, without extents, nativeLimit=false
             // -------------------------------------------------------------
             query = QueryFactory.newQuery(Article.class, crit);
+            query.addOrderByAscending("articleId");
             query.setWithExtents(false);
             query.setStartAtIndex(startIndex);
             query.setEndAtIndex(endIndex);
@@ -527,6 +568,7 @@
             // expect ChainingIterator instance, with extents, nativeLimit=true
             // -------------------------------------------------------------
             query = QueryFactory.newQuery(Article.class, crit);
+            query.addOrderByAscending("articleId");
             // now we want all results with extents, in this case OJB
             // will use a chaining iterator
             query.setWithExtents(true);
@@ -571,6 +613,7 @@
             // expect ChainingIterator instance, with extents, nativeLimit=false
             // -------------------------------------------------------------
             query = QueryFactory.newQuery(Article.class, crit);
+            query.addOrderByAscending("articleId");
             // now we want all results with extents, in this case OJB
             // will use a chaining iterator
             query.setWithExtents(true);
@@ -662,16 +705,19 @@
 
     public void testPagingPosition_4()
     {
-        String name = "testPagingPosition_4_" + System.currentTimeMillis();
-        int articleCount = 20;
-        int startIndex = 10;
-        int endIndex = 14;
-        // move to last position
-        int absoluteIndex = -1;
-        int expectedStockValue = 14;
-        boolean allowRelativePlusOneCall = false;
+        for(int i=0; i<5; i++)
+        {
+            String name = "testPagingPosition_4_" + System.currentTimeMillis() + i;
+            int articleCount = 20;
+            int startIndex = 10;
+            int endIndex = 14;
+            // move to last position
+            int absoluteIndex = -1;
+            int expectedStockValue = 14;
+            boolean allowRelativePlusOneCall = false;
 
-        pagingPositionTest(name, articleCount, startIndex, endIndex, absoluteIndex, expectedStockValue,
allowRelativePlusOneCall);
+            pagingPositionTest(name, articleCount, startIndex, endIndex, absoluteIndex, expectedStockValue,
allowRelativePlusOneCall);
+        }
     }
 
     public void testPagingPosition_5()
@@ -840,7 +886,7 @@
         query.setStartAtIndex(fullSize - 9);
         query.setEndAtIndex(fullSize + 9);
         ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
-        assertEquals("end index out of range expecting 0 rows", 10,ojbIter.size());
+        assertEquals("end index out of range expecting 10 rows", 10,ojbIter.size());
         ojbIter.releaseDbResources();
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message