db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker QueryTest.java
Date Wed, 02 Jun 2004 11:48:39 GMT
arminw      2004/06/02 04:48:39

  Modified:    src/test/org/apache/ojb/broker QueryTest.java
  Log:
  add new test, add and query object with non primitive PK field
  with value 0 (test handling of 0 values)
  
  Revision  Changes    Path
  1.58      +45 -50    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.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- QueryTest.java	25 May 2004 20:43:48 -0000	1.57
  +++ QueryTest.java	2 Jun 2004 11:48:39 -0000	1.58
  @@ -18,63 +18,64 @@
   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.junit.PBTestCase;
   
   /**
    * Testing the query API
    */
  -public class QueryTest extends TestCase
  +public class QueryTest extends PBTestCase
   {
  -
  -    PersistenceBroker broker;
  -
  -    private static Class CLASS = QueryTest.class;
  -
       /**
   	 * BrokerTests constructor comment.
  -	 *
  -	 * @param name
  -	 *            java.lang.String
   	 */
       public QueryTest(String name)
       {
           super(name);
       }
   
  -    /**
  -	 * Insert the method's description here. Creation date: (23.12.2000
  -	 * 18:30:38)
  -	 *
  -	 * @param args
  -	 *            java.lang.String[]
  -	 */
       public static void main(String[] args)
       {
  -        String[] arr = { CLASS.getName()};
  +        String[] arr = {QueryTest.class.getName()};
           junit.textui.TestRunner.main(arr);
       }
   
  -    /**
  -	 * Insert the method's description here. Creation date: (06.12.2000
  -	 * 21:58:53)
  -	 */
  -    public void setUp()
  +    public void testQueryZero()
       {
  -        try
  -        {
  -            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        }
  -        catch (PBFactoryException e)
  -        {
  -        }
  -    }
  +        String name = "testQueryZero_" + System.currentTimeMillis();
  +        ObjectRepository.Group group = new ObjectRepository.Group();
  + 	    group.setId(new Integer(0));
  +        group.setName(name);
   
  -    /**
  -	 * Insert the method's description here. Creation date: (06.12.2000
  -	 * 21:59:14)
  -	 */
  -    public void tearDown()
  -    {
  -        broker.close();
  +        // prepare test
  +        broker.beginTransaction();
  +        Query q = QueryFactory.newQuery(group);
  +        broker.deleteByQuery(q);
  +        broker.commitTransaction();
  +        broker.clearCache();
  +
  + 	    QueryByCriteria query = new QueryByCriteria(group);
  + 	    ObjectRepository.Group newGroup = ( ObjectRepository.Group ) broker.getObjectByQuery(query);
  +        assertNull(newGroup);
  +
  +        broker.beginTransaction();
  +        broker.store(group);
  +        broker.commitTransaction();
  +
  +        ObjectRepository.Group groupTemp = new ObjectRepository.Group();
  + 	    groupTemp.setId(new Integer(0));
  +        Query queryNew = QueryFactory.newQuery(groupTemp);
  + 	    newGroup = ( ObjectRepository.Group ) broker.getObjectByQuery(queryNew);
  +        assertNotNull(newGroup);
  +        assertEquals(new Integer(0), newGroup.getId());
  +
  + 	    newGroup = ( ObjectRepository.Group ) broker.getObjectByQuery(queryNew);
  +        assertNotNull(newGroup);
  +        assertEquals(new Integer(0), newGroup.getId());
  +
  +        broker.clearCache();
  +        newGroup = ( ObjectRepository.Group ) broker.getObjectByQuery(queryNew);
  +        assertNotNull(newGroup);
  +        assertEquals(new Integer(0), newGroup.getId());
       }
   
       /**
  @@ -683,7 +684,6 @@
   	 */
       public void testReportQueryGroupBy()
       {
  -
           Criteria crit = new Criteria();
           Collection results = new Vector();
           ReportQueryByCriteria q = QueryFactory.newReportQuery(ProductGroup.class, crit);
  @@ -700,8 +700,7 @@
   
           // compare with count
           int count = broker.getCount(q);
  -//        assertEquals(results.size(), count);   // FAILS !
  -
  +        // assertEquals(results.size(), count);   // FAILS !
       }
   
       /**
  @@ -906,7 +905,6 @@
           }
   
           assertTrue(list.size() > 0);
  -
       }
   
       /**
  @@ -915,8 +913,7 @@
   	 */
       public void tesXNestedJoins2()
       {
  -        ArrayList list = new java.util.ArrayList();
  -
  +        ArrayList list = new ArrayList();
           Criteria crit = new Criteria();
           ReportQueryByCriteria q = QueryFactory.newReportQuery(Task.class, crit);
   
  @@ -927,9 +924,7 @@
           {
               list.add(iter.next());
           }
  -
           assertTrue(list.size() > 0);
  -
       }
   
       /**
  @@ -1012,10 +1007,12 @@
       /**
   	 * test PathExpression pointing to abstract class (InterfaceArticle)
   	 */
  -    public void tesXReportPathExpressionAbstractExtent()
  +    public void testReportPathExpressionAbstractExtent()
       {
  -        ArrayList list = new java.util.ArrayList();
  +        // TODO: make path expressions extent aware
  +        if(ojbSkipKnownIssueProblem()) return;
   
  +        ArrayList list = new ArrayList();
           Criteria crit = new Criteria();
           crit.addEqualTo("groupId", new Integer(5));
   
  @@ -1032,9 +1029,7 @@
           //	assertEquals("check size", list.size(), 12);
           //
           //  BRJ: path expression is not yet extent aware
  -
  -        assertEquals("check size", list.size(), 7);
  -
  +        assertEquals("check size", 12, list.size());
       }
   
       /**
  
  
  

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