mkalen      2005/03/04 14:42:37

  Modified:    src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        QueryTest.java
  Log:
  Work-around some really weird behaviour with PostgreSQL JDBC. Behaviour 
changes when matching report query attribute "count(productGroupId)" with 
String("10") or Integer(10). Can't ensure this in platform since generic 
stmt.setObject is used for the query attribute's value.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.61.2.12 +30 -8     db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
  
  Index: QueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
  retrieving revision 1.61.2.11
  retrieving revision 1.61.2.12
  diff -u -r1.61.2.11 -r1.61.2.12
  --- QueryTest.java    23 Feb 2005 18:04:39 -0000      1.61.2.11
  +++ QueryTest.java    4 Mar 2005 22:42:37 -0000       1.61.2.12
  @@ -1,5 +1,20 @@
   package org.apache.ojb.broker;
   
  +/* Copyright 2002-2004 The Apache Software Foundation
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +
   import java.sql.Types;
   import java.util.ArrayList;
   import java.util.Arrays;
  @@ -25,10 +40,17 @@
   import org.apache.ojb.junit.PBTestCase;
   
   /**
  - * Testing the query API
  + * Testing the query API.
  + * @version $Id$
    */
   public class QueryTest extends PBTestCase
   {
  +
  +    // Product groups above high water mark are modified by other testcases,
  +    // setting this low makes it easier to re-run this test
  +    private static final Integer PGROUP_ID_HI_WATERMARK =
  +            new Integer(4000);
  +    
       /**
        * BrokerTests constructor comment.
        */
  @@ -289,9 +311,7 @@
   
           results = broker.getCollectionByQuery(q);
           assertNotNull(results);
  -        // System.out.println("*** Found " + results.size() + " empty 
ProductGroups ***");
           assertEquals("Result of the query with sub-query does not match", 
loops, results.size());
  -
       }
   
       /**
  @@ -339,12 +359,12 @@
   
           crit.addLessThan("10", subQuery); // MORE than 10 articles, uses
           // attribute as value !
  -        crit.addLessThan("groupId", new Integer(987654));
  +        crit.addLessThan("groupId", PGROUP_ID_HI_WATERMARK);
           Query q = QueryFactory.newQuery(ProductGroup.class, crit);
   
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
  -        assertTrue(results.size() == 4);
  +        assertEquals(4, results.size());
       }
   
       /**
  @@ -363,13 +383,15 @@
           subQuery = QueryFactory.newReportQuery(Article.class, subCrit);
           subQuery.setAttributes(new String[]{"count(productGroupId)"});
   
  -        crit.addGreaterThan(subQuery, "10"); // MORE than 10 articles
  -        crit.addLessThan("groupId", new Integer(987654));
  +        // mkalen: if using String("10") instead of Integer below,
  +        // PostgreSQL will return 7 (sic!) groups
  +        crit.addGreaterThan(subQuery, new Integer(10)); // MORE than 10 
articles
  +        crit.addLessThan("groupId", PGROUP_ID_HI_WATERMARK);
           Query q = QueryFactory.newQuery(ProductGroup.class, crit);
   
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
  -        assertTrue(results.size() == 4);
  +        assertEquals(4, results.size());
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to