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 br...@apache.org on 2005/03/09 20:40:41 UTC

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

brj         2005/03/09 11:40:41

  Modified:    src/test/org/apache/ojb/broker CollectionTest.java
  Log:
  Testcase for RemovalAwareCollection
  
  Revision  Changes    Path
  1.17      +61 -1     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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CollectionTest.java	13 Dec 2004 18:25:13 -0000	1.16
  +++ CollectionTest.java	9 Mar 2005 19:40:41 -0000	1.17
  @@ -13,6 +13,7 @@
   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.util.collections.RemovalAwareCollection;
   import org.apache.ojb.junit.PBTestCase;
   
   /**
  @@ -794,6 +795,65 @@
       }
   
   
  +    /**
  +     * Test RemovalAwareCollection remove() and clear()
  +     */
  +    public void testRemovalAwareCollection()
  +    {
  +        String prefix = "testRemovalAwareCollection_" + System.currentTimeMillis();
  +
  +        Identity gathererId;
  +        Gatherer loadedCopy;
  +        Gatherer gatherer = new Gatherer(null, "Gatherer_" + prefix);
  +        List coll = new ArrayList();
  +        coll.add(new CollectibleBase("Base_1_" + prefix));
  +        coll.add(new CollectibleBase("Base_2_" + prefix));
  +        coll.add(new CollectibleBase("Base_3_" + prefix));
  +        gatherer.setCollectiblesBase(coll);
  +
  +        broker.beginTransaction();
  +        broker.store(gatherer);
  +        broker.commitTransaction();
  +        assertTrue(gatherer.getGatId() != null);
  +        gathererId = broker.serviceIdentity().buildIdentity(gatherer);
  +
  +        broker.clearCache();
  +        loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
  +        assertNotNull(loadedCopy);
  +        assertNotNull(loadedCopy.getCollectiblesBase());
  +        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
  +        assertEquals(3, loadedCopy.getCollectiblesBase().size());
  +        
  +        //
  +        // Remove a single element
  +        //
  +        broker.beginTransaction();
  +        loadedCopy.getCollectiblesBase().remove(2);
  +        broker.store(loadedCopy);
  +        broker.commitTransaction();
  +        
  +        broker.clearCache();
  +        loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
  +        assertNotNull(loadedCopy);
  +        assertNotNull(loadedCopy.getCollectiblesBase());
  +        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
  +        assertEquals(2, loadedCopy.getCollectiblesBase().size());
  +
  +        //
  +        // Remove all elements
  +        //
  +        broker.beginTransaction();
  +        loadedCopy.getCollectiblesBase().clear();
  +        broker.store(loadedCopy);
  +        broker.commitTransaction();
  +        
  +        broker.clearCache();
  +        loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
  +        assertNotNull(loadedCopy);
  +        assertNotNull(loadedCopy.getCollectiblesBase());
  +        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
  +        assertEquals(0, loadedCopy.getCollectiblesBase().size());
  +    }
   
       //************************************************************
       // helper methods
  
  
  

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