database.delete(test);
}
@Test(dependsOnMethods = "testCascadeDeleteSimpleObject")
public void testCascadeDeleteCollections() {
JavaCascadeDeleteTestClass test = database.newInstance(JavaCascadeDeleteTestClass.class);
Child listChild1 = database.newInstance(Child.class);
listChild1.setName("list1");
test.getList().add(listChild1);
Child listChild2 = database.newInstance(Child.class);
listChild2.setName("list2");
test.getList().add(listChild2);
Child listChild3 = database.newInstance(Child.class);
listChild3.setName("list3");
test.getList().add(listChild3);
Child setChild1 = database.newInstance(Child.class);
setChild1.setName("set1");
test.getSet().add(setChild1);
Child setChild2 = database.newInstance(Child.class);
setChild2.setName("set2");
test.getSet().add(setChild2);
Child setChild3 = database.newInstance(Child.class);
setChild3.setName("set3");
test.getSet().add(setChild3);
database.save(test);
ORID testRid = database.getRecordByUserObject(test, false).getIdentity();
ORID list1Rid = database.getRecordByUserObject(listChild1, false).getIdentity();
ORID list2Rid = database.getRecordByUserObject(listChild2, false).getIdentity();
ORID list3Rid = database.getRecordByUserObject(listChild3, false).getIdentity();
ORID set1Rid = database.getRecordByUserObject(setChild1, false).getIdentity();
ORID set2Rid = database.getRecordByUserObject(setChild2, false).getIdentity();
ORID set3Rid = database.getRecordByUserObject(setChild3, false).getIdentity();
database.close();
database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
database.delete(testRid);
listChild1 = database.load(list1Rid);
listChild2 = database.load(list2Rid);
listChild3 = database.load(list3Rid);
setChild1 = database.load(set1Rid);
setChild2 = database.load(set2Rid);
setChild3 = database.load(set3Rid);
Assert.assertNull(listChild1);
Assert.assertNull(listChild2);
Assert.assertNull(listChild3);
Assert.assertNull(setChild1);
Assert.assertNull(setChild2);
Assert.assertNull(setChild3);
// LIST UPDATE TEST
test = database.newInstance(JavaCascadeDeleteTestClass.class);
listChild1 = database.newInstance(Child.class);
listChild1.setName("list1");
test.getList().add(listChild1);
listChild2 = database.newInstance(Child.class);
listChild2.setName("list2");
test.getList().add(listChild2);
listChild3 = database.newInstance(Child.class);
listChild3.setName("list3");
test.getList().add(listChild3);
Child listChild4 = database.newInstance(Child.class);
listChild4.setName("list4");
test.getList().add(listChild4);
setChild1 = database.newInstance(Child.class);
setChild1.setName("set1");
test.getSet().add(setChild1);
setChild2 = database.newInstance(Child.class);
setChild2.setName("set2");
test.getSet().add(setChild2);
setChild3 = database.newInstance(Child.class);
setChild3.setName("set3");
test.getSet().add(setChild3);
Child setChild4 = database.newInstance(Child.class);
setChild4.setName("set4");
test.getSet().add(setChild4);
database.save(test);
testRid = database.getRecordByUserObject(test, false).getIdentity();
list1Rid = database.getRecordByUserObject(listChild1, false).getIdentity();
list2Rid = database.getRecordByUserObject(listChild2, false).getIdentity();
list3Rid = database.getRecordByUserObject(listChild3, false).getIdentity();
ORID list4Rid = database.getRecordByUserObject(listChild4, false).getIdentity();
set1Rid = database.getRecordByUserObject(setChild1, false).getIdentity();
set2Rid = database.getRecordByUserObject(setChild2, false).getIdentity();
set3Rid = database.getRecordByUserObject(setChild3, false).getIdentity();
ORID set4Rid = database.getRecordByUserObject(setChild4, false).getIdentity();
database.close();
database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
test = database.load(testRid);
test.getList().remove(listChild4);
test.getList().remove(0);
test.getList().remove(listChild3);
test.getList().add(listChild4);
Iterator<Child> it = test.getList().iterator();
it.next();
it.remove();
test.getSet().remove(setChild1);
test.getSet().remove(setChild4);
Assert.assertFalse(test.getSet().contains(setChild1));
Assert.assertFalse(test.getSet().contains(setChild4));
it = test.getSet().iterator();
it.next();
it.remove();
Assert.assertTrue((!test.getSet().contains(setChild2) || !test.getSet().contains(setChild3)));
test.getSet().add(setChild4);
database.save(test);
test = database.load(testRid);
Assert.assertTrue(!test.getList().contains(listChild3));
listChild1 = database.load(list1Rid);
listChild2 = database.load(list2Rid);
listChild3 = database.load(list3Rid);
listChild4 = database.load(list4Rid);
setChild1 = database.load(set1Rid);