Search in sources :

Example 1 with Master

use of org.apache.cayenne.testdo.relationships_child_master.Master in project cayenne by apache.

the class NestedDataContextParentPeerEventsIT method testPeerObjectUpdatedSimpleProperty.

@Test
public void testPeerObjectUpdatedSimpleProperty() throws Exception {
    Master a = parentContext1.newObject(Master.class);
    a.setName("X");
    parentContext1.commitChanges();
    Master a1 = parentContext2.localObject(a);
    final ObjectContext child = runtime.newContext(parentContext1);
    final Master a2 = child.localObject(a);
    a1.setName("Y");
    assertEquals("X", a2.getName());
    parentContext2.commitChangesToParent();
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertEquals("Y", a2.getName());
            assertFalse("Peer data context became dirty on event processing", child.hasChanges());
        }
    }.runTest(2000);
}
Also used : Master(org.apache.cayenne.testdo.relationships_child_master.Master) ObjectContext(org.apache.cayenne.ObjectContext) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 2 with Master

use of org.apache.cayenne.testdo.relationships_child_master.Master 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);
}
Also used : Master(org.apache.cayenne.testdo.relationships_child_master.Master) ObjectContext(org.apache.cayenne.ObjectContext) Child(org.apache.cayenne.testdo.relationships_child_master.Child) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 3 with Master

use of org.apache.cayenne.testdo.relationships_child_master.Master 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);
}
Also used : Master(org.apache.cayenne.testdo.relationships_child_master.Master) ObjectContext(org.apache.cayenne.ObjectContext) Child(org.apache.cayenne.testdo.relationships_child_master.Child) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)3 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)3 Master (org.apache.cayenne.testdo.relationships_child_master.Master)3 Test (org.junit.Test)3 Child (org.apache.cayenne.testdo.relationships_child_master.Child)2