You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/01/12 11:55:47 UTC

cvs commit: db-ojb/src/test/org/apache/ojb/broker CollectionTest.java

arminw      2004/01/12 02:55:47

  Modified:    src/test/org/apache/ojb repository_junit_reference.xml
               src/test/org/apache/ojb/broker CollectionTest.java
  Log:
  add new test for user defined collection class
  in collection-descriptor
  
  Revision  Changes    Path
  1.3       +11 -1     db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml
  
  Index: repository_junit_reference.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- repository_junit_reference.xml	12 Dec 2003 21:58:16 -0000	1.2
  +++ repository_junit_reference.xml	12 Jan 2004 10:55:47 -0000	1.3
  @@ -383,6 +383,16 @@
           />
   
           <collection-descriptor
  +        name="collectionDummy"
  +        element-class-ref="org.apache.ojb.broker.CollectionTest$CollectibleBase"
  +        collection-class="org.apache.ojb.broker.CollectionTest$CollectionClassDummy"
  +        auto-retreive="true"
  +        auto-update="true">
  +            <orderby name="colId" sort="ASC"/>
  +            <inverse-foreignkey field-ref="gathererId"/>
  +     </collection-descriptor>
  +
  +        <collection-descriptor
               name="collectiblesBase"
               element-class-ref="org.apache.ojb.broker.CollectionTest$CollectibleBase"
               proxy="false"
  
  
  
  1.6       +109 -2    db-ojb/src/test/org/apache/ojb/broker/CollectionTest.java
  
  Index: CollectionTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/CollectionTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CollectionTest.java	12 Dec 2003 21:58:17 -0000	1.5
  +++ CollectionTest.java	12 Jan 2004 10:55:47 -0000	1.6
  @@ -6,6 +6,7 @@
   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 java.io.Serializable;
   import java.util.Arrays;
  @@ -90,6 +91,65 @@
           }
       }
   
  +    public void testStoreReadOfUserDefinedCollectionClass()
  +    {
  +        String name = "testStoreReadOfUserDefinedCollectionClass_"+System.currentTimeMillis();
  +        Gatherer gat = new Gatherer(null, name);
  +
  +        CollectibleBase[] collBase = prepareCollectibleBase(name);
  +        CollectionClassDummy dummyList = new CollectionClassDummy();
  +        for (int i = 0; i < collBase.length; i++)
  +        {
  +            CollectibleBase collectibleBase = collBase[i];
  +            dummyList.ojbAdd(collectibleBase);
  +        }
  +        gat.setCollectionDummy(dummyList);
  +
  +        broker.beginTransaction();
  +        broker.store(gat);
  +        broker.commitTransaction();
  +
  +        Identity oid = new Identity(gat, broker);
  +        broker.clearCache();
  +        Gatherer new_gat = (Gatherer) broker.getObjectByIdentity(oid);
  +        assertNotNull(new_gat);
  +        assertNotNull(new_gat.getCollectionDummy());
  +        assertEquals(collBase.length, new_gat.getCollectionDummy().size());
  +
  +    }
  +
  +    public void testStoreReadOfUserDefinedCollectionClass_2()
  +    {
  +        String name = "testStoreReadOfUserDefinedCollectionClass_2_"+System.currentTimeMillis();
  +        Gatherer gat = new Gatherer(null, name);
  +
  +        CollectibleBase[] collBase = prepareCollectibleBase(name);
  +        CollectionClassDummy dummyList = new CollectionClassDummy();
  +        for (int i = 0; i < collBase.length; i++)
  +        {
  +            CollectibleBase collectibleBase = collBase[i];
  +            dummyList.ojbAdd(collectibleBase);
  +        }
  +        gat.setCollectionDummy(dummyList);
  +
  +        broker.beginTransaction();
  +        broker.store(gat);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        Query q = QueryFactory.newQuery(Gatherer.class, crit);
  +        Collection result = broker.getCollectionByQuery(q);
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        Gatherer new_gat = (Gatherer) result.iterator().next();
  +        assertNotNull(new_gat);
  +        assertNotNull(new_gat.getCollectionDummy());
  +        assertEquals(collBase.length, new_gat.getCollectionDummy().size());
  +
  +    }
  +
       /**
        * generate main object with collections and store
        * main object to make all persistent
  @@ -729,8 +789,44 @@
   
   
       //*********************************************************************
  -    // inner class - persistent object
  +    // inner classes - persistent object
       //*********************************************************************
  +
  +    public static class CollectionClassDummy implements ManageableCollection
  +    {
  +        ArrayList list = new ArrayList();
  +
  +        public void ojbAdd(Object anObject)
  +        {
  +            list.add(anObject);
  +        }
  +
  +        public void ojbAddAll(ManageableCollection otherCollection)
  +        {
  +            Iterator it = otherCollection.ojbIterator();
  +            while (it.hasNext())
  +            {
  +                list.add(it.next());
  +            }
  +        }
  +
  +        public Iterator ojbIterator()
  +        {
  +            return list.iterator();
  +        }
  +
  +        public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
  +        {
  +            //noop
  +        }
  +
  +        public int size()
  +        {
  +            return list.size();
  +        }
  +    }
  +
  +
       public static class Gatherer implements Serializable
       {
           private Integer gatId;
  @@ -742,6 +838,7 @@
           private List collectiblesCCC;
           private List collectiblesD;
           private List collectiblesDD;
  +        private CollectionClassDummy collectionDummy;
   
           public Gatherer()
           {
  @@ -771,6 +868,16 @@
           public void setName(String name)
           {
               this.name = name;
  +        }
  +
  +        public CollectionClassDummy getCollectionDummy()
  +        {
  +            return collectionDummy;
  +        }
  +
  +        public void setCollectionDummy(CollectionClassDummy collectionDummy)
  +        {
  +            this.collectionDummy = collectionDummy;
           }
   
           public List getCollectiblesBase()
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org