brj         2005/04/06 13:32:15

  Modified:    src/test/org/apache/ojb/broker PersistenceBrokerTest.java
  Log:
  additional testcases for deleteByQuery
  
  Revision  Changes    Path
  1.51      +107 -2    
db-ojb/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java
  
  Index: PersistenceBrokerTest.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- PersistenceBrokerTest.java        1 Apr 2005 20:42:33 -0000       1.50
  +++ PersistenceBrokerTest.java        6 Apr 2005 20:32:14 -0000       1.51
  @@ -1,6 +1,7 @@
   package org.apache.ojb.broker;
   
   import java.sql.Statement;
  +import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Enumeration;
   import java.util.HashSet;
  @@ -427,9 +428,9 @@
       /**
        * test the the PB deleteByQuery() method.
        */
  -    public void testDeleteByQuery() throws Exception
  +    public void testDeleteByQuery1() throws Exception
       {
  -        String name = "Funny_testDelete_" + System.currentTimeMillis();
  +        String name = "Funny_testDelete1_" + System.currentTimeMillis();
           ProductGroup pg;
           pg = new ProductGroup();
           pg.setGroupName(name);
  @@ -466,6 +467,110 @@
           assertEquals("there should be no more matching items", 0, 
col.size());
       }
   
  +    /**
  +     * test the the PB deleteByQuery() using pathExpressions and 
IN-Statement.
  +     */
  +    public void testDeleteByQuery2() throws Exception
  +    {
  +        String name = "Funny_testDelete2_" + System.currentTimeMillis();
  +        ProductGroup pg;
  +        pg = new ProductGroup();
  +        pg.setGroupName(name);
  +
  +        broker.beginTransaction();
  +        broker.store(pg);
  +        broker.commitTransaction();
  +
  +        Article a = createArticle(pg, name);
  +        Article b = createArticle(pg, name);
  +        CdArticle c = createCdArticle(pg, name);
  +
  +        storeArticle(a);
  +        storeArticle(b);
  +        storeArticle(c);
  +
  +        broker.clearCache();
  +
  +        Criteria rCrit = new Criteria();
  +        rCrit.addEqualTo("productGroup.groupName", name);
  +        rCrit.addEqualTo("articleName", name);
  +        ReportQueryByCriteria rq = 
QueryFactory.newReportQuery(Article.class, rCrit);
  +        rq.setAttributes(new String[]{"articleId"});
  +
  +        // read the ids to be used in IN-Statement
  +        Iterator ids = broker.getReportQueryIteratorByQuery(rq);
  +        Collection idCol = new ArrayList();
  +        while (ids.hasNext())
  +        {
  +            Object[] row = (Object[]) ids.next();
  +            idCol.add(row[0]);
  +        }
  +        assertEquals("There should be 3 matching items", 3, idCol.size());
  +
  +        // 1. check for matching items using IN
  +        broker.clearCache();
  +        
  +        Criteria crit = new Criteria();
  +        crit.addIn("articleId", idCol);
  +        Query q = QueryFactory.newQuery(Article.class, crit);
  +        Collection col = broker.getCollectionByQuery(q);
  +        assertEquals("There should be 3 matching items", 3, col.size());
  +
  +        // 2. perform delete by query
  +        broker.deleteByQuery(q);
  +
  +        // 3. recheck for matching elements
  +        col = broker.getCollectionByQuery(q);
  +        assertEquals("there should be no more matching items", 0, 
col.size());
  +    }
  +
  +    /**
  +     * test the the PB deleteByQuery() using pathExpressions and SubQuery.
  +     */
  +    public void testDeleteByQuery3() throws Exception
  +    {
  +        String name = "Funny_testDelete3_" + System.currentTimeMillis();
  +        ProductGroup pg;
  +        pg = new ProductGroup();
  +        pg.setGroupName(name);
  +
  +        broker.beginTransaction();
  +        broker.store(pg);
  +        broker.commitTransaction();
  +
  +        Article a = createArticle(pg, name);
  +        Article b = createArticle(pg, name);
  +        Article c = createArticle(pg, name);  // SubQuery is not 
extent-aware !!!
  +
  +        storeArticle(a);
  +        storeArticle(b);
  +        storeArticle(c);
  +
  +        broker.clearCache();
  +
  +        Criteria rCrit = new Criteria();
  +        rCrit.addEqualTo("productGroup.groupName", name);
  +        rCrit.addEqualTo("articleName", name);
  +        ReportQueryByCriteria rq = 
QueryFactory.newReportQuery(Article.class, rCrit);
  +        rq.setAttributes(new String[]{"articleId"});
  +
  +
  +        // 1. check for matching items using sub-query
  +        broker.clearCache();
  +        
  +        Criteria crit = new Criteria();
  +        crit.addIn("articleId", rq);
  +        Query q = QueryFactory.newQuery(Article.class, crit);
  +        Collection col = broker.getCollectionByQuery(q);
  +        assertEquals("There should be 3 matching items", 3, col.size());
  +
  +        // 2. perform delete by query
  +        broker.deleteByQuery(q);
  +
  +        // 3. recheck for matching elements
  +        col = broker.getCollectionByQuery(q);
  +        assertEquals("there should be no more matching items", 0, 
col.size());
  +    }
   
       /**
        * performs a test of the inheritance mapping to one table.
  
  
  

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

Reply via email to