use of org.apache.cayenne.testdo.mt.ClientMtTable1 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.ClientMtTable1 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.ClientMtTable1 in project cayenne by apache.
the class CayenneContextEJBQLIT method testEJBQLSelect.
@Test
public void testEJBQLSelect() throws Exception {
createTwoRecords();
EJBQLQuery query = new EJBQLQuery("SELECT a FROM MtTable1 a");
List<ClientMtTable1> results = context.performQuery(query);
assertEquals(2, results.size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextGraphDiffCompressorIT method testDelete.
@Test
public void testDelete() {
ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
o1.setGlobalAttribute1("v1");
context.deleteObjects(o1);
DataChannelSyncStats stats = clientServerInterceptor.runWithSyncStatsCollection(new UnitTestClosure() {
public void execute() {
context.commitChanges();
}
});
assertEquals(0, stats.nodePropertiesChanged);
assertEquals(0, stats.nodesCreated);
assertEquals(0, stats.nodesRemoved);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextIT method testBeforeHollowDeleteShouldChangeStateToCommited.
@Test
public void testBeforeHollowDeleteShouldChangeStateToCommited() {
ObjectId gid = new ObjectId("MtTable1", "a", "b");
final ClientMtTable1 inflated = new ClientMtTable1();
inflated.setPersistenceState(PersistenceState.COMMITTED);
inflated.setObjectId(gid);
inflated.setGlobalAttribute1("abc");
ClientConnection connection = mock(ClientConnection.class);
when(connection.sendMessage((ClientMessage) any())).thenAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
if (arg instanceof BootstrapMessage) {
return new EntityResolver();
} else {
return new GenericResponse(Arrays.asList(inflated));
}
}
});
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false);
CayenneContext context = new CayenneContext(channel);
context.setEntityResolver(serverContext.getEntityResolver().getClientEntityResolver());
ClientMtTable1 hollow = context.localObject(inflated);
assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
// testing this...
context.deleteObjects(hollow);
assertSame(hollow, context.getGraphManager().getNode(gid));
assertEquals(inflated.getGlobalAttribute1Direct(), hollow.getGlobalAttribute1Direct());
assertEquals(PersistenceState.DELETED, hollow.getPersistenceState());
}
Aggregations