You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/02/18 17:43:57 UTC
cvs commit: db-ojb/src/test/org/apache/ojb/odmg CollectionsTest.java
arminw 2004/02/18 08:43:57
Modified: src/test/org/apache/ojb/odmg CollectionsTest.java
Log:
update test cases
Revision Changes Path
1.10 +106 -29 db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java
Index: CollectionsTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- CollectionsTest.java 24 Jan 2004 14:15:55 -0000 1.9
+++ CollectionsTest.java 18 Feb 2004 16:43:57 -0000 1.10
@@ -65,6 +65,82 @@
}
}
+ /**
+ * Create an main object Gatherer with a collection of objects CollectiblesC.
+ * CollectiblesC hasn't a reference back to the main object. After creation we
+ * remove an collection element.
+ */
+ public void testRemoveCollectionElementWithoutBackReference() throws Exception
+ {
+ // String queryColl = "select colls from " + CollectibleC.class.getName() + " where name=$1";
+ String queryGat = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
+ String prefix = "testDeleteCollectionElementWithoutBackReference_" + System.currentTimeMillis();
+
+ // prepare test case
+ Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
+ // we don't set the gatId in CollectiblesC, because we don't have one
+ // Set List of CollectiblesC objects
+ gat.setCollectiblesC(Arrays.asList(prepareCollectibleC(null, prefix)));
+ TransactionExt tx = (TransactionExt)odmg.newTransaction();
+ tx.begin();
+ db.makePersistent(gat);
+ tx.commit();
+
+ // check if gatherer was stored
+ tx.begin();
+ tx.getBroker().clearCache();
+ assertNotNull(gat.getGatId());
+
+ OQLQuery query = odmg.newOQLQuery();
+ query.create(queryGat);
+ query.bind(gat.getGatId());
+
+ Collection result = (Collection) query.execute();
+ tx.commit();
+ assertEquals("Wrong number of objects found", 1, result.size());
+ Gatherer fetchedGat = (Gatherer) result.iterator().next();
+ assertNotNull(fetchedGat);
+
+ // check if gatherer contains list of CollectibleBase
+ List colC = fetchedGat.getCollectiblesC();
+ assertEquals("Wrong number of CollectiblesC", 3, colC.size());
+
+ tx.begin();
+ //*************************************
+ tx.lock(fetchedGat, Transaction.WRITE);
+ // Remove collection object
+ fetchedGat.getCollectiblesC().remove(0);
+ //*************************************
+ tx.commit();
+
+ // check if the Collectibles were really deleted from DB
+ tx.begin();
+ tx.getBroker().clearCache();
+
+ query = odmg.newOQLQuery();
+ query.create("select colls from " + CollectibleC.class.getName() +
+ " where name like $1");
+ query.bind(prefix + "%");
+ result = (Collection) query.execute();
+ assertEquals("Wrong number of objects found", 2, result.size());
+ tx.commit();
+
+ // check if the gatherer now contains a CollectibleBase list
+ // increased by the added
+ tx.begin();
+ tx.getBroker().clearCache();
+ query = odmg.newOQLQuery();
+ query.create(queryGat);
+ query.bind(gat.getGatId());
+ result = (Collection) query.execute();
+ assertEquals("Wrong number of objects found", 1, result.size());
+ fetchedGat = (Gatherer) result.iterator().next();
+ colC = fetchedGat.getCollectiblesC();
+ assertEquals("Wrong number of CollectiblesA found in Gatherer", 2, colC.size());
+ tx.commit();
+ assertNotNull(colC.get(0));
+ }
+
public void testStoreFetchDeleteCollectionWithBackReference() throws Exception
{
String prefix = "testStoreFetchDeleteCollectionWithBackReference_" + System.currentTimeMillis();
@@ -94,11 +170,11 @@
assertEquals("Wrong number of objects found", 1, result.size());
Gatherer fetchedGat = (Gatherer) result.iterator().next();
- // check if gatherer contains list of CollectibleBase
- tx.begin();
List colsA = fetchedGat.getCollectiblesA();
assertEquals("Wrong number of CollectiblesA", 3, colsA.size());
-
+ // check if gatherer contains list of CollectibleBase
+ tx.begin();
+ //*************************************
// delete one of the CollectibleBase
// we have to set the new reduced list in the
// gatherer object
@@ -107,7 +183,9 @@
newCols.add(colsA.get(2));
fetchedGat.setCollectiblesA(newCols);
tx.lock(fetchedGat, Transaction.WRITE);
+ // todo: do we need to delete removed reference explicit?
db.deletePersistent(colsA.get(0));
+ //*************************************
tx.commit();
// check if the CollectibleBase was really deleted from DB
@@ -136,9 +214,9 @@
colsA.get(0);
}
- public void testStoreUpdateCollectionWithBackReference() throws Exception
+ public void testStoreDeleteCollectionElementWithBackReference() throws Exception
{
- String prefix = "testStoreUpdateCollectionWithBackReference_" + System.currentTimeMillis();
+ String prefix = "testStoreUpdateCollectionElementWithBackReference_" + System.currentTimeMillis();
String queryStr = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
TransactionExt tx = (TransactionExt) odmg.newTransaction();
@@ -178,9 +256,11 @@
tx.begin();
tx.getBroker().clearCache();
+ //*************************************
tx.lock(fetchedGat, Transaction.WRITE);
fetchedGat.getCollectiblesA().remove(0);
fetchedGat.getCollectiblesB().remove(0);
+ //*************************************
tx.commit();
tx.begin();
@@ -341,14 +421,13 @@
* then we exchange the collections
* gat1{collC2} and gat2{collC1}
* and commit. So the size of the collection
- * hold by the main object doesn't change and current
- * implementation dosen't mark main object as dirty
+ * hold by the main object doesn't change
*
- * see ...odmg.ObjectEnvelope line 311
+ * todo: see ...odmg.ObjectEnvelope line 311
*/
- public void testUpdateCollection_2() throws Exception
+ public void testUpdateWhenExchangeObjectsInCollection() throws Exception
{
- final String prefix = "testUpdateCollection_2" + System.currentTimeMillis();
+ final String prefix = "testUpdateWhenExchangeObjectsInCollection" + System.currentTimeMillis();
final String queryStr = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1 or gatId=$2";
// prepare test case
@@ -436,11 +515,11 @@
* main object, because we don't know it at creation time.
* Then we remove one object of the collection
*/
- public void testStoreUpdateCollectionWithoutBackReference() throws Exception
+ public void testRemoveCollectionElementWithoutBackReference_2() throws Exception
{
// String queryColl = "select colls from " + CollectibleC.class.getName() + " where name=$1";
String queryGat = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
- String prefix = "testStoreUpdateCollectionWithoutBackReference_" + System.currentTimeMillis();
+ String prefix = "testRemoveCollectionObjectWithoutBackReference_2_" + System.currentTimeMillis();
// prepare test case
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
@@ -467,21 +546,22 @@
Gatherer fetchedGat = (Gatherer) result.iterator().next();
assertNotNull(fetchedGat);
- // check if gatherer contains list of CollectibleBase
- tx.begin();
List colC = fetchedGat.getCollectiblesC();
assertEquals("Wrong number of CollectiblesC", 3, colC.size());
-
- // delete one of the CollectibleBase
- // we have to set the new reduced list in the
- // gatherer object
+ // check if gatherer contains list of CollectibleBase
+ tx.begin();
+ //**********************************************************
+ // we replace the collection of main object with a new collection
+ // reduced by one element
List newCols = new ArrayList();
newCols.add(colC.get(1));
newCols.add(colC.get(2));
// lock object before do changes
tx.lock(fetchedGat, Transaction.WRITE);
fetchedGat.setCollectiblesA(newCols);
+ // todo: we need to delete removed object explicit?
db.deletePersistent(colC.get(0));
+ //**********************************************************
tx.commit();
// check if the Collectibles were really deleted from DB
@@ -550,18 +630,19 @@
Gatherer fetchedGat = (Gatherer) result.iterator().next();
assertNotNull(fetchedGat);
-
- tx.begin();
// check if gatherer contains list of CollectibleBase
List colC = fetchedGat.getCollectiblesC();
assertEquals("Wrong number of CollectiblesC", 3, colC.size());
+ tx.begin();
//*************************************
+ tx.lock(fetchedGat, Transaction.WRITE);
// Now add a new collection object
- CollectibleC newC = new CollectibleC(prefix, null, "new added");
+ CollectibleC newC = new CollectibleC(prefix, null, "### new added ###");
fetchedGat.getCollectiblesC().add(newC);
+ newC.setGathererId(fetchedGat.getGatId());
+ tx.lock(newC, Transaction.WRITE);
//*************************************
-
tx.commit();
// check if the Collectibles were really deleted from DB
@@ -573,7 +654,7 @@
" where name like $1");
query.bind(prefix + "%");
result = (Collection) query.execute();
- assertEquals("Wrong number of objects found", 3, result.size());
+ assertEquals("Wrong number of objects found", 4, result.size());
tx.commit();
// check if the gatherer now contains a CollectibleBase list
@@ -587,7 +668,7 @@
assertEquals("Wrong number of objects found", 1, result.size());
fetchedGat = (Gatherer) result.iterator().next();
colC = fetchedGat.getCollectiblesC();
- assertEquals("Wrong number of CollectiblesA found in Gatherer", 3, colC.size());
+ assertEquals("Wrong number of CollectiblesA found in Gatherer", 4, colC.size());
tx.commit();
colC.get(0);
@@ -702,10 +783,6 @@
*/
public void testAddCollectionElementCrossAPI() throws Exception
{
- // Lookup current odmg-collection class
- Class oqlCollectionClass = ((OdmgConfiguration) PersistenceBrokerFactory.getConfigurator().
- getConfigurationFor(null)).getOqlCollectionClass();
-
String name = "testAddCollectionElementCrossAPI_"+System.currentTimeMillis();
// prepare test case
Gatherer gat = new Gatherer(null, name);
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org