Author: arminw
Date: Sun Nov 12 11:27:52 2006
New Revision: 474017

URL: http://svn.apache.org/viewvc?view=rev&rev=474017
Log:
update test

Modified:
    
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java?view=diff&rev=474017&r1=474016&r2=474017
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java 
(original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java 
Sun Nov 12 11:27:52 2006
@@ -320,6 +320,7 @@
         list_projects.add(p2);
         p.setProjects(list_projects);
 
+        // another Project but without associated Person objects
         Project p3 = new Project();
         p3.setTitle(name);
         ArrayList list_3 = new ArrayList();
@@ -329,9 +330,11 @@
         broker.beginTransaction();
         broker.store(p1);
         //broker.store(p2);
-        //broker.store(p3);
+        broker.store(p3);
         broker.commitTransaction();
 
+        broker.clearCache();
+
         Criteria crit = new Criteria();
         crit.addLike("title", name);
         QueryByCriteria q = QueryFactory.newQuery(Project.class, crit);
@@ -346,6 +349,20 @@
         // compare with count
         int count = broker.getCount(q);
         assertEquals(results.size(), count);
+
+        // next query without join to Person object
+        crit = new Criteria();
+        crit.addLike("title", name);
+        q = QueryFactory.newQuery(Project.class, crit);
+        q.addOrderByAscending("title");
+
+        results = broker.getCollectionByQuery(q);
+        assertNotNull(results);
+        assertEquals(3, results.size());
+
+        // compare with count
+        count = broker.getCount(q);
+        assertEquals(results.size(), count);
     }
 
     /**
@@ -377,7 +394,7 @@
     public void testSubQuery2()
     {
         Collection results = null;
-        String stamp = "" + System.currentTimeMillis();
+        String stamp = "testSubQuery2_" + System.currentTimeMillis();
         int loops = 10;
         // create ProductGroups without article
         broker.beginTransaction();
@@ -1331,55 +1348,62 @@
         ClassDescriptor cldArticle = broker.getClassDescriptor(Article.class);
         Class articleProxy = cldArticle.getProxyClass();
 
-        //
-        // use ProductGroup and Articles with disabled Proxy
-        //
-        broker.clearCache();
-        cldArticle.setProxyClass(null);
-
-        Criteria crit = new Criteria();
-        crit.addLessOrEqualThan("groupId", new Integer(5));
-        QueryByCriteria q = QueryFactory.newQuery(ProductGroupWithArray.class, 
crit);
-        q.addOrderByDescending("groupId");
-        q.addPrefetchedRelationship("allArticlesInGroup");
-
-        Collection results = broker.getCollectionByQuery(q);
-        assertNotNull(results);
-        assertTrue(results.size() > 0);
-        ProductGroupWithArray pg = (ProductGroupWithArray) 
results.toArray()[0];
-        int articleSize = pg.getAllArticles().length;
-        assertTrue(articleSize != 0);
-        String articleString = Arrays.asList(pg.getAllArticles()).toString();
-
-        //
-        // use ProductGroupWithArray and Articles with original Proxy settings
-        //
-        broker.clearCache();
-        cldArticle.setProxyClass(articleProxy);
-
-
-        crit = new Criteria();
-        crit.addEqualTo("groupId", new Integer(5));
-        q = QueryFactory.newQuery(ProductGroupWithArray.class, crit);
-        results = broker.getCollectionByQuery(q);
-        ProductGroupWithArray pg2 = (ProductGroupWithArray) 
results.toArray()[0];
-        InterfaceArticle[] articles = pg2.getAllArticles();
-        assertNotNull("Array of articles should not be null!", articles);
-        assertTrue("Array should contain more than 0 entries!", 
articles.length != 0);
-
-        // force materialization
-        for(int i = 0; i < articles.length; i++)
-        {
-            articles[i].getArticleName();
-        }
-        int articleSize2 = articles.length;
-        String articleString2 = Arrays.asList(articles).toString();
-
-        //
-        // compare prefetched and 'normal' data
-        //
-        assertEquals("Check size", articleSize, articleSize2);
-        assertEquals("Check content", articleString, articleString2);
+        try
+        {
+            //
+            // use ProductGroup and Articles with disabled Proxy
+            //
+            broker.clearCache();
+            cldArticle.setProxyClass(null);
+
+            Criteria crit = new Criteria();
+            crit.addLessOrEqualThan("groupId", new Integer(5));
+            QueryByCriteria q = 
QueryFactory.newQuery(ProductGroupWithArray.class, crit);
+            q.addOrderByDescending("groupId");
+            q.addPrefetchedRelationship("allArticlesInGroup");
+
+            Collection results = broker.getCollectionByQuery(q);
+            assertNotNull(results);
+            assertTrue(results.size() > 0);
+            ProductGroupWithArray pg = (ProductGroupWithArray) 
results.toArray()[0];
+            int articleSize = pg.getAllArticles().length;
+            assertTrue(articleSize != 0);
+            String articleString = 
Arrays.asList(pg.getAllArticles()).toString();
+
+            //
+            // use ProductGroupWithArray and Articles with original Proxy 
settings
+            //
+            broker.clearCache();
+            cldArticle.setProxyClass(articleProxy);
+
+
+            crit = new Criteria();
+            crit.addEqualTo("groupId", new Integer(5));
+            q = QueryFactory.newQuery(ProductGroupWithArray.class, crit);
+            results = broker.getCollectionByQuery(q);
+            ProductGroupWithArray pg2 = (ProductGroupWithArray) 
results.toArray()[0];
+            InterfaceArticle[] articles = pg2.getAllArticles();
+            assertNotNull("Array of articles should not be null!", articles);
+            assertTrue("Array should contain more than 0 entries!", 
articles.length != 0);
+
+            // force materialization
+            for(int i = 0; i < articles.length; i++)
+            {
+                articles[i].getArticleName();
+            }
+            int articleSize2 = articles.length;
+            String articleString2 = Arrays.asList(articles).toString();
+
+            //
+            // compare prefetched and 'normal' data
+            //
+            assertEquals("Check size", articleSize, articleSize2);
+            assertEquals("Check content", articleString, articleString2);
+        }
+        finally
+        {
+            cldArticle.setProxyClass(articleProxy);
+        }
 
     }
 
@@ -1394,73 +1418,80 @@
         Class articleProxy = cldArticle.getProxyClass();
         CollectionDescriptor cds = 
cldProductGroup.getCollectionDescriptorByName("allArticlesInGroup");
 
-        //
-        // use ProductGroup and Articles with disabled Proxy
-        //
-        cldProductGroup.setProxyClass(null);
-        cldProductGroup.setProxyClassName(null);
-        cldArticle.setProxyClass(null);
-        cldArticle.setProxyClassName(null);
-        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
-        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
-        
-        //
-        // orderby articleId, ASC
-        //
-        broker.clearCache();
-        cds.getOrderBy().clear();
-        cds.addOrderBy("articleId", true);
-         
-        Criteria crit = new Criteria();
-        crit.addLessOrEqualThan("groupId", new Integer(5));
-        QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
-        q.addOrderByDescending("groupId");
-        q.addPrefetchedRelationship("allArticlesInGroup");
-
-        Collection results = broker.getCollectionByQuery(q);
-        assertNotNull(results);
-        assertTrue(results.size() == 5);
-        InterfaceProductGroup pg = (InterfaceProductGroup) 
results.toArray()[1];
-        assertNotNull(pg.getAllArticles());
-        Object articles[] = pg.getAllArticles().toArray();
-        int articleSize = articles.length;
-        assertTrue(articleSize == 10);
-        Article a1 = (Article) articles[0];
-        Article a2 = (Article) articles[9];
-        assertTrue(a1.getArticleId().intValue() < 
a2.getArticleId().intValue());
-
-        //
-        // orderby articleId, DESC
-        //
-        broker.clearCache();
-        cds.getOrderBy().clear();
-        cds.addOrderBy("articleId", false);
-
-        results = broker.getCollectionByQuery(q);
-        assertNotNull(results);
-        assertTrue(results.size() == 5);
-        pg = (InterfaceProductGroup) results.toArray()[1];
-        assertNotNull(pg.getAllArticles());
-        articles = pg.getAllArticles().toArray();
-        articleSize = articles.length;
-        assertTrue(articleSize == 10);
-        Article b1 = (Article) articles[0];
-        Article b2 = (Article) articles[9];
-        assertTrue(b1.getArticleId().intValue() > 
b2.getArticleId().intValue());
-
-        assertEquals(a1.getArticleId(), b2.getArticleId());
-        assertEquals(a2.getArticleId(), b1.getArticleId());
-
-        //
-        // use ProductGroup and Articles with original Proxy settings
-        //
-        cldProductGroup.setProxyClass(productGroupProxy);
-        cldProductGroup.setProxyClassName(productGroupProxy.getName());
-        cldArticle.setProxyClass(articleProxy);
-        cldArticle.setProxyClassName(articleProxy.getName());
-        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
-        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
-   }
+        try
+        {
+            //
+            // use ProductGroup and Articles with disabled Proxy
+            //
+            cldProductGroup.setProxyClass(null);
+            cldProductGroup.setProxyClassName(null);
+            cldArticle.setProxyClass(null);
+            cldArticle.setProxyClassName(null);
+            
broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
+            broker.getDescriptorRepository().setClassDescriptor(cldArticle);
+
+            //
+            // orderby articleId, ASC
+            //
+            broker.clearCache();
+            cds.getOrderBy().clear();
+            cds.addOrderBy("articleId", true);
+
+            Criteria crit = new Criteria();
+            crit.addLessOrEqualThan("groupId", new Integer(5));
+            QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, 
crit);
+            q.addOrderByDescending("groupId");
+            q.addPrefetchedRelationship("allArticlesInGroup");
+
+            Collection results = broker.getCollectionByQuery(q);
+            assertNotNull(results);
+            assertTrue(results.size() == 5);
+            InterfaceProductGroup pg = (InterfaceProductGroup) 
results.toArray()[1];
+            assertNotNull(pg.getAllArticles());
+            Object articles[] = pg.getAllArticles().toArray();
+            int articleSize = articles.length;
+            assertTrue(articleSize == 10);
+            Article a1 = (Article) articles[0];
+            Article a2 = (Article) articles[9];
+            assertTrue(a1.getArticleId().intValue() < 
a2.getArticleId().intValue());
+
+            //
+            // orderby articleId, DESC
+            //
+            broker.clearCache();
+            cds.getOrderBy().clear();
+            cds.addOrderBy("articleId", false);
+
+            results = broker.getCollectionByQuery(q);
+            assertNotNull(results);
+            assertTrue(results.size() == 5);
+            pg = (InterfaceProductGroup) results.toArray()[1];
+            assertNotNull(pg.getAllArticles());
+            articles = pg.getAllArticles().toArray();
+            articleSize = articles.length;
+            assertTrue(articleSize == 10);
+            Article b1 = (Article) articles[0];
+            Article b2 = (Article) articles[9];
+            assertTrue(b1.getArticleId().intValue() > 
b2.getArticleId().intValue());
+
+            assertEquals(a1.getArticleId(), b2.getArticleId());
+            assertEquals(a2.getArticleId(), b1.getArticleId());
+
+
+        }
+        finally
+        {
+            //
+            // use ProductGroup and Articles with original Proxy settings
+            //
+            cldProductGroup.setProxyClass(productGroupProxy);
+            cldProductGroup.setProxyClassName(productGroupProxy.getName());
+            cldArticle.setProxyClass(articleProxy);
+            cldArticle.setProxyClassName(articleProxy.getName());
+            
broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
+            broker.getDescriptorRepository().setClassDescriptor(cldArticle);
+        }
+    }
 
     /**
      * prefetch Articles for ProductGroups
@@ -1472,60 +1503,68 @@
         Class productGroupProxy = cldProductGroup.getProxyClass();
         Class articleProxy = cldArticle.getProxyClass();
 
-        //
-        // use ProductGroup and Articles with disabled Proxy
-        //
-        broker.clearCache();
-        cldProductGroup.setProxyClass(null);
-        cldProductGroup.setProxyClassName(null);
-        cldArticle.setProxyClass(null);
-        cldArticle.setProxyClassName(null);
-        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
-        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
-
-        Criteria crit = new Criteria();
-        crit.addLessOrEqualThan("groupId", new Integer(5));
-        QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
-        q.addOrderByDescending("groupId");
-        q.addPrefetchedRelationship("allArticlesInGroup");
-
-        Collection results = broker.getCollectionByQuery(q);
-        assertNotNull(results);
-        assertTrue(results.size() > 0);
-        InterfaceProductGroup pg = (InterfaceProductGroup) 
results.toArray()[0];
-        assertNotNull(pg.getAllArticles());
-        int articleSize = pg.getAllArticles().size();
-        String articleString = pg.getAllArticles().toString();
-
-        //
-        // use ProductGroup and Articles with original Proxy settings
-        //
-        broker.clearCache();
-        cldProductGroup.setProxyClass(productGroupProxy);
-        cldProductGroup.setProxyClassName(productGroupProxy.getName());
-        cldArticle.setProxyClass(articleProxy);
-        cldArticle.setProxyClassName(articleProxy.getName());
-        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
-        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
-
-        crit = new Criteria();
-        crit.addEqualTo("groupId", new Integer(5));
-        q = QueryFactory.newQuery(ProductGroup.class, crit);
-        results = broker.getCollectionByQuery(q);
-        InterfaceProductGroup pg2 = (InterfaceProductGroup) 
results.toArray()[0];
-        // force materialization
-        for(Iterator it = pg2.getAllArticles().iterator(); it.hasNext();)
-        {
-            ((InterfaceArticle) it.next()).getArticleName();
-        }
-        int articleSize2 = pg2.getAllArticles().size();
-        String articleString2 = pg2.getAllArticles().toString();
-
-        //
-        // compare prefetched and 'normal' data
-        //
-        assertEquals("Check size", articleSize, articleSize2);
-        assertEquals("Check content", articleString, articleString2);
+        try
+        {
+            //
+            // use ProductGroup and Articles with disabled Proxy
+            //
+            broker.clearCache();
+            cldProductGroup.setProxyClass(null);
+            cldProductGroup.setProxyClassName(null);
+            cldArticle.setProxyClass(null);
+            cldArticle.setProxyClassName(null);
+            
broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
+            broker.getDescriptorRepository().setClassDescriptor(cldArticle);
+
+            Criteria crit = new Criteria();
+            crit.addLessOrEqualThan("groupId", new Integer(5));
+            QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, 
crit);
+            q.addOrderByDescending("groupId");
+            q.addPrefetchedRelationship("allArticlesInGroup");
+
+            Collection results = broker.getCollectionByQuery(q);
+            assertNotNull(results);
+            assertTrue(results.size() > 0);
+            InterfaceProductGroup pg = (InterfaceProductGroup) 
results.toArray()[0];
+            assertNotNull(pg.getAllArticles());
+            int articleSize = pg.getAllArticles().size();
+            String articleString = pg.getAllArticles().toString();
+
+            //
+            // use ProductGroup and Articles with original Proxy settings
+            //
+            broker.clearCache();
+            cldProductGroup.setProxyClass(productGroupProxy);
+            cldProductGroup.setProxyClassName(productGroupProxy.getName());
+            cldArticle.setProxyClass(articleProxy);
+            cldArticle.setProxyClassName(articleProxy.getName());
+            
broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
+            broker.getDescriptorRepository().setClassDescriptor(cldArticle);
+
+            crit = new Criteria();
+            crit.addEqualTo("groupId", new Integer(5));
+            q = QueryFactory.newQuery(ProductGroup.class, crit);
+            results = broker.getCollectionByQuery(q);
+            InterfaceProductGroup pg2 = (InterfaceProductGroup) 
results.toArray()[0];
+            // force materialization
+            for(Iterator it = pg2.getAllArticles().iterator(); it.hasNext();)
+            {
+                ((InterfaceArticle) it.next()).getArticleName();
+            }
+            int articleSize2 = pg2.getAllArticles().size();
+            String articleString2 = pg2.getAllArticles().toString();
+
+            //
+            // compare prefetched and 'normal' data
+            //
+            assertEquals("Check size", articleSize, articleSize2);
+            assertEquals("Check content", articleString, articleString2);
+        }
+        finally
+        {
+            cldProductGroup.setProxyClass(productGroupProxy);
+            cldArticle.setProxyClass(articleProxy);
+        }
     }
 
     /**
@@ -1600,70 +1639,78 @@
         Class productGroupProxy = cldProductGroup.getProxyClass();
         Class articleProxy = cldArticle.getProxyClass();
 
-        //
-        // use ProductGroup and Articles with disabled Proxy
-        //
-        broker.clearCache();
-        cldProductGroup.setProxyClass(null);
-        cldProductGroup.setProxyClassName(null);
-        cldArticle.setProxyClass(null);
-        cldArticle.setProxyClassName(null);
-        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
-        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
-
-        Criteria crit = new Criteria();
-        crit.addNotNull("productGroupId");
-        crit.addLessOrEqualThan("productGroupId", new Integer(5));
-        QueryByCriteria q = QueryFactory.newQuery(Article.class, crit);
-        q.addOrderByDescending("productGroupId");
-        q.addPrefetchedRelationship("productGroup");
-
-        Collection results = broker.getCollectionByQuery(q);
-        Set pgs = new HashSet();
-        Iterator iter = results.iterator();
-        while(iter.hasNext())
+        try
         {
-            InterfaceArticle a = (InterfaceArticle) iter.next();
-            pgs.add(a.getProductGroup().getName());
+            //
+            // use ProductGroup and Articles with disabled Proxy
+            //
+            broker.clearCache();
+            cldProductGroup.setProxyClass(null);
+            cldProductGroup.setProxyClassName(null);
+            cldArticle.setProxyClass(null);
+            cldArticle.setProxyClassName(null);
+            
broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
+            broker.getDescriptorRepository().setClassDescriptor(cldArticle);
+
+            Criteria crit = new Criteria();
+            crit.addNotNull("productGroupId");
+            crit.addLessOrEqualThan("productGroupId", new Integer(5));
+            QueryByCriteria q = QueryFactory.newQuery(Article.class, crit);
+            q.addOrderByDescending("productGroupId");
+            q.addPrefetchedRelationship("productGroup");
+
+            Collection results = broker.getCollectionByQuery(q);
+            Set pgs = new HashSet();
+            Iterator iter = results.iterator();
+            while(iter.hasNext())
+            {
+                InterfaceArticle a = (InterfaceArticle) iter.next();
+                pgs.add(a.getProductGroup().getName());
+            }
+
+            assertTrue(pgs.size() > 0);
+            String pgsString = pgs.toString();
+
+            //
+            // use ProductGroup and Articles with original Proxy settings
+            //
+            broker.clearCache();
+            cldProductGroup.setProxyClass(productGroupProxy);
+            cldProductGroup.setProxyClassName(productGroupProxy.getName());
+            cldArticle.setProxyClass(articleProxy);
+            cldArticle.setProxyClassName(articleProxy.getName());
+            
broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
+            broker.getDescriptorRepository().setClassDescriptor(cldArticle);
+
+            crit = new Criteria();
+            crit.addNotNull("productGroupId");
+            crit.addLessOrEqualThan("productGroupId", new Integer(5));
+            q = QueryFactory.newQuery(Article.class, crit);
+            q.addOrderByDescending("productGroupId");
+
+            results = broker.getCollectionByQuery(q);
+            Set pgs2 = new HashSet();
+            iter = results.iterator();
+            while(iter.hasNext())
+            {
+                InterfaceArticle a = (InterfaceArticle) iter.next();
+                pgs2.add(a.getProductGroup().getName());
+            }
+
+            assertTrue(pgs2.size() > 0);
+            String pgsString2 = pgs2.toString();
+
+            //
+            // compare prefetched and 'normal' data
+            //
+            assertEquals("Check size", pgs.size(), pgs2.size());
+            assertEquals("Check content", pgsString, pgsString2);
         }
-
-        assertTrue(pgs.size() > 0);
-        String pgsString = pgs.toString();
-
-        //
-        // use ProductGroup and Articles with original Proxy settings
-        //
-        broker.clearCache();
-        cldProductGroup.setProxyClass(productGroupProxy);
-        cldProductGroup.setProxyClassName(productGroupProxy.getName());
-        cldArticle.setProxyClass(articleProxy);
-        cldArticle.setProxyClassName(articleProxy.getName());
-        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
-        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
-
-        crit = new Criteria();
-        crit.addNotNull("productGroupId");
-        crit.addLessOrEqualThan("productGroupId", new Integer(5));
-        q = QueryFactory.newQuery(Article.class, crit);
-        q.addOrderByDescending("productGroupId");
-
-        results = broker.getCollectionByQuery(q);
-        Set pgs2 = new HashSet();
-        iter = results.iterator();
-        while(iter.hasNext())
+        finally
         {
-            InterfaceArticle a = (InterfaceArticle) iter.next();
-            pgs2.add(a.getProductGroup().getName());
+            cldProductGroup.setProxyClass(productGroupProxy);
+            cldArticle.setProxyClass(articleProxy);
         }
-
-        assertTrue(pgs2.size() > 0);
-        String pgsString2 = pgs2.toString();
-
-        //
-        // compare prefetched and 'normal' data
-        //
-        assertEquals("Check size", pgs.size(), pgs2.size());
-        assertEquals("Check content", pgsString, pgsString2);
 
     }
 



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

Reply via email to