use of com.orientechnologies.orient.test.domain.cycle.CycleChild in project orientdb by orientechnologies.
the class ObjectDetachingTest method testDetachAllWithCycles.
public void testDetachAllWithCycles() {
database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.cycle");
CycleParent parent = new CycleParent();
parent.setName("parent");
CycleChild cycleChild1 = new CycleChild();
cycleChild1.setParent(parent);
cycleChild1.setName("child1");
parent.getChildren().add(cycleChild1);
CycleChild cycleChild2 = new CycleChild();
cycleChild2.setName("child2");
cycleChild2.setParent(parent);
parent.getChildren().add(cycleChild2);
GrandChild grandChild = new GrandChild();
grandChild.setName("grandchild");
grandChild.setGrandParent(parent);
cycleChild1.getGrandChildren().add(grandChild);
CycleParent attached = database.save(parent);
CycleParent detachedParent = database.detachAll(attached, true);
Assert.assertEquals(detachedParent.getName(), parent.getName());
Assert.assertEquals(detachedParent.getChildren().getClass(), ArrayList.class);
CycleChild detachedCycleChild1 = detachedParent.getChildren().get(0);
CycleChild detachedCycleChild2 = detachedParent.getChildren().get(1);
Assert.assertEquals(detachedCycleChild1.getName(), cycleChild1.getName());
Assert.assertEquals(detachedCycleChild2.getName(), cycleChild2.getName());
Assert.assertEquals(detachedCycleChild1.getGrandChildren().getClass(), HashSet.class);
GrandChild detachedGrandChild = detachedCycleChild1.getGrandChildren().iterator().next();
Assert.assertEquals(detachedGrandChild.getName(), grandChild.getName());
Assert.assertSame(detachedGrandChild.getGrandParent(), detachedParent);
}
Aggregations