svn commit: r616988 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r616988 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java

Armin Waibel
Author: arminw
Date: Wed Jan 30 18:17:02 2008
New Revision: 616988

URL: http://svn.apache.org/viewvc?rev=616988&view=rev
Log:
add new tests to reproduce a query bug

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?rev=616988&r1=616987&r2=616988&view=diff
==============================================================================
--- 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 Wed Jan 30 18:17:02 2008
@@ -73,6 +73,100 @@
     }
 
     /**
+     * ReportQuery returning rows with some "Liquor" data ordered by price
+     */
+    public void testReportQueryDistinct()
+    {
+
+        Criteria crit = new Criteria();
+        Collection results = new Vector();
+        crit.addEqualTo("productGroup.groupName", "Liquors");
+        ReportQueryByCriteria q = QueryFactory.newReportQuery(Article.class, crit);
+        q.setAttributes(new String[]{"articleId", "articleName", "price"});
+        q.addOrderByAscending("price");
+        q.setDistinct(true);
+
+        Iterator iter = broker.getReportQueryIteratorByQuery(q);
+        assertNotNull(iter);
+        while(iter.hasNext())
+        {
+            results.add(iter.next());
+        }
+        assertTrue(results.size() > 0);
+
+        // compare with count
+        int count = broker.getCount(q);
+        assertEquals(results.size(), count);
+
+    }
+
+    /**
+     * test OrderBy joined column
+     */
+    public void testCountDistinctWithInCriteria()
+    {
+        String name = ojbTestMethodIdentifier();
+        Person person = new Person();
+        person.setFirstname("tom");
+        person.setLastname(name);
+
+        Project project_1 = new Project();
+        project_1.setTitle(name);
+        ArrayList list_1 = new ArrayList();
+        list_1.add(person);
+        project_1.setPersons(list_1);
+
+        Project project_2 = new Project();
+        project_2.setTitle(name);
+        ArrayList list_2 = new ArrayList();
+        list_2.add(person);
+        project_2.setPersons(list_2);
+
+        ArrayList list_projects = new ArrayList();
+        list_projects.add(project_1);
+        list_projects.add(project_2);
+        person.setProjects(list_projects);
+
+        // another Project but without associated Person objects
+        Project project_3 = new Project();
+        project_3.setTitle(name);
+        ArrayList list_3 = new ArrayList();
+        // empty list
+        project_3.setPersons(list_3);
+
+        broker.beginTransaction();
+        broker.store(project_1);
+        //broker.store(project_2);
+        broker.store(project_3);
+        broker.commitTransaction();
+
+        broker.clearCache();
+
+        Criteria crit_in = new Criteria().addLike("firstname", "tom")
+                .addOrCriteria(new Criteria().addLike("firstname", "john"));
+        Query in_query = QueryFactory.newReportQuery(Person.class, new String[]{"id"}, crit_in, true);
+        Criteria crit = new Criteria().addLike("title", name).addIn("persons.id", in_query);
+        ReportQueryByCriteria q = QueryFactory.newReportQuery(Project.class, new String[]{"id"}, crit, true);
+        q.setDistinct(true);
+
+        int count = broker.getCount(q);
+        //System.out.println("Count: " + count);
+        assertEquals(2, count);
+
+        List list = new ArrayList();
+        list.add(new Integer(person.getId()));
+        list.add(new Integer(12));
+        list.add(new Integer(13));
+        crit = new Criteria().addIn("persons.id", list);
+        q = QueryFactory.newReportQuery(Project.class, new String[]{"id"}, crit, true);
+        q.setDistinct(true);
+
+        count = broker.getCount(q);
+        //System.out.println("Count: " + count);
+        assertEquals(2, count);
+    }
+
+    /**
      * test OrderBy joined column
      */
     public void testCountWithInCriteria()



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]