use of org.apache.cayenne.testdo.relationships_child_master.Child in project cayenne by apache.
the class NestedDataContextParentPeerEventsIT method testPeerObjectUpdatedToOneRelationship.
@Test
public void testPeerObjectUpdatedToOneRelationship() throws Exception {
Master a = parentContext1.newObject(Master.class);
Master altA = parentContext1.newObject(Master.class);
Child p = parentContext1.newObject(Child.class);
p.setMaster(a);
a.setName("X");
altA.setName("Y");
parentContext1.commitChanges();
Child p1 = parentContext2.localObject(p);
Master altA1 = parentContext2.localObject(altA);
final ObjectContext childContext1 = runtime.newContext(parentContext1);
final Child p2 = childContext1.localObject(p);
final Master altA2 = childContext1.localObject(altA);
Master a2 = childContext1.localObject(a);
p1.setMaster(altA1);
assertSame(a2, p2.getMaster());
assertNotSame(altA2, p2.getMaster());
parentContext2.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertSame(altA2, p2.getMaster());
assertFalse("Peer data context became dirty on event processing", childContext1.hasChanges());
}
}.runTest(2000);
}
use of org.apache.cayenne.testdo.relationships_child_master.Child in project cayenne by apache.
the class NestedDataContextParentPeerEventsIT method testPeerObjectUpdatedToManyRelationship.
@Test
public void testPeerObjectUpdatedToManyRelationship() throws Exception {
Master a = parentContext1.newObject(Master.class);
a.setName("X");
Child px = parentContext1.newObject(Child.class);
px.setMaster(a);
Child py = parentContext1.newObject(Child.class);
parentContext1.commitChanges();
Child py1 = parentContext2.localObject(py);
Master a1 = parentContext2.localObject(a);
final ObjectContext peer2 = runtime.newContext(parentContext1);
final Child py2 = peer2.localObject(py);
final Master a2 = peer2.localObject(a);
a1.addToChildren(py1);
assertEquals(1, a2.getChildren().size());
assertFalse(a2.getChildren().contains(py2));
parentContext2.commitChangesToParent();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals(2, a2.getChildren().size());
assertTrue(a2.getChildren().contains(py2));
assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
}.runTest(2000);
}
Aggregations