brj         2005/03/09 12:59:34

  Modified:    src/test/org/apache/ojb/broker CollectionTest.java
  Log:
  Testcase for RemovalAwareCollection ProductGroup/Article
  
  Revision  Changes    Path
  1.18      +66 -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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CollectionTest.java       9 Mar 2005 19:40:41 -0000       1.17
  +++ CollectionTest.java       9 Mar 2005 20:59:34 -0000       1.18
  @@ -855,6 +855,71 @@
           assertEquals(0, loadedCopy.getCollectiblesBase().size());
       }
   
  +    /**
  +     * Test RemovalAwareCollection remove() and clear()
  +     */
  +    public void testRemovalAwareCollectionProxy()
  +    {
  +        String prefix = "testRemovalAwareCollectionProxy_" + 
System.currentTimeMillis();
  +
  +        Identity pgId;
  +        ProductGroup loadedCopy;
  +        InterfaceArticle article;
  +        ProductGroup pg = new ProductGroup(null, "PG_" + prefix, null);
  +        article = new Article();
  +        article.setArticleName("Art_1_" + prefix);
  +        pg.add(article);
  +        article = new Article();
  +        article.setArticleName("Art_2_" + prefix);
  +        pg.add(article);
  +        article = new Article();
  +        article.setArticleName("Art_3_" + prefix);
  +        pg.add(article);
  +
  +        broker.beginTransaction();
  +        broker.store(pg);
  +        broker.commitTransaction();
  +        assertTrue(pg.getGroupId() != null);
  +        pgId = broker.serviceIdentity().buildIdentity(pg);
  +
  +        broker.clearCache();
  +        loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
  +        assertNotNull(loadedCopy);
  +        assertNotNull(loadedCopy.getAllArticlesInGroup());
  +        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof 
RemovalAwareCollection);
  +        assertEquals(3, loadedCopy.getAllArticlesInGroup().size());
  +        
  +        //
  +        // Remove a single element
  +        //
  +        broker.beginTransaction();
  +        loadedCopy.getAllArticlesInGroup().remove(2);
  +        broker.store(loadedCopy);
  +        broker.commitTransaction();
  +        
  +        broker.clearCache();
  +        loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
  +        assertNotNull(loadedCopy);
  +        assertNotNull(loadedCopy.getAllArticlesInGroup());
  +        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof 
RemovalAwareCollection);
  +        assertEquals(2, loadedCopy.getAllArticlesInGroup().size());
  +
  +        //
  +        // Remove all elements
  +        //
  +        broker.beginTransaction();
  +        loadedCopy.getAllArticlesInGroup().clear();
  +        broker.store(loadedCopy);
  +        broker.commitTransaction();
  +        
  +        broker.clearCache();
  +        loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
  +        assertNotNull(loadedCopy);
  +        assertNotNull(loadedCopy.getAllArticlesInGroup());
  +        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof 
RemovalAwareCollection);
  +        assertEquals(0, loadedCopy.getAllArticlesInGroup().size());
  +    }
  +    
       //************************************************************
       // helper methods
       //************************************************************
  
  
  

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

Reply via email to