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/junit OJBTestCase.java JUnitExtensions.java
Date Mon, 05 Apr 2004 17:11:49 GMT
arminw      2004/04/05 10:11:49

  Modified:    .        build.xml build.properties
               src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/odmg ODMGRollbackTest.java
                        LockingMultithreadedTest.java CollectionsTest.java
               src/test/org/apache/ojb/broker ReferenceTest.java
                        QueryTest.java OneToManyTest.java
                        NestedFieldsTest.java MultithreadedReadTest.java
                        MultipleTableExtentAwareQueryTest.java
                        MtoNTest.java M2NTest.java
                        KeyConstraintViolationTest.java
                        InheritanceMultipleTableTest.java
                        CollectionTest2.java AutomaticForeignKeys.java
                        AllTests.java
  Added:       src/test/org/apache/ojb/junit OJBTestCase.java
                        JUnitExtensions.java
  Removed:     src/test/org/apache/ojb/broker OneToOneTest.java
                        ManyToManyTest.java JUnitExtensions.java
  Log:
  - Add new package for OJB junit extension classes
  
  - Add OJBTestCase, a base class for all junit tests.
  This class provide a method called "ojbSkipKnownIssueProblem()"
  help to skip failure tests
  
  public void testXYZ()
  {
     if(ojbSkipKnownIssueProblem()) return;
  
     // now the test began
     ...
  }
  
  This will skip the test by default (and print a message).
  If in build.properties OJB.skip.issues=false
  was set, the test wasn't skip.
  
  - add new tests, update tests
  
  - remove "empty" tests and test files
  
  Revision  Changes    Path
  1.121     +3 -1      db-ojb/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/build.xml,v
  retrieving revision 1.120
  retrieving revision 1.121
  diff -u -r1.120 -r1.121
  --- build.xml	5 Apr 2004 00:52:54 -0000	1.120
  +++ build.xml	5 Apr 2004 17:11:47 -0000	1.121
  @@ -889,6 +889,7 @@
   
           <junit printsummary="yes" fork="yes" dir="${build.test}/ojb">
           	<jvmarg value="-DOJB.bootLogLevel=INFO" />
  +            <jvmarg value="-DOJB.skip.issues=${OJB.skip.issues}" />
               <classpath refid="runtime-classpath"/>
               <formatter type="plain" />
               <formatter type="xml" />
  @@ -929,6 +930,7 @@
     <target name="junit-sqlcount-no-compile-no-prepare" depends="checkP6Spy" if="shouldUseP6Spy">
       <junit printsummary="yes" fork="yes" dir="${build.test}/ojb">
           	<jvmarg value="-DOJB.bootLogLevel=INFO" />
  +        	<jvmarg value="-DOJB.skip.issues=${OJB.skip.issues}" />
               <classpath refid="runtime-classpath"/>
               <formatter type="plain" />
               <formatter type="xml" />
  
  
  
  1.52      +7 -1      db-ojb/build.properties
  
  Index: build.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/build.properties,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- build.properties	5 Apr 2004 13:58:58 -0000	1.51
  +++ build.properties	5 Apr 2004 17:11:48 -0000	1.52
  @@ -50,6 +50,12 @@
   # By default the HSQLDB driver is used.
   #useP6Spy=true
   
  +###
  +# If 'true', junit tests marked as known issue in the junit-test
  +# source code (see OJBTestCase class for more detailed info) will be
  +# skipped. Default value is 'true'. For development 'false' is recommended,
  +# because this will show unsolved problems.
  +OJB.skip.issues=true
   
   # -------------------------------------------------------------------
   # You should NOT have to edit anything below here.
  
  
  
  1.111     +37 -2     db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.110
  retrieving revision 1.111
  diff -u -r1.110 -r1.111
  --- repository_junit.xml	5 Apr 2004 13:58:59 -0000	1.110
  +++ repository_junit.xml	5 Apr 2004 17:11:48 -0000	1.111
  @@ -1,6 +1,6 @@
   <!-- Mapping of classes used in junit tests and tutorials starts here -->
   <!--
  -#/* Copyright 2002-2004 The Apache Software Foundation
  +/* 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.
  @@ -1895,6 +1895,22 @@
           column="NAME"
           jdbc-type="VARCHAR"
       />
  +
  +    <field-descriptor
  +        name="fkAddress"
  +        column="FK_ADDRESS"
  +        jdbc-type="INTEGER"
  +        access="anonymous"
  +    />
  +
  +    <reference-descriptor name="address"
  +        class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Address"
  +        auto-retrieve="true"
  +        auto-update="object"
  +        auto-delete="object"
  +    >
  +        <foreignkey field-ref="fkAddress" />
  +    </reference-descriptor>
   </class-descriptor>
   
   <class-descriptor
  @@ -1984,6 +2000,25 @@
       >
               <inverse-foreignkey field-ref="managerId"/>
       </collection-descriptor>
  +</class-descriptor>
  +
  +<class-descriptor
  +	class="org.apache.ojb.broker.InheritanceMultipleTableTest$Address"
  +	table="INHERITANCE_MULTI_ADDRESS"
  + >
  +    <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"
  +    />
  +
  +    <field-descriptor
  +        name="street"
  +        column="STREET"
  +        jdbc-type="VARCHAR"
  +    />
   </class-descriptor>
   
   
  
  
  
  1.22      +9 -6      db-ojb/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java
  
  Index: ODMGRollbackTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ODMGRollbackTest.java	28 Mar 2004 10:48:41 -0000	1.21
  +++ ODMGRollbackTest.java	5 Apr 2004 17:11:48 -0000	1.22
  @@ -5,7 +5,6 @@
   import java.util.Iterator;
   import java.util.List;
   
  -import junit.framework.TestCase;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.Project;
  @@ -13,8 +12,9 @@
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
  -import org.apache.ojb.broker.query.QueryFactory;
   import org.apache.ojb.broker.query.QueryByIdentity;
  +import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.OJBTestCase;
   import org.odmg.Database;
   import org.odmg.Implementation;
   import org.odmg.OQLQuery;
  @@ -24,7 +24,7 @@
    * Do some rollback tests and check behavior within transactions.
    * CAUTION: This tests works only against the default repository.
    */
  -public class ODMGRollbackTest extends TestCase
  +public class ODMGRollbackTest extends OJBTestCase
   {
       private String databaseName;
   
  @@ -99,8 +99,10 @@
        * TODO: this testcase seems to fail for some strange problems with the testbed data
        * the thrown error is unrelated to the things covered in the testcase.
        */
  -    public void tes_tResultsWhileTransactionWithCheckpoint() throws Exception
  +    public void testResultsWhileTransactionWithCheckpoint() throws Exception
       {
  +        if(ojbSkipKnownIssueProblem()) return;
  +
           Implementation ojb = OJB.getInstance();
           Database db = ojb.newDatabase();
           db.open(databaseName, Database.OPEN_READ_WRITE);
  @@ -180,10 +182,11 @@
        * thma:
        * TODO: this testcase seems to fail for some strange problems with the testbed data
        * the thrown error is unrelated to the things covered in the testcase.
  -
        */
  -    public void tes_tResultsAfterTransaction() throws Exception
  +    public void testResultsAfterTransaction() throws Exception
       {
  +        if(ojbSkipKnownIssueProblem()) return;
  +
           Implementation ojb = OJB.getInstance();
           Database db = ojb.newDatabase();
           db.open(databaseName, Database.OPEN_READ_WRITE);
  
  
  
  1.2       +2 -2      db-ojb/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java
  
  Index: LockingMultithreadedTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LockingMultithreadedTest.java	11 Dec 2003 20:13:23 -0000	1.1
  +++ LockingMultithreadedTest.java	5 Apr 2004 17:11:48 -0000	1.2
  @@ -1,8 +1,8 @@
   package org.apache.ojb.odmg;
   
  -import org.apache.ojb.broker.JUnitExtensions;
   import org.apache.ojb.broker.TestHelper;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.junit.JUnitExtensions;
   import org.odmg.Database;
   import org.odmg.Implementation;
   import org.odmg.LockNotGrantedException;
  
  
  
  1.13      +66 -13    db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java
  
  Index: CollectionsTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CollectionsTest.java	28 Mar 2004 10:48:41 -0000	1.12
  +++ CollectionsTest.java	5 Apr 2004 17:11:48 -0000	1.13
  @@ -1,32 +1,32 @@
   package org.apache.ojb.odmg;
   
  -import junit.framework.TestCase;
  -import org.apache.ojb.broker.TestHelper;
  +import java.io.Serializable;
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.Vector;
  +
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.TestHelper;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.OJBTestCase;
   import org.odmg.Database;
   import org.odmg.Implementation;
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  -import java.io.Serializable;
  -import java.util.ArrayList;
  -import java.util.Arrays;
  -import java.util.Collection;
  -import java.util.List;
  -import java.util.Vector;
  -import java.util.Iterator;
  -
   /**
    * Test case handles with collections.
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class CollectionsTest extends TestCase
  +public class CollectionsTest extends OJBTestCase
   {
       private Implementation odmg;
       private Database db;
  @@ -65,6 +65,57 @@
           }
       }
   
  +
  +    public void testStoreCollectionElementWithoutBackReference() throws Exception
  +    {
  +        // String queryColl = "select colls from " + CollectibleC.class.getName() + " where name=$1";
  +        String queryGat = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
  +        String prefix = "testStoreCollectionElementWithoutBackReference_" + System.currentTimeMillis();
  +
  +        // prepare test case
  +        Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
  +        TransactionExt tx = (TransactionExt)odmg.newTransaction();
  +        tx.begin();
  +        db.makePersistent(gat);
  +        tx.commit();
  +        // check if gatherer was stored
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +        assertNotNull(gat.getGatId());
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create(queryGat);
  +        query.bind(gat.getGatId());
  +        Collection result = (Collection) query.execute();
  +        tx.commit();
  +        assertEquals("Wrong number of objects found", 1, result.size());
  +        gat = (Gatherer) result.iterator().next();
  +        assertNotNull(gat);
  +        //**********************************************
  +        CollectibleC child = new CollectibleC(prefix, null, "a new CollectibleC");
  +        tx.begin();
  +        tx.lock(gat, Transaction.WRITE);
  +        tx.lock(child, Transaction.WRITE);
  +        List childs = new ArrayList();
  +        childs.add(child);
  +        gat.setCollectiblesB(childs);
  +        tx.commit();
  +        //**********************************************
  +        // check if gatherer was stored
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +        assertNotNull(gat.getGatId());
  +        query = odmg.newOQLQuery();
  +        query.create(queryGat);
  +        query.bind(gat.getGatId());
  +        result = (Collection) query.execute();
  +        tx.commit();
  +        assertEquals("Wrong number of objects found", 1, result.size());
  +        gat = (Gatherer) result.iterator().next();
  +        assertNotNull(gat);
  +        assertNotNull(gat.getCollectiblesC());
  +        assertEquals(1, gat.getCollectiblesC().size());
  +    }
  +
       /**
        * Create an main object Gatherer with a collection of objects CollectiblesC.
        * CollectiblesC hasn't a reference back to the main object. After creation we
  @@ -426,8 +477,10 @@
        * todo: see ...odmg.ObjectEnvelope line 311
        * todo: as this bug is documented in the release notes I've taken it out from the Junit suite.
        */
  -    public void tes_tUpdateWhenExchangeObjectsInCollection() throws Exception
  +    public void testUpdateWhenExchangeObjectsInCollection() throws Exception
       {
  +        if(ojbSkipKnownIssueProblem()) return;
  +
           final String prefix = "testUpdateWhenExchangeObjectsInCollection" + System.currentTimeMillis();
           final String queryStr = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1 or gatId=$2";
   
  
  
  
  1.13      +24 -3     db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java
  
  Index: ReferenceTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ReferenceTest.java	30 Mar 2004 17:44:10 -0000	1.12
  +++ ReferenceTest.java	5 Apr 2004 17:11:48 -0000	1.13
  @@ -4,12 +4,12 @@
   import java.util.Collection;
   import java.util.Iterator;
   
  -import junit.framework.TestCase;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.OJBTestCase;
   
   /**
    * Test case for checking the management of references.
  @@ -17,7 +17,7 @@
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class ReferenceTest extends TestCase
  +public class ReferenceTest extends OJBTestCase
   {
       private static String REF_TEST_STRING = "refTest";
       private PersistenceBroker broker;
  @@ -879,6 +879,27 @@
   
           return new RepositoryFK[]{repository, repository2, repository3};
       }
  +
  +    public void testMassOperations()
  +    {
  +        broker.beginTransaction();
  +        for (int i = 1; i < 100; i++)
  +        {
  +
  +            ProductGroup pg = new ProductGroup();
  +            pg.setGroupName("1-1 test productgroup_" + i);
  +            broker.store(pg);
  +
  +            Article article = Article.createInstance();
  +            article.setArticleName("1-1 test article_" + i);
  +            article.setProductGroupId(pg.getGroupId());
  +
  +            broker.retrieveReference(article, "productGroup");
  +            broker.store(article);
  +        }
  +        broker.commitTransaction();
  +    }
  +
   
   
   
  
  
  
  1.55      +36 -36    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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- QueryTest.java	31 Mar 2004 19:16:09 -0000	1.54
  +++ QueryTest.java	5 Apr 2004 17:11:48 -0000	1.55
  @@ -76,7 +76,7 @@
       {
           broker.close();
       }
  -    
  +
       /**
        * Criteria containing other Criteria only
        */
  @@ -85,16 +85,16 @@
           Criteria crit1 = new Criteria();
           Criteria crit2 = new Criteria();
           Criteria crit3 = new Criteria();
  -     
  +
           crit2.addEqualTo("lastname","tom");
           crit2.setNegative(true);
  -        
  +
           crit3.addEqualTo("firstname","tom");
           crit3.setNegative(true);
  -        
  +
           crit1.addAndCriteria(crit2);
           crit1.addAndCriteria(crit3);
  -               
  +
           Query q = QueryFactory.newQuery(Person.class, crit1);
           Collection results = broker.getCollectionByQuery(q);
   
  @@ -247,7 +247,7 @@
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
           assertTrue(results.size() > 0);
  -        
  +
           // compare with count
           int count = broker.getCount(q);
           assertEquals(results.size(), count);
  @@ -265,7 +265,7 @@
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
           assertEquals(results.size(), 1);
  -        
  +
           // compare with count
           int count = broker.getCount(q);
           assertEquals(results.size(), count);
  @@ -277,7 +277,7 @@
       public void testLikeEscapedCriteria2()
       {
           LikeCriteria.setEscapeCharacter('|');
  -        
  +
           Criteria crit = new Criteria();
           crit.addLike("firstname", "h%|%");
           Query q = QueryFactory.newQuery(Person.class, crit);
  @@ -285,7 +285,7 @@
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
           assertEquals(results.size(), 1);
  -        
  +
           // compare with count
           int count = broker.getCount(q);
           assertEquals(results.size(), count);
  @@ -428,7 +428,7 @@
           crit.addLike("allArticlesInGroup.articleName", "C%");
           QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit, true);
           q.addOrderByAscending("groupId");
  -        
  +
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
           assertEquals(results.size(), 5);
  @@ -447,17 +447,17 @@
           Criteria crit = new Criteria();
           crit.addEqualTo("project_id", new Integer(1));
           QueryByCriteria q = QueryFactory.newQuery(Role.class, crit, true);
  -        
  +
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
           assertEquals(results.size(), 3);
   
           // compare with count
           int count = broker.getCount(q);
  -        
  +
           assertEquals(results.size(), count); // FAILS
       }
  -    
  +
       /**
   	 * Simple ReportQuery returning rows with 3 columns of Person
   	 */
  @@ -478,10 +478,10 @@
           {
               Object[] row = (Object[])iter.next();
               assertEquals(row.length, 3);
  -            
  +
               results.add(row);
           }
  -        
  +
           assertEquals(results.size(), 5);
   
           // compare with count
  @@ -499,7 +499,7 @@
           Criteria crit = new Criteria();
           Collection results = new Vector();
           int types[] = new int[]{Types.DECIMAL, Types.VARCHAR, Types.BIGINT};
  -        
  +
           crit.addLike("firstname", "%o%");
           ReportQueryByCriteria q = QueryFactory.newReportQuery(Person.class, crit);
           q.setAttributes(new String[] { "id", "firstname", "count(*)" });
  @@ -513,18 +513,18 @@
           {
               Object[] row = (Object[])iter.next();
               assertEquals(row.length, 3);
  -            
  +
   //            assertEquals(row[0].getClass(), BigDecimal.class);
   //            assertEquals(row[1].getClass(), String.class);
   //            assertEquals(row[2].getClass(), Long.class);
   
               results.add(row);
           }
  -        
  +
           assertEquals(results.size(), 5);
   
       }
  -    
  +
       /**
   	 * Simple ReportQuery returning rows with 2 columns of Person
        * needs SQL paging
  @@ -575,8 +575,8 @@
   
           // compare with count
           int count = broker.getCount(q);
  -        assertEquals(results.size(), count);  
  -        
  +        assertEquals(results.size(), count);
  +
       }
   
       /**
  @@ -601,10 +601,10 @@
   
           // compare with count
           int count = broker.getCount(q);
  -        assertEquals(results.size(), count);  
  -        
  +        assertEquals(results.size(), count);
  +
       }
  -    
  +
       /**
   	 * ReportQuery returning rows with some "Liquor" data ordered by price
   	 */
  @@ -628,8 +628,8 @@
   
           // compare with count
           int count = broker.getCount(q);
  -        assertEquals(results.size(), count);  
  -        
  +        assertEquals(results.size(), count);
  +
       }
   
       /**
  @@ -655,10 +655,10 @@
   
           // compare with count
           int count = broker.getCount(q);
  -        assertEquals(results.size(), count); 
  +        assertEquals(results.size(), count);
   
       }
  -    
  +
       /**
   	 * ReportQuery returning rows with summed stock and price per article group
   	 */
  @@ -678,10 +678,10 @@
               results.add(iter.next());
           }
           assertTrue(results.size() > 0);
  -        
  +
           // compare with count
           int count = broker.getCount(q);
  -//        assertEquals(results.size(), count);   // FAILS ! 
  +//        assertEquals(results.size(), count);   // FAILS !
   
       }
   
  @@ -1039,7 +1039,7 @@
           assertTrue(results.size() > 0);
   
       }
  -    
  +
       /**
   	 * test PathExpression pointing to abstract class (InterfaceArticle)
   	 */
  @@ -1370,7 +1370,7 @@
           assertNotNull(result);
           assertTrue(result.size() == 5); // bob, tom, cindy, albert ,betrand
       }
  -    
  +
       public void testQueryCommutative12() throws Exception
       {
           Collection result;
  @@ -1391,12 +1391,12 @@
   
           result = broker.getCollectionByQuery(qry12);
           assertNotNull(result);
  -        
  +
           int count = broker.getCount(qry12);
           assertEquals(count, result.size());
       }
  -    
  -    
  +
  +
       public void testQueryCommutative21()
       {
           Collection result;
  @@ -1409,7 +1409,7 @@
   
           Criteria crit3 = new Criteria();
           crit3.addEqualTo("stock", new Integer(42));
  -        
  +
           crit2.addOrCriteria(crit3);
           crit2.addAndCriteria(crit1);
           QueryByCriteria qry21 = QueryFactory.newQuery(Article.class, crit2);
  
  
  
  1.9       +0 -20     db-ojb/src/test/org/apache/ojb/broker/OneToManyTest.java
  
  Index: OneToManyTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/OneToManyTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- OneToManyTest.java	11 Aug 2003 08:53:00 -0000	1.8
  +++ OneToManyTest.java	5 Apr 2004 17:11:48 -0000	1.9
  @@ -1,11 +1,3 @@
  -/*
  - * Created by IntelliJ IDEA.
  - * User: Matt
  - * Date: Jun 9, 2002
  - * Time: 10:29:27 PM
  - * To change template for new class use
  - * Code Style | Class Templates options (Tools | IDE Options).
  - */
   package org.apache.ojb.broker;
   
   import java.util.List;
  @@ -104,28 +96,16 @@
           assertEquals(3, animals.size());
       }
   
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (24.12.2000 00:33:40)
  -     */
       public OneToManyTest(String name)
       {
           super(name);
       }
   
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (06.12.2000 21:58:53)
  -     */
       public void setUp() throws PBFactoryException
       {
           broker = PersistenceBrokerFactory.defaultPersistenceBroker();
       }
   
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (06.12.2000 21:59:14)
  -     */
       public void tearDown()
       {
           try
  
  
  
  1.8       +1 -0      db-ojb/src/test/org/apache/ojb/broker/NestedFieldsTest.java
  
  Index: NestedFieldsTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/NestedFieldsTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NestedFieldsTest.java	3 Mar 2004 21:18:14 -0000	1.7
  +++ NestedFieldsTest.java	5 Apr 2004 17:11:48 -0000	1.8
  @@ -6,6 +6,7 @@
   import org.apache.ojb.broker.query.QueryFactory;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.junit.OJBTestCase;
   
   import java.util.Collection;
   import java.util.ArrayList;
  
  
  
  1.3       +2 -1      db-ojb/src/test/org/apache/ojb/broker/MultithreadedReadTest.java
  
  Index: MultithreadedReadTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MultithreadedReadTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MultithreadedReadTest.java	5 Feb 2004 17:43:12 -0000	1.2
  +++ MultithreadedReadTest.java	5 Apr 2004 17:11:48 -0000	1.3
  @@ -8,6 +8,7 @@
   
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.QueryByCriteria;
  +import org.apache.ojb.junit.JUnitExtensions;
   
   /**
    * Tests multithreaded read of objects using proxy for nested 1:1 references
  
  
  
  1.2       +2 -1      db-ojb/src/test/org/apache/ojb/broker/MultipleTableExtentAwareQueryTest.java
  
  Index: MultipleTableExtentAwareQueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MultipleTableExtentAwareQueryTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MultipleTableExtentAwareQueryTest.java	5 Sep 2003 14:45:55 -0000	1.1
  +++ MultipleTableExtentAwareQueryTest.java	5 Apr 2004 17:11:48 -0000	1.2
  @@ -4,6 +4,7 @@
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.OJBTestCase;
   
   import java.util.Collection;
   import java.util.Iterator;
  
  
  
  1.14      +21 -38    db-ojb/src/test/org/apache/ojb/broker/MtoNTest.java
  
  Index: MtoNTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MtoNTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MtoNTest.java	26 Feb 2004 20:22:37 -0000	1.13
  +++ MtoNTest.java	5 Apr 2004 17:11:48 -0000	1.14
  @@ -1,7 +1,3 @@
  -/**
  - * User: om
  - */
  -
   package org.apache.ojb.broker;
   
   import java.util.ArrayList;
  @@ -12,7 +8,6 @@
   import java.util.Vector;
   
   import junit.framework.TestCase;
  -
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.util.collections.ManageableArrayList;
  @@ -96,7 +91,7 @@
       }
   
       /**
  -     * Store m-side and intermediary 
  +     * Store m-side and intermediary
        */
       public void testStoringWithAutoUpdateFalse1()
       {
  @@ -105,7 +100,7 @@
           boolean autoUpdate = cod.getCascadeStore();
   
           cod.setCascadeStore(false);
  - 
  +
           try
           {
               String now = new Date().toString();
  @@ -119,7 +114,7 @@
               broker.store(paper);        // store Paper and intermediary table only
               Identity paperId = new Identity(paper, broker);
               broker.commitTransaction();
  -                       
  +
               broker.clearCache();
               broker.beginTransaction();
               Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
  @@ -133,7 +128,7 @@
       }
   
       /**
  -     * Store m-side, intermediary and n-side 
  +     * Store m-side, intermediary and n-side
        * n-side forced by using broker.store()
        */
       public void testStoringWithAutoUpdateFalse2()
  @@ -143,7 +138,7 @@
           boolean autoUpdate = cod.getCascadeStore();
   
           cod.setCascadeStore(false);
  - 
  +
           try
           {
               String now = new Date().toString();
  @@ -158,7 +153,7 @@
               broker.store(qual);         // store Qualifier
               Identity paperId = new Identity(paper, broker);
               broker.commitTransaction();
  -                       
  +
               broker.clearCache();
               broker.beginTransaction();
               Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
  @@ -170,9 +165,9 @@
               cod.setCascadeStore(autoUpdate);
           }
       }
  -    
  +
       /**
  -     * Store m-side, intermediary and n-side 
  +     * Store m-side, intermediary and n-side
        */
       public void testStoringWithAutoUpdateTrue()
       {
  @@ -181,7 +176,7 @@
           boolean autoUpdate = cod.getCascadeStore();
   
           cod.setCascadeStore(true);
  - 
  +
           try
           {
               String now = new Date().toString();
  @@ -195,7 +190,7 @@
               broker.store(paper);        // store Paper, intermediary and Qualifier
               Identity paperId = new Identity(paper, broker);
               broker.commitTransaction();
  -                       
  +
               broker.clearCache();
               broker.beginTransaction();
               Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
  @@ -333,7 +328,7 @@
           Qualifier qual1 = (Qualifier) qualifiers.get(0);
           Qualifier qual2 = (Qualifier) qualifiers.get(1);
   
  -        // now clear collection 
  +        // now clear collection
           paper.getQualifiers().clear();
           broker.beginTransaction();
           broker.store(paper);
  @@ -379,11 +374,11 @@
   
           assertNotNull(retQual1);
           assertNotNull(retQual2);
  -        
  +
           broker.commitTransaction();
       }
   
  -   
  +
       public void testDeleteMtoNImplementor()
           throws Exception
       {
  @@ -399,7 +394,7 @@
   
   		broker.clearCache();
   		newNews = (News) broker.getObjectByIdentity(id);
  -        
  +
           assertEquals(size - 1,newNews.getQualifiers().size());
       }
   
  @@ -418,35 +413,29 @@
   
   		broker.clearCache();
   		newNews = (News) broker.getObjectByIdentity(id);
  -        
  +
   		assertEquals(size + 1,newNews.getQualifiers().size());
  -	
  +
   	}
   
  - 
  +
       // Bidirectional m:n relationship using Collection
       public void testStoreBidirectionalCollection()
       {
  -        int id = (int)System.currentTimeMillis();       
  -        id = Math.abs(id);
  -        
           Person personA = new Person();
  -        personA.setId(id++);
           personA.setFirstname("Anton");
   
           Project proj1 = new Project();
  -        proj1.setId(id++);
           proj1.setTitle("Project 1");
   
           Project proj2 = new Project();
  -        proj2.setId(id++);
           proj2.setTitle("Project 2");
   
           Collection persons = new ArrayList();
           persons.add(personA);
           proj1.setPersons(persons);
           proj2.setPersons(persons);
  -        
  +
           Collection projects = new ArrayList();
           projects.add(proj1);
           projects.add(proj2);
  @@ -457,24 +446,18 @@
           broker.store(proj1);
           broker.store(proj2);
           broker.commitTransaction();
  -    }  
  -    
  +    }
  +
       // Bidirectional m:n relationship using Array
       public void testStoreBidirectionalArray()
       {
  -        int id = (int)System.currentTimeMillis();
  -        id = Math.abs(id);
  -
           PersonWithArray personA = new PersonWithArray();
  -        personA.setId(id++);
           personA.setFirstname("Anton");
   
           ProjectWithArray proj1 = new ProjectWithArray();
  -        proj1.setId(id++);
           proj1.setTitle("Project 1");
   
           ProjectWithArray proj2 = new ProjectWithArray();
  -        proj2.setId(id++);
           proj2.setTitle("Project 2");
   
           proj1.setPersons(new PersonWithArray[] { personA });
  
  
  
  1.3       +3 -2      db-ojb/src/test/org/apache/ojb/broker/M2NTest.java
  
  Index: M2NTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/M2NTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- M2NTest.java	30 Mar 2004 17:44:10 -0000	1.2
  +++ M2NTest.java	5 Apr 2004 17:11:48 -0000	1.3
  @@ -12,6 +12,7 @@
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.OJBTestCase;
   
   /**
    * Test (non-decomposed) M:N relations.
  @@ -435,7 +436,7 @@
   
       public void doTestStoreUpdateTTXX()
       {
  -        String postfix = "" + System.currentTimeMillis();
  +        String postfix = "doTestStoreUpdateTTXX_" + System.currentTimeMillis();
           Movie movie = buildMovieWithActors(postfix);
   
           broker.beginTransaction();
  
  
  
  1.5       +23 -45    db-ojb/src/test/org/apache/ojb/broker/KeyConstraintViolationTest.java
  
  Index: KeyConstraintViolationTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/KeyConstraintViolationTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- KeyConstraintViolationTest.java	5 Apr 2004 00:14:51 -0000	1.4
  +++ KeyConstraintViolationTest.java	5 Apr 2004 17:11:48 -0000	1.5
  @@ -1,46 +1,32 @@
   package org.apache.ojb.broker;
   
  -import junit.framework.TestCase;
   import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
  +import org.apache.ojb.junit.OJBTestCase;
   
   /**
    * @author Matthew Baird
    *
    */
  -public class KeyConstraintViolationTest  extends TestCase
  +public class KeyConstraintViolationTest  extends OJBTestCase
   {
   	public static void main(String[] args)
   	{
  -		String[] arr = { CLASS.getName()};
  +		String[] arr = {KeyConstraintViolationTest.class.getName()};
   		junit.textui.TestRunner.main(arr);
   	}
   
   	PersistenceBroker broker;
  -	private static Class CLASS = BlobTest.class;
   
  -	/**
  -	 * Insert the method's description here.
  -	 * 
  -	 * Creation date: (24.12.2000 00:33:40)
  -	 */
  -	public KeyConstraintViolationTest(String name)
  +    public KeyConstraintViolationTest(String name)
   	{
   		super(name);
   	}
   
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:58:53)
  -	 */
   	public void setUp() throws PBFactoryException
   	{
   		broker = PersistenceBrokerFactory.defaultPersistenceBroker();
   	}
   
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:59:14)
  -	 */
   	public void tearDown()
   	{
   		try
  @@ -53,49 +39,41 @@
   		}
   	}
   
  -
  -	/** 
  +	/**
   	 * Test creating two objects with the same ID, should fail with
  -	 * key constraint error 
  +	 * key constraint error
   	 **/
   	public void testKeyViolation() throws Exception
   	{
  -		try
  +        ObjectModificationDefaultImpl objMod = new ObjectModificationDefaultImpl();
  +        objMod.setNeedsInsert(true);
  +
  +        broker.beginTransaction();
  +        Article obj = new Article();
  +        obj.setProductGroupId(1);
  +        obj.articleName = "repeated Article";
  +        // storing once should be ok.
  +        broker.store(obj,objMod);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        try
   		{
  -			ObjectModificationDefaultImpl objMod = new ObjectModificationDefaultImpl();
  -			objMod.setNeedsInsert(true);
  -			
  -			broker.beginTransaction();
  -			Article obj = new Article();
  -			obj.articleId = 5440;
  -			obj.articleName = "repeated Article";
  -			
  -			// storing once should be ok.
  -			broker.store(obj,objMod);
  -			
  -			broker.clearCache();
  -			
  -			broker.commitTransaction();
  -			
   			broker.beginTransaction();
   			Article obj2 = new Article();
  -			obj2.articleId = 5440;
  +			obj2.articleId = obj.getArticleId();
  +            obj2.setProductGroupId(1);
   			obj2.articleName = "repeated Article";
  -			
  +
   			// store it again!
   			broker.store(obj2,objMod);
   			broker.commitTransaction();
  -			
  +
   			fail("Should have thrown a KeyConstraintViolatedException");
   		}
   		catch (KeyConstraintViolatedException t)
   		{
   			// this is a success.
  -		}
  -		catch (Throwable t)
  -		{
  -			System.out.println("CAUGHT");
  -			t.printStackTrace();
   		}
   	}
   }
  
  
  
  1.2       +200 -4    db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
  
  Index: InheritanceMultipleTableTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InheritanceMultipleTableTest.java	26 Mar 2004 21:31:56 -0000	1.1
  +++ InheritanceMultipleTableTest.java	5 Apr 2004 17:11:48 -0000	1.2
  @@ -1,16 +1,16 @@
   package org.apache.ojb.broker;
   
  -import java.util.Collection;
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.List;
   
  -import junit.framework.TestCase;
   import org.apache.commons.lang.builder.EqualsBuilder;
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.ToStringStyle;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.OJBTestCase;
   
   /**
    *
  @@ -18,7 +18,7 @@
    * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
    * @version $Id$
    */
  -public class InheritanceMultipleTableTest extends TestCase
  +public class InheritanceMultipleTableTest extends OJBTestCase
   {
       private PersistenceBroker broker;
   
  @@ -40,6 +40,156 @@
            }
       }
   
  +    public void testQuery()
  +    {
  +        String name = "testInsert" + System.currentTimeMillis();
  +        Manager m_1 = new Manager(name + "_manager_1");
  +        Manager m_2 = new Manager(name + "_manager_2");
  +        Manager m_3 = new Manager(name + "_manager_3");
  +        m_3.setDepartment("none");
  +
  +        Executive ex_1 = new Executive(name+"_executive", "department_1", null);
  +        Executive ex_2 = new Executive(name+"_executive", "department_1", null);
  +
  +        Employee em = new Employee(name+"_employee");
  +
  +        broker.beginTransaction();
  +        broker.store(m_1);
  +        broker.store(m_2);
  +        broker.store(m_3);
  +        broker.store(ex_1);
  +        broker.store(ex_2);
  +        broker.store(em);
  +        broker.commitTransaction();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("department", "none");
  +        Query query = QueryFactory.newQuery(Manager.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name+"%");
  +        query = QueryFactory.newQuery(Employee.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(6, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name+"%");
  +        query = QueryFactory.newQuery(Executive.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(5, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name+"%");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(3, result.size());
  +    }
  +
  +    private void prepareForQueryTests(String name)
  +    {
  +        Manager m_1 = new Manager(name + "_manager_1");
  +        Manager m_2 = new Manager(name + "_manager_2");
  +        Manager m_3 = new Manager(name + "_manager_3");
  +        m_3.setDepartment("none");
  +        Address a_1 = new Address("snob allee");
  +        m_1.setAddress(a_1);
  +
  +        Executive ex_1 = new Executive(name+"_executive", "department_1", null);
  +        Executive ex_2 = new Executive(name+"_executive", "department_1", null);
  +
  +        Employee em = new Employee(name+"_employee");
  +        Address a_2 = new Address("cockroaches valley");
  +        em.setAddress(a_2);
  +
  +        broker.beginTransaction();
  +        broker.store(m_1);
  +        broker.store(m_2);
  +        broker.store(m_3);
  +        broker.store(ex_1);
  +        broker.store(ex_2);
  +        broker.store(em);
  +        broker.commitTransaction();
  +    }
  +
  +    public void testQuery_InheritedObjects()
  +    {
  +        String name = "testQuery_InheritedObjects" + System.currentTimeMillis();
  +        prepareForQueryTests(name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name+"%");
  +        Query query = QueryFactory.newQuery(Employee.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(6, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name+"%");
  +        query = QueryFactory.newQuery(Executive.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(5, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name+"%");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(3, result.size());
  +    }
  +
  +    public void testQuery_InheritedField()
  +    {
  +        String name = "testQuery_InheritedField" + System.currentTimeMillis();
  +        prepareForQueryTests(name);
  +        broker.clearCache();
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("department", "none");
  +        Query query = QueryFactory.newQuery(Manager.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +    }
  +
  +    public void testQuery_Reference()
  +    {
  +        String name = "testQuery_Reference" + System.currentTimeMillis();
  +        prepareForQueryTests(name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("address.street", "%valley");
  +        Query query = QueryFactory.newQuery(Employee.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +    }
  +
  +    public void testQuery_InheritedReference()
  +    {
  +        // TODO: skip this test, we have to fix this after 1.0
  +        if(ojbSkipKnownIssueProblem()) return;
  +
  +        String name = "testQuery_InheritedReference" + System.currentTimeMillis();
  +        prepareForQueryTests(name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addEqualTo("address.street", "snob allee");
  +        Query query = QueryFactory.newQuery(Manager.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +        Manager retManager = (Manager) result.iterator().next();
  +        assertNotNull(retManager);
  +        assertEquals(name + "_manager_1", retManager.getName());
  +        assertNotNull(retManager.getAddress());
  +        assertEquals("snob allee", retManager.getAddress().getStreet());
  +    }
  +
       public void testInsertQuery()
       {
           String name = "testInsert" + System.currentTimeMillis();
  @@ -270,6 +420,7 @@
       {
           private Integer id;
           private String name;
  +        private Address address;
   
           public Employee()
           {
  @@ -290,6 +441,16 @@
               this.id = id;
           }
   
  +        public Address getAddress()
  +        {
  +            return address;
  +        }
  +
  +        public void setAddress(Address address)
  +        {
  +            this.address = address;
  +        }
  +
           public String getName()
           {
               return name;
  @@ -313,6 +474,41 @@
           public String toString()
           {
               return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, Employee.class);
  +        }
  +    }
  +
  +    public static class Address
  +    {
  +        private Integer id;
  +        private String street;
  +
  +        public Address()
  +        {
  +        }
  +
  +        public Address(String street)
  +        {
  +            this.street = street;
  +        }
  +
  +        public Integer getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(Integer id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getStreet()
  +        {
  +            return street;
  +        }
  +
  +        public void setStreet(String street)
  +        {
  +            this.street = street;
           }
       }
   }
  
  
  
  1.3       +75 -3     db-ojb/src/test/org/apache/ojb/broker/CollectionTest2.java
  
  Index: CollectionTest2.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/CollectionTest2.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CollectionTest2.java	30 Mar 2004 17:44:10 -0000	1.2
  +++ CollectionTest2.java	5 Apr 2004 17:11:48 -0000	1.3
  @@ -4,13 +4,13 @@
   import java.util.Collection;
   import java.util.Iterator;
   
  -import junit.framework.TestCase;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.OJBTestCase;
   
   /**
    * Test case for collection handling.
  @@ -22,7 +22,7 @@
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class CollectionTest2 extends TestCase
  +public class CollectionTest2 extends OJBTestCase
   {
       private PersistenceBroker broker;
   
  @@ -476,6 +476,78 @@
           assertEquals(0, result.size());
       }
   
  +    public void testUpdate_1()
  +    {
  +        changeAutoSetting(Project.class, "subProjects", true,
  +                CollectionDescriptor.CASCADE_OBJECT, CollectionDescriptor.CASCADE_NONE, false);
  +        changeAutoSetting(Project.class, "developers", true,
  +                CollectionDescriptor.CASCADE_LINK, CollectionDescriptor.CASCADE_LINK, false);
  +        changeAutoSetting(SubProject.class, "project", true,
  +                CollectionDescriptor.CASCADE_OBJECT, CollectionDescriptor.CASCADE_NONE, false);
  +    }
  +
  +    public void testUpdate_2()
  +    {
  +        changeAutoSetting(Project.class, "subProjects", true,
  +                CollectionDescriptor.CASCADE_OBJECT, CollectionDescriptor.CASCADE_NONE, true);
  +        changeAutoSetting(Project.class, "developers", true,
  +                CollectionDescriptor.CASCADE_LINK, CollectionDescriptor.CASCADE_LINK, true);
  +        changeAutoSetting(SubProject.class, "project", true,
  +                CollectionDescriptor.CASCADE_OBJECT, CollectionDescriptor.CASCADE_NONE, true);
  +    }
  +
  +    public void doTestUpdate()
  +    {
  +        String name = "testStoreUpdateDelete_2" + System.currentTimeMillis();
  +
  +        changeAutoSetting(Project.class, "subProjects", true,
  +                CollectionDescriptor.CASCADE_OBJECT, CollectionDescriptor.CASCADE_NONE, false);
  +        changeAutoSetting(Project.class, "developers", true,
  +                CollectionDescriptor.CASCADE_LINK, CollectionDescriptor.CASCADE_LINK, false);
  +        changeAutoSetting(SubProject.class, "project", true,
  +                CollectionDescriptor.CASCADE_OBJECT, CollectionDescriptor.CASCADE_NONE, false);
  +
  +        Developer dev1 = new Developer(name);
  +        Developer dev2 = new Developer(name);
  +        ArrayList devList = new ArrayList();
  +        devList.add(dev1);
  +        devList.add(dev2);
  +
  +        SubProject sub1 = new SubProject(name, null);
  +        SubProject sub2 = new SubProject(name, null);
  +        ArrayList subList = new ArrayList();
  +        subList.add(sub1);
  +        subList.add(sub2);
  +
  +        Project pro = new Project(name, subList, devList);
  +        sub1.setProject(pro);
  +        sub2.setProject(pro);
  +
  +        sub1.setProject(pro);
  +        sub2.setProject(pro);
  +        pro.setSubProjects(subList);
  +        pro.setDevelopers(devList);
  +
  +        Query queryProject = createQueryFor(Project.class, "name", name);
  +        Query querySubProject = createQueryFor(SubProject.class, "name", name);
  +        Query queryDeveloper = createQueryFor(Developer.class, "name", name);
  +
  +        //*****************************************
  +        // insert
  +        //*****************************************
  +        broker.beginTransaction();
  +        broker.store(pro);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        Collection result = broker.getCollectionByQuery(queryProject);
  +        assertEquals(1, result.size());
  +        assertNotNull(result.iterator().next());
  +        result = broker.getCollectionByQuery(querySubProject);
  +        assertEquals(2, result.size());
  +        result = broker.getCollectionByQuery(queryDeveloper);
  +        assertEquals(0, result.size());
  +    }
   
       //============================================================================
       // helper methods
  
  
  
  1.7       +6 -18     db-ojb/src/test/org/apache/ojb/broker/AutomaticForeignKeys.java
  
  Index: AutomaticForeignKeys.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AutomaticForeignKeys.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AutomaticForeignKeys.java	28 Jun 2003 15:59:17 -0000	1.6
  +++ AutomaticForeignKeys.java	5 Apr 2004 17:11:48 -0000	1.7
  @@ -1,35 +1,27 @@
   package org.apache.ojb.broker;
  -import junit.framework.TestCase;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  +import org.apache.ojb.junit.OJBTestCase;
   
   /**
    * This TestClass tests OJB facilities to work with polymorphism.
    */
  -public class AutomaticForeignKeys extends TestCase
  +public class AutomaticForeignKeys extends OJBTestCase
   {
   	public static void main(String[] args)
   	{
  -		String[] arr = { CLASS.getName()};
  +		String[] arr = {AutomaticForeignKeys.class.getName()};
   		junit.textui.TestRunner.main(arr);
   	}
  -	PersistenceBroker broker;
  -	private static Class CLASS = AutomaticForeignKeys.class;
   
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (24.12.2000 00:33:40)
  -	 */
  -	public AutomaticForeignKeys(String name)
  +	private PersistenceBroker broker;
  +
  +    public AutomaticForeignKeys(String name)
   
   	{
   		super(name);
   	}
   
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:58:53)
  -	 */
   	public void setUp() throws PBFactoryException
   	{
   		broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  @@ -39,10 +31,6 @@
   		ord.setCascadeStore(true);
   	}
   
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:59:14)
  -	 */
   	public void tearDown()
   
   	{
  
  
  
  1.42      +0 -2      db-ojb/src/test/org/apache/ojb/broker/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AllTests.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- AllTests.java	26 Mar 2004 21:31:56 -0000	1.41
  +++ AllTests.java	5 Apr 2004 17:11:48 -0000	1.42
  @@ -63,8 +63,6 @@
           suite.addTestSuite(RsIteratorTest.class);
           suite.addTestSuite(BlobTest.class); /* doesn't work for hsqldb */
           suite.addTestSuite(LogServiceTest.class);
  -        suite.addTestSuite(ManyToManyTest.class);
  -        suite.addTestSuite(OneToOneTest.class);
           suite.addTestSuite(MetaDataSerializationTest.class);
           suite.addTestSuite(MetadataTest.class);
           suite.addTestSuite(MetadataMultithreadedTest.class);
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/junit/OJBTestCase.java
  
  Index: OJBTestCase.java
  ===================================================================
  package org.apache.ojb.junit;
  
  import junit.framework.TestCase;
  
  /**
   * Extension of the JUnit test class.
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: OJBTestCase.java,v 1.1 2004/04/05 17:11:49 arminw Exp $
   */
  public class OJBTestCase extends TestCase
  {
      private static final String SKIP_STR = "OJB.skip.issues";
      private static final String SKIP_DEFAULT_VALUE = "true";
  
      public OJBTestCase()
      {
      }
  
      public OJBTestCase(String name)
      {
          super(name);
      }
  
      /**
       * This method could be used to skip 'problematic' test cases or known issues before
       * a release was made. To enable the skipped tests set a system property 'skip.issues'
       * to <tt>false</tt>.
       */
      public boolean ojbSkipKnownIssueProblem()
      {
          return skipKnownIssueProblem(null);
      }
  
      /**
       * This method could be used to skip 'problematic' test cases or known issues before
       * a release was made. To enable the skipped tests set a system property 'skip.issues'
       * to <tt>false</tt>.
       */
      public boolean skipKnownIssueProblem(String message)
      {
          String result = SKIP_DEFAULT_VALUE;
          boolean skip = true;
          try
          {
              result = System.getProperty(SKIP_STR, result);
              skip = new Boolean(result).booleanValue();
          }
          catch(Exception e)
          {
              System.err.println("Seems that system property '" + SKIP_STR + "=" + result + "' is not a valid boolean value");
          }
          if(skip)
          {
              if(message == null)
              {
                 message = "Will skip a known issue";
              }
              String className = this.getClass().getName();
              System.out.println("# [Skip test in " + className + "] " + message + " #");
          }
          return skip;
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/junit/JUnitExtensions.java
  
  Index: JUnitExtensions.java
  ===================================================================
  package org.apache.ojb.junit;
  
  import junit.framework.AssertionFailedError;
  import junit.framework.TestCase;
  import junit.framework.TestResult;
  
  /**
   * Extensions for junit to write test cases for multithreaded tests.
   * All classes are from an
   * <a href="http://www.javaworld.com/javaworld/jw-12-2000/jw-1221-junit.html">
   * javaworld article</a> about junit.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: JUnitExtensions.java,v 1.1 2004/04/05 17:11:49 arminw Exp $
   */
  public class JUnitExtensions
  {
      /**
       * A multi-threaded JUnit test case.
       * To perform test cases that spin off threads to do tests: <p>
       * <UL>
       * <LI>Extend <code>MultiThreadedTestCase</code>
       * <LI>Write your tests cases as normal except for when you want to spin off threads.
       * <LI>When you want to spin off threads:
       * <UL>
       * <LI>Instead of implementing <code>Runnable</code> extend <code>MultiThreadedTestCase.TestCaseRunnable</code>.
       * <LI>Define <code>runTestCase ()</code> to do your test, you may call <code>fail (), assert ()</code> etc. and throw
       * exceptions with impunity.
       * <LI>Handle thread interrupts by finishing.
       * </UL>
       * <LI>Instantiate all the runnables (one for each thread you wish to spawn) and pass an array of them
       * to <code>runTestCaseRunnables ()</code>.
       * </UL>
       * That's it. An example is below:
       * <PRE>
       * public class MTTest extends JUnitExtensions.MultiThreadedTestCase
       * {
       *   MTTest (String s) { super (s); }
       *   public class CounterThread extends JUnitExtensions.TestCaseRunnable
       *   {
       *     public void runTestCase () throws Throwable
       *     {
       *       for (int i = 0; i < 1000; i++)
       *       {
       *         System.out.println ("Counter Thread: " + Thread.currentThread () + " : " + i);
       *         // Do some testing...
       *         if (Thread.currentThread ().isInterrupted ()) {
       *           return;
       *         }
       *       }
       *     }
       *   }
       *
       *   public void test1 ()
       *   {
       *     TestCaseRunnable tct [] = new TestCaseRunnable [5];
       *     for (int i = 0; i < 5; i++)
       *     {
       *       tct[i] = new CounterThread ();
       *      }
       *     runTestCaseRunnables (tct);
       *   }
       * }
       * </PRE>
       * <BR><STRONG>Category: Test</STRONG>
       * <BR><STRONG>Not guaranteed to be thread safe.</STRONG>
       */
      public static class MultiThreadedTestCase extends TestCase
      {
          /**
           * The threads that are executing.
           */
          private Thread threads[] = null;
          /**
           * The tests TestResult.*/
          private TestResult testResult = null;
  
          /**
           * Simple constructor.
           */
  
          public MultiThreadedTestCase(String s)
          {
              super(s);
          }
  
          /**
           * Interrupt the running threads.
           */
          public void interruptThreads()
          {
              if (threads != null)
              {
                  for (int i = 0; i < threads.length; i++)
                  {
                      threads[i].interrupt();
                  }
              }
          }
  
          /**
           * Override run so we can squirrel away the test result.*/
  
          public void run(final TestResult result)
          {
              testResult = result;
              super.run(result);
              testResult = null;
          }
  
          /**
           * Run the test case threads.*/
  
          protected void runTestCaseRunnables(final TestCaseRunnable[] runnables)
          {
              if (runnables == null)
              {
                  throw new IllegalArgumentException("runnables is null");
              }
              threads = new Thread[runnables.length];
              for (int i = 0; i < threads.length; i++)
              {
                  threads[i] = new Thread(runnables[i]);
              }
              for (int i = 0; i < threads.length; i++)
              {
                  threads[i].start();
              }
              try
              {
                  for (int i = 0; i < threads.length; i++)
                  {
                      threads[i].join();
                  }
              }
              catch (InterruptedException ignore)
              {
                  System.out.println("Thread join interrupted.");
              }
              threads = null;
          }
  
          /**
           * Handle an exception. Since multiple threads won't have their
           * exceptions caught the threads must manually catch them and call
           * <code>handleException ()</code>.
           * @param t Exception to handle.
           */
          private void handleException(final Throwable t)
          {
              synchronized (testResult)
              {
                  if (t instanceof AssertionFailedError)
                  {
                      testResult.addFailure(this, (AssertionFailedError) t);
                  }
                  else
                  {
                      testResult.addError(this, t);
                  }
              }
          }
  
          // ======================================================================
          // inner class
          // ======================================================================
          /**
           * A test case thread. Override runTestCase () and define
           * behaviour of test in there.*/
          protected abstract class TestCaseRunnable implements Runnable
          {
              /**
               * Override this to define the test*/
  
              public abstract void runTestCase()
                      throws Throwable;
  
              /**
               * Run the test in an environment where
               * we can handle the exceptions generated by the test method.*/
  
              public void run()
              {
                  try
                  {
                      runTestCase();
                  }
                  catch (Throwable t) /* Any other exception we handle and then we interrupt the other threads.*/
                  {
                      handleException(t);
                      interruptThreads();
                  }
              }
          }
      }
  }
  
  
  

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