Revision: 8799
Author: [email protected]
Date: Thu Sep 16 08:54:56 2010
Log: Simplifies the RequestObject api:
* No more clearUsed(). Requests are always usable
* No more reset(), it was basically unused, and untested
* RequestData move to an impl package
Also fixes violation reporting in AbstractProxyEditActivity,
and simplifies its last remaining echo of future ids
Review at http://gwt-code-reviews.appspot.com/880801
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8799
Added:
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/RequestData.java
Deleted:
/trunk/user/src/com/google/gwt/requestfactory/shared/RequestData.java
Modified:
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/server/SchoolCalendarService.java
/trunk/user/src/com/google/gwt/app/place/AbstractProxyEditActivity.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
/trunk/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
/trunk/user/src/com/google/gwt/requestfactory/shared/RequestObject.java
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
/trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
=======================================
--- /dev/null
+++
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/RequestData.java
Thu Sep 16 08:54:56 2010
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.requestfactory.shared.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * <p>
+ * <span style="color:red">Experimental API: This class is still under
rapid
+ * development, and is very likely to be deleted. Use it at your own risk.
+ * </span>
+ * </p>
+ * A class that encapsulates the parameters and method name to be invoked
on the
+ * server.
+ */
+public class RequestData {
+
+ public static final String CONTENT_TOKEN = "contentData";
+ public static final String OPERATION_TOKEN = "operation";
+ public static final String PARAM_TOKEN = "param";
+ public static final String PROPERTY_REF_TOKEN = "propertyRefs";
+
+ public static final String RESULT_TOKEN = "result";
+
+ public static final String RELATED_TOKEN = "related";
+
+ public static final String SIDE_EFFECTS_TOKEN = "sideEffects";
+
+ // TODO: non-final is a hack for now.
+ private final String operation;
+ private final Object[] parameters;
+
+ private final Set<String> propertyRefs;
+
+ public RequestData(String operation, Object[] parameters,
+ Set<String> propertyRefs) {
+ this.operation = operation;
+ this.parameters = parameters;
+ this.propertyRefs = propertyRefs;
+ }
+
+ /**
+ * Returns the string that encodes the request data.
+ *
+ */
+ public Map<String, String> getRequestMap(String contentData) {
+ Map<String, String> requestMap = new HashMap<String, String>();
+ requestMap.put(OPERATION_TOKEN, operation);
+ if (parameters != null) {
+ for (int i = 0; i < parameters.length; i++) {
+ Object value = parameters[i];
+ requestMap.put(PARAM_TOKEN + i, value.toString());
+ }
+ }
+ if (contentData != null) {
+ requestMap.put(CONTENT_TOKEN, contentData);
+ }
+
+ if (propertyRefs != null && !propertyRefs.isEmpty()) {
+ StringBuffer props = new StringBuffer();
+ Iterator<String> propIt = propertyRefs.iterator();
+ while (propIt.hasNext()) {
+ props.append(propIt.next());
+ if (propIt.hasNext()) {
+ props.append(",");
+ }
+ }
+ requestMap.put(PROPERTY_REF_TOKEN, props.toString());
+ }
+ return requestMap;
+ }
+}
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/RequestData.java
Thu Aug 19 13:24:10 2010
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
- * use this file except in compliance with the License. You may obtain a
copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
under
- * the License.
- */
-package com.google.gwt.requestfactory.shared;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * <p>
- * <span style="color:red">Experimental API: This class is still under
rapid
- * development, and is very likely to be deleted. Use it at your own risk.
- * </span>
- * </p>
- * A class that encapsulates the parameters and method name to be invoked
on the
- * server.
- *
- * TODO: add appropriate unit tests.
- */
-public class RequestData {
-
- public static final String CONTENT_TOKEN = "contentData";
- public static final String OPERATION_TOKEN = "operation";
- public static final String PARAM_TOKEN = "param";
- public static final String PROPERTY_REF_TOKEN = "propertyRefs";
-
- public static final String RESULT_TOKEN = "result";
-
- public static final String RELATED_TOKEN = "related";
-
- public static final String SIDE_EFFECTS_TOKEN = "sideEffects";
-
- // TODO: non-final is a hack for now.
- private String operation;
- private final Object[] parameters;
-
- private Set<String> propertyRefs;
-
- public RequestData(String operation, Object[] parameters,
- Set<String> propertyRefs) {
- this.operation = operation;
- this.parameters = parameters;
- this.propertyRefs = propertyRefs;
- }
-
- /**
- * Returns the string that encodes the request data.
- *
- */
- public Map<String, String> getRequestMap(String contentData) {
- Map<String, String> requestMap = new HashMap<String, String>();
- requestMap.put(OPERATION_TOKEN, operation);
- if (parameters != null) {
- for (int i = 0; i < parameters.length; i++) {
- Object value = parameters[i];
- requestMap.put(PARAM_TOKEN + i, value.toString());
- }
- }
- if (contentData != null) {
- requestMap.put(CONTENT_TOKEN, contentData);
- }
-
- if (propertyRefs != null && !propertyRefs.isEmpty()) {
- StringBuffer props = new StringBuffer();
- Iterator<String> propIt = propertyRefs.iterator();
- while (propIt.hasNext()) {
- props.append(propIt.next());
- if (propIt.hasNext()) {
- props.append(",");
- }
- }
- requestMap.put(PROPERTY_REF_TOKEN, props.toString());
- }
- return requestMap;
- }
-}
=======================================
---
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
Wed Sep 15 02:26:39 2010
+++
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
Thu Sep 16 08:54:56 2010
@@ -120,7 +120,6 @@
@Override
public void onViolation(Set<Violation> errors) {
dialog.setText("Errors detected on the server");
- request.clearUsed();
editorDriver.setViolations(errors);
}
});
=======================================
---
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/server/SchoolCalendarService.java
Mon Sep 13 09:30:34 2010
+++
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/server/SchoolCalendarService.java
Thu Sep 16 08:54:56 2010
@@ -76,7 +76,7 @@
}
}
- public void init(FilterConfig config) throws ServletException {
+ public void init(FilterConfig config) {
backingStore = (PersonSource) config.getServletContext().getAttribute(
SchoolCalendarService.class.getName());
if (backingStore == null) {
=======================================
--- /trunk/user/src/com/google/gwt/app/place/AbstractProxyEditActivity.java
Thu Sep 16 04:46:26 2010
+++ /trunk/user/src/com/google/gwt/app/place/AbstractProxyEditActivity.java
Thu Sep 16 08:54:56 2010
@@ -24,6 +24,7 @@
import com.google.gwt.requestfactory.shared.Receiver;
import com.google.gwt.requestfactory.shared.RequestFactory;
import com.google.gwt.requestfactory.shared.RequestObject;
+import com.google.gwt.requestfactory.shared.ServerFailure;
import com.google.gwt.requestfactory.shared.SyncResult;
import com.google.gwt.requestfactory.shared.Violation;
import com.google.gwt.user.client.Window;
@@ -74,10 +75,7 @@
String unsavedChangesWarning = mayStop();
if ((unsavedChangesWarning == null)
|| Window.confirm(unsavedChangesWarning)) {
- if (requestObject != null) {
- // silence the next mayStop() call when place changes
- requestObject.reset();
- }
+ requestObject = null;
exit(false);
}
}
@@ -113,27 +111,26 @@
}
view.setEnabled(false);
- final RequestObject<Void> toCommit = requestObject;
- requestObject = null;
-
- Receiver<Void> receiver = new Receiver<Void>() {
+ requestObject.fire(new Receiver<Void>() {
+ @Override
+ public void onFailure(ServerFailure error) {
+ view.setEnabled(true);
+ super.onFailure(error);
+ }
+
@Override
public void onSuccess(Void ignore, Set<SyncResult> response) {
- // TODO(rjrjr): This can be simplified with
RequestFactory.refresh()
if (display == null) {
return;
}
- for (SyncResult syncResult : response) {
- EntityProxy syncRecord = syncResult.getProxy();
- if (creating) {
- if (!stableId.equals(syncRecord.stableId())) {
- continue;
- }
- record = cast(syncRecord);
- } else {
- if (!syncRecord.getId().equals(record.getId())) {
- continue;
+ if (creating) {
+ // TODO(amitmanjhi) Not needed once events are proxy id based
+ for (SyncResult syncResult : response) {
+ EntityProxy syncRecord = syncResult.getProxy();
+ if (stableId.equals(syncRecord.stableId())) {
+ record = cast(syncRecord);
+ break;
}
}
}
@@ -144,17 +141,12 @@
public void onViolation(Set<Violation> errors) {
Map<String, String> toShow = new HashMap<String, String>();
for (Violation error : errors) {
- if (error.getProxyId().equals(stableId)) {
- toShow.put(error.getPath(), error.getMessage());
- }
+ toShow.put(error.getPath(), error.getMessage());
}
view.showErrors(toShow);
- requestObject = toCommit;
- requestObject.clearUsed();
view.setEnabled(true);
}
- };
- toCommit.fire(receiver);
+ });
}
public void start(AcceptsOneWidget display, EventBus eventBus) {
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java
Wed Sep 15 12:32:43 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java
Thu Sep 16 08:54:56 2010
@@ -27,6 +27,7 @@
import com.google.gwt.requestfactory.shared.SyncResult;
import com.google.gwt.requestfactory.shared.Violation;
import com.google.gwt.requestfactory.shared.impl.Property;
+import com.google.gwt.requestfactory.shared.impl.RequestData;
import java.util.Collection;
import java.util.Collections;
@@ -62,10 +63,6 @@
this.deltaValueStore = new DeltaValueStoreJsonImpl(valueStore,
requestFactory);
}
-
- public void clearUsed() {
- deltaValueStore.clearUsed();
- }
@SuppressWarnings("unchecked")
public <P extends EntityProxy> P edit(P record) {
@@ -99,6 +96,8 @@
public Set<String> getPropertyRefs() {
return Collections.unmodifiableSet(propertyRefs);
}
+
+ public abstract RequestData getRequestData();
public void handleResponseText(String responseText) {
JsonResults results = JsonResults.fromResults(responseText);
@@ -168,11 +167,6 @@
ProxyJsoImpl.create(jso, requestFactory.getSchema(schemaToken),
requestFactory));
}
-
- public void reset() {
- ValueStoreJsonImpl valueStore = requestFactory.getValueStore();
- deltaValueStore = new DeltaValueStoreJsonImpl(valueStore,
requestFactory);
- }
public R with(String... propertyRef) {
for (String ref : propertyRef) {
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
Wed Sep 15 12:32:43 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
Thu Sep 16 08:54:56 2010
@@ -109,7 +109,6 @@
return new SyncResultImpl(jso.getSchema().create(jso), futureId);
}
- private boolean used = false;
private final ValueStoreJsonImpl master;
private final RequestFactoryJsonImpl requestFactory;
@@ -131,10 +130,6 @@
public void addValidation() {
throw new UnsupportedOperationException("Auto-generated method stub");
}
-
- public void clearUsed() {
- used = false;
- }
public Set<SyncResult> commit(JavaScriptObject returnedJso) {
Set<SyncResult> syncResults = new HashSet<SyncResult>();
@@ -225,12 +220,11 @@
}
public boolean isChanged() {
- assert !used;
return !operations.isEmpty();
}
public <V> void set(Property<V> property, EntityProxy record, V value) {
- checkArgumentsAndState(record, "set");
+ checkArgumentsAndState(record);
ProxyImpl recordImpl = (ProxyImpl) record;
EntityProxyId recordKey = recordImpl.stableId();
@@ -281,8 +275,6 @@
}
String toJson() {
- used = true;
-
StringBuffer jsonData = new StringBuffer("{");
for (WriteOperation writeOperation : new WriteOperation[] {
WriteOperation.CREATE, WriteOperation.UPDATE}) {
@@ -315,11 +307,7 @@
return false;
}
- private void checkArgumentsAndState(EntityProxy record, String
methodName) {
- if (used) {
- throw new IllegalStateException(methodName
- + " can only be called on an un-used DeltaValueStore");
- }
+ private void checkArgumentsAndState(EntityProxy record) {
if (!(record instanceof ProxyImpl)) {
throw new IllegalArgumentException(record + " + must be an instance
of "
+ ProxyImpl.class);
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
Wed Sep 15 03:48:29 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
Thu Sep 16 08:54:56 2010
@@ -119,7 +119,8 @@
GWT.getHostPageBaseURL() + RequestFactory.URL);
builder.setHeader("Content-Type",
RequestFactory.JSON_CONTENT_TYPE_UTF8);
builder.setHeader("pageurl", Location.getHref());
-
builder.setRequestData(ClientRequestHelper.getRequestString(requestObject.getRequestData().getRequestMap(
+
+
builder.setRequestData(ClientRequestHelper.getRequestString(((AbstractRequest<?, ?>)
requestObject).getRequestData().getRequestMap(
((AbstractRequest<?, ?>)
requestObject).deltaValueStore.toJson())));
builder.setCallback(new RequestCallback() {
@@ -130,21 +131,23 @@
public void onResponseReceived(Request request, Response response) {
wireLogger.finest("Response received");
- if (200 == response.getStatusCode()) {
- String text = response.getText();
- ((AbstractRequest<?, ?>) requestObject).handleResponseText(text);
- } else if (Response.SC_UNAUTHORIZED == response.getStatusCode()) {
- wireLogger.finest("Need to log in");
- } else if (response.getStatusCode() > 0) {
- // During the redirection for logging in, we get a response with
no
- // status code, but it's not an error, so we only log errors with
- // bad status codes here.
- wireLogger.severe(SERVER_ERROR + " " + response.getStatusCode()
+ " "
- + response.getText());
- }
- postRequestEvent(State.RECEIVED, response);
- }
-
+ try {
+ if (200 == response.getStatusCode()) {
+ String text = response.getText();
+ ((AbstractRequest<?, ?>)
requestObject).handleResponseText(text);
+ } else if (Response.SC_UNAUTHORIZED == response.getStatusCode())
{
+ wireLogger.finest("Need to log in");
+ } else if (response.getStatusCode() > 0) {
+ // During the redirection for logging in, we get a response
with no
+ // status code, but it's not an error, so we only log errors
with
+ // bad status codes here.
+ wireLogger.severe(SERVER_ERROR + " " + response.getStatusCode()
+ + " " + response.getText());
+ }
+ } finally {
+ postRequestEvent(State.RECEIVED, response);
+ }
+ }
});
try {
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
Wed Sep 15 12:32:43 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
Thu Sep 16 08:54:56 2010
@@ -58,9 +58,9 @@
import com.google.gwt.requestfactory.shared.EntityProxyId;
import com.google.gwt.requestfactory.shared.ProxyListRequest;
import com.google.gwt.requestfactory.shared.ProxyRequest;
-import com.google.gwt.requestfactory.shared.RequestData;
import com.google.gwt.requestfactory.shared.RequestFactory;
import com.google.gwt.requestfactory.shared.WriteOperation;
+import com.google.gwt.requestfactory.shared.impl.RequestData;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
Wed Sep 15 12:32:43 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
Thu Sep 16 08:54:56 2010
@@ -18,9 +18,9 @@
import com.google.gwt.requestfactory.shared.EntityProxy;
import com.google.gwt.requestfactory.shared.EntityProxyId;
import com.google.gwt.requestfactory.shared.ProxyFor;
-import com.google.gwt.requestfactory.shared.RequestData;
import com.google.gwt.requestfactory.shared.WriteOperation;
import com.google.gwt.requestfactory.shared.impl.Property;
+import com.google.gwt.requestfactory.shared.impl.RequestData;
import org.json.JSONArray;
import org.json.JSONException;
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
Mon Aug 30 08:52:55 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
Thu Sep 16 08:54:56 2010
@@ -15,8 +15,8 @@
*/
package com.google.gwt.requestfactory.server;
-import com.google.gwt.requestfactory.shared.RequestData;
import com.google.gwt.requestfactory.shared.RequestFactory;
+import com.google.gwt.requestfactory.shared.impl.RequestData;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/RequestObject.java
Thu Sep 16 04:46:26 2010
+++ /trunk/user/src/com/google/gwt/requestfactory/shared/RequestObject.java
Thu Sep 16 08:54:56 2010
@@ -22,30 +22,25 @@
* </span>
* </p>
* Implemented by the request objects created by this factory.
+ *
* @param <T> The return type of objects in the corresponding response.
*/
public interface RequestObject<T> {
/**
- * Enable a RequestObject to be reused again. For example, when the edit
- * fails on the server.
+ * @return an editable version of the given {...@link EntityProxy}
*/
- void clearUsed();
-
- <P extends EntityProxy> P edit(P record);
-
+ <P extends EntityProxy> P edit(P proxy);
+
+ /**
+ * Submit this request. Results will be passed to the receiver
asynchronously.
+ */
void fire(Receiver<T> receiver);
- RequestData getRequestData();
-
/**
* Return true if there are outstanding changes that have not been
* communicated to the server yet. Note that it is illegal to call this
method
* after a request using it has been fired.
*/
boolean isChanged();
-
- // reset the DeltaValueStore.
- void reset();
-
-}
+}
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Thu Sep 16 08:28:57 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Thu Sep 16 08:54:56 2010
@@ -85,6 +85,7 @@
foo);
fooReq.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(final SimpleFooProxy returned,
Set<SyncResult> syncResults) {
Object futureId = foo.getId();
@@ -101,6 +102,7 @@
delayTestFinish(5000);
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResult) {
assertEquals(42, (int) response.getIntId());
@@ -118,6 +120,7 @@
delayTestFinish(5000);
req.simpleFooRequest().findSimpleFooById(999L).with("barField").fire(
new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResult) {
assertEquals(42, (int) response.getIntId());
@@ -133,7 +136,8 @@
/*
* tests that (a) any method can have a side effect that is handled
correctly.
- * (b) instance methods are handled correctly.
+ * (b) instance methods are handled correctly and (c) you don't grow
horns
+ * or anything if you reuse the request object
*/
public void testMethodWithSideEffects() {
delayTestFinish(5000);
@@ -141,6 +145,7 @@
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy newFoo,
Set<SyncResult> syncResults) {
final RequestObject<Long> fooReq =
req.simpleFooRequest().countSimpleFooWithUserNameSideEffect(
@@ -148,6 +153,7 @@
newFoo = fooReq.edit(newFoo);
newFoo.setUserName("Ray");
fooReq.fire(new Receiver<Long>() {
+ @Override
public void onSuccess(Long response, Set<SyncResult>
syncResults) {
assertEquals(new Long(1L), response);
// confirm that there was a sideEffect.
@@ -160,11 +166,37 @@
// sideEffect.
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy finalFoo,
Set<SyncResult> syncResults) {
assertEquals("Ray", finalFoo.getUserName());
finishTestAndReset();
}
+ });
+ }
+ });
+
+ /*
+ * Firing the request a second time just to show that we
+ * can. Note that we *do not* try to change the value,
+ * as we're unclear which response will come back first,
+ * and who should win. That's not the point. The point
+ * is that both callbacks get called.
+ */
+
+ newFoo.setUserName("Barney"); // Just to prove we can, used to
fail assert
+ newFoo.setUserName("Ray"); // Change it back to diminish
chance of flakes
+ fooReq.fire(new Receiver<Long>() {
+ @Override
+ public void onSuccess(Long response, Set<SyncResult>
syncResults) {
+ req.simpleFooRequest().findSimpleFooById(999L).fire(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy finalFoo,
+ Set<SyncResult> syncResults) {
+ assertEquals("Ray", finalFoo.getUserName());
+ finishTestAndReset();
+ }
});
}
});
@@ -181,10 +213,12 @@
req.simpleBarRequest().findSimpleBarById(999L).fire(
new Receiver<SimpleBarProxy>() {
+ @Override
public void onSuccess(final SimpleBarProxy barProxy,
Set<SyncResult> syncResults) {
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy fooProxy,
Set<SyncResult> syncResults) {
RequestObject<Void> updReq =
req.simpleFooRequest().persist(
@@ -192,6 +226,7 @@
fooProxy = updReq.edit(fooProxy);
fooProxy.setBarField(barProxy);
updReq.fire(new Receiver<Void>() {
+ @Override
public void onSuccess(Void response,
Set<SyncResult> syncResults) {
finishTestAndReset();
@@ -218,6 +253,7 @@
final SimpleBarProxy finalNewBar = newBar;
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResults) {
RequestObject<Void> fooReq = req.simpleFooRequest().persist(
@@ -225,9 +261,11 @@
response = fooReq.edit(response);
response.setBarField(finalNewBar);
fooReq.fire(new Receiver<Void>() {
+ @Override
public void onSuccess(Void response, Set<SyncResult>
syncResults) {
req.simpleFooRequest().findSimpleFooById(999L).with(
"barField.userName").fire(new
Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy finalFooProxy,
Set<SyncResult> syncResults) {
// barReq hasn't been persisted, so old value
@@ -259,13 +297,16 @@
final SimpleFooProxy finalFoo = newFoo;
req.simpleBarRequest().findSimpleBarById(999L).fire(
new Receiver<SimpleBarProxy>() {
+ @Override
public void onSuccess(SimpleBarProxy response,
Set<SyncResult> syncResults) {
finalFoo.setBarField(response);
fooReq.fire(new Receiver<Void>() {
+ @Override
public void onSuccess(Void response, Set<SyncResult>
syncResults) {
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy finalFooProxy,
Set<SyncResult> syncResults) {
// newFoo hasn't been persisted, so userName is
the old
@@ -301,9 +342,11 @@
newBar.setUserName("Amit");
fooReq.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(final SimpleFooProxy persistedFoo,
Set<SyncResult> syncResult) {
barReq.fire(new Receiver<SimpleBarProxy>() {
+ @Override
public void onSuccess(final SimpleBarProxy persistedBar,
Set<SyncResult> syncResults) {
assertEquals("Ray", persistedFoo.getUserName());
@@ -312,9 +355,11 @@
SimpleFooProxy editablePersistedFoo =
fooReq2.edit(persistedFoo);
editablePersistedFoo.setBarField(persistedBar);
fooReq2.fire(new Receiver<Void>() {
+ @Override
public void onSuccess(Void response, Set<SyncResult>
syncResults) {
req.simpleFooRequest().findSimpleFooById(999L).with(
"barField.userName").fire(new
Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy finalFooProxy,
Set<SyncResult> syncResults) {
assertEquals("Amit",
@@ -340,6 +385,7 @@
rayFoo.setUserName("Ray");
rayFoo.setFooField(rayFoo);
persistRay.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(final SimpleFooProxy persistedRay,
Set<SyncResult> ignored) {
finishTestAndReset();
@@ -357,6 +403,7 @@
rayFoo.setUserName("Ray");
persistRay.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(final SimpleFooProxy persistedRay,
Set<SyncResult> ignored) {
@@ -367,6 +414,7 @@
amitBar.setUserName("Amit");
persistAmit.fire(new Receiver<SimpleBarProxy>() {
+ @Override
public void onSuccess(SimpleBarProxy persistedAmit,
Set<SyncResult> ignored) {
@@ -376,6 +424,7 @@
newRec.setBarField(persistedAmit);
persistRelationship.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy relatedRay,
Set<SyncResult> ignored) {
assertEquals("Amit",
relatedRay.getBarField().getUserName());
@@ -392,6 +441,7 @@
delayTestFinish(5000);
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResult) {
SimpleBarProxy bar = req.create(SimpleBarProxy.class);
@@ -400,6 +450,7 @@
bar = helloReq.edit(bar);
bar.setUserName("BAR");
helloReq.fire(new Receiver<String>() {
+ @Override
public void onSuccess(String response, Set<SyncResult>
syncResults) {
assertEquals("Greetings BAR from GWT", response);
finishTestAndReset();
@@ -427,6 +478,7 @@
newFoo.setUserName("GWT basic user");
fooReq.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(final SimpleFooProxy returned,
Set<SyncResult> syncResults) {
assertEquals(futureId, foo.getId());
@@ -445,6 +497,7 @@
editableFoo.setUserName("GWT power user");
editRequest.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy returnedAfterEdit,
Set<SyncResult> syncResults) {
checkStableIdEquals(editableFoo, returnedAfterEdit);
@@ -466,6 +519,7 @@
newFoo.setUserName("Amit"); // will not cause violation.
fooReq.fire(new Receiver<Void>() {
+ @Override
public void onSuccess(Void ignore, Set<SyncResult> syncResults) {
assertEquals(1, syncResults.size());
finishTestAndReset();
@@ -496,6 +550,7 @@
newFoo.setUserName("GWT User");
fooReq.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy returned, Set<SyncResult>
syncResults) {
assertEquals(1, syncResults.size());
@@ -520,6 +575,7 @@
newFoo.setUserName("GWT User");
fooReq.fire(new Receiver<SimpleFooProxy>() {
+ @Override
public void onSuccess(SimpleFooProxy returned, Set<SyncResult>
syncResults) {
assertEquals(1, syncResults.size());
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java
Tue Sep 14 17:54:04 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java
Thu Sep 16 08:54:56 2010
@@ -32,8 +32,6 @@
*/
public class DeltaValueStoreJsonImplTest extends GWTTestCase {
- private static final String SIMPLE_FOO_CLASS_NAME
= "com.google.gwt.requestfactory.shared.SimpleFooProxy";
-
/*
* sub-classed it here so that the protected constructor of {...@link
ProxyImpl}
* can remain as such.
@@ -44,6 +42,8 @@
super(proxy, false);
}
}
+
+ private static final String SIMPLE_FOO_CLASS_NAME
= "com.google.gwt.requestfactory.shared.SimpleFooProxy";
ValueStoreJsonImpl valueStore = null;
RequestFactoryJsonImpl requestFactory = null;
@@ -86,22 +86,26 @@
assertFalse(jsonObject.containsKey(WriteOperation.CREATE.getUnObfuscatedEnumName()));
}
- public void testCreateWithSet() {
+ public void testCreateUpdate() {
EntityProxy created = requestFactory.create(SimpleFooProxy.class);
- assertNotNull(created.getId());
- assertNotNull(created.getVersion());
-
DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
valueStore, requestFactory);
// DVS does not know about the created entity.
assertFalse(deltaValueStore.isChanged());
deltaValueStore.set(SimpleFooProxyProperties.userName,
created, "harry");
assertTrue(deltaValueStore.isChanged());
- testAndGetChangeProxy(deltaValueStore.toJson(), WriteOperation.CREATE);
+ JSONObject changeProxy =
testAndGetChangeProxy(deltaValueStore.toJson(),
+ WriteOperation.CREATE);
+ assertEquals(
+ "harry",
+ changeProxy.get("userName").isString().stringValue());
}
- public void testCreateUpdate() {
+ public void testCreateWithSet() {
EntityProxy created = requestFactory.create(SimpleFooProxy.class);
+ assertNotNull(created.getId());
+ assertNotNull(created.getVersion());
+
DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
valueStore, requestFactory);
// DVS does not know about the created entity.
@@ -123,16 +127,6 @@
assertTrue(deltaValueStore.isChanged());
deltaValueStore.toJson();
-
- try {
- deltaValueStore.set(SimpleFooProxyProperties.userName, new
MyProxyImpl(jso),
- "harry");
- fail("Modifying DeltaValueStore after calling toJson should throw a
RuntimeException");
- } catch (RuntimeException ex) {
- // expected.
- }
-
- deltaValueStore.clearUsed();
deltaValueStore.set(SimpleFooProxyProperties.userName, new
MyProxyImpl(jso),
"harry");
}
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
Tue Sep 14 11:13:50 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
Thu Sep 16 08:54:56 2010
@@ -15,11 +15,11 @@
*/
package com.google.gwt.requestfactory.server;
-import com.google.gwt.requestfactory.shared.RequestData;
import com.google.gwt.requestfactory.shared.SimpleBarProxy;
import com.google.gwt.requestfactory.shared.SimpleEnum;
import com.google.gwt.requestfactory.shared.SimpleFooProxy;
import com.google.gwt.requestfactory.shared.WriteOperation;
+import com.google.gwt.requestfactory.shared.impl.RequestData;
import junit.framework.TestCase;
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors