SimpleFooRequest context = simpleFooRequest();
foo = context.edit(foo);
// Create
SimpleValueProxy created = context.create(SimpleValueProxy.class);
created.setNumber(42);
created.setString("Hello world!");
created.setSimpleFoo(foo);
// That proxy is a "clone" of the 'create' one
SimpleValueProxy other = context.create(SimpleValueProxy.class);
other.setNumber(42);
other.setString("Hello world!");
other.setSimpleFoo(foo);
// Test cycles in value
created.setSimpleValue(Arrays.asList(created, other));
other.setSimpleValue(Arrays.asList(created, other));
// Set
foo.setSimpleValue(created);
foo.setSimpleValues(Collections.singletonList(created));
// Retrieve
context.persistAndReturnSelf().using(foo).with("simpleValue.simpleFoo",
"simpleValue.simpleValue").fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy foo) {
foo = checkSerialization(foo);
SimpleFooRequest context = simpleFooRequest();
// edit() still doesn't cause a change
foo = context.edit(foo);
assertFalse(context.isChanged());
// Change to a referenced value proxy causes a change
foo.getSimpleValue().setNumber(43);
assertTrue(context.isChanged());
// Undo the change
foo.getSimpleValue().setNumber(42);
assertFalse(context.isChanged());
// Change to another value proxy causes a change
// Note that create() doesn't cause a change, see testChangedCreate
SimpleValueProxy old = foo.getSimpleValue();
SimpleValueProxy created = context.create(SimpleValueProxy.class);
foo.setSimpleValue(created);
assertTrue(context.isChanged());
// An equivalent value proxy reverts the change
foo.setSimpleValue(old.getSimpleValue().get(1));