db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r449988 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest.java
Date Tue, 26 Sep 2006 11:23:14 GMT
Author: arminw
Date: Tue Sep 26 04:23:13 2006
New Revision: 449988

URL: http://svn.apache.org/viewvc?view=rev&rev=449988
Log:
add new test, fix tests

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

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest.java?view=diff&rev=449988&r1=449987&r2=449988
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest.java Tue
Sep 26 04:23:13 2006
@@ -12,10 +12,10 @@
 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
 import org.apache.ojb.broker.query.Criteria;
 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.query.QueryByCriteria;
 import org.apache.ojb.broker.util.ObjectModification;
-import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
+import org.apache.ojb.broker.util.collections.RemovalAwareList;
 import org.apache.ojb.junit.PBTestCase;
 
 /**
@@ -65,7 +65,6 @@
  *
  * TODO: Need some refactoring and more structured tests of different auto_xyz/proxy settings
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class CollectionTest extends PBTestCase
@@ -120,7 +119,7 @@
         broker.clearCache();
         Criteria criteria = new Criteria();
         criteria.addLike("name", prefix + "%");
-        Query q = new QueryByCriteria(BookShelfItem.class, criteria);
+        Query q = QueryFactory.newQuery(BookShelfItem.class, criteria);
         Collection result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals(3, result.size());
@@ -182,7 +181,7 @@
         broker.clearCache();
         Criteria criteria = new Criteria();
         criteria.addLike("name", prefix + "%");
-        Query q = new QueryByCriteria(BookShelfItem.class, criteria);
+        Query q = QueryFactory.newQuery(BookShelfItem.class, criteria);
         Collection items = broker.getCollectionByQuery(q);
         assertNotNull(items);
         assertEquals(2, items.size());
@@ -221,6 +220,36 @@
         assertEquals(4, i);
     }
 
+    public void testDeleteProxyCollection() throws Exception
+    {
+        String name = "testDeleteProxyCollection_"+System.currentTimeMillis();
+        Gatherer gat = new Gatherer(null, name);
+        CollectibleB[] cols = prepareCollectibleB(name);
+
+        gat.setCollectiblesB(Arrays.asList(cols));
+        broker.beginTransaction();
+        broker.store(gat);
+        broker.commitTransaction();
+
+        broker.clearCache();
+        broker.beginTransaction();
+        Criteria crit1 = new Criteria();
+        crit1.addLike("name", name);
+        Query q1 = QueryFactory.newQuery(Gatherer.class, crit1);
+        Gatherer newGat1 = (Gatherer)broker.getObjectByQuery(q1);
+        newGat1.getCollectiblesB().clear();
+        broker.store(newGat1);			// should delete CollectibleBs
+        broker.commitTransaction();
+
+        broker.clearCache();
+        Criteria crit2 = new Criteria();
+        crit2.addLike("name", name);
+        Query q2 = QueryFactory.newQuery(Gatherer.class, crit2);
+        Gatherer newGat2 = (Gatherer)broker.getObjectByQuery(q2);
+        int size = newGat2.getCollectiblesB().size();
+        assertEquals(0, size);
+    }
+
     public void testStoreReadOfUserDefinedCollectionClass()
     {
         String name = "testStoreReadOfUserDefinedCollectionClass_"+System.currentTimeMillis();
@@ -319,20 +348,21 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colBase*");
-        Query q = new QueryByCriteria(CollectibleBase.class, criteria);
+        Query q = QueryFactory.newQuery(CollectibleBase.class, criteria);
         Collection result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 3, result.size());
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colB*");
-        q = new QueryByCriteria(CollectibleB.class, criteria);
+        q = QueryFactory.newQuery(CollectibleB.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 4, result.size());
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
+        //q = QueryFactory.newQuery(CollectibleBaseIF.class, criteria);
         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
@@ -358,7 +388,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colBase*");
-        q = new QueryByCriteria(CollectibleBase.class, criteria);
+        q = QueryFactory.newQuery(CollectibleBase.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         // auto-delete is set true
@@ -366,7 +396,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colB*");
-        q = new QueryByCriteria(CollectibleB.class, criteria);
+        q = QueryFactory.newQuery(CollectibleB.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         // auto-delete is set false, but we removed manually
@@ -374,6 +404,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
+        //q = QueryFactory.newQuery(CollectibleBaseIF.class, criteria);
         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
@@ -421,27 +452,28 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colBase*");
-        Query q = new QueryByCriteria(CollectibleBase.class, criteria);
+        Query q = QueryFactory.newQuery(CollectibleBase.class, criteria);
         Collection result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 3, result.size());
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colB*");
-        q = new QueryByCriteria(CollectibleB.class, criteria);
+        q = QueryFactory.newQuery(CollectibleB.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 4, result.size());
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
+        //q = QueryFactory.newQuery(CollectibleBaseIF.class, criteria);
         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 7, result.size());
 
         broker.beginTransaction();
-        // now get all CollectibleB
+        // now get all CollectibleB and delete them, because auto-delete is false
         List colBList = new_gatherer.getCollectiblesB();
         for (Iterator iterator = colBList.iterator(); iterator.hasNext();)
         {
@@ -457,7 +489,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colBase*");
-        q = new QueryByCriteria(CollectibleBase.class, criteria);
+        q = QueryFactory.newQuery(CollectibleBase.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         // auto-delete is set true
@@ -465,7 +497,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colB*");
-        q = new QueryByCriteria(CollectibleB.class, criteria);
+        q = QueryFactory.newQuery(CollectibleB.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         // auto-delete is set false
@@ -473,6 +505,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
+        //q = QueryFactory.newQuery(CollectibleBaseIF.class, criteria);
         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
@@ -516,7 +549,7 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
-        Query q = new QueryByCriteria(CollectibleC2.class, criteria);
+        Query q = QueryFactory.newQuery(CollectibleC2.class, criteria);
         Collection result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 5, result.size());
@@ -536,7 +569,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
-        q = new QueryByCriteria(CollectibleC2.class, criteria);
+        q = QueryFactory.newQuery(CollectibleC2.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 0, result.size());
@@ -584,14 +617,14 @@
         Criteria criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colD*");
         criteria.addLike("name", colPrefix + "*");
-        Query q = new QueryByCriteria(CollectibleD.class, criteria);
+        Query q = QueryFactory.newQuery(CollectibleD.class, criteria);
         Collection result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 2, result.size());
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colDD*");
-        q = new QueryByCriteria(CollectibleDD.class, criteria);
+        q = QueryFactory.newQuery(CollectibleDD.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 3, result.size());
@@ -600,20 +633,21 @@
         // should only return CollectibleD class instances
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
-        q = new QueryByCriteria(CollectibleD.class, criteria);
+        q = QueryFactory.newQuery(CollectibleD.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 2, result.size());
         // now test objConcreteClass feature
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
-        q = new QueryByCriteria(CollectibleDD.class, criteria);
+        q = QueryFactory.newQuery(CollectibleDD.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 3, result.size());
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
+        //q = QueryFactory.newQuery(CollectibleBaseIF.class, criteria);
         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
@@ -632,7 +666,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colD*");
-        q = new QueryByCriteria(CollectibleD.class, criteria);
+        q = QueryFactory.newQuery(CollectibleD.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         // auto-delete is set true
@@ -640,7 +674,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colDD*");
-        q = new QueryByCriteria(CollectibleDD.class, criteria);
+        q = QueryFactory.newQuery(CollectibleDD.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         // auto-delete is set true
@@ -648,6 +682,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
+        //q = QueryFactory.newQuery(CollectibleBaseIF.class, criteria);
         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
@@ -686,20 +721,21 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colBase*");
-        Query q = new QueryByCriteria(CollectibleBase.class, criteria);
+        Query q = QueryFactory.newQuery(CollectibleBase.class, criteria);
         Collection result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 3, result.size());
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colB*");
-        q = new QueryByCriteria(CollectibleB.class, criteria);
+        q = QueryFactory.newQuery(CollectibleB.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 4, result.size());
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
+        //q = QueryFactory.newQuery(CollectibleBaseIF.class, criteria);
         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
@@ -739,7 +775,7 @@
         // additional check, read reference objects by query
         Criteria criteria = new Criteria();
         criteria.addLike("name", colPrefix+"*");
-        Query q = new QueryByCriteria(CollectibleBase.class, criteria);
+        Query q = QueryFactory.newQuery(CollectibleBase.class, criteria);
         Collection result = broker.getCollectionByQuery(q);
         assertNotNull(result);
         assertEquals("Wrong number of queried objects", 3, result.size());
@@ -804,6 +840,7 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", colPrefix + "_colC*");
+        // Query q = QueryFactory.newQuery(CollectibleC.class, criteria);
         Query q = new QueryByCriteria(CollectibleC.class, criteria);
         Collection result = broker.getCollectionByQuery(q);
         assertNotNull(result);
@@ -811,6 +848,7 @@
 
         criteria = new Criteria();
         criteria.addLike("name", colPrefix + "*");
+        //q = QueryFactory.newQuery(CollectibleBaseIF.class, criteria);
         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
         result = broker.getCollectionByQuery(q);
         assertNotNull(result);
@@ -844,7 +882,7 @@
         broker.clearCache();
         Criteria criteria = new Criteria();
         criteria.addLike("name", prefix);
-        Query q = new QueryByCriteria(BookShelf.class, criteria);
+        Query q = QueryFactory.newQuery(BookShelf.class, criteria);
         Collection books = broker.getCollectionByQuery(q);
         assertNotNull(books);
         assertEquals(1, books.size());
@@ -882,7 +920,7 @@
         broker.clearCache();
         Criteria criteria = new Criteria();
         criteria.addLike("name", prefix);
-        Query q = new QueryByCriteria(BookShelf.class, criteria);
+        Query q = QueryFactory.newQuery(BookShelf.class, criteria);
         Iterator books = broker.getIteratorByQuery(q);
         assertTrue(books.hasNext());
         loadedCopy = (BookShelf) books.next();
@@ -917,7 +955,7 @@
         loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
         assertNotNull(loadedCopy);
         assertNotNull(loadedCopy.getCollectiblesBase());
-        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
+        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareList);
         assertEquals(3, loadedCopy.getCollectiblesBase().size());
 
         //
@@ -932,7 +970,7 @@
         loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
         assertNotNull(loadedCopy);
         assertNotNull(loadedCopy.getCollectiblesBase());
-        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
+        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareList);
         assertEquals(2, loadedCopy.getCollectiblesBase().size());
 
         //
@@ -947,7 +985,7 @@
         loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
         assertNotNull(loadedCopy);
         assertNotNull(loadedCopy.getCollectiblesBase());
-        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
+        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareList);
         assertEquals(0, loadedCopy.getCollectiblesBase().size());
     }
 
@@ -976,7 +1014,7 @@
         loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
         assertNotNull(loadedCopy);
         assertNotNull(loadedCopy.getCollectiblesBase());
-        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
+        assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareList);
         assertEquals(2, loadedCopy.getCollectiblesBase().size());
 
         // add and remove non persistent obj
@@ -1020,7 +1058,7 @@
         loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
         assertNotNull(loadedCopy);
         assertNotNull(loadedCopy.getAllArticlesInGroup());
-        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareCollection);
+        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareList);
         assertEquals(3, loadedCopy.getAllArticlesInGroup().size());
 
         //
@@ -1035,7 +1073,7 @@
         loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
         assertNotNull(loadedCopy);
         assertNotNull(loadedCopy.getAllArticlesInGroup());
-        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareCollection);
+        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareList);
         assertEquals(2, loadedCopy.getAllArticlesInGroup().size());
 
         //
@@ -1050,7 +1088,7 @@
         loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
         assertNotNull(loadedCopy);
         assertNotNull(loadedCopy.getAllArticlesInGroup());
-        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareCollection);
+        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareList);
         assertEquals(0, loadedCopy.getAllArticlesInGroup().size());
     }
 



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