Proxy IDs have to be the same for a given proxy in the response payload.
More specifically, IDs of the operation messages have to be the same as
those of the IdMessages for the same proxy, so they're deserialized into
SimpleProxyIds having the same hashCode and comparing equal: if the ID
wasEphemeral, it has to contain both the client and server IDs in all
places, not only in operation messages.
Fixes issue 7900
Change-Id: I6c2ccbcfc67323e9e5cae214b0d101ddfc1a2298
Review-Link: https://gwt-review.googlesource.com/#/c/1770/
Review by: goktug@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11482 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/web/bindery/requestfactory/server/RequestState.java b/user/src/com/google/web/bindery/requestfactory/server/RequestState.java
index 93e7078..c1d698a 100644
--- a/user/src/com/google/web/bindery/requestfactory/server/RequestState.java
+++ b/user/src/com/google/web/bindery/requestfactory/server/RequestState.java
@@ -157,7 +157,8 @@
/**
* EntityCodex support. This method is identical to
* {@link IdFactory#getHistoryToken(SimpleProxyId)} except that it
- * base64-encodes the server ids.
+ * base64-encodes the server ids and adds client ids for stable ids
+ * that were ephemeral.
* <p>
* XXX: Merge this with AbstsractRequestContext's implementation
*/
@@ -172,6 +173,9 @@
ref.setStrength(Strength.EPHEMERAL);
ref.setClientId(stableId.getClientId());
} else {
+ if (stableId.wasEphemeral()) {
+ ref.setClientId(stableId.getClientId());
+ }
ref.setServerId(SimpleRequestProcessor.toBase64(stableId.getServerId()));
}
return AutoBeanCodex.encode(bean);
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java b/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java
index c4f68b3..3bcffa3 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java
@@ -1269,6 +1269,8 @@
}
processReturnOperation(id, op, toPropagate);
}
+
+ assert state.returnedProxies.size() == ops.size();
}
/**
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTest.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTest.java
index 90dcd71..caf6670 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTest.java
@@ -16,6 +16,7 @@
package com.google.web.bindery.requestfactory.gwt.client;
import com.google.web.bindery.autobean.shared.AutoBeanCodex;
+import com.google.web.bindery.autobean.shared.AutoBeanUtils;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxyChange;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
@@ -275,6 +276,63 @@
});
}
+ /**
+ * See https://code.google.com/p/google-web-toolkit/issues/detail?id=7900
+ */
+ public void testCreatePersistCascadingAndReturnSelfEditWithReferences() {
+ delayTestFinish(DELAY_TEST_FINISH);
+
+ SimpleFooRequest context = simpleFooRequest();
+ SimpleFooProxy foo = context.create(SimpleFooProxy.class);
+ SimpleBarProxy bar = context.create(SimpleBarProxy.class);
+ foo.setBarField(bar);
+ Request<SimpleFooProxy> fooReq = context.persistCascadingAndReturnSelf()
+ .using(foo).with("barField");
+ fooReq.fire(new Receiver<SimpleFooProxy>() {
+
+ @Override
+ public void onSuccess(SimpleFooProxy returned) {
+ assertTrue(AutoBeanUtils.getAutoBean(returned).isFrozen());
+ assertTrue(AutoBeanUtils.getAutoBean(returned.getBarField()).isFrozen());
+
+ simpleFooRequest().edit(returned);
+
+ finishTestAndReset();
+ }
+ });
+ }
+
+ /**
+ * See https://code.google.com/p/google-web-toolkit/issues/detail?id=7900
+ */
+ public void testCreateReferencePersistCascadingAndReturnSelfEdit() {
+ delayTestFinish(DELAY_TEST_FINISH);
+
+ simpleFooRequest().findSimpleFooById(1L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ SimpleFooRequest context = simpleFooRequest();
+ SimpleFooProxy foo = context.edit(response);
+ SimpleBarProxy bar = context.create(SimpleBarProxy.class);
+ foo.setBarField(bar);
+ Request<SimpleFooProxy> fooReq = context.persistCascadingAndReturnSelf()
+ .using(foo).with("barField");
+ fooReq.fire(new Receiver<SimpleFooProxy>() {
+
+ @Override
+ public void onSuccess(SimpleFooProxy returned) {
+ assertTrue(AutoBeanUtils.getAutoBean(returned).isFrozen());
+ assertTrue(AutoBeanUtils.getAutoBean(returned.getBarField()).isFrozen());
+
+ simpleFooRequest().edit(returned);
+
+ finishTestAndReset();
+ }
+ });
+ }
+ });
+ }
+
public void testChangedCreate() {
SimpleFooRequest context = simpleFooRequest();
@@ -606,6 +664,9 @@
assertEquals(2, handler.totalEventCount);
checkStableIdEquals(foo, returned);
+
+ simpleFooRequest().edit(returned);
+
finishTestAndReset();
}
});