db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r450813 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
Date Thu, 28 Sep 2006 11:48:35 GMT
Author: arminw
Date: Thu Sep 28 04:48:34 2006
New Revision: 450813

URL: http://svn.apache.org/viewvc?view=rev&rev=450813
Log:
add new ReportQuery test

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

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java?view=diff&rev=450813&r1=450812&r2=450813
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java Thu Sep
28 04:48:34 2006
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+import java.math.BigDecimal;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -24,7 +25,6 @@
 import java.util.List;
 import java.util.Set;
 import java.util.Vector;
-import java.math.BigDecimal;
 
 import org.apache.commons.lang.time.StopWatch;
 import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
@@ -37,8 +37,6 @@
 import org.apache.ojb.broker.query.QueryByCriteria;
 import org.apache.ojb.broker.query.QueryFactory;
 import org.apache.ojb.broker.query.ReportQueryByCriteria;
-import org.apache.ojb.broker.util.collections.ManageableHashSet;
-import org.apache.ojb.broker.util.collections.RemovalAwareSet;
 import org.apache.ojb.junit.PBTestCase;
 
 /**
@@ -65,6 +63,78 @@
     {
         String[] arr = {QueryTest.class.getName()};
         junit.textui.TestRunner.main(arr);
+    }
+
+    /**
+     * Simple ReportQuery returning rows with 3 columns of Person
+     */
+    public void testReportQueryNullFields()
+    {
+        String name = "testReportQueryNullFields_" + System.currentTimeMillis();
+        Person p1 = new Person();
+        p1.setFirstname("Robert");
+        p1.setLastname(name);
+        Person p2 = new Person();
+        p2.setFirstname(null);
+        p2.setLastname(name);
+        Person p3 = new Person();
+        p3.setFirstname(null);
+        p3.setLastname(name);
+        broker.beginTransaction();
+        broker.store(p1);
+        broker.store(p2);
+        broker.store(p3);
+        broker.commitTransaction();
+
+
+        Criteria crit = new Criteria();
+        crit.addLike("lastname", name);
+        Criteria crit2 = new Criteria();
+        crit2.addColumnIsNull("firstname");
+        crit.addAndCriteria(crit2);
+        ReportQueryByCriteria q = QueryFactory.newReportQuery(Person.class, crit);
+        q.setAttributes(new String[]{"firstname", "lastname", "count(*)"});
+        q.addGroupBy(new String[]{"firstname", "lastname"});
+
+        Iterator iter = broker.getReportQueryIteratorByQuery(q);
+        assertNotNull(iter);
+        int result = 0;
+        List results = new ArrayList();
+        while(iter.hasNext())
+        {
+            Object[] row = (Object[]) iter.next();
+            assertEquals(3, row.length);
+            results.add(row);
+            result += ((Integer) row[2]).intValue();
+            //System.out.println("Result_1: " + ArrayUtils.toString(row));
+        }
+        assertEquals(2, result);
+        // compare with count
+        int count = broker.getCount(q);
+        assertEquals(result, count);
+
+        crit = new Criteria();
+        crit.addLike("lastname", name);
+        q = QueryFactory.newReportQuery(Person.class, crit);
+        q.setAttributes(new String[]{"firstname", "lastname", "count(*)"});
+        q.addGroupBy(new String[]{"firstname", "lastname"});
+
+        iter = broker.getReportQueryIteratorByQuery(q);
+        assertNotNull(iter);
+        results = new ArrayList();
+        result = 0;
+        while(iter.hasNext())
+        {
+            Object[] row = (Object[]) iter.next();
+            assertEquals(3, row.length);
+            results.add(row);
+            result += ((Integer) row[2]).intValue();
+            //System.out.println("Result_2: " + ArrayUtils.toString(row));
+        }
+        assertEquals(3, result);
+        // compare with count
+        count = broker.getCount(q);
+        assertEquals(result, count);
     }
 
     public void testQueryZero()



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