Search in sources :

Example 46 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedToManyRelationship.

@Test
public void testPeerObjectUpdatedToManyRelationship() throws Exception {
    ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
    a.setGlobalAttribute1("X");
    ClientMtTable2 px = clientContext.newObject(ClientMtTable2.class);
    px.setTable1(a);
    px.setGlobalAttribute("PX");
    ClientMtTable2 py = clientContext.newObject(ClientMtTable2.class);
    py.setGlobalAttribute("PY");
    clientContext.commitChanges();
    ObjectContext peer1 = runtime.newContext(clientContext);
    ClientMtTable2 py1 = peer1.localObject(py);
    ClientMtTable1 a1 = peer1.localObject(a);
    ObjectContext peer2 = runtime.newContext(clientContext);
    ClientMtTable2 py2 = peer2.localObject(py);
    ClientMtTable1 a2 = peer2.localObject(a);
    a1.addToTable2Array(py1);
    assertEquals(1, a2.getTable2Array().size());
    assertFalse(a2.getTable2Array().contains(py2));
    peer1.commitChangesToParent();
    assertEquals(2, a2.getTable2Array().size());
    assertTrue(a2.getTable2Array().contains(py2));
    assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 47 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class RelationshipChangeIT method testNullify.

@Test
public void testNullify() {
    ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable2 o2 = clientContext.newObject(ClientMtTable2.class);
    o2.setTable1(o1);
    assertEquals(1, o1.getTable2Array().size());
    clientContext.commitChanges();
    o2.setTable1(null);
    assertEquals(0, o1.getTable2Array().size());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 48 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class RemoteIncrementalFaultListIT method testLastIndexOf.

@Test
public void testLastIndexOf() throws Exception {
    prepareList(6);
    Expression qual = ExpressionFactory.matchExp(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, "g20");
    SelectQuery<ClientMtTable1> query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class, qual);
    List<?> objects = list.context.performQuery(query);
    assertEquals(1, objects.size());
    ClientMtTable1 row = (ClientMtTable1) objects.get(0);
    assertEquals(19, list.lastIndexOf(row));
    assertEquals(-1, list.lastIndexOf(list.context.newObject(ClientMtTable1.class)));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 49 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class RemoteRollbackIT method testRollbackRelationshipModification.

@Test
public void testRollbackRelationshipModification() {
    String o1Name = "relationshipModClientMtTable1";
    String o2Title = "relationshipTestClientMtTable2";
    ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1(o1Name);
    ClientMtTable2 o2 = clientContext.newObject(ClientMtTable2.class);
    o2.setGlobalAttribute(o2Title);
    o2.setTable1(o1);
    assertEquals(1, o1.getTable2Array().size());
    clientContext.commitChanges();
    assertEquals(1, o1.getTable2Array().size());
    o2.setTable1(null);
    assertEquals(0, o1.getTable2Array().size());
    clientContext.rollbackChanges();
    assertEquals(1, o1.getTable2Array().size());
    assertEquals(o1, o2.getTable1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 50 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class RemoteRollbackIT method testRollbackModifiedObject.

@Test
public void testRollbackModifiedObject() {
    String o1Name = "initialTestClientMtTable1";
    ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1(o1Name);
    clientContext.commitChanges();
    o1.setGlobalAttribute1("a new value");
    clientContext.rollbackChanges();
    // Make sure the inmemory changes have been rolled back
    assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
    assertEquals(o1Name, o1.getGlobalAttribute1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Aggregations

ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)112 Test (org.junit.Test)112 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)46 SelectQuery (org.apache.cayenne.query.SelectQuery)26 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)19 ObjectContext (org.apache.cayenne.ObjectContext)12 Expression (org.apache.cayenne.exp.Expression)12 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)11 List (java.util.List)8 ObjectId (org.apache.cayenne.ObjectId)7 EntityResolver (org.apache.cayenne.map.EntityResolver)7 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)7 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)6 GraphDiff (org.apache.cayenne.graph.GraphDiff)5 MockEventManager (org.apache.cayenne.event.MockEventManager)4 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)3 MtTable1 (org.apache.cayenne.testdo.mt.MtTable1)3