* Test saving/searching/loading an object that contains itself.
*/
@Test
public void testSelfContaining() throws Exception
{
PersistenceManager persist = new PersistenceManager(driver, database, login, password);
SelfContainingObject sco = new SelfContainingObject();
sco.setSelf(sco);
persist.saveObject(sco);
persist = new PersistenceManager(driver, database, login, password);
List<SelfContainingObject> scos = persist.getObjects(SelfContainingObject.class, new All());
assertEquals(1, scos.size());
assertNotNull(scos.get(0).getSelf());
Layer1 l1 = new Layer1();
l1.setLayer2(new Layer2());
l1.getLayer2().setLayer3(new Layer3());
l1.getLayer2().getLayer3().setLayer1(l1);
persist.saveObject(l1);
persist.close();
persist = new PersistenceManager(driver, database, login, password);
// it should not be possible to delete l2, since it is part of l1.
List<Layer2> l2s = persist.getObjects(Layer2.class, new All());
assertEquals(1, l2s.size());
persist.deleteObjects(Layer2.class, new All());
l2s = persist.getObjects(Layer2.class, new All());
assertEquals(1, l2s.size());
// it should not be possible to delete l3, since it is part of l2.
List<Layer3> l3s = persist.getObjects(Layer3.class, new All());
assertEquals(1, l3s.size());
persist.deleteObjects(Layer3.class, new All());
l3s = persist.getObjects(Layer3.class, new All());
assertEquals(1, l3s.size());
// it should be possible to delete l1.
List<Layer1> l1s = persist.getObjects(Layer1.class, new All());
assertEquals(1, l1s.size());
persist.deleteObjects(Layer1.class, new All());
l1s = persist.getObjects(Layer1.class, new All());
assertEquals(0, l1s.size());
// deleting l1 should remove l2 and l3.
l3s = persist.getObjects(Layer3.class, new All());
assertEquals(0, l3s.size());
l2s = persist.getObjects(Layer2.class, new All());
assertEquals(0, l2s.size());
persist.close();
}