*/
public void testLoadingRecursiveDepth() {
logger.log(BasicLevel.DEBUG, "************testLoadingRecursiveDepth**************");
Country country = new Country("sp","Espagne");
Address address = new Address("Rue Rio", "Santander", country);
Person parent = new Person();
parent.setName("Casillas Joel");
parent.setAge(63);
parent.setAddress(address);
Person child1 = new Person("Casillas Sofia", address, null, 30);
Person child2 = new Person("Casillas Michael", address, null, 40);
Set children = new HashSet();
children.add(child1);
children.add(child2);
parent.setChildren(children);
Person child11 = new Person("Casillas Maria", address, null, 14);
Person child21 = new Person("Casillas Juan", address, null, 11);
Set children1 = new HashSet();
children1.add(child11);
Set children2 = new HashSet();
children2.add(child21);
child1.setChildren(children1);
child2.setChildren(children2);
PersistenceManager pm = pmf.getPersistenceManager();
FetchPlan fp = pm.getFetchPlan();
fp.clearGroups();
fp.addGroup("detailChildren").removeGroup("default");
pm.currentTransaction().begin();
logger.log(BasicLevel.DEBUG, "make persistent the person " + parent.toString());
pm.makePersistent(parent);
pm.currentTransaction().commit();
logger.log(BasicLevel.DEBUG, "FG: " + fp.getGroups());
try {
pm.currentTransaction().begin();
Person detachedParent = (Person) pm.detachCopy(parent);
assertEquals(parent.getName(), detachedParent.getName());
assertEquals(parent.getAge(), detachedParent.getAge());
assertEquals(parent.getAddress().getCity(), detachedParent.getAddress().getCity());
assertEquals(parent.getAddress().getCountry().getCode(), detachedParent.getAddress().getCountry().getCode());
assertEquals(parent.getAddress().getCountry().getName(), detachedParent.getAddress().getCountry().getName());
assertEquals(parent.getAddress().getStreet(), detachedParent.getAddress().getStreet());
assertEquals(parent.getChildren().size(), detachedParent.getChildren().size());
logger.log(BasicLevel.DEBUG, "Name can be accessed: " + detachedParent.getName());
logger.log(BasicLevel.DEBUG, "Age can be accessed: " + detachedParent.getAge());
logger.log(BasicLevel.DEBUG, "Address can be accessed: " +
detachedParent.getAddress().getStreet() + ", " + detachedParent.getAddress().getCity()
+ ", " + detachedParent.getAddress().getCountry().getCode());
Collection childrenTmp = detachedParent.getChildren();
logger.log(BasicLevel.DEBUG, "Children names and address.country.code can be accessed: ");
Iterator it = childrenTmp.iterator();
while(it.hasNext()){
Person p = (Person) it.next();
logger.log(BasicLevel.DEBUG, "Child: " + p.getName() + ", " + p.getAge() + ", " + p.getAddress().getStreet() + ", " + p.getAddress().getCity()
+ ", " + p.getAddress().getCountry().getCode());
}
it = childrenTmp.iterator();
while(it.hasNext()){
Person p = (Person) it.next();
Iterator it2 = p.getChildren().iterator();
while(it2.hasNext()){
Person person = (Person) it2.next();
logger.log(BasicLevel.DEBUG, "\tChild of children should not be accessed: " + person.toString());
}
}
} catch(Exception e) {
assertEquals(e.getClass(), JDODetachedFieldAccessException.class);
assertTrue(e.getMessage().indexOf("children") != -1);