db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r520717 - in /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb: broker/AllTests.java broker/FunctionTest.java repository_junit.xml
Date Wed, 21 Mar 2007 02:25:04 GMT
Author: arminw
Date: Tue Mar 20 19:25:03 2007
New Revision: 520717

URL: http://svn.apache.org/viewvc?view=rev&rev=520717
Log:
add new test for scalar functions to test-suite, fix mapping

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java
    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/repository_junit.xml

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java?view=diff&rev=520717&r1=520716&r2=520717
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java Tue Mar 20
19:25:03 2007
@@ -137,10 +137,7 @@
         suite.addTestSuite(DatabaseIdentityMySqlTest.class);
         suite.addTestSuite(DatabaseIdentityMaxDBTest.class);
         suite.addTestSuite(SeqManMultiHsqlTest.class);
-        /*
-        arminw: comment in after 1.0.5 release
-        */
-        //suite.addTestSuite(FunctionTest.class);
+        suite.addTestSuite(FunctionTest.class);
 
         // BRJ: ensure shutdown of hsqldb
         suite.addTestSuite(HsqldbShutdown.class);

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=520717&r1=520716&r2=520717
==============================================================================
--- 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 Tue Mar
20 19:25:03 2007
@@ -25,6 +25,7 @@
 import org.apache.ojb.broker.query.Query;
 import org.apache.ojb.broker.query.QueryFactory;
 import org.apache.ojb.broker.query.ReportQueryByCriteria;
+import org.apache.ojb.broker.util.AttributeTokenizer;
 import org.apache.commons.lang.builder.EqualsBuilder;
 
 /**
@@ -42,6 +43,7 @@
 
     public FunctionTest()
     {
+        super();
     }
 
     public FunctionTest(String name)
@@ -49,6 +51,28 @@
         super(name);
     }
 
+    public void testAttributeTokenizer()
+    {
+        assertEquals("id", cleanPath("id"));
+        assertEquals("id", cleanPath("sum(id)"));
+        assertEquals("id", cleanPath("sum ( id) "));
+        assertEquals("id", cleanPath("abs(sum(id))"));
+        assertEquals("id", cleanPath("abs (sum(id  ))"));
+        assertEquals("id", cleanPath("count(distinct id)"));
+        assertEquals("id", cleanPath("  count   (   distinct   id  )  "));
+        assertEquals("distinct", cleanPath("  count   (   distinct   distinct  )  "));
+        assertEquals("as", cleanPath("  count   (   distinct   as  )  "));
+        assertEquals("as", cleanPath("((  count   (   distinct   as  )  ))"));
+        assertEquals("curdate.sum", cleanPath("sum(curdate.sum)"));
+        assertEquals("as", cleanPath("abs(as)"));
+        assertEquals("author.books.pages", cleanPath("count(distinct author.books.pages)"));
+    }
+
+    private String cleanPath(String str)
+    {
+        return new AttributeTokenizer(str).getCleanPath();
+    }
+
     Key createTestObject(String name)
     {
         Key key = new Key(name);
@@ -91,41 +115,112 @@
         Integer pk = ((Many) key.getCurdate().getSum().get(0)).getSum();
         Criteria crit = new Criteria()
                 .addEqualTo("curdate.sum.sum", pk)
-                .addGreaterThan("mod(max, mod)", new Integer(key.getMod().intValue() + 10))
+                .addLessThan("mod(max, mod)", new Integer(key.getMod().intValue() + 10))
                 .addGreaterThan("abs(as)", new Integer(0));
         Query q = QueryFactory.newQuery(Key.class, crit);
-
         Key keyNew = (Key) broker.getObjectByQuery(q);
+        assertNotNull(keyNew);
+        assertEquals(key, keyNew);
 
+
+        crit = new Criteria()
+                .addEqualTo("  curdate.sum.sum  ", pk)
+                .addLessThan("mod( max,  mod  )", new Integer(key.getMod().intValue() + 10))
+                .addGreaterThan("abs( as) ", new Integer(0));
+        q = QueryFactory.newQuery(Key.class, crit);
+        keyNew = (Key) broker.getObjectByQuery(q);
         assertNotNull(keyNew);
         assertEquals(key, keyNew);
     }
 
-    public void testReportQuery()
+    public void testReportQuery_1()
     {
-        String name = "testReportQuery_" + System.currentTimeMillis();
+        String name = "testReportQuery_1_" + System.currentTimeMillis();
+        createTestObject(name);
+        broker.clearCache();
+
+        Criteria crit = new Criteria().addEqualTo("name", name);
+        ReportQueryByCriteria q = QueryFactory.newReportQuery(Key.class, crit);
+        q.setAttributes(new String[]{"name", "sum(curdate.sum.sum)"});
+        q.addGroupBy("name");
+
+        Iterator it = broker.getReportQueryIteratorByQuery(q);
+        int size = 0;
+        while(it.hasNext())
+        {
+            Object[] arr =  (Object[]) it.next();
+            assertNotNull(arr[0]);
+            assertNotNull(arr[1]);
+            ++size;
+//            System.out.println("arr[0]=" +arr[0]);
+//            System.out.println("arr[1]=" +arr[1]);
+        }
+        assertEquals(1, size);
+    }
+
+    public void testReportQuery_2()
+    {
+        String name = "testReportQuery_2_" + System.currentTimeMillis();
         Key key = createTestObject(name);
         broker.clearCache();
 
         Integer pk = ((Many) key.getCurdate().getSum().get(0)).getSum();
-        Criteria crit = new Criteria().addEqualTo("curdate.sum.sum", pk);
+        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)"});
+        q.setAttributes(new String[]{"name", "sum(curdate.sum.fkOne)"});
+        q.addGroupBy("name");
 
         Iterator it = broker.getReportQueryIteratorByQuery(q);
+        int size = 0;
         while(it.hasNext())
         {
             Object[] arr =  (Object[]) it.next();
             assertNotNull(arr[0]);
             assertNotNull(arr[1]);
+            ++size;
 //            System.out.println("arr[0]=" +arr[0]);
 //            System.out.println("arr[1]=" +arr[1]);
         }
+        assertEquals(1, size);
+    }
+
+    public void testReportQuery_3()
+    {
+        String name = "testReportQuery_3_" + System.currentTimeMillis();
+        Key key = createTestObject(name);
+        broker.clearCache();
+
+        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.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);
+
+        Iterator it = broker.getReportQueryIteratorByQuery(q);
+        int size = 0;
+        while(it.hasNext())
+        {
+            Object[] arr =  (Object[]) it.next();
+            assertNotNull(arr[0]);
+            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]);
+
+        }
+        assertEquals(1, size);
     }
 
-    /*
-    count,min,max,avg,sum,upper,lower,distinct,as
-    */
+
     /**
      * This persistence capable class contains field names equal to
      * sql-query function names and keywords.

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml?view=diff&rev=520717&r1=520716&r2=520717
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml Tue Mar 20
19:25:03 2007
@@ -3376,7 +3376,7 @@
         <reference-descriptor
            name="curdate"
            class-ref="org.apache.ojb.broker.FunctionTest$One"
-           proxy="true"
+           proxy="false"
            auto-retrieve="true"
            auto-update="object"
            auto-delete="object"
@@ -3406,7 +3406,7 @@
         <collection-descriptor
          name="sum"
          element-class-ref="org.apache.ojb.broker.FunctionTest$Many"
-         proxy="true"
+         proxy="false"
          auto-retrieve="true"
          auto-update="object"
          auto-delete="object"



---------------------------------------------------------------------
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