Search in sources :

Example 26 with ClientMtTable2

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

the class HessianROPSerializationServiceIT method testByteArraySerialization.

@Test
public void testByteArraySerialization() throws Exception {
    ClientMtTable1 table1 = context.newObject(ClientMtTable1.class);
    table1.setGlobalAttribute1("Test table1");
    ClientMtTable2 table2 = context.newObject(ClientMtTable2.class);
    table2.setGlobalAttribute("Test table2");
    table2.setTable1(table1);
    ROPSerializationService clientService = createClientSerializationService();
    ROPSerializationService serverService = createServerSerializationService();
    // test client to server serialization
    byte[] data = clientService.serialize(table2);
    ClientMtTable2 serverTable2 = serverService.deserialize(data, ClientMtTable2.class);
    assertEquals("Test table2", serverTable2.getGlobalAttribute());
    assertEquals("Test table1", serverTable2.getTable1().getGlobalAttribute1());
    // test server to client serialization
    data = serverService.serialize(table2);
    ClientMtTable2 clientTable2 = clientService.deserialize(data, ClientMtTable2.class);
    assertEquals("Test table2", clientTable2.getGlobalAttribute());
    assertEquals("Test table1", clientTable2.getTable1().getGlobalAttribute1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ROPSerializationService(org.apache.cayenne.rop.ROPSerializationService) Test(org.junit.Test)

Example 27 with ClientMtTable2

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

the class PersistentObjectHolderTest method testInvalidate.

@Test
public void testInvalidate() {
    ObjectContext context = mock(ObjectContext.class);
    ClientMtTable2 o = new ClientMtTable2();
    o.setPersistenceState(PersistenceState.COMMITTED);
    o.setObjectContext(context);
    PersistentObjectHolder holder = new PersistentObjectHolder(o, ClientMtTable2.TABLE1_PROPERTY);
    assertTrue(holder.isFault());
    ClientMtTable1 o1 = new ClientMtTable1();
    o1.setObjectContext(context);
    holder.setValueDirectly(o1);
    holder.invalidate();
    assertTrue(holder.isFault());
    assertNull(holder.value);
}
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 28 with ClientMtTable2

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

the class CayenneContextClientChannelEventsIT method testSyncToManyRelationship.

@Test
public void testSyncToManyRelationship() throws Exception {
    tMtTable1.insert(1, "g1", "s1");
    tMtTable2.insert(1, 1, "g1");
    CayenneContext c1 = (CayenneContext) runtime.newContext();
    CayenneContext c2 = (CayenneContext) runtime.newContext();
    ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
    ClientMtTable1 o2 = (ClientMtTable1) Cayenne.objectForQuery(c2, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
    assertEquals(1, o1.getTable2Array().size());
    assertEquals(1, o2.getTable2Array().size());
    ClientMtTable2 o1r = c1.newObject(ClientMtTable2.class);
    o1r.setGlobalAttribute("X");
    o1.addToTable2Array(o1r);
    c1.commitChanges();
    // let the events propagate to peers
    Thread.sleep(500);
    assertEquals(2, o1.getTable2Array().size());
    assertEquals(2, o2.getTable2Array().size());
    assertFalse(c1.internalGraphManager().hasChanges());
    assertFalse(c2.internalGraphManager().hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 29 with ClientMtTable2

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

the class CayenneContextServerDiffsIT method testReturnDiffClientArcChanges.

@Test
public void testReturnDiffClientArcChanges() {
    LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
    try {
        callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersist");
        ClientMtTable1 o = context.newObject(ClientMtTable1.class);
        ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
        o.addToTable2Array(o1);
        context.commitChanges();
        assertFalse(o.getObjectId().isTemporary());
        assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
        assertEquals("XXX", o.getGlobalAttribute1());
    } finally {
        callbackRegistry.clear();
    }
}
Also used : ClientChannelServerDiffsListener1(org.apache.cayenne.remote.ClientChannelServerDiffsListener1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) LifecycleCallbackRegistry(org.apache.cayenne.reflect.LifecycleCallbackRegistry) Test(org.junit.Test)

Example 30 with ClientMtTable2

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

the class PersistentObjectHolderTest method testSetInitialValue.

@Test
public void testSetInitialValue() {
    ObjectContext context = mock(ObjectContext.class);
    ClientMtTable2 o = new ClientMtTable2();
    o.setPersistenceState(PersistenceState.COMMITTED);
    o.setObjectContext(context);
    PersistentObjectHolder holder = new PersistentObjectHolder(o, ClientMtTable2.TABLE1_PROPERTY);
    assertTrue(holder.isFault());
    ClientMtTable1 o1 = new ClientMtTable1();
    o1.setObjectContext(context);
    holder.setValueDirectly(o1);
    assertFalse(holder.isFault());
    assertSame(o1, holder.value);
}
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)

Aggregations

ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)48 Test (org.junit.Test)48 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)46 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)9 Expression (org.apache.cayenne.exp.Expression)7 SelectQuery (org.apache.cayenne.query.SelectQuery)7 ObjectContext (org.apache.cayenne.ObjectContext)6 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 Iterator (java.util.Iterator)3 List (java.util.List)3 GraphDiff (org.apache.cayenne.graph.GraphDiff)3 PersistentObjectHolder (org.apache.cayenne.util.PersistentObjectHolder)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)2 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)2 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)2 ROPSerializationService (org.apache.cayenne.rop.ROPSerializationService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CayenneContext (org.apache.cayenne.CayenneContext)1 ValueHolder (org.apache.cayenne.ValueHolder)1