arminw 2005/04/09 15:35:58
Modified: src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
NamedRootsTest.java
Log:
update test
Revision Changes Path
No revision
No revision
1.1.2.3 +93 -2 db-ojb/src/test/org/apache/ojb/odmg/NamedRootsTest.java
Index: NamedRootsTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/NamedRootsTest.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- NamedRootsTest.java 3 Apr 2005 01:48:10 -0000 1.1.2.2
+++ NamedRootsTest.java 9 Apr 2005 22:35:58 -0000 1.1.2.3
@@ -7,6 +7,8 @@
import org.apache.ojb.junit.ODMGTestCase;
import org.apache.ojb.odmg.shared.Article;
import org.apache.ojb.odmg.shared.ProductGroup;
+import org.apache.ojb.odmg.collections.DListImpl;
+import org.odmg.DList;
import org.odmg.ObjectNameNotFoundException;
import org.odmg.ObjectNameNotUniqueException;
import org.odmg.Transaction;
@@ -51,9 +53,96 @@
return example;
}
+ public void testBindPersistentCapableObjectCollection() throws Exception
+ {
+ String bindingName = "testBindPersistentCapableObjectCollection_" +
System.currentTimeMillis();
+
+ TransactionExt tx = (TransactionExt) odmg.newTransaction();
+ //bind object to name
+ tx.begin();
+
+ // get new DList instance
+ DList dlist = odmg.newDList();
+ Article a1 = createArticle();
+ Article a2 = createArticle();
+ Article a3 = createArticle();
+ dlist.add(a1);
+ dlist.add(a2);
+ dlist.add(a3);
+ database.bind(dlist, bindingName);
+ // lookup the named object - DList
+ List value = (List) database.lookup(bindingName);
+ assertNotNull("Could not lookup object for binding name:
"+bindingName, value);
+ tx.commit();
+
+ try
+ {
+ tx.begin();
+ database.bind(dlist, bindingName);
+ tx.commit();
+ fail("We expected a ObjectNameNotUniqueException, but was not
thrown");
+ }
+ catch (ObjectNameNotUniqueException ex)
+ {
+ // we wait for this exception
+ assertTrue(true);
+ tx.abort();
+ }
+
+ try
+ {
+ tx.begin();
+ tx.getBroker().clearCache();
+ database.bind(dlist, bindingName);
+ tx.commit();
+ fail("We expected a ObjectNameNotUniqueException, but was not
thrown");
+ }
+ catch (ObjectNameNotUniqueException ex)
+ {
+ // we wait for this exception
+ assertTrue(true);
+ tx.abort();
+ }
+
+ tx.begin();
+ List result = (List) database.lookup(bindingName);
+ assertNotNull(result);
+ assertEquals(3, result.size());
+ Article newA1 = (Article) result.get(0);
+ assertNotNull(newA1);
+ assertEquals(a1.getArticleName(), newA1.getArticleName());
+ tx.commit();
+
+ tx.begin();
+ // we want to completely remove the named object
+ // the persisted DList with all DList entries,
+ // but the Article objects itself shouldn't be deleted:
+ // 1. mandatory, clear the list to remove all entries
+ result.clear();
+ // 2. unbind named object
+ database.unbind(bindingName);
+
+ // alternative can be used
+ //tx.setCascadingDelete(DListImpl.class, true);
+ //database.unbind(bindingName);
+ tx.commit();
+
+ tx.begin();
+ try
+ {
+ database.lookup(bindingName);
+ }
+ catch(ObjectNameNotFoundException e)
+ {
+ // expected exception
+ assertTrue(true);
+ }
+ tx.commit();
+ }
+
public void testBindPersistentCapableObject() throws Exception
{
- String bindingName = "testBind_" + System.currentTimeMillis();
+ String bindingName = "testBindPersistentCapableObject_" +
System.currentTimeMillis();
TransactionImpl tx = (TransactionImpl) odmg.newTransaction();
//bind object to name
tx.begin();
@@ -78,6 +167,8 @@
}
tx.begin();
+ // this only remove the named object link, the Article object
+ // itself will not be touched
database.unbind(bindingName);
tx.commit();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]