*/
public void testLoadingDoubleDepth() {
logger.log(BasicLevel.DEBUG, "************testLoadingDoubleDepth**************");
Country country = new Country("bl","Belarus");
Address address = new Address("Rue Kaloc", "Minsk", country);
Person parent = new Person();
parent.setName("Castuk Joel");
parent.setAge(63);
parent.setAddress(address);
Person child1 = new Person("Castuk Sofia", address, null, 30);
Person child2 = new Person("Castuk Michael", address, null, 40);
Set children = new HashSet();
children.add(child1);
children.add(child2);
parent.setChildren(children);
Person child11 = new Person("Castuk Maria", address, null, 14);
Person child21 = new Person("Castuk 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("detailChildren2").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 " + person.getName() + ", " + person.getAge() + ", " + person.getAddress().getStreet() + ", " + person.getAddress().getCity()
+ ", " + person.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();
Iterator it3 = person.getChildren().iterator();
while(it3.hasNext()){
Person pf = (Person) it3.next();
logger.log(BasicLevel.DEBUG, "\t\tChild: " + pf.toString());
}
}
}
} catch(Exception e){
assertEquals("Supposed to be a " + JDODetachedFieldAccessException.class.getName(), JDODetachedFieldAccessException.class, e.getClass());