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());
}
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);
}
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());
}
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();
}
}
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);
}
Aggregations