db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker QueryTest.java
Date Fri, 27 Aug 2004 19:25:12 GMT
brj         2004/08/27 12:25:12

  Modified:    src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        QueryTest.java
  Log:
  modified testcases for subqueries using extents
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.61.2.4  +62 -7     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.61.2.3
  retrieving revision 1.61.2.4
  diff -u -r1.61.2.3 -r1.61.2.4
  --- QueryTest.java	23 Aug 2004 18:24:10 -0000	1.61.2.3
  +++ QueryTest.java	27 Aug 2004 19:25:12 -0000	1.61.2.4
  @@ -729,10 +729,13 @@
           assertEquals(results.size(), count);
       }
   
  -    public void testReportQueryAgainstAbstractClasses()
  +    /**
  +     * Concrete Class in SubQuery
  +     */
  +    public void testSubQueryAgainstConcreteClass()
       {
  -        String name = "testReportQueryAgainstAbstractClasses_"+System.currentTimeMillis();
  -        Article article = new Article();
  +        String name = "testSubQueryAgainstConcreteClass_"+System.currentTimeMillis();
  +        Article article = new BookArticle();
           article.setArticleName(name);
           ProductGroup group = new ProductGroup();
           group.setGroupName(name);
  @@ -747,11 +750,12 @@
           Criteria critSub = new Criteria();
   
           critSub.addEqualTo("articleName", name);
  -        ReportQueryByCriteria querySub = QueryFactory.newReportQuery(AbstractArticle.class,
critSub);
  +        ReportQueryByCriteria querySub = QueryFactory.newReportQuery(BookArticle.class,
critSub);
           querySub.setAttributes(new String[] { "productGroupId"});
   
  -        critMain.addIn("productGroup.groupId", querySub);
           ReportQueryByCriteria queryMain = QueryFactory.newReportQuery(AbstractProductGroup.class,
critMain);
  +        queryMain.setAttributes(new String[] { "groupId", "groupName"});
  +        critMain.addIn("groupId", querySub);
   
           Iterator iter = broker.getReportQueryIteratorByQuery(queryMain);
           int result = 0;
  @@ -769,6 +773,57 @@
       }
   
       /**
  +     * Class with extents in SubQuery.
  +     * SubQueries are NOT extent aware ! so we have to use two queries.
  +     */
  +    public void testSubQueryAgainstExtents()
  +    {
  +        String name = "testSubQueryAgainstExtents_"+System.currentTimeMillis();
  +        Article article = new BookArticle();
  +        article.setArticleName(name);
  +        ProductGroup group = new ProductGroup();
  +        group.setGroupName(name);
  +        article.setProductGroup(group);
  +    
  +        broker.beginTransaction();
  +        broker.store(group);
  +        broker.store(article);
  +        broker.commitTransaction();
  +    
  +        Criteria critMain = new Criteria();
  +        Criteria critSub = new Criteria();
  +    
  +        critSub.addEqualTo("articleName", name);
  +        ReportQueryByCriteria querySub = QueryFactory.newReportQuery(Article.class, critSub);
  +        querySub.setAttributes(new String[] { "productGroupId"});
  +        Iterator subIter = broker.getReportQueryIteratorByQuery(querySub);
  +        Collection subIds = new ArrayList();
  +        while (subIter.hasNext())
  +        {
  +            Object[] id = (Object[])subIter.next();
  +            subIds.add(id[0]);
  +        }
  +            
  +        ReportQueryByCriteria queryMain = QueryFactory.newReportQuery(AbstractProductGroup.class,
critMain);
  +        queryMain.setAttributes(new String[] { "groupId", "groupName"});
  +        critMain.addIn("groupId", subIds);
  +    
  +        Iterator iter = broker.getReportQueryIteratorByQuery(queryMain);
  +        int result = 0;
  +        assertNotNull(iter);
  +        while (iter.hasNext())
  +        {
  +            iter.next();
  +            ++result;
  +        }
  +        assertEquals(1, result);
  +    
  +        // compare with count
  +        int count = broker.getCount(queryMain);
  +        assertEquals(result, count);
  +    }
  +    
  +    /**
        * ReportQuery with pathExpression in columns
        */
       public void testReportQueryPathExpression()
  @@ -1322,7 +1377,6 @@
           {
               Object obj = iter.next();
               list.add(obj);
  -            int i = ((Integer)((Object[]) obj)[2]).intValue();
   
               /*
               arminw:
  @@ -1336,7 +1390,8 @@
   //                        + "  " + ((Object[]) obj)[1]
   //                        + "  " + ((Object[]) obj)[2]);
   
  -                assertTrue(i<6 & i>0);
  +                int i = ((Integer)((Object[]) obj)[2]).intValue();
  +                assertTrue("i=" + i, i<6 & i>0);
               }
           }
       }
  
  
  

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