db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r524864 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
Date Mon, 02 Apr 2007 18:14:41 GMT
Author: arminw
Date: Mon Apr  2 11:14:41 2007
New Revision: 524864

URL: http://svn.apache.org/viewvc?view=rev&rev=524864
Log:
fix tests, add new 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=524864&r1=524863&r2=524864
==============================================================================
--- 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 Mon Apr
 2 11:14:41 2007
@@ -84,7 +84,7 @@
         ClassDescriptor cld = broker.getClassDescriptor(Article.class);
         FieldDescriptor fld = cld.getFieldDescriptorByName("articleName");
 
-        String sql = "select * from " + cld.getFullTableName() + " as A1 where A1." + fld.getColumnName()
+ " = '" + name + "'";
+        String sql = "select * from " + cld.getFullTableName() + " A1 where A1." + fld.getColumnName()
+ " = '" + name + "'";
 
         Query query = QueryFactory.newQuery(sql);
         Iterator it = broker.getReportQueryIteratorByQuery(query);
@@ -491,12 +491,59 @@
 
         ReportQueryByCriteria subQuery;
         Criteria subCrit = new Criteria();
+        // we want to execute a "not in" query, so we have to guaratee none null
+        // results in the sub-query, else the whole sub-result will be false
+        subCrit.addNotNull("productGroupId");
+
+        subQuery = QueryFactory.newReportQuery(Article.class, subCrit);
+        subQuery.setAttributes(new String[]{"productGroupId"});
+        subQuery.setDistinct(true);
+
         Criteria crit = new Criteria();
+        crit.addEqualTo("groupName", "test group " + stamp);
+        crit.addNotIn("groupId", subQuery);
+        Query q = QueryFactory.newQuery(ProductGroup.class, crit);
+
+        results = broker.getCollectionByQuery(q);
+        assertNotNull(results);
+        assertEquals("Result of the query with sub-query does not match", loops, results.size());
+    }
+
+    /**
+     * test Subquery get all product groups without articles, with orderby in sub-query
+     * <p/>
+     * test may fail if db does not support sub queries
+     */
+    public void testSubQuery2a()
+    {
+        Collection results;
+        String stamp = "testSubQuery2a_" + System.currentTimeMillis();
+        int loops = 10;
+        // create ProductGroups without article
+        broker.beginTransaction();
+        for(int i = 0; i < loops; i++)
+        {
+            ProductGroup pg = new ProductGroup();
+            pg.setGroupName("test group " + stamp);
+            pg.setDescription("build by QueryTest#testSubQuery2");
+            broker.store(pg);
+        }
+        broker.commitTransaction();
+
+        ReportQueryByCriteria subQuery;
+        Criteria subCrit = new Criteria();
+        // we want to execute a "not in" query, so we have to guaratee none null
+        // results in the sub-query, else the whole sub-result will be false
+        subCrit.addNotNull("productGroupId");
 
         subQuery = QueryFactory.newReportQuery(Article.class, subCrit);
         subQuery.setAttributes(new String[]{"productGroupId"});
         subQuery.setDistinct(true);
+        // this doesn't make sense in this test, it's only added to check
+        // orderby clause in sub-query
+        subQuery.addOrderBy("productGroupId", true);
 
+        Criteria crit = new Criteria();
         crit.addEqualTo("groupName", "test group " + stamp);
         crit.addNotIn("groupId", subQuery);
         Query q = QueryFactory.newQuery(ProductGroup.class, crit);
@@ -1878,8 +1925,6 @@
      */
     public void testReportPathExpressionForExtents1()
     {
-        ArrayList list = new java.util.ArrayList();
-
         Criteria crit = new Criteria();
         crit.addGreaterOrEqualThan("allArticlesInGroup.articleId", new Integer(1));
         crit.addLessOrEqualThan("allArticlesInGroup.articleId", new Integer(5));
@@ -1898,7 +1943,6 @@
             assertTrue("ReportQuery result row is not Object[]",
                     row instanceof Object[]);
             columns = (Object[]) row;
-            list.add(columns);
 
             assertTrue("ReportQuery result row does not contain all expected columns",
                     columns.length == 3);
@@ -1908,6 +1952,7 @@
             think hsql returns the wrong result or interpret the query in wrong
             way (e.g. using hashcode of values instead values itself), so skip test
             evaluation for this DB
+            TODO: check hsql for test compatibility (from time to time)
             */
             if(!broker.serviceConnectionManager().getSupportedPlatform().getClass().equals(PlatformHsqldbImpl.class))
             {



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