brj 2005/03/09 11:42:17
Modified: src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
CollectionTest.java
Log:
Testcase for RemovalAwareCollection
Revision Changes Path
No revision
No revision
1.11.2.2 +61 -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.11.2.1
retrieving revision 1.11.2.2
diff -u -r1.11.2.1 -r1.11.2.2
--- CollectionTest.java 23 Jan 2005 03:03:19 -0000 1.11.2.1
+++ CollectionTest.java 9 Mar 2005 19:42:17 -0000 1.11.2.2
@@ -13,6 +13,7 @@
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.util.collections.RemovalAwareCollection;
import org.apache.ojb.junit.PBTestCase;
/**
@@ -771,7 +772,66 @@
}
+ /**
+ * Test RemovalAwareCollection remove() and clear()
+ */
+ public void testRemovalAwareCollection()
+ {
+ String prefix = "testRemovalAwareCollection_" +
System.currentTimeMillis();
+
+ Identity gathererId;
+ Gatherer loadedCopy;
+ Gatherer gatherer = new Gatherer(null, "Gatherer_" + prefix);
+ List coll = new ArrayList();
+ coll.add(new CollectibleBase("Base_1_" + prefix));
+ coll.add(new CollectibleBase("Base_2_" + prefix));
+ coll.add(new CollectibleBase("Base_3_" + prefix));
+ gatherer.setCollectiblesBase(coll);
+
+ broker.beginTransaction();
+ broker.store(gatherer);
+ broker.commitTransaction();
+ assertTrue(gatherer.getGatId() != null);
+ gathererId = broker.serviceIdentity().buildIdentity(gatherer);
+ broker.clearCache();
+ loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
+ assertNotNull(loadedCopy);
+ assertNotNull(loadedCopy.getCollectiblesBase());
+ assertTrue(loadedCopy.getCollectiblesBase() instanceof
RemovalAwareCollection);
+ assertEquals(3, loadedCopy.getCollectiblesBase().size());
+
+ //
+ // Remove a single element
+ //
+ broker.beginTransaction();
+ loadedCopy.getCollectiblesBase().remove(2);
+ broker.store(loadedCopy);
+ broker.commitTransaction();
+
+ broker.clearCache();
+ loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
+ assertNotNull(loadedCopy);
+ assertNotNull(loadedCopy.getCollectiblesBase());
+ assertTrue(loadedCopy.getCollectiblesBase() instanceof
RemovalAwareCollection);
+ assertEquals(2, loadedCopy.getCollectiblesBase().size());
+
+ //
+ // Remove all elements
+ //
+ broker.beginTransaction();
+ loadedCopy.getCollectiblesBase().clear();
+ broker.store(loadedCopy);
+ broker.commitTransaction();
+
+ broker.clearCache();
+ loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
+ assertNotNull(loadedCopy);
+ assertNotNull(loadedCopy.getCollectiblesBase());
+ assertTrue(loadedCopy.getCollectiblesBase() instanceof
RemovalAwareCollection);
+ assertEquals(0, loadedCopy.getCollectiblesBase().size());
+ }
+
//************************************************************
// helper methods
//************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]