context.findSimpleFooById(1L).with("barField", "oneToManyField").fire(
new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(final SimpleFooProxy response) {
SimpleFooRequest context = factory.simpleFooRequest();
final SimpleFooProxy foo = context.edit(response);
// simply casting 'factory' to AbstractRequestFactory would fail
// when run as a JRE test.
final AbstractRequestFactory abstractRequestFactory =
AutoBeanUtils.getAutoBean(foo).<AbstractRequestContext.State> getTag(
Constants.REQUEST_CONTEXT_STATE).requestFactory;
final String fooTypeToken = abstractRequestFactory.getTypeToken(SimpleFooProxy.class);
final String valueTypeToken =
abstractRequestFactory.getTypeToken(SimpleValueProxy.class);
// Create
final SimpleValueProxy created = context.create(SimpleValueProxy.class);
created.setNumber(42);
created.setString("Hello world!");
created.setSimpleFoo(foo);
// Test cycles in value
created.setSimpleValue(Arrays.asList(created));
// Set
foo.setSimpleValue(created);
foo.setSimpleValues(Collections.singletonList(created));
context.persistAndReturnSelf().using(foo).with("barField", "oneToManyField",
"oneToManySetField", "simpleValue", "simpleValues").fire(
new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
RequestMessage requestMessage =
AutoBeanCodex.decode(MessageFactoryHolder.FACTORY, RequestMessage.class,
transport.lastRequestPayload).as();
int seenFoos = 0;
int seenValues = 0;
for (OperationMessage operationMessage : requestMessage.getOperations()) {
if (fooTypeToken.equals(operationMessage.getTypeToken())) {
seenFoos++;
@SuppressWarnings("unchecked")
SimpleProxyId<?> id = (SimpleProxyId<?>) foo.stableId();
assertEquals(id.getServerId(), operationMessage.getServerId());
assertEquals(2, operationMessage.getPropertyMap().size());
assertTrue(operationMessage.getPropertyMap().containsKey("simpleValue"));
assertTrue(operationMessage.getPropertyMap().containsKey("simpleValues"));
} else if (valueTypeToken.equals(operationMessage.getTypeToken())) {