Object mainMessage = channel.getRequestObjects().iterator().next();
assertTrue(mainMessage instanceof GraphDiff);
}
public void testCommitChangesNew() {
final CompoundDiff diff = new CompoundDiff();
final Object newObjectId = new ObjectId("test", "key", "generated");
final EventManager eventManager = new DefaultEventManager(0);
// test that ids that are passed back are actually propagated to the right
// objects...
MockDataChannel channel = new MockDataChannel() {
@Override
public GraphDiff onSync(
ObjectContext originatingContext,
GraphDiff changes,
int syncType) {
return diff;
}
// must provide a channel with working event manager
@Override
public EventManager getEventManager() {
return eventManager;
}
};
CayenneContext context = new CayenneContext(channel);
ObjEntity entity = new ObjEntity("test_entity");
entity.setClassName(MockPersistentObject.class.getName());
DataMap dataMap = new DataMap("test");
dataMap.addObjEntity(entity);
Collection<DataMap> entities = Collections.singleton(dataMap);
context.setEntityResolver(new EntityResolver(entities));
Persistent object = context.newObject(MockPersistentObject.class);
// record change here to make it available to the anonymous connector method..
diff.add(new NodeIdChangeOperation(object.getObjectId(), newObjectId));
// check that a generated object ID is assigned back to the object...
assertNotSame(newObjectId, object.getObjectId());
context.commitChanges();
assertSame(newObjectId, object.getObjectId());