Switch RequestFactory to use the real ConstraintViolation instead of the hacky Violation interface.
Deprecate Violation and Receiver.onViolation().
Patch by: bobv
Review by: rjrjr
Review at http://gwt-code-reviews.appspot.com/1422809
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10053 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
index 6b9073e..7a8893f 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
@@ -40,10 +40,11 @@
import com.google.web.bindery.requestfactory.shared.Receiver;
import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
-import com.google.web.bindery.requestfactory.shared.Violation;
import java.util.Set;
+import javax.validation.ConstraintViolation;
+
/**
* This class shows how the UI for editing a person is wired up to the
* RequestFactoryEditorDelegate. It is also responsible for showing and
@@ -134,16 +135,16 @@
// Send the request
context.fire(new Receiver<Void>() {
@Override
- public void onSuccess(Void response) {
- // If everything went as planned, just dismiss the dialog box
- dialog.hide();
+ public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
+ // Otherwise, show ConstraintViolations in the UI
+ dialog.setText("Errors detected on the server");
+ editorDriver.setConstraintViolations(errors);
}
@Override
- public void onViolation(Set<Violation> errors) {
- // Otherwise, show ConstraintViolations in the UI
- dialog.setText("Errors detected on the server");
- editorDriver.setViolations(errors);
+ public void onSuccess(Void response) {
+ // If everything went as planned, just dismiss the dialog box
+ dialog.hide();
}
});
}
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryEditorDriver.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryEditorDriver.java
index e5535e2..9274f43 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryEditorDriver.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryEditorDriver.java
@@ -20,7 +20,6 @@
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
-import com.google.web.bindery.requestfactory.shared.Violation;
/**
* The interface that links RequestFactory and the Editor framework together.
@@ -47,8 +46,8 @@
* @see com.google.web.bindery.requestfactory.gwt.client.testing.MockRequestFactoryEditorDriver
* MockRequestFactoryEditorDriver
*/
-public interface RequestFactoryEditorDriver<P, E extends Editor<? super P>>
- extends EditorDriver<RequestContext> {
+public interface RequestFactoryEditorDriver<P, E extends Editor<? super P>> extends
+ EditorDriver<RequestContext> {
/**
* Start driving the Editor and its sub-editors with data for display-only
* mode.
@@ -126,9 +125,14 @@
* {@link com.google.gwt.editor.client.EditorError#getUserData()
* getUserData()} method can be used to access the original Violation object.
*
- * @param violations an Iterable over {@link Violation} instances
+ * @param violations an Iterable over
+ * {@link com.google.web.bindery.requestfactory.shared.Violation}
+ * instances
* @return <code>true</code> if there were any unconsumed EditorErrors which
* can be retrieved from {@link #getErrors()}
+ * @deprecated Users should switch to
+ * {@link #setConstraintViolations(Iterable)}
*/
- boolean setViolations(Iterable<Violation> violations);
+ @Deprecated
+ boolean setViolations(Iterable<com.google.web.bindery.requestfactory.shared.Violation> violations);
}
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
index 94f71ba..79a767f 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
@@ -15,8 +15,6 @@
*/
package com.google.web.bindery.requestfactory.gwt.client.impl;
-import com.google.web.bindery.autobean.shared.AutoBean;
-import com.google.web.bindery.autobean.shared.AutoBeanUtils;
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.EditorContext;
import com.google.gwt.editor.client.EditorVisitor;
@@ -25,6 +23,8 @@
import com.google.gwt.editor.client.impl.DelegateMap;
import com.google.gwt.editor.client.impl.DelegateMap.KeyMethod;
import com.google.gwt.editor.client.impl.SimpleViolation;
+import com.google.web.bindery.autobean.shared.AutoBean;
+import com.google.web.bindery.autobean.shared.AutoBeanUtils;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.gwt.client.HasRequestContext;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
@@ -32,7 +32,6 @@
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.ValueProxy;
-import com.google.web.bindery.requestfactory.shared.Violation;
import com.google.web.bindery.requestfactory.shared.impl.Constants;
import java.util.Iterator;
@@ -50,13 +49,14 @@
/**
* Adapts a RequestFactory Violation object to the SimpleViolation interface.
*/
+ @SuppressWarnings("deprecation")
static class SimpleViolationAdapter extends SimpleViolation {
- private final Violation v;
+ private final com.google.web.bindery.requestfactory.shared.Violation v;
/**
* @param v
*/
- private SimpleViolationAdapter(Violation v) {
+ private SimpleViolationAdapter(com.google.web.bindery.requestfactory.shared.Violation v) {
this.v = v;
}
@@ -84,16 +84,17 @@
* Provides a source of SimpleViolation objects based on RequestFactory's
* simplified Violation interface.
*/
+ @SuppressWarnings("deprecation")
static class ViolationIterable implements Iterable<SimpleViolation> {
- private final Iterable<Violation> violations;
+ private final Iterable<com.google.web.bindery.requestfactory.shared.Violation> violations;
- public ViolationIterable(Iterable<Violation> violations) {
+ public ViolationIterable(Iterable<com.google.web.bindery.requestfactory.shared.Violation> violations) {
this.violations = violations;
}
public Iterator<SimpleViolation> iterator() {
- final Iterator<Violation> source = violations.iterator();
+ final Iterator<com.google.web.bindery.requestfactory.shared.Violation> source = violations.iterator();
return new Iterator<SimpleViolation>() {
public boolean hasNext() {
return source.hasNext();
@@ -202,7 +203,8 @@
initialize(requestFactory.getEventBus(), requestFactory, editor);
}
- public boolean setViolations(Iterable<Violation> violations) {
+ @SuppressWarnings("deprecation")
+ public boolean setViolations(Iterable<com.google.web.bindery.requestfactory.shared.Violation> violations) {
return doSetViolations(new ViolationIterable(violations));
}
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/testing/MockRequestFactoryEditorDriver.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/testing/MockRequestFactoryEditorDriver.java
index 5cc2223..e6f06a2 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/testing/MockRequestFactoryEditorDriver.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/testing/MockRequestFactoryEditorDriver.java
@@ -22,7 +22,6 @@
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
-import com.google.web.bindery.requestfactory.shared.Violation;
import java.util.Collections;
import java.util.List;
@@ -166,7 +165,8 @@
/**
* A no-op method that always returns false.
*/
- public boolean setViolations(Iterable<Violation> errors) {
+ @SuppressWarnings("deprecation")
+ public boolean setViolations(Iterable<com.google.web.bindery.requestfactory.shared.Violation> errors) {
return false;
}
}
diff --git a/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java b/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java
index 1395ba8..fc6c173 100644
--- a/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java
+++ b/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java
@@ -60,7 +60,6 @@
import com.google.web.bindery.requestfactory.shared.ServiceLocator;
import com.google.web.bindery.requestfactory.shared.ServiceName;
import com.google.web.bindery.requestfactory.shared.ValueProxy;
-import com.google.web.bindery.requestfactory.shared.Violation;
import com.google.web.bindery.requestfactory.shared.WriteOperation;
import com.google.web.bindery.requestfactory.vm.RequestFactorySource;
@@ -244,8 +243,8 @@
}
@Override
- public void visit(int version, int access, String name, String signature,
- String superName, String[] interfaces) {
+ public void visit(int version, int access, String name, String signature, String superName,
+ String[] interfaces) {
name = processInternalName(sourceType, name);
superName = processInternalName(sourceType, superName);
if (interfaces != null) {
@@ -263,24 +262,22 @@
}
@Override
- public FieldVisitor visitField(int access, String name, String desc,
- String signature, Object value) {
+ public FieldVisitor visitField(int access, String name, String desc, String signature,
+ Object value) {
desc = processDescriptor(sourceType, desc);
- return new FieldProcessor(sourceType, super.visitField(access, name, desc, signature,
- value));
+ return new FieldProcessor(sourceType, super.visitField(access, name, desc, signature, value));
}
@Override
- public void visitInnerClass(String name, String outerName,
- String innerName, int access) {
+ public void visitInnerClass(String name, String outerName, String innerName, int access) {
name = processInternalName(sourceType, name);
outerName = processInternalName(sourceType, outerName);
super.visitInnerClass(name, outerName, innerName, access);
}
@Override
- public MethodVisitor visitMethod(int access, String name, String desc,
- String signature, String[] exceptions) {
+ public MethodVisitor visitMethod(int access, String name, String desc, String signature,
+ String[] exceptions) {
Method method = processMethod(sourceType, name, desc);
desc = method.getDescriptor();
if (exceptions != null) {
@@ -288,8 +285,7 @@
exceptions[i] = processInternalName(sourceType, exceptions[i]);
}
}
- MethodVisitor mv = super.visitMethod(access, name, desc, signature,
- exceptions);
+ MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
if (mv != null) {
mv = new MethodProcessor(sourceType, mv);
}
@@ -342,8 +338,7 @@
String destPath = getPackagePath(state.type) + state.source;
if (sources.add(sourcePath) && loader.exists(sourcePath)) {
String contents = Util.readStreamAsString(loader.getResourceAsStream(sourcePath));
- emitter.emit(destPath,
- new ByteArrayInputStream(Util.getBytes(contents)));
+ emitter.emit(destPath, new ByteArrayInputStream(Util.getBytes(contents)));
}
}
return null;
@@ -375,7 +370,7 @@
private class MethodProcessor extends MethodAdapter {
private final String sourceType;
-
+
public MethodProcessor(String sourceType, MethodVisitor mv) {
super(mv);
this.sourceType = sourceType;
@@ -393,16 +388,14 @@
}
@Override
- public void visitFieldInsn(int opcode, String owner, String name,
- String desc) {
+ public void visitFieldInsn(int opcode, String owner, String name, String desc) {
owner = processInternalName(sourceType, owner);
desc = processDescriptor(sourceType, desc);
super.visitFieldInsn(opcode, owner, name, desc);
}
@Override
- public void visitFrame(int type, int nLocal, Object[] local, int nStack,
- Object[] stack) {
+ public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) {
for (int i = 0, j = local.length; i < j; i++) {
if (local[i] instanceof String) {
local[i] = processInternalName(sourceType, (String) local[i]);
@@ -423,15 +416,14 @@
}
@Override
- public void visitLocalVariable(String name, String desc, String signature,
- Label start, Label end, int index) {
+ public void visitLocalVariable(String name, String desc, String signature, Label start,
+ Label end, int index) {
desc = processDescriptor(sourceType, desc);
super.visitLocalVariable(name, desc, signature, start, end, index);
}
@Override
- public void visitMethodInsn(int opcode, String owner, String name,
- String desc) {
+ public void visitMethodInsn(int opcode, String owner, String name, String desc) {
owner = processInternalName(sourceType, owner);
desc = processMethod(sourceType, name, desc).getDescriptor();
super.visitMethodInsn(opcode, owner, name, desc);
@@ -444,15 +436,13 @@
}
@Override
- public AnnotationVisitor visitParameterAnnotation(int parameter,
- String desc, boolean visible) {
+ public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) {
desc = processDescriptor(sourceType, desc);
return super.visitParameterAnnotation(parameter, desc, visible);
}
@Override
- public void visitTryCatchBlock(Label start, Label end, Label handler,
- String type) {
+ public void visitTryCatchBlock(Label start, Label end, Label handler, String type) {
type = processInternalName(sourceType, type);
super.visitTryCatchBlock(start, end, handler, type);
}
@@ -475,11 +465,11 @@
}
@Override
- public MethodVisitor visitMethod(int access, String name, String desc,
- String signature, String[] exceptions) {
+ public MethodVisitor visitMethod(int access, String name, String desc, String signature,
+ String[] exceptions) {
if ((access & Opcodes.ACC_NATIVE) != 0) {
- MethodVisitor mv = super.visitMethod(access & ~Opcodes.ACC_NATIVE,
- name, desc, signature, exceptions);
+ MethodVisitor mv =
+ super.visitMethod(access & ~Opcodes.ACC_NATIVE, name, desc, signature, exceptions);
if (mv != null) {
mv.visitCode();
String exceptionName = Type.getInternalName(RuntimeException.class);
@@ -495,7 +485,8 @@
// obj
mv.visitInsn(Opcodes.ATHROW);
- // Count argument slots - long and double arguments each take up 2 slots
+ // Count argument slots - long and double arguments each take up 2
+ // slots
int numSlots = 0;
for (Type t : Type.getArgumentTypes(desc)) {
numSlots += t.getSize();
@@ -534,11 +525,9 @@
ClassVisitor cv = writer;
cv = new ClassProcessor(typeName, cv, state);
cv = new NativeMethodDefanger(cv);
- visit(logger.setType(state.type), loader, state.type.getInternalName(),
- cv);
+ visit(logger.setType(state.type), loader, state.type.getInternalName(), cv);
state.contents = new ByteArrayInputStream(writer.toByteArray());
- assert seen.containsKey(state.originalType) : "No type for "
- + state.type.getClassName();
+ assert seen.containsKey(state.originalType) : "No type for " + state.type.getClassName();
state.type = seen.get(state.originalType);
emit(state);
@@ -600,7 +589,8 @@
/**
* A map of target names to the types that target should use as a base.
*/
- private static final Map<String, List<Class<?>>> SEEDS = new LinkedHashMap<String, List<Class<?>>>();
+ private static final Map<String, List<Class<?>>> SEEDS =
+ new LinkedHashMap<String, List<Class<?>>>();
/**
* Server public API classes and interfaces.
@@ -608,21 +598,21 @@
private static final Class<?>[] SERVER_CLASSES = {
DefaultExceptionHandler.class, ExceptionHandler.class, Logging.class, LoggingRequest.class,
RequestFactoryServlet.class, ServiceLayer.class, ServiceLayerDecorator.class,
- SimpleRequestProcessor.class
- };
+ SimpleRequestProcessor.class};
/**
* Shared public API classes and interfaces.
*/
+ @SuppressWarnings("deprecation")
private static final Class<?>[] SHARED_CLASSES = {
BaseProxy.class, DefaultProxyStore.class, EntityProxy.class, EntityProxyChange.class,
EntityProxyId.class, InstanceRequest.class, JsonRpcContent.class, JsonRpcProxy.class,
JsonRpcService.class, JsonRpcWireName.class, Locator.class, ProxyFor.class,
ProxyForName.class, ProxySerializer.class, ProxyStore.class, Receiver.class, Request.class,
RequestContext.class, RequestFactory.class, RequestTransport.class, ServerFailure.class,
- Service.class, ServiceLocator.class, ServiceName.class, ValueProxy.class, Violation.class,
- WriteOperation.class, RequestFactorySource.class, SimpleEventBus.class
- };
+ Service.class, ServiceLocator.class, ServiceName.class, ValueProxy.class,
+ com.google.web.bindery.requestfactory.shared.Violation.class, WriteOperation.class,
+ RequestFactorySource.class, SimpleEventBus.class};
/**
* Maximum number of threads to use to run the Extractor.
@@ -658,11 +648,9 @@
* lookup, since the gwt-user code is compiled separately from its tests.
*/
try {
- SEEDS.put(
- "test" + CODE_AND_SOURCE,
- Collections.unmodifiableList(Arrays.<Class<?>> asList(
- Class.forName("com.google.web.bindery.requestfactory.vm.RequestFactoryJreSuite"),
- Class.forName("com.google.web.bindery.requestfactory.server.SimpleBar"))));
+ SEEDS.put("test" + CODE_AND_SOURCE, Collections.unmodifiableList(Arrays.<Class<?>> asList(
+ Class.forName("com.google.web.bindery.requestfactory.vm.RequestFactoryJreSuite"), Class
+ .forName("com.google.web.bindery.requestfactory.server.SimpleBar"))));
} catch (ClassNotFoundException ignored) {
}
}
@@ -670,8 +658,7 @@
public static void main(String[] args) throws IOException {
if (args.length < 2) {
System.err.println("Usage: java -cp gwt-dev.jar:gwt-user.jar:json.jar"
- + RequestFactoryJarExtractor.class.getCanonicalName()
- + " <target-name> outfile.jar");
+ + RequestFactoryJarExtractor.class.getCanonicalName() + " <target-name> outfile.jar");
System.err.println("Valid targets:");
for (String target : SEEDS.keySet()) {
System.err.println(" " + target);
@@ -686,11 +673,11 @@
}
Mode mode = Mode.match(target);
Logger errorContext = Logger.getLogger(RequestFactoryJarExtractor.class.getName());
- ClassLoaderLoader classLoader = new ClassLoaderLoader(
- Thread.currentThread().getContextClassLoader());
+ ClassLoaderLoader classLoader =
+ new ClassLoaderLoader(Thread.currentThread().getContextClassLoader());
JarEmitter jarEmitter = new JarEmitter(new File(args[1]));
- RequestFactoryJarExtractor extractor = new RequestFactoryJarExtractor(
- errorContext, classLoader, jarEmitter, seeds, mode);
+ RequestFactoryJarExtractor extractor =
+ new RequestFactoryJarExtractor(errorContext, classLoader, jarEmitter, seeds, mode);
extractor.run();
System.exit(extractor.isExecutionFailed() ? 1 : 0);
}
@@ -709,8 +696,8 @@
*
* @return <code>true</code> if the visitor was successfully visited
*/
- private static boolean visit(ErrorContext logger, Loader loader,
- String internalName, ClassVisitor visitor) {
+ private static boolean visit(ErrorContext logger, Loader loader, String internalName,
+ ClassVisitor visitor) {
assert Name.isInternalName(internalName) : "internalName";
logger.spam("Visiting " + internalName);
InputStream inputStream = null;
@@ -749,8 +736,8 @@
private final Set<String> sources = new ConcurrentSkipListSet<String>();
private final ExecutorService writerService;
- public RequestFactoryJarExtractor(Logger logger, Loader loader,
- Emitter emitter, List<Class<?>> seeds, Mode mode) {
+ public RequestFactoryJarExtractor(Logger logger, Loader loader, Emitter emitter,
+ List<Class<?>> seeds, Mode mode) {
this.logger = new ErrorContext(logger);
this.loader = loader;
this.emitter = emitter;
@@ -835,13 +822,13 @@
for (int i = 0, j = argumentTypes.length; i < j; i++) {
argumentTypes[i] = processType(sourceType, argumentTypes[i]);
}
- method = new Method(name, processType(sourceType, method.getReturnType()),
- argumentTypes);
+ method = new Method(name, processType(sourceType, method.getReturnType()), argumentTypes);
return method;
}
/**
* Process a type, possibly returning a rebased type.
+ *
* @param sourceType TODO
*/
private Type processType(String sourceType, Type type) {
@@ -863,8 +850,7 @@
return toReturn;
}
assert type.getInternalName().charAt(0) != 'L';
- if (type.getInternalName().startsWith("java/")
- || type.getInternalName().startsWith("javax/")) {
+ if (type.getInternalName().startsWith("java/") || type.getInternalName().startsWith("javax/")) {
return toReturn;
}
if (VERBOSE) {
diff --git a/user/src/com/google/web/bindery/requestfactory/server/SimpleRequestProcessor.java b/user/src/com/google/web/bindery/requestfactory/server/SimpleRequestProcessor.java
index a763dbb..d998dbe 100644
--- a/user/src/com/google/web/bindery/requestfactory/server/SimpleRequestProcessor.java
+++ b/user/src/com/google/web/bindery/requestfactory/server/SimpleRequestProcessor.java
@@ -37,6 +37,7 @@
import com.google.web.bindery.requestfactory.shared.impl.EntityProxyCategory;
import com.google.web.bindery.requestfactory.shared.impl.SimpleProxyId;
import com.google.web.bindery.requestfactory.shared.impl.ValueProxyCategory;
+import com.google.web.bindery.requestfactory.shared.messages.IdMessage;
import com.google.web.bindery.requestfactory.shared.messages.IdMessage.Strength;
import com.google.web.bindery.requestfactory.shared.messages.InvocationMessage;
import com.google.web.bindery.requestfactory.shared.messages.MessageFactory;
@@ -71,8 +72,7 @@
* specific type.
*/
@SuppressWarnings("serial")
- static class IdToEntityMap extends
- HashMap<SimpleProxyId<?>, AutoBean<? extends BaseProxy>> {
+ static class IdToEntityMap extends HashMap<SimpleProxyId<?>, AutoBean<? extends BaseProxy>> {
}
/**
@@ -80,8 +80,8 @@
* create an AutoBeanFactory with the desired annotations.
*/
static final Configuration CONFIGURATION = new Configuration.Builder().setCategories(
- EntityProxyCategory.class, ValueProxyCategory.class,
- BaseProxyCategory.class).setNoWrap(EntityProxyId.class).build();
+ EntityProxyCategory.class, ValueProxyCategory.class, BaseProxyCategory.class).setNoWrap(
+ EntityProxyId.class).build();
/**
* Vends message objects.
@@ -118,8 +118,7 @@
* @return a payload to return to the client
*/
public String process(String payload) {
- RequestMessage req = AutoBeanCodex.decode(FACTORY, RequestMessage.class,
- payload).as();
+ RequestMessage req = AutoBeanCodex.decode(FACTORY, RequestMessage.class, payload).as();
AutoBean<ResponseMessage> responseBean = FACTORY.response();
try {
process(req, responseBean.as());
@@ -144,17 +143,17 @@
<T> Splittable createOobMessage(List<T> domainValues) {
RequestState state = new RequestState(service);
- List<Splittable> encodedValues = new ArrayList<Splittable>(
- domainValues.size());
+ List<Splittable> encodedValues = new ArrayList<Splittable>(domainValues.size());
for (T domainValue : domainValues) {
Object clientValue;
if (domainValue == null) {
clientValue = null;
} else {
- Class<?> clientType = service.resolveClientType(domainValue.getClass(),
- BaseProxy.class, true);
- clientValue = state.getResolver().resolveClientValue(domainValue,
- clientType, Collections.<String> emptySet());
+ Class<?> clientType =
+ service.resolveClientType(domainValue.getClass(), BaseProxy.class, true);
+ clientValue =
+ state.getResolver().resolveClientValue(domainValue, clientType,
+ Collections.<String> emptySet());
}
encodedValues.add(EntityCodex.encode(state, clientValue));
}
@@ -178,15 +177,13 @@
* Decode an out-of-band message.
*/
<T> List<T> decodeOobMessage(Class<T> domainClass, Splittable payload) {
- Class<?> proxyType = service.resolveClientType(domainClass,
- BaseProxy.class, true);
+ Class<?> proxyType = service.resolveClientType(domainClass, BaseProxy.class, true);
RequestState state = new RequestState(service);
- RequestMessage message = AutoBeanCodex.decode(FACTORY,
- RequestMessage.class, payload).as();
+ RequestMessage message = AutoBeanCodex.decode(FACTORY, RequestMessage.class, payload).as();
processOperationMessages(state, message);
- List<Object> decoded = decodeInvocationArguments(state,
- message.getInvocations().get(0).getParameters(),
- new Class<?>[] {proxyType}, new Type[] {domainClass});
+ List<Object> decoded =
+ decodeInvocationArguments(state, message.getInvocations().get(0).getParameters(),
+ new Class<?>[] {proxyType}, new Type[] {domainClass});
@SuppressWarnings("unchecked")
List<T> toReturn = (List<T>) decoded;
@@ -214,8 +211,7 @@
// Invoke methods
List<Splittable> invocationResults = new ArrayList<Splittable>();
List<Boolean> invocationSuccess = new ArrayList<Boolean>();
- processInvocationMessages(source, req, invocationResults,
- invocationSuccess, returnState);
+ processInvocationMessages(source, req, invocationResults, invocationSuccess, returnState);
// Store return objects
List<OperationMessage> operations = new ArrayList<OperationMessage>();
@@ -234,10 +230,9 @@
}
}
- private AutoBean<ServerFailureMessage> createFailureMessage(
- ReportableException e) {
- ServerFailure failure = exceptionHandler.createServerFailure(e.getCause() == null
- ? e : e.getCause());
+ private AutoBean<ServerFailureMessage> createFailureMessage(ReportableException e) {
+ ServerFailure failure =
+ exceptionHandler.createServerFailure(e.getCause() == null ? e : e.getCause());
AutoBean<ServerFailureMessage> bean = FACTORY.failure();
ServerFailureMessage msg = bean.as();
msg.setExceptionType(failure.getExceptionType());
@@ -247,8 +242,8 @@
return bean;
}
- private void createReturnOperations(List<OperationMessage> operations,
- RequestState returnState, IdToEntityMap toProcess) {
+ private void createReturnOperations(List<OperationMessage> operations, RequestState returnState,
+ IdToEntityMap toProcess) {
for (Map.Entry<SimpleProxyId<?>, AutoBean<? extends BaseProxy>> entry : toProcess.entrySet()) {
SimpleProxyId<?> id = entry.getKey();
@@ -258,8 +253,8 @@
if (id.isEphemeral()) {
// See if the entity has been persisted in the meantime
- returnState.getResolver().resolveClientValue(domainObject,
- id.getProxyClass(), Collections.<String> emptySet());
+ returnState.getResolver().resolveClientValue(domainObject, id.getProxyClass(),
+ Collections.<String> emptySet());
}
if (id.isEphemeral() || id.isSynthetic() || domainObject == null) {
@@ -274,8 +269,7 @@
}
Splittable version = null;
- if (writeOperation == WriteOperation.PERSIST
- || writeOperation == WriteOperation.UPDATE) {
+ if (writeOperation == WriteOperation.PERSIST || writeOperation == WriteOperation.UPDATE) {
/*
* If we're sending an operation, the domain object must be persistent.
* This means that it must also have a non-null version.
@@ -354,8 +348,8 @@
* Decode the arguments to pass into the domain method. If the domain method
* is not static, the instance object will be in the 0th position.
*/
- private List<Object> decodeInvocationArguments(RequestState source,
- InvocationMessage invocation, Method contextMethod) {
+ private List<Object> decodeInvocationArguments(RequestState source, InvocationMessage invocation,
+ Method contextMethod) {
boolean isStatic = Request.class.isAssignableFrom(contextMethod.getReturnType());
int baseLength = contextMethod.getParameterTypes().length;
int length = baseLength + (isStatic ? 0 : 1);
@@ -364,25 +358,24 @@
Type[] genericArgs = new Type[length];
if (!isStatic) {
- genericArgs[0] = TypeUtils.getSingleParameterization(
- InstanceRequest.class, contextMethod.getGenericReturnType());
+ genericArgs[0] =
+ TypeUtils.getSingleParameterization(InstanceRequest.class, contextMethod
+ .getGenericReturnType());
contextArgs[0] = TypeUtils.ensureBaseType(genericArgs[0]);
}
- System.arraycopy(contextMethod.getParameterTypes(), 0, contextArgs, offset,
- baseLength);
- System.arraycopy(contextMethod.getGenericParameterTypes(), 0, genericArgs,
- offset, baseLength);
+ System.arraycopy(contextMethod.getParameterTypes(), 0, contextArgs, offset, baseLength);
+ System.arraycopy(contextMethod.getGenericParameterTypes(), 0, genericArgs, offset, baseLength);
- List<Object> args = decodeInvocationArguments(source,
- invocation.getParameters(), contextArgs, genericArgs);
+ List<Object> args =
+ decodeInvocationArguments(source, invocation.getParameters(), contextArgs, genericArgs);
return args;
}
/**
* Handles instance invocations as the instance at the 0th parameter.
*/
- private List<Object> decodeInvocationArguments(RequestState source,
- List<Splittable> parameters, Class<?>[] contextArgs, Type[] genericArgs) {
+ private List<Object> decodeInvocationArguments(RequestState source, List<Splittable> parameters,
+ Class<?>[] contextArgs, Type[] genericArgs) {
if (parameters == null) {
// Can't return Collections.emptyList() because this must be mutable
return new ArrayList<Object>();
@@ -395,24 +388,24 @@
Class<?> elementType = null;
Splittable split;
if (Collection.class.isAssignableFrom(type)) {
- elementType = TypeUtils.ensureBaseType(TypeUtils.getSingleParameterization(
- Collection.class, genericArgs[i]));
+ elementType =
+ TypeUtils.ensureBaseType(TypeUtils.getSingleParameterization(Collection.class,
+ genericArgs[i]));
split = parameters.get(i);
} else {
split = parameters.get(i);
}
Object arg = EntityCodex.decode(source, type, elementType, split);
- arg = source.getResolver().resolveDomainValue(arg,
- !EntityProxyId.class.equals(contextArgs[i]));
+ arg =
+ source.getResolver().resolveDomainValue(arg, !EntityProxyId.class.equals(contextArgs[i]));
args.add(arg);
}
return args;
}
- private void processInvocationMessages(RequestState state,
- RequestMessage req, List<Splittable> results, List<Boolean> success,
- RequestState returnState) {
+ private void processInvocationMessages(RequestState state, RequestMessage req,
+ List<Splittable> results, List<Boolean> success, RequestState returnState) {
List<InvocationMessage> invocations = req.getInvocations();
if (invocations == null) {
// No method invocations which can happen via RequestContext.fire()
@@ -422,25 +415,22 @@
try {
// Find the Method
String[] operation = invocation.getOperation().split("::");
- Method contextMethod = service.resolveRequestContextMethod(
- operation[0], operation[1]);
+ Method contextMethod = service.resolveRequestContextMethod(operation[0], operation[1]);
if (contextMethod == null) {
- throw new UnexpectedException("Cannot resolve operation "
- + invocation.getOperation(), null);
+ throw new UnexpectedException("Cannot resolve operation " + invocation.getOperation(),
+ null);
}
Method domainMethod = service.resolveDomainMethod(contextMethod);
if (domainMethod == null) {
- throw new UnexpectedException("Cannot resolve domain method "
- + invocation.getOperation(), null);
+ throw new UnexpectedException(
+ "Cannot resolve domain method " + invocation.getOperation(), null);
}
// Compute the arguments
- List<Object> args = decodeInvocationArguments(state, invocation,
- contextMethod);
+ List<Object> args = decodeInvocationArguments(state, invocation, contextMethod);
// Possibly use a ServiceLocator
if (service.requiresServiceLocator(contextMethod, domainMethod)) {
- Object serviceInstance = service.createServiceInstance(contextMethod,
- domainMethod);
+ Object serviceInstance = service.createServiceInstance(contextMethod, domainMethod);
args.add(0, serviceInstance);
}
// Invoke it
@@ -448,8 +438,9 @@
// Convert domain object to client object
Type requestReturnType = service.getRequestReturnType(contextMethod);
- returnValue = state.getResolver().resolveClientValue(returnValue,
- requestReturnType, invocation.getPropertyRefs());
+ returnValue =
+ state.getResolver().resolveClientValue(returnValue, requestReturnType,
+ invocation.getPropertyRefs());
// Convert the client object to a string
results.add(EntityCodex.encode(returnState, returnValue));
@@ -461,8 +452,7 @@
}
}
- private void processOperationMessages(final RequestState state,
- RequestMessage req) {
+ private void processOperationMessages(final RequestState state, RequestMessage req) {
List<OperationMessage> operations = req.getOperations();
if (operations == null) {
return;
@@ -485,16 +475,17 @@
if (flatValueMap != null) {
bean.accept(new AutoBeanVisitor() {
@Override
- public boolean visitReferenceProperty(String propertyName,
- AutoBean<?> value, PropertyContext ctx) {
+ public boolean visitReferenceProperty(String propertyName, AutoBean<?> value,
+ PropertyContext ctx) {
// containsKey to distinguish null from unknown
if (flatValueMap.containsKey(propertyName)) {
- Class<?> elementType = ctx instanceof CollectionPropertyContext
- ? ((CollectionPropertyContext) ctx).getElementType() : null;
- Object newValue = EntityCodex.decode(state, ctx.getType(),
- elementType, flatValueMap.get(propertyName));
- Object resolved = state.getResolver().resolveDomainValue(
- newValue, false);
+ Class<?> elementType =
+ ctx instanceof CollectionPropertyContext ? ((CollectionPropertyContext) ctx)
+ .getElementType() : null;
+ Object newValue =
+ EntityCodex.decode(state, ctx.getType(), elementType, flatValueMap
+ .get(propertyName));
+ Object resolved = state.getResolver().resolveDomainValue(newValue, false);
service.setProperty(domain, propertyName,
service.resolveDomainClass(ctx.getType()), resolved);
}
@@ -502,15 +493,12 @@
}
@Override
- public boolean visitValueProperty(String propertyName,
- Object value, PropertyContext ctx) {
+ public boolean visitValueProperty(String propertyName, Object value, PropertyContext ctx) {
if (flatValueMap.containsKey(propertyName)) {
Splittable split = flatValueMap.get(propertyName);
Object newValue = ValueCodex.decode(ctx.getType(), split);
- Object resolved = state.getResolver().resolveDomainValue(
- newValue, false);
- service.setProperty(domain, propertyName, ctx.getType(),
- resolved);
+ Object resolved = state.getResolver().resolveDomainValue(newValue, false);
+ service.setProperty(domain, propertyName, ctx.getType(), resolved);
}
return false;
}
@@ -535,17 +523,38 @@
if (errors != null && !errors.isEmpty()) {
SimpleProxyId<?> id = entry.getKey();
for (ConstraintViolation<Object> error : errors) {
- ViolationMessage message = FACTORY.violation().as();
- message.setClientId(id.getClientId());
- message.setMessage(error.getMessage());
- message.setPath(error.getPropertyPath().toString());
+ // Construct an ID that represents domainObject
+ IdMessage rootId = FACTORY.id().as();
+ rootId.setClientId(id.getClientId());
+ rootId.setTypeToken(service.resolveTypeToken(id.getProxyClass()));
if (id.isEphemeral()) {
- message.setClientId(id.getClientId());
- message.setStrength(Strength.EPHEMERAL);
+ rootId.setStrength(Strength.EPHEMERAL);
} else {
- message.setServerId(toBase64(id.getServerId()));
+ rootId.setServerId(toBase64(id.getServerId()));
}
- message.setTypeToken(service.resolveTypeToken(id.getProxyClass()));
+
+ // If possible, also include the id of the leaf bean
+ IdMessage leafId = null;
+ if (error.getLeafBean() != null) {
+ SimpleProxyId<?> stableId = source.getStableId(error.getLeafBean());
+ if (stableId != null) {
+ leafId = FACTORY.id().as();
+ leafId.setClientId(stableId.getClientId());
+ leafId.setTypeToken(service.resolveTypeToken(stableId.getProxyClass()));
+ if (stableId.isEphemeral()) {
+ leafId.setStrength(Strength.EPHEMERAL);
+ } else {
+ leafId.setServerId(toBase64(stableId.getServerId()));
+ }
+ }
+ }
+
+ ViolationMessage message = FACTORY.violation().as();
+ message.setLeafBeanId(leafId);
+ message.setMessage(error.getMessage());
+ message.setMessageTemplate(error.getMessageTemplate());
+ message.setPath(error.getPropertyPath().toString());
+ message.setRootBeanId(rootId);
errorMessages.add(message);
}
}
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/Receiver.java b/user/src/com/google/web/bindery/requestfactory/shared/Receiver.java
index 1bd6fed..0077afd 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/Receiver.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/Receiver.java
@@ -15,8 +15,16 @@
*/
package com.google.web.bindery.requestfactory.shared;
+import com.google.web.bindery.autobean.shared.AutoBean;
+import com.google.web.bindery.autobean.shared.AutoBeanUtils;
+import com.google.web.bindery.requestfactory.shared.impl.Constants;
+
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Set;
+import javax.validation.ConstraintViolation;
+
/**
* Callback object for {@link Request#fire(Receiver)} and
* {@link RequestContext#fire(Receiver)}.
@@ -50,11 +58,52 @@
* </code> is not empty.
*
* @param errors a Set of {@link Violation} instances
+ * @deprecated Use {@link #onConstraintViolation(Set)} instead
*/
+ @Deprecated
public void onViolation(Set<Violation> errors) {
if (!errors.isEmpty()) {
- onFailure(new ServerFailure(
- "The call failed on the server due to a ConstraintViolation"));
+ onFailure(new ServerFailure("The call failed on the server due to a ConstraintViolation"));
}
}
+
+ /**
+ * Called if an object sent to the server could not be validated. The default
+ * implementation calls {@link #onViolation(Set)}, converting the
+ * {@link ConstraintViolation} objects to the deprecated {@link Violation}
+ * type.
+ *
+ * @param errors a Set of {@link ConstraintViolation} instances
+ */
+ @SuppressWarnings("deprecation")
+ public void onConstraintViolation(Set<ConstraintViolation<?>> violations) {
+ Set<Violation> converted = new HashSet<Violation>();
+ for (final ConstraintViolation<?> v : violations) {
+ converted.add(new Violation() {
+ public BaseProxy getInvalidProxy() {
+ return (BaseProxy) v.getRootBean();
+ }
+
+ public String getMessage() {
+ return v.getMessage();
+ }
+
+ public BaseProxy getOriginalProxy() {
+ AutoBean<? extends BaseProxy> parent =
+ AutoBeanUtils.getAutoBean(v.getRootBean()).getTag(Constants.PARENT_OBJECT);
+ return parent == null ? null : parent.as();
+ }
+
+ public String getPath() {
+ return v.getPropertyPath().toString();
+ }
+
+ public EntityProxyId<?> getProxyId() {
+ return v.getRootBean() instanceof EntityProxy ? ((EntityProxy) v.getRootBean())
+ .stableId() : null;
+ }
+ });
+ }
+ onViolation(Collections.unmodifiableSet(converted));
+ }
}
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/Violation.java b/user/src/com/google/web/bindery/requestfactory/shared/Violation.java
index 3d68373..75869e7 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/Violation.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/Violation.java
@@ -18,7 +18,14 @@
/**
* A lightweight representation of a
* {@link javax.validation.ConstraintViolation}.
+ *
+ * @deprecated users should upgrade to the full
+ * {@link javax.validation.ConstraintViolation} type by switching
+ * their {@link Receiver} implementations to use
+ * {@link Receiver#onConstraintViolation(java.util.Set)} instead of
+ * {@link Receiver#onViolation(java.util.Set)}.
*/
+@Deprecated
public interface Violation {
/**
* If the ConstraintViolation occurred while validating a object, this method
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequest.java b/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequest.java
index f7faed5..0a83bdc 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequest.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequest.java
@@ -22,13 +22,14 @@
import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.ServerFailure;
-import com.google.web.bindery.requestfactory.shared.Violation;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import javax.validation.ConstraintViolation;
+
/**
* Abstract implementation of {@link Request}. Each request stores a
* {@link DeltaValueStoreJsonImpl}.
@@ -124,10 +125,10 @@
}
}
- void onViolation(Set<Violation> errors) {
+ void onViolation(Set<ConstraintViolation<?>> errors) {
// The user may not have called to()
if (receiver != null) {
- receiver.onViolation(errors);
+ receiver.onConstraintViolation(errors);
}
}
}
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 5e2a151..70129c5 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
@@ -33,12 +33,10 @@
import com.google.web.bindery.requestfactory.shared.BaseProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxyChange;
-import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.Receiver;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestTransport.TransportReceiver;
import com.google.web.bindery.requestfactory.shared.ServerFailure;
-import com.google.web.bindery.requestfactory.shared.Violation;
import com.google.web.bindery.requestfactory.shared.WriteOperation;
import com.google.web.bindery.requestfactory.shared.impl.posers.DatePoser;
import com.google.web.bindery.requestfactory.shared.messages.IdMessage;
@@ -58,11 +56,16 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Path;
+import javax.validation.metadata.ConstraintDescriptor;
+
/**
* Base implementations for RequestContext services.
*/
@@ -303,9 +306,9 @@
// Process violations and then stop
if (response.getViolations() != null) {
- Set<Violation> errors = new HashSet<Violation>();
+ Set<ConstraintViolation<?>> errors = new HashSet<ConstraintViolation<?>>();
for (ViolationMessage message : response.getViolations()) {
- errors.add(new MyViolation(message));
+ errors.add(new MyConstraintViolation(message));
}
violation(receiver, errors);
@@ -358,54 +361,76 @@
}
}
- private class MyViolation implements Violation {
-
- private final BaseProxy currentProxy;
- private final EntityProxyId<?> id;
+ private class MyConstraintViolation implements ConstraintViolation<BaseProxy> {
+ private final BaseProxy leafBean;
+ private final String messageTemplate;
private final String message;
private final String path;
- private final BaseProxy parentProxy;
+ private final BaseProxy rootBean;
+ private final Class<? extends BaseProxy> rootBeanClass;
- public MyViolation(ViolationMessage message) {
- // Support violations for value objects.
- SimpleProxyId<BaseProxy> baseId = getId(message);
- if (baseId instanceof EntityProxyId<?>) {
- id = (EntityProxyId<?>) baseId;
- } else {
- id = null;
- }
- // The stub is empty, since we don't process any OperationMessages
- AutoBean<BaseProxy> stub = getProxyForReturnPayloadGraph(baseId);
-
- // So pick up the instance that we just sent to the server
- AutoBean<?> edited = state.editedProxies.get(BaseProxyCategory.stableId(stub));
- currentProxy = (BaseProxy) edited.as();
-
- // Try to find the original, immutable version.
- AutoBean<BaseProxy> parentBean = edited.getTag(Constants.PARENT_OBJECT);
- parentProxy = parentBean == null ? null : parentBean.as();
- path = message.getPath();
- this.message = message.getMessage();
+ public MyConstraintViolation(ViolationMessage msg) {
+ AutoBean<? extends BaseProxy> leafProxy = findEditedProxy(msg.getLeafBeanId());
+ leafBean = leafProxy == null ? null : leafProxy.as();
+ message = msg.getMessage();
+ messageTemplate = msg.getMessageTemplate();
+ path = msg.getPath();
+ AutoBean<? extends BaseProxy> rootProxy = findEditedProxy(msg.getRootBeanId());
+ rootBeanClass = rootProxy.getType();
+ rootBean = rootProxy.as();
}
- public BaseProxy getInvalidProxy() {
- return currentProxy;
+ public ConstraintDescriptor<?> getConstraintDescriptor() {
+ return null;
+ }
+
+ public Object getInvalidValue() {
+ return null;
+ }
+
+ public Object getLeafBean() {
+ return leafBean;
}
public String getMessage() {
return message;
}
- public BaseProxy getOriginalProxy() {
- return parentProxy;
+ public String getMessageTemplate() {
+ return messageTemplate;
}
- public String getPath() {
- return path;
+ public Path getPropertyPath() {
+ return new Path() {
+ public Iterator<Node> iterator() {
+ return Collections.<Node> emptyList().iterator();
+ }
+
+ @Override
+ public String toString() {
+ return path;
+ }
+ };
}
- public EntityProxyId<?> getProxyId() {
- return id;
+ public BaseProxy getRootBean() {
+ return rootBean;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Class<BaseProxy> getRootBeanClass() {
+ return (Class<BaseProxy>) rootBeanClass;
+ }
+
+ private AutoBean<? extends BaseProxy> findEditedProxy(IdMessage idMessage) {
+ // Support violations for value objects.
+ SimpleProxyId<BaseProxy> rootId = getId(idMessage);
+
+ // The stub is empty, since we don't process any OperationMessages
+ AutoBean<BaseProxy> stub = getProxyForReturnPayloadGraph(rootId);
+
+ // So pick up the instance that we just sent to the server
+ return state.editedProxies.get(BaseProxyCategory.stableId(stub));
}
}
@@ -643,7 +668,7 @@
* Invoke the appropriate {@code onViolation} callbacks, possibly throwing an
* {@link UmbrellaException} if one or more callbacks fails.
*/
- protected void violation(final Receiver<Void> receiver, Set<Violation> errors) {
+ protected void violation(final Receiver<Void> receiver, Set<ConstraintViolation<?>> errors) {
reuse();
Set<Throwable> causes = null;
for (AbstractRequest<?> request : new ArrayList<AbstractRequest<?>>(state.invocations)) {
@@ -658,7 +683,7 @@
}
if (receiver != null) {
try {
- receiver.onViolation(errors);
+ receiver.onConstraintViolation(errors);
} catch (Throwable t) {
if (causes == null) {
causes = new HashSet<Throwable>();
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/messages/ViolationMessage.java b/user/src/com/google/web/bindery/requestfactory/shared/messages/ViolationMessage.java
index 5b7725f..1736aac 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/messages/ViolationMessage.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/messages/ViolationMessage.java
@@ -20,19 +20,40 @@
/**
* Represents a ConstraintViolation.
*/
-public interface ViolationMessage extends IdMessage {
+public interface ViolationMessage {
+ String LEAF = "L";
String MESSAGE = "M";
String PATH = "P";
+ String ROOT = "R";
+ String TEMPLATE = "T";
+
+ @PropertyName(LEAF)
+ IdMessage getLeafBeanId();
@PropertyName(MESSAGE)
String getMessage();
+ @PropertyName(TEMPLATE)
+ String getMessageTemplate();
+
@PropertyName(PATH)
String getPath();
+ @PropertyName(ROOT)
+ IdMessage getRootBeanId();
+
+ @PropertyName(LEAF)
+ void setLeafBeanId(IdMessage id);
+
@PropertyName(MESSAGE)
void setMessage(String value);
+ @PropertyName(TEMPLATE)
+ void setMessageTemplate(String value);
+
@PropertyName(PATH)
void setPath(String value);
+
+ @PropertyName(ROOT)
+ void setRootBeanId(IdMessage id);
}
diff --git a/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java b/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java
index 54f9691..ba3ae78 100644
--- a/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java
+++ b/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java
@@ -46,13 +46,13 @@
import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
-import com.google.web.bindery.requestfactory.shared.Violation;
import junit.framework.TestCase;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -504,6 +504,12 @@
assertNull(editorField.getSetterName());
}
+ @SuppressWarnings("deprecation")
+ private Set<Resource> getDeprecatedResources() {
+ return Collections.<Resource> singleton(new EmptyMockJavaResource(
+ com.google.web.bindery.requestfactory.shared.Violation.class));
+ }
+
private Set<Resource> getJavaResources() {
MockJavaResource[] javaFiles = {new MockJavaResource("t.AddressProxy") {
@Override
@@ -958,8 +964,8 @@
new EmptyMockJavaResource(RequestContext.class),
new RealJavaResource(SimpleEditor.class),
new RealJavaResource(TakesValue.class),
- new EmptyMockJavaResource(ValueAwareEditor.class),
- new EmptyMockJavaResource(Violation.class),}));
+ new EmptyMockJavaResource(ValueAwareEditor.class)}));
+ toReturn.addAll(getDeprecatedResources());
toReturn.addAll(Arrays.asList(JavaResourceBase.getStandardResources()));
return toReturn;
}
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryExceptionPropagationTest.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryExceptionPropagationTest.java
index 48482c7..23223ef 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryExceptionPropagationTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryExceptionPropagationTest.java
@@ -22,10 +22,11 @@
import com.google.web.bindery.requestfactory.shared.ServerFailure;
import com.google.web.bindery.requestfactory.shared.SimpleFooProxy;
import com.google.web.bindery.requestfactory.shared.SimpleFooRequest;
-import com.google.web.bindery.requestfactory.shared.Violation;
import java.util.Set;
+import javax.validation.ConstraintViolation;
+
/**
* Tests that an exception thrown by a {@link Receiver} does not prevent other
* {@link Receiver}s from being called.
@@ -37,6 +38,7 @@
*/
private class CountingReceiver extends Receiver<Object> {
+ int constraintViolationCallCount;
int failureCallCount;
int successCallCount;
int violationCallCount;
@@ -45,8 +47,16 @@
int expectedSuccessCallCount, int expectedViolationCallCount) {
assertEquals(expectedFailureCallCount, failureCallCount);
assertEquals(expectedSuccessCallCount, successCallCount);
+ assertEquals(expectedViolationCallCount, constraintViolationCallCount);
assertEquals(expectedViolationCallCount, violationCallCount);
}
+
+ @Override
+ public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
+ constraintViolationCallCount++;
+ // Forward to onViolation
+ super.onConstraintViolation(errors);
+ }
@Override
public void onFailure(ServerFailure error) {
@@ -58,8 +68,9 @@
successCallCount++;
}
+ @SuppressWarnings("deprecation")
@Override
- public void onViolation(Set<Violation> errors) {
+ public void onViolation(Set<com.google.web.bindery.requestfactory.shared.Violation> errors) {
violationCallCount++;
}
}
@@ -81,8 +92,9 @@
throw e;
}
+ @SuppressWarnings("deprecation")
@Override
- public void onViolation(Set<Violation> errors) {
+ public void onViolation(Set<com.google.web.bindery.requestfactory.shared.Violation> errors) {
throw e;
}
}
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 b23c76e..8924cbe 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
@@ -31,7 +31,6 @@
import com.google.web.bindery.requestfactory.shared.SimpleFooRequest;
import com.google.web.bindery.requestfactory.shared.SimpleValueContext;
import com.google.web.bindery.requestfactory.shared.SimpleValueProxy;
-import com.google.web.bindery.requestfactory.shared.Violation;
import com.google.web.bindery.requestfactory.shared.impl.SimpleEntityProxyId;
import java.math.BigDecimal;
@@ -47,8 +46,11 @@
import java.util.List;
import java.util.Set;
+import javax.validation.ConstraintViolation;
+
/**
- * Tests for {@link com.google.web.bindery.requestfactory.shared.RequestFactory}.
+ * Tests for {@link com.google.web.bindery.requestfactory.shared.RequestFactory}
+ * .
*/
public class RequestFactoryTest extends RequestFactoryTestBase {
/*
@@ -63,8 +65,8 @@
private Request<SimpleFooProxy> persistRequest;
private String expectedException;
- public FooReciever(SimpleFooProxy mutableFoo,
- Request<SimpleFooProxy> persistRequest, String exception) {
+ public FooReciever(SimpleFooProxy mutableFoo, Request<SimpleFooProxy> persistRequest,
+ String exception) {
this.mutableFoo = mutableFoo;
this.persistRequest = persistRequest;
this.expectedException = exception;
@@ -78,8 +80,7 @@
assertEquals("THIS EXCEPTION IS EXPECTED BY A TEST", error.getMessage());
} else {
assertEquals(null, error.getStackTraceString());
- assertEquals("Server Error: THIS EXCEPTION IS EXPECTED BY A TEST",
- error.getMessage());
+ assertEquals("Server Error: THIS EXCEPTION IS EXPECTED BY A TEST", error.getMessage());
}
// Now show that we can fix the error and try again with the same
@@ -100,8 +101,9 @@
fail("Failure expected but onSuccess() was called");
}
+ @SuppressWarnings("deprecation")
@Override
- public void onViolation(Set<Violation> errors) {
+ public void onViolation(Set<com.google.web.bindery.requestfactory.shared.Violation> errors) {
fail("Failure expected but onViolation() was called");
}
}
@@ -120,13 +122,26 @@
private final Request<T> request;
private boolean voidReturnExpected;
- FailFixAndRefire(SimpleFooProxy proxy, RequestContext context,
- Request<T> request) {
+ FailFixAndRefire(SimpleFooProxy proxy, RequestContext context, Request<T> request) {
this.proxy = context.edit(proxy);
this.request = request;
}
@Override
+ public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
+ assertEquals(1, errors.size());
+ ConstraintViolation<?> error = errors.iterator().next();
+ assertEquals("userName", error.getPropertyPath().toString());
+ assertEquals("size must be between 3 and 30", error.getMessage());
+ assertEquals("{javax.validation.constraints.Size.message}", error.getMessageTemplate());
+ assertSame(proxy, error.getRootBean());
+ assertSame(proxy, error.getLeafBean());
+ assertEquals(proxy.stableId().getProxyClass(), error.getRootBeanClass());
+ // Forward to onViolation()
+ super.onConstraintViolation(errors);
+ }
+
+ @Override
public void onSuccess(T response) {
/*
* Make sure your class path includes:
@@ -140,13 +155,14 @@
+ "see the comment above this line)");
}
+ @SuppressWarnings("deprecation")
@Override
- public void onViolation(Set<Violation> errors) {
+ public void onViolation(Set<com.google.web.bindery.requestfactory.shared.Violation> errors) {
// size violation expected
assertEquals(1, errors.size());
- Violation error = errors.iterator().next();
+ com.google.web.bindery.requestfactory.shared.Violation error = errors.iterator().next();
assertEquals("userName", error.getPath());
assertEquals("size must be between 3 and 30", error.getMessage());
assertEquals(proxy.stableId(), error.getProxyId());
@@ -160,8 +176,7 @@
if (voidReturnExpected) {
assertNull(response);
} else {
- assertEquals(proxy.stableId(),
- ((SimpleFooProxy) response).stableId());
+ assertEquals(proxy.stableId(), ((SimpleFooProxy) response).stableId());
}
finishTestAndReset();
}
@@ -189,12 +204,10 @@
return;
}
}
- assertTrue("Value " + value + " not found in collection " + col.toString(),
- false);
+ assertTrue("Value " + value + " not found in collection " + col.toString(), false);
}
- public <T extends EntityProxy> void assertNotContains(Collection<T> col,
- T value) {
+ public <T extends EntityProxy> void assertNotContains(Collection<T> col, T value) {
for (T x : col) {
assertNotSame(x.stableId(), value.stableId());
}
@@ -210,17 +223,16 @@
*/
public void testAntiAliasing() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().fetchDoubleReference().with("fooField",
- "selfOneToManyField").fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertNotNull(response.getFooField());
- assertSame(response.getFooField(),
- response.getSelfOneToManyField().get(0));
- finishTestAndReset();
- }
- });
+ simpleFooRequest().fetchDoubleReference().with("fooField", "selfOneToManyField").fire(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertNotNull(response.getFooField());
+ assertSame(response.getFooField(), response.getSelfOneToManyField().get(0));
+ finishTestAndReset();
+ }
+ });
}
public void testAppend() {
@@ -317,12 +329,11 @@
bars.add(bar0);
bars.add(bar1);
- final SimpleFooEventHandler<SimpleBarProxy> handler = new SimpleFooEventHandler<SimpleBarProxy>();
- EntityProxyChange.registerForProxyType(req.getEventBus(),
- SimpleBarProxy.class, handler);
+ final SimpleFooEventHandler<SimpleBarProxy> handler =
+ new SimpleFooEventHandler<SimpleBarProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleBarProxy.class, handler);
- Request<SimpleFooProxy> request = context.persistCascadingAndReturnSelf().using(
- foo);
+ Request<SimpleFooProxy> request = context.persistCascadingAndReturnSelf().using(foo);
SimpleFooProxy editFoo = context.edit(foo);
editFoo.setOneToManyField(bars);
request.fire(new Receiver<SimpleFooProxy>() {
@@ -372,37 +383,35 @@
public void testChangedEdit() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(1L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(1L).fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy foo) {
- foo = checkSerialization(foo);
- SimpleFooRequest context = simpleFooRequest();
+ @Override
+ public void onSuccess(SimpleFooProxy foo) {
+ foo = checkSerialization(foo);
+ SimpleFooRequest context = simpleFooRequest();
- // edit() doesn't cause a change
- foo = context.edit(foo);
- assertFalse(context.isChanged());
+ // edit() doesn't cause a change
+ foo = context.edit(foo);
+ assertFalse(context.isChanged());
- final String newName = "something else;";
- String oldName = foo.getUserName();
- assertFalse("Don't accidentally set the same name",
- newName.equals(oldName));
+ final String newName = "something else;";
+ String oldName = foo.getUserName();
+ assertFalse("Don't accidentally set the same name", newName.equals(oldName));
- // gets don't cause a change
- assertFalse(context.isChanged());
+ // gets don't cause a change
+ assertFalse(context.isChanged());
- // Change
- foo.setUserName(newName);
- assertTrue(context.isChanged());
+ // Change
+ foo.setUserName(newName);
+ assertTrue(context.isChanged());
- // Undo the change
- foo.setUserName(oldName);
- assertFalse(context.isChanged());
+ // Undo the change
+ foo.setUserName(oldName);
+ assertFalse(context.isChanged());
- finishTestAndReset();
- }
- });
+ finishTestAndReset();
+ }
+ });
}
public void testChangedNothing() {
@@ -420,39 +429,36 @@
public void testCollectionSubProperties() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().getSimpleFooWithSubPropertyCollection().with(
- "selfOneToManyField", "selfOneToManyField.fooField").fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertEquals(
- "I'm here",
- response.getSelfOneToManyField().get(0).getFooField().getUserName());
- finishTestAndReset();
- }
- });
+ simpleFooRequest().getSimpleFooWithSubPropertyCollection().with("selfOneToManyField",
+ "selfOneToManyField.fooField").fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertEquals("I'm here", response.getSelfOneToManyField().get(0).getFooField()
+ .getUserName());
+ finishTestAndReset();
+ }
+ });
}
public void testDomainUpcast() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().returnSimpleFooSubclass().fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertEquals(42, response.getIntId().intValue());
- finishTestAndReset();
- }
- });
+ simpleFooRequest().returnSimpleFooSubclass().fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertEquals(42, response.getIntId().intValue());
+ finishTestAndReset();
+ }
+ });
}
public void testDummyCreate() {
delayTestFinish(DELAY_TEST_FINISH);
- final SimpleFooEventHandler<SimpleFooProxy> handler = new SimpleFooEventHandler<SimpleFooProxy>();
- EntityProxyChange.registerForProxyType(req.getEventBus(),
- SimpleFooProxy.class, handler);
+ final SimpleFooEventHandler<SimpleFooProxy> handler =
+ new SimpleFooEventHandler<SimpleFooProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleFooProxy.class, handler);
SimpleFooRequest context = simpleFooRequest();
final SimpleFooProxy foo = context.create(SimpleFooProxy.class);
@@ -535,13 +541,12 @@
}
try {
- contextB.persistAndReturnSelf().using(fromA).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- fail();
- }
- });
+ contextB.persistAndReturnSelf().using(fromA).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ fail();
+ }
+ });
fail();
} catch (IllegalArgumentException expected) {
}
@@ -565,13 +570,12 @@
public void testEnumOnlyUsedByRequestContext() {
delayTestFinish(DELAY_TEST_FINISH);
SimpleFooRequest ctx = simpleFooRequest();
- ctx.receiveEnum(OnlyUsedByRequestContextMethod.FOO).fire(
- new Receiver<Void>() {
- @Override
- public void onSuccess(Void response) {
- finishTest();
- }
- });
+ ctx.receiveEnum(OnlyUsedByRequestContextMethod.FOO).fire(new Receiver<Void>() {
+ @Override
+ public void onSuccess(Void response) {
+ finishTest();
+ }
+ });
}
/**
@@ -579,52 +583,48 @@
*/
public void testEnumProperty() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ assertEquals(SimpleEnum.FOO, response.getEnumField());
+ SimpleFooRequest ctx = simpleFooRequest();
+ response = ctx.edit(response);
+ response.setEnumField(SimpleEnum.BAR);
+ ctx.persistAndReturnSelf().using(response).fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
- assertEquals(SimpleEnum.FOO, response.getEnumField());
+ assertEquals(SimpleEnum.BAR, response.getEnumField());
SimpleFooRequest ctx = simpleFooRequest();
response = ctx.edit(response);
- response.setEnumField(SimpleEnum.BAR);
- ctx.persistAndReturnSelf().using(response).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- assertEquals(SimpleEnum.BAR, response.getEnumField());
- SimpleFooRequest ctx = simpleFooRequest();
- response = ctx.edit(response);
- response.setEnumField(null);
- ctx.persistAndReturnSelf().using(response).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- assertNull(response.getEnumField());
- finishTestAndReset();
- }
- });
- }
- });
+ response.setEnumField(null);
+ ctx.persistAndReturnSelf().using(response).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ assertNull(response.getEnumField());
+ finishTestAndReset();
+ }
+ });
}
});
+ }
+ });
}
public void testFetchEntity() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertEquals(42, (int) response.getIntId());
- assertEquals("GWT", response.getUserName());
- assertEquals(8L, (long) response.getLongField());
- assertEquals(com.google.web.bindery.requestfactory.shared.SimpleEnum.FOO,
- response.getEnumField());
- assertEquals(null, response.getBarField());
- finishTestAndReset();
- }
- });
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertEquals(42, (int) response.getIntId());
+ assertEquals("GWT", response.getUserName());
+ assertEquals(8L, (long) response.getLongField());
+ assertEquals(com.google.web.bindery.requestfactory.shared.SimpleEnum.FOO, response
+ .getEnumField());
+ assertEquals(null, response.getBarField());
+ finishTestAndReset();
+ }
+ });
}
public void testFetchEntityWithRelation() {
@@ -637,8 +637,8 @@
assertEquals(42, (int) response.getIntId());
assertEquals("GWT", response.getUserName());
assertEquals(8L, (long) response.getLongField());
- assertEquals(com.google.web.bindery.requestfactory.shared.SimpleEnum.FOO,
- response.getEnumField());
+ assertEquals(com.google.web.bindery.requestfactory.shared.SimpleEnum.FOO, response
+ .getEnumField());
assertNotNull(response.getBarField());
finishTestAndReset();
}
@@ -654,8 +654,8 @@
assertEquals(42, (int) response.getIntId());
assertEquals("GWT", response.getUserName());
assertEquals(8L, (long) response.getLongField());
- assertEquals(com.google.web.bindery.requestfactory.shared.SimpleEnum.FOO,
- response.getEnumField());
+ assertEquals(com.google.web.bindery.requestfactory.shared.SimpleEnum.FOO, response
+ .getEnumField());
finishTestAndReset();
}
});
@@ -675,63 +675,58 @@
public void testFindFindEdit() {
delayTestFinish(DELAY_TEST_FINISH);
- final SimpleFooEventHandler<SimpleFooProxy> handler = new SimpleFooEventHandler<SimpleFooProxy>();
- EntityProxyChange.registerForProxyType(req.getEventBus(),
- SimpleFooProxy.class, handler);
+ final SimpleFooEventHandler<SimpleFooProxy> handler =
+ new SimpleFooEventHandler<SimpleFooProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleFooProxy.class, handler);
- req.simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ req.simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+
+ @Override
+ public void onSuccess(SimpleFooProxy newFoo) {
+ newFoo = checkSerialization(newFoo);
+ assertEquals(1, handler.updateEventCount);
+ assertEquals(1, handler.totalEventCount);
+
+ req.simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy newFoo) {
newFoo = checkSerialization(newFoo);
+ // no events are fired second time.
assertEquals(1, handler.updateEventCount);
assertEquals(1, handler.totalEventCount);
+ SimpleFooRequest context = req.simpleFooRequest();
+ final Request<Void> mutateRequest = context.persist().using(newFoo);
+ newFoo = context.edit(newFoo);
+ newFoo.setUserName("Ray");
+ mutateRequest.fire(new Receiver<Void>() {
+ @Override
+ public void onSuccess(Void response) {
+ // events fired on updates.
+ assertEquals(2, handler.updateEventCount);
+ assertEquals(2, handler.totalEventCount);
- req.simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
-
- @Override
- public void onSuccess(SimpleFooProxy newFoo) {
- newFoo = checkSerialization(newFoo);
- // no events are fired second time.
- assertEquals(1, handler.updateEventCount);
- assertEquals(1, handler.totalEventCount);
- SimpleFooRequest context = req.simpleFooRequest();
- final Request<Void> mutateRequest = context.persist().using(
- newFoo);
- newFoo = context.edit(newFoo);
- newFoo.setUserName("Ray");
- mutateRequest.fire(new Receiver<Void>() {
- @Override
- public void onSuccess(Void response) {
- // events fired on updates.
- assertEquals(2, handler.updateEventCount);
- assertEquals(2, handler.totalEventCount);
-
- finishTestAndReset();
- }
- });
- }
- });
+ finishTestAndReset();
+ }
+ });
}
});
+ }
+ });
}
public void testForwardReferenceDecode() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().getTripletReference().with(
- "selfOneToManyField.selfOneToManyField.fooField").fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().getTripletReference().with("selfOneToManyField.selfOneToManyField.fooField")
+ .fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
response = checkSerialization(response);
assertNotNull(response.getSelfOneToManyField().get(0));
assertNotNull(response.getSelfOneToManyField().get(0).getSelfOneToManyField());
- assertNotNull(response.getSelfOneToManyField().get(0).getSelfOneToManyField().get(
- 0));
- assertNotNull(response.getSelfOneToManyField().get(0).getSelfOneToManyField().get(
- 0).getFooField());
+ assertNotNull(response.getSelfOneToManyField().get(0).getSelfOneToManyField().get(0));
+ assertNotNull(response.getSelfOneToManyField().get(0).getSelfOneToManyField().get(0)
+ .getFooField());
finishTestAndReset();
}
});
@@ -807,13 +802,11 @@
// Check that the persisted object can be found with future token
assertEquals(futureId, req.getProxyId(futureToken));
assertEquals(futureId, req.getProxyId(persistedToken));
- assertEquals(futureId.getProxyClass(),
- req.getProxyClass(persistedToken));
+ assertEquals(futureId.getProxyClass(), req.getProxyClass(persistedToken));
assertEquals(persistedId, req.getProxyId(futureToken));
assertEquals(persistedId, req.getProxyId(persistedToken));
- assertEquals(persistedId.getProxyClass(),
- req.getProxyClass(futureToken));
+ assertEquals(persistedId.getProxyClass(), req.getProxyClass(futureToken));
finishTestAndReset();
}
@@ -848,13 +841,13 @@
public void testLoggingService() {
delayTestFinish(DELAY_TEST_FINISH);
String logRecordJson = new StringBuilder("{") //
- .append("\"level\": \"ALL\", ") //
- .append("\"loggerName\": \"logger\", ") //
- .append("\"msg\": \"Hi mom\", ") //
- .append("\"timestamp\": \"1234567890\",") //
- .append("\"thrown\": {}") //
- .append("}") //
- .toString();
+ .append("\"level\": \"ALL\", ") //
+ .append("\"loggerName\": \"logger\", ") //
+ .append("\"msg\": \"Hi mom\", ") //
+ .append("\"timestamp\": \"1234567890\",") //
+ .append("\"thrown\": {}") //
+ .append("}") //
+ .toString();
req.loggingRequest().logMessage(logRecordJson).fire(new Receiver<Void>() {
@Override
@@ -872,58 +865,56 @@
delayTestFinish(DELAY_TEST_FINISH);
// Handle changes to SimpleFooProxy.
- final SimpleFooEventHandler<SimpleFooProxy> fooHandler = new SimpleFooEventHandler<SimpleFooProxy>();
- EntityProxyChange.registerForProxyType(req.getEventBus(),
- SimpleFooProxy.class, fooHandler);
+ final SimpleFooEventHandler<SimpleFooProxy> fooHandler =
+ new SimpleFooEventHandler<SimpleFooProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleFooProxy.class, fooHandler);
// Handle changes to SimpleBarProxy.
- final SimpleFooEventHandler<SimpleBarProxy> barHandler = new SimpleFooEventHandler<SimpleBarProxy>();
- EntityProxyChange.registerForProxyType(req.getEventBus(),
- SimpleBarProxy.class, barHandler);
+ final SimpleFooEventHandler<SimpleBarProxy> barHandler =
+ new SimpleFooEventHandler<SimpleBarProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleBarProxy.class, barHandler);
// Persist bar.
SimpleBarRequest context = req.simpleBarRequest();
final SimpleBarProxy bar = context.create(SimpleBarProxy.class);
- context.persistAndReturnSelf().using(bar).fire(
- new Receiver<SimpleBarProxy>() {
+ context.persistAndReturnSelf().using(bar).fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onSuccess(SimpleBarProxy persistentBar) {
+ persistentBar = checkSerialization(persistentBar);
+ // Persist foo with bar as a child.
+ SimpleFooRequest context = req.simpleFooRequest();
+ SimpleFooProxy foo = context.create(SimpleFooProxy.class);
+ final Request<SimpleFooProxy> persistRequest =
+ context.persistAndReturnSelf().using(foo).with("barField");
+ foo = context.edit(foo);
+ foo.setUserName("John");
+ foo.setBarField(bar);
+ persistRequest.fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleBarProxy persistentBar) {
- persistentBar = checkSerialization(persistentBar);
- // Persist foo with bar as a child.
+ public void onSuccess(SimpleFooProxy persistentFoo) {
+ persistentFoo = checkSerialization(persistentFoo);
+
+ // Delete bar.
SimpleFooRequest context = req.simpleFooRequest();
- SimpleFooProxy foo = context.create(SimpleFooProxy.class);
- final Request<SimpleFooProxy> persistRequest = context.persistAndReturnSelf().using(
- foo).with("barField");
- foo = context.edit(foo);
- foo.setUserName("John");
- foo.setBarField(bar);
- persistRequest.fire(new Receiver<SimpleFooProxy>() {
+ final Request<Void> deleteRequest = context.deleteBar().using(persistentFoo);
+ deleteRequest.fire(new Receiver<Void>() {
@Override
- public void onSuccess(SimpleFooProxy persistentFoo) {
- persistentFoo = checkSerialization(persistentFoo);
+ public void onSuccess(Void response) {
+ assertEquals(1, fooHandler.persistEventCount);
+ assertEquals(2, fooHandler.updateEventCount);
+ assertEquals(3, fooHandler.totalEventCount);
- // Delete bar.
- SimpleFooRequest context = req.simpleFooRequest();
- final Request<Void> deleteRequest = context.deleteBar().using(
- persistentFoo);
- deleteRequest.fire(new Receiver<Void>() {
- @Override
- public void onSuccess(Void response) {
- assertEquals(1, fooHandler.persistEventCount);
- assertEquals(2, fooHandler.updateEventCount);
- assertEquals(3, fooHandler.totalEventCount);
-
- assertEquals(1, barHandler.persistEventCount);
- assertEquals(1, barHandler.updateEventCount);
- assertEquals(1, barHandler.deleteEventCount);
- assertEquals(3, barHandler.totalEventCount);
- finishTestAndReset();
- }
- });
+ assertEquals(1, barHandler.persistEventCount);
+ assertEquals(1, barHandler.updateEventCount);
+ assertEquals(1, barHandler.deleteEventCount);
+ assertEquals(3, barHandler.totalEventCount);
+ finishTestAndReset();
}
});
}
});
+ }
+ });
}
/*
@@ -934,56 +925,54 @@
public void testMethodWithSideEffects() {
delayTestFinish(DELAY_TEST_FINISH);
- final SimpleFooEventHandler<SimpleFooProxy> handler = new SimpleFooEventHandler<SimpleFooProxy>();
- EntityProxyChange.registerForProxyType(req.getEventBus(),
- SimpleFooProxy.class, handler);
+ final SimpleFooEventHandler<SimpleFooProxy> handler =
+ new SimpleFooEventHandler<SimpleFooProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleFooProxy.class, handler);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy newFoo) {
+ newFoo = checkSerialization(newFoo);
+ assertEquals(1, handler.updateEventCount);
+ assertEquals(1, handler.totalEventCount);
+ SimpleFooRequest context = simpleFooRequest();
+ final Request<Long> mutateRequest =
+ context.countSimpleFooWithUserNameSideEffect().using(newFoo);
+ newFoo = context.edit(newFoo);
+ newFoo.setUserName("Ray");
+ mutateRequest.fire(new Receiver<Long>() {
@Override
- public void onSuccess(SimpleFooProxy newFoo) {
- newFoo = checkSerialization(newFoo);
- assertEquals(1, handler.updateEventCount);
- assertEquals(1, handler.totalEventCount);
- SimpleFooRequest context = simpleFooRequest();
- final Request<Long> mutateRequest = context.countSimpleFooWithUserNameSideEffect().using(
- newFoo);
- newFoo = context.edit(newFoo);
- newFoo.setUserName("Ray");
- mutateRequest.fire(new Receiver<Long>() {
+ public void onSuccess(Long response) {
+ assertCannotFire(mutateRequest);
+ assertEquals(new Long(2L), response);
+ assertEquals(2, handler.updateEventCount);
+ assertEquals(2, handler.totalEventCount);
+
+ // confirm that the instance method did have the desired
+ // sideEffect.
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(Long response) {
- assertCannotFire(mutateRequest);
- assertEquals(new Long(2L), response);
+ public void onSuccess(SimpleFooProxy finalFoo) {
+ finalFoo = checkSerialization(finalFoo);
+ assertEquals("Ray", finalFoo.getUserName());
assertEquals(2, handler.updateEventCount);
assertEquals(2, handler.totalEventCount);
-
- // confirm that the instance method did have the desired
- // sideEffect.
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy finalFoo) {
- finalFoo = checkSerialization(finalFoo);
- assertEquals("Ray", finalFoo.getUserName());
- assertEquals(2, handler.updateEventCount);
- assertEquals(2, handler.totalEventCount);
- finishTestAndReset();
- }
- });
+ finishTestAndReset();
}
-
});
-
- try {
- newFoo.setUserName("Barney");
- fail();
- } catch (IllegalStateException e) {
- /* pass, cannot change a request that is in flight */
- }
}
+
});
+
+ try {
+ newFoo.setUserName("Barney");
+ fail();
+ } catch (IllegalStateException e) {
+ /* pass, cannot change a request that is in flight */
+ }
+ }
+ });
}
public void testMultipleEdits() {
@@ -1049,8 +1038,7 @@
*/
public void testNullSimpleFooRequest() {
delayTestFinish(DELAY_TEST_FINISH);
- final Request<Void> fooReq = req.simpleFooRequest().receiveNullSimpleFoo(
- null);
+ final Request<Void> fooReq = req.simpleFooRequest().receiveNullSimpleFoo(null);
fooReq.fire(new Receiver<Void>() {
@Override
public void onSuccess(Void v) {
@@ -1066,21 +1054,19 @@
delayTestFinish(DELAY_TEST_FINISH);
// Get a valid proxy entity.
- req.simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ req.simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ Request<Void> fooReq = req.simpleFooRequest().receiveNull(null).using(response);
+ fooReq.fire(new Receiver<Void>() {
@Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- Request<Void> fooReq = req.simpleFooRequest().receiveNull(null).using(
- response);
- fooReq.fire(new Receiver<Void>() {
- @Override
- public void onSuccess(Void v) {
- finishTestAndReset();
- }
- });
+ public void onSuccess(Void v) {
+ finishTestAndReset();
}
});
+ }
+ });
}
/**
@@ -1112,24 +1098,22 @@
delayTestFinish(DELAY_TEST_FINISH);
// Get a valid proxy entity.
- req.simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ req.simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ List<SimpleFooProxy> list = new ArrayList<SimpleFooProxy>();
+ list.add(response); // non-null
+ list.add(null); // null
+ final Request<Void> fooReq = req.simpleFooRequest().receiveNullValueInEntityList(list);
+ fooReq.fire(new Receiver<Void>() {
@Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- List<SimpleFooProxy> list = new ArrayList<SimpleFooProxy>();
- list.add(response); // non-null
- list.add(null); // null
- final Request<Void> fooReq = req.simpleFooRequest().receiveNullValueInEntityList(
- list);
- fooReq.fire(new Receiver<Void>() {
- @Override
- public void onSuccess(Void v) {
- finishTestAndReset();
- }
- });
+ public void onSuccess(Void v) {
+ finishTestAndReset();
}
});
+ }
+ });
}
/**
@@ -1138,8 +1122,7 @@
public void testNullValueInIntegerListRequest() {
delayTestFinish(DELAY_TEST_FINISH);
List<Integer> list = Arrays.asList(new Integer[] {1, 2, null});
- final Request<Void> fooReq = req.simpleFooRequest().receiveNullValueInIntegerList(
- list);
+ final Request<Void> fooReq = req.simpleFooRequest().receiveNullValueInIntegerList(list);
fooReq.fire(new Receiver<Void>() {
@Override
public void onSuccess(Void v) {
@@ -1154,8 +1137,7 @@
public void testNullValueInStringListRequest() {
delayTestFinish(DELAY_TEST_FINISH);
List<String> list = Arrays.asList(new String[] {"nonnull", "null", null});
- final Request<Void> fooReq = req.simpleFooRequest().receiveNullValueInStringList(
- list);
+ final Request<Void> fooReq = req.simpleFooRequest().receiveNullValueInStringList(list);
fooReq.fire(new Receiver<Void>() {
@Override
public void onSuccess(Void v) {
@@ -1221,77 +1203,73 @@
*/
public void testPersistedEntityWithNullVersion() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().getSimpleFooWithNullVersion().fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().getSimpleFooWithNullVersion().fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onFailure(ServerFailure error) {
- finishTestAndReset();
- }
+ @Override
+ public void onFailure(ServerFailure error) {
+ finishTestAndReset();
+ }
- @Override
- public void onSuccess(SimpleFooProxy response) {
- fail();
- }
- });
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ fail();
+ }
+ });
}
public void testPersistExistingEntityExistingRelation() {
delayTestFinish(DELAY_TEST_FINISH);
// Retrieve a Bar
- simpleBarRequest().findSimpleBarById("999L").fire(
- new Receiver<SimpleBarProxy>() {
+ simpleBarRequest().findSimpleBarById("999L").fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onSuccess(SimpleBarProxy response) {
+ final SimpleBarProxy barProxy = checkSerialization(response);
+ // Retrieve a Foo
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleBarProxy response) {
- final SimpleBarProxy barProxy = checkSerialization(response);
- // Retrieve a Foo
- simpleFooRequest().findSimpleFooById(999L).fire(
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ fooProxy = context.edit(fooProxy);
+ // Make the Foo point to the Bar
+ fooProxy.setBarField(barProxy);
+ fooProxy.setUserName("Hello");
+ fooProxy.setByteField((byte) 55);
+ context.persistAndReturnSelf().using(fooProxy).with("barField").fire(
new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- fooProxy = context.edit(fooProxy);
- // Make the Foo point to the Bar
- fooProxy.setBarField(barProxy);
- fooProxy.setUserName("Hello");
- fooProxy.setByteField((byte) 55);
- context.persistAndReturnSelf().using(fooProxy).with(
- "barField").fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy received) {
- received = checkSerialization(received);
- // Check that Foo points to Bar
- assertNotNull(received.getBarField());
- assertEquals(barProxy.stableId(),
- received.getBarField().stableId());
- assertEquals("Hello", received.getUserName());
- assertTrue(55 == received.getByteField());
+ public void onSuccess(SimpleFooProxy received) {
+ received = checkSerialization(received);
+ // Check that Foo points to Bar
+ assertNotNull(received.getBarField());
+ assertEquals(barProxy.stableId(), received.getBarField().stableId());
+ assertEquals("Hello", received.getUserName());
+ assertTrue(55 == received.getByteField());
- // Unset the association
- SimpleFooRequest context = simpleFooRequest();
- received = context.edit(received);
- received.setBarField(null);
- received.setUserName(null);
- received.setByteField(null);
- context.persistAndReturnSelf().using(received).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertNull(response.getBarField());
- assertNull(response.getUserName());
- assertNull(response.getByteField());
- finishTestAndReset();
- }
- });
- }
- });
+ // Unset the association
+ SimpleFooRequest context = simpleFooRequest();
+ received = context.edit(received);
+ received.setBarField(null);
+ received.setUserName(null);
+ received.setByteField(null);
+ context.persistAndReturnSelf().using(received).fire(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertNull(response.getBarField());
+ assertNull(response.getUserName());
+ assertNull(response.getByteField());
+ finishTestAndReset();
+ }
+ });
}
});
}
});
+ }
+ });
}
/*
@@ -1302,8 +1280,7 @@
// Make a new bar
SimpleBarRequest context = simpleBarRequest();
SimpleBarProxy makeABar = context.create(SimpleBarProxy.class);
- Request<SimpleBarProxy> persistRequest = context.persistAndReturnSelf().using(
- makeABar);
+ Request<SimpleBarProxy> persistRequest = context.persistAndReturnSelf().using(makeABar);
makeABar = context.edit(makeABar);
makeABar.setUserName("Amit");
@@ -1313,39 +1290,36 @@
final SimpleBarProxy persistedBar = checkSerialization(response);
// It was made, now find a foo to assign it to
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+
+ // Found the foo, edit it
+ SimpleFooRequest context = simpleFooRequest();
+ Request<Void> fooReq = context.persist().using(response);
+ response = context.edit(response);
+ response.setBarField(persistedBar);
+ fooReq.fire(new Receiver<Void>() {
@Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
+ public void onSuccess(Void response) {
- // Found the foo, edit it
- SimpleFooRequest context = simpleFooRequest();
- Request<Void> fooReq = context.persist().using(response);
- response = context.edit(response);
- response.setBarField(persistedBar);
- fooReq.fire(new Receiver<Void>() {
- @Override
- public void onSuccess(Void response) {
+ // Foo was persisted, fetch it again check the goods
+ simpleFooRequest().findSimpleFooById(999L).with("barField.userName").fire(
+ new Receiver<SimpleFooProxy>() {
- // Foo was persisted, fetch it again check the goods
- simpleFooRequest().findSimpleFooById(999L).with(
- "barField.userName").fire(
- new Receiver<SimpleFooProxy>() {
-
- // Here it is
- @Override
- public void onSuccess(SimpleFooProxy finalFooProxy) {
- finalFooProxy = checkSerialization(finalFooProxy);
- assertEquals("Amit",
- finalFooProxy.getBarField().getUserName());
- finishTestAndReset();
- }
- });
- }
- });
+ // Here it is
+ @Override
+ public void onSuccess(SimpleFooProxy finalFooProxy) {
+ finalFooProxy = checkSerialization(finalFooProxy);
+ assertEquals("Amit", finalFooProxy.getBarField().getUserName());
+ finishTestAndReset();
+ }
+ });
}
});
+ }
+ });
}
});
}
@@ -1364,8 +1338,7 @@
SimpleFooProxy newFoo = context.create(SimpleFooProxy.class);
final SimpleBarProxy newBar = context.create(SimpleBarProxy.class);
- Request<SimpleFooProxy> fooReq = context.persistAndReturnSelf().using(
- newFoo).with("barField");
+ Request<SimpleFooProxy> fooReq = context.persistAndReturnSelf().using(newFoo).with("barField");
newFoo = context.edit(newFoo);
newFoo.setBarField(newBar);
@@ -1394,30 +1367,28 @@
newFoo.setUserName("Ray");
final SimpleFooProxy finalFoo = newFoo;
- simpleBarRequest().findSimpleBarById("999L").fire(
- new Receiver<SimpleBarProxy>() {
+ simpleBarRequest().findSimpleBarById("999L").fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onSuccess(SimpleBarProxy response) {
+ response = checkSerialization(response);
+ finalFoo.setBarField(response);
+ fooReq.fire(new Receiver<Void>() {
@Override
- public void onSuccess(SimpleBarProxy response) {
- response = checkSerialization(response);
- finalFoo.setBarField(response);
- fooReq.fire(new Receiver<Void>() {
+ public void onSuccess(Void response) {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(Void response) {
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy finalFooProxy) {
- finalFooProxy = checkSerialization(finalFooProxy);
- // newFoo hasn't been persisted, so userName is the old
- // value.
- assertEquals("GWT", finalFooProxy.getUserName());
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleFooProxy finalFooProxy) {
+ finalFooProxy = checkSerialization(finalFooProxy);
+ // newFoo hasn't been persisted, so userName is the old
+ // value.
+ assertEquals("GWT", finalFooProxy.getUserName());
+ finishTestAndReset();
}
});
}
});
+ }
+ });
}
/*
@@ -1429,15 +1400,13 @@
SimpleFooRequest context = simpleFooRequest();
SimpleFooProxy newFoo = context.create(SimpleFooProxy.class);
- final Request<SimpleFooProxy> fooReq = context.persistAndReturnSelf().using(
- newFoo);
+ final Request<SimpleFooProxy> fooReq = context.persistAndReturnSelf().using(newFoo);
newFoo = context.edit(newFoo);
newFoo.setUserName("Ray");
SimpleBarRequest context2 = simpleBarRequest();
SimpleBarProxy newBar = context2.create(SimpleBarProxy.class);
- final Request<SimpleBarProxy> barReq = context2.persistAndReturnSelf().using(
- newBar);
+ final Request<SimpleBarProxy> barReq = context2.persistAndReturnSelf().using(newBar);
newBar = context2.edit(newBar);
newBar.setUserName("Amit");
@@ -1463,8 +1432,7 @@
@Override
public void onSuccess(SimpleFooProxy finalFooProxy) {
finalFooProxy = checkSerialization(finalFooProxy);
- assertEquals("Amit",
- finalFooProxy.getBarField().getUserName());
+ assertEquals("Amit", finalFooProxy.getBarField().getUserName());
finishTestAndReset();
}
});
@@ -1483,39 +1451,37 @@
public void testPersistOneToManyExistingEntityExistingRelation() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleBarRequest().findSimpleBarById("999L").fire(
- new Receiver<SimpleBarProxy>() {
- @Override
- public void onSuccess(SimpleBarProxy response) {
- final SimpleBarProxy barProxy = checkSerialization(response);
- simpleFooRequest().findSimpleFooById(999L).with("oneToManyField").fire(
- new Receiver<SimpleFooProxy>() {
+ simpleBarRequest().findSimpleBarById("999L").fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onSuccess(SimpleBarProxy response) {
+ final SimpleBarProxy barProxy = checkSerialization(response);
+ simpleFooRequest().findSimpleFooById(999L).with("oneToManyField").fire(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq =
+ context.persistAndReturnSelf().using(fooProxy).with("oneToManyField");
+ fooProxy = context.edit(fooProxy);
+
+ List<SimpleBarProxy> barProxyList = fooProxy.getOneToManyField();
+ final int listCount = barProxyList.size();
+ barProxyList.add(barProxy);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
-
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy).with("oneToManyField");
- fooProxy = context.edit(fooProxy);
-
- List<SimpleBarProxy> barProxyList = fooProxy.getOneToManyField();
- final int listCount = barProxyList.size();
- barProxyList.add(barProxy);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertEquals(response.getOneToManyField().size(),
- listCount + 1);
- assertContains(response.getOneToManyField(), barProxy);
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertEquals(response.getOneToManyField().size(), listCount + 1);
+ assertContains(response.getOneToManyField(), barProxy);
+ finishTestAndReset();
}
});
- }
- });
+ }
+ });
+ }
+ });
}
public void testPersistRecursiveRelation() {
@@ -1523,8 +1489,7 @@
SimpleFooRequest context = simpleFooRequest();
SimpleFooProxy rayFoo = context.create(SimpleFooProxy.class);
- final Request<SimpleFooProxy> persistRay = context.persistAndReturnSelf().using(
- rayFoo);
+ final Request<SimpleFooProxy> persistRay = context.persistAndReturnSelf().using(rayFoo);
rayFoo = context.edit(rayFoo);
rayFoo.setUserName("Ray");
rayFoo.setFooField(rayFoo);
@@ -1542,8 +1507,7 @@
SimpleFooRequest context = simpleFooRequest();
SimpleFooProxy rayFoo = context.create(SimpleFooProxy.class);
- final Request<SimpleFooProxy> persistRay = context.persistAndReturnSelf().using(
- rayFoo);
+ final Request<SimpleFooProxy> persistRay = context.persistAndReturnSelf().using(rayFoo);
rayFoo = context.edit(rayFoo);
rayFoo.setUserName("Ray");
@@ -1553,8 +1517,7 @@
final SimpleFooProxy persistedRay = checkSerialization(response);
SimpleBarRequest context = simpleBarRequest();
SimpleBarProxy amitBar = context.create(SimpleBarProxy.class);
- final Request<SimpleBarProxy> persistAmit = context.persistAndReturnSelf().using(
- amitBar);
+ final Request<SimpleBarProxy> persistAmit = context.persistAndReturnSelf().using(amitBar);
amitBar = context.edit(amitBar);
amitBar.setUserName("Amit");
@@ -1564,8 +1527,8 @@
response = checkSerialization(response);
SimpleFooRequest context = simpleFooRequest();
- final Request<SimpleFooProxy> persistRelationship = context.persistAndReturnSelf().using(
- persistedRay).with("barField");
+ final Request<SimpleFooProxy> persistRelationship =
+ context.persistAndReturnSelf().using(persistedRay).with("barField");
SimpleFooProxy newRec = context.edit(persistedRay);
newRec.setBarField(response);
@@ -1592,8 +1555,8 @@
public void onSuccess(SimpleFooProxy fooProxy) {
fooProxy = checkSerialization(fooProxy);
SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy).with("selfOneToManyField");
+ Request<SimpleFooProxy> updReq =
+ context.persistAndReturnSelf().using(fooProxy).with("selfOneToManyField");
fooProxy = context.edit(fooProxy);
List<SimpleFooProxy> fooProxyList = fooProxy.getSelfOneToManyField();
final int listCount = fooProxyList.size();
@@ -1602,8 +1565,7 @@
@Override
public void onSuccess(SimpleFooProxy response) {
response = checkSerialization(response);
- assertEquals(response.getSelfOneToManyField().size(),
- listCount + 1);
+ assertEquals(response.getSelfOneToManyField().size(), listCount + 1);
assertContains(response.getSelfOneToManyField(), response);
finishTestAndReset();
}
@@ -1619,26 +1581,24 @@
public void testPersistValueList() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(fooProxy);
+ fooProxy = context.edit(fooProxy);
+ fooProxy.getNumberListField().add(100);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy);
- fooProxy = context.edit(fooProxy);
- fooProxy.getNumberListField().add(100);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertTrue(response.getNumberListField().contains(100));
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertTrue(response.getNumberListField().contains(100));
+ finishTestAndReset();
}
});
+ }
+ });
}
/*
@@ -1652,28 +1612,26 @@
*/
public void testPersistValueListNull() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy);
- fooProxy = context.edit(fooProxy);
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(fooProxy);
+ fooProxy = context.edit(fooProxy);
- fooProxy.setNumberListField(null);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- List<Integer> list = response.getNumberListField();
- assertNull(list);
- finishTestAndReset();
- }
- });
+ fooProxy.setNumberListField(null);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ List<Integer> list = response.getNumberListField();
+ assertNull(list);
+ finishTestAndReset();
}
});
+ }
+ });
}
/*
@@ -1682,26 +1640,24 @@
*/
public void testPersistValueListRemove() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(fooProxy);
+ fooProxy = context.edit(fooProxy);
+ final int oldValue = fooProxy.getNumberListField().remove(0);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy);
- fooProxy = context.edit(fooProxy);
- final int oldValue = fooProxy.getNumberListField().remove(0);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertFalse(response.getNumberListField().contains(oldValue));
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertFalse(response.getNumberListField().contains(oldValue));
+ finishTestAndReset();
}
});
+ }
+ });
}
/*
@@ -1710,33 +1666,31 @@
*/
public void testPersistValueListReplace() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(fooProxy);
+ fooProxy = context.edit(fooProxy);
+ final ArrayList<Integer> al = new ArrayList<Integer>();
+ al.add(5);
+ al.add(8);
+ al.add(13);
+ fooProxy.setNumberListField(al);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy);
- fooProxy = context.edit(fooProxy);
- final ArrayList<Integer> al = new ArrayList<Integer>();
- al.add(5);
- al.add(8);
- al.add(13);
- fooProxy.setNumberListField(al);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- List<Integer> list = response.getNumberListField();
- assertEquals(5, (int) list.get(0));
- assertEquals(8, (int) list.get(1));
- assertEquals(13, (int) list.get(2));
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ List<Integer> list = response.getNumberListField();
+ assertEquals(5, (int) list.get(0));
+ assertEquals(8, (int) list.get(1));
+ assertEquals(13, (int) list.get(2));
+ finishTestAndReset();
}
});
+ }
+ });
}
/*
@@ -1745,30 +1699,28 @@
*/
public void testPersistValueListReverse() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(fooProxy);
+ fooProxy = context.edit(fooProxy);
+ final ArrayList<Integer> al = new ArrayList<Integer>();
+ List<Integer> listField = fooProxy.getNumberListField();
+ al.addAll(listField);
+ Collections.reverse(listField);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy);
- fooProxy = context.edit(fooProxy);
- final ArrayList<Integer> al = new ArrayList<Integer>();
- List<Integer> listField = fooProxy.getNumberListField();
- al.addAll(listField);
- Collections.reverse(listField);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- Collections.reverse(al);
- assertTrue(response.getNumberListField().equals(al));
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ Collections.reverse(al);
+ assertTrue(response.getNumberListField().equals(al));
+ finishTestAndReset();
}
});
+ }
+ });
}
/*
@@ -1777,26 +1729,24 @@
*/
public void testPersistValueListSetIndex() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(fooProxy);
+ fooProxy = context.edit(fooProxy);
+ fooProxy.getNumberListField().set(0, 10);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy);
- fooProxy = context.edit(fooProxy);
- fooProxy.getNumberListField().set(0, 10);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertTrue(response.getNumberListField().get(0) == 10);
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertTrue(response.getNumberListField().get(0) == 10);
+ finishTestAndReset();
}
});
+ }
+ });
}
/*
@@ -1808,39 +1758,36 @@
SimpleBarRequest context = simpleBarRequest();
SimpleBarProxy newBar = context.create(SimpleBarProxy.class);
- context.persistAndReturnSelf().using(newBar).fire(
- new Receiver<SimpleBarProxy>() {
- @Override
- public void onSuccess(SimpleBarProxy response) {
- final SimpleBarProxy barProxy = checkSerialization(response);
- simpleFooRequest().findSimpleFooById(999L).with("oneToManySetField").fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy).with("oneToManySetField");
- fooProxy = context.edit(fooProxy);
+ context.persistAndReturnSelf().using(newBar).fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onSuccess(SimpleBarProxy response) {
+ final SimpleBarProxy barProxy = checkSerialization(response);
+ simpleFooRequest().findSimpleFooById(999L).with("oneToManySetField").fire(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq =
+ context.persistAndReturnSelf().using(fooProxy).with("oneToManySetField");
+ fooProxy = context.edit(fooProxy);
- Set<SimpleBarProxy> setField = fooProxy.getOneToManySetField();
- final int listCount = setField.size();
- setField.add(barProxy);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertEquals(listCount + 1,
- response.getOneToManySetField().size());
- assertContains(response.getOneToManySetField(),
- barProxy);
- finishTestAndReset();
- }
- });
+ Set<SimpleBarProxy> setField = fooProxy.getOneToManySetField();
+ final int listCount = setField.size();
+ setField.add(barProxy);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertEquals(listCount + 1, response.getOneToManySetField().size());
+ assertContains(response.getOneToManySetField(), barProxy);
+ finishTestAndReset();
}
});
- }
- });
+ }
+ });
+ }
+ });
}
/*
@@ -1850,41 +1797,38 @@
public void testPersistValueSetAlreadyExists() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleBarRequest().findSimpleBarById("1L").fire(
- new Receiver<SimpleBarProxy>() {
- @Override
- public void onSuccess(SimpleBarProxy response) {
- final SimpleBarProxy barProxy = checkSerialization(response);
+ simpleBarRequest().findSimpleBarById("1L").fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onSuccess(SimpleBarProxy response) {
+ final SimpleBarProxy barProxy = checkSerialization(response);
- simpleFooRequest().findSimpleFooById(999L).with("oneToManySetField").fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).with("oneToManySetField").fire(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq =
+ context.persistAndReturnSelf().using(fooProxy).with("oneToManySetField");
+ fooProxy = context.edit(fooProxy);
+
+ Set<SimpleBarProxy> setField = fooProxy.getOneToManySetField();
+ final int listCount = setField.size();
+ assertContains(setField, barProxy);
+ setField.add(barProxy);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy).with("oneToManySetField");
- fooProxy = context.edit(fooProxy);
-
- Set<SimpleBarProxy> setField = fooProxy.getOneToManySetField();
- final int listCount = setField.size();
- assertContains(setField, barProxy);
- setField.add(barProxy);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertEquals(response.getOneToManySetField().size(),
- listCount);
- assertContains(response.getOneToManySetField(),
- barProxy);
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertEquals(response.getOneToManySetField().size(), listCount);
+ assertContains(response.getOneToManySetField(), barProxy);
+ finishTestAndReset();
}
});
- }
- });
+ }
+ });
+ }
+ });
}
/*
@@ -1894,41 +1838,38 @@
public void testPersistValueSetRemove() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleBarRequest().findSimpleBarById("1L").fire(
- new Receiver<SimpleBarProxy>() {
- @Override
- public void onSuccess(SimpleBarProxy response) {
- final SimpleBarProxy barProxy = checkSerialization(response);
- simpleFooRequest().findSimpleFooById(999L).with("oneToManySetField").fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy fooProxy) {
- fooProxy = checkSerialization(fooProxy);
- SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> updReq = context.persistAndReturnSelf().using(
- fooProxy).with("oneToManySetField");
- fooProxy = context.edit(fooProxy);
+ simpleBarRequest().findSimpleBarById("1L").fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onSuccess(SimpleBarProxy response) {
+ final SimpleBarProxy barProxy = checkSerialization(response);
+ simpleFooRequest().findSimpleFooById(999L).with("oneToManySetField").fire(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy fooProxy) {
+ fooProxy = checkSerialization(fooProxy);
+ SimpleFooRequest context = simpleFooRequest();
+ Request<SimpleFooProxy> updReq =
+ context.persistAndReturnSelf().using(fooProxy).with("oneToManySetField");
+ fooProxy = context.edit(fooProxy);
- Set<SimpleBarProxy> setField = fooProxy.getOneToManySetField();
- final int listCount = setField.size();
- assertContains(setField, barProxy);
- setField.remove(context.edit(barProxy));
- assertNotContains(setField, barProxy);
- updReq.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertEquals(listCount - 1,
- response.getOneToManySetField().size());
- assertNotContains(response.getOneToManySetField(),
- barProxy);
- finishTestAndReset();
- }
- });
+ Set<SimpleBarProxy> setField = fooProxy.getOneToManySetField();
+ final int listCount = setField.size();
+ assertContains(setField, barProxy);
+ setField.remove(context.edit(barProxy));
+ assertNotContains(setField, barProxy);
+ updReq.fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertEquals(listCount - 1, response.getOneToManySetField().size());
+ assertNotContains(response.getOneToManySetField(), barProxy);
+ finishTestAndReset();
}
});
- }
- });
+ }
+ });
+ }
+ });
}
public void testPrimitiveList() {
@@ -1948,14 +1889,13 @@
public void testPrimitiveListAsParameter() {
delayTestFinish(DELAY_TEST_FINISH);
- final Request<SimpleFooProxy> fooReq = simpleFooRequest().findSimpleFooById(
- 999L);
+ final Request<SimpleFooProxy> fooReq = simpleFooRequest().findSimpleFooById(999L);
fooReq.fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
response = checkSerialization(response);
- final Request<Integer> sumReq = simpleFooRequest().sum(
- Arrays.asList(1, 2, 3)).using(response);
+ final Request<Integer> sumReq =
+ simpleFooRequest().sum(Arrays.asList(1, 2, 3)).using(response);
sumReq.fire(new Receiver<Integer>() {
@Override
public void onSuccess(Integer response) {
@@ -1976,15 +1916,14 @@
testList.add(new BigDecimal("12345.6789") {
// This is an anonymous subtype
});
- simpleFooRequest().processBigDecimalList(testList).fire(
- new Receiver<List<BigDecimal>>() {
- @Override
- public void onSuccess(List<BigDecimal> response) {
- // Check upcasted values only
- assertEquals(testList, response);
- finishTestAndReset();
- }
- });
+ simpleFooRequest().processBigDecimalList(testList).fire(new Receiver<List<BigDecimal>>() {
+ @Override
+ public void onSuccess(List<BigDecimal> response) {
+ // Check upcasted values only
+ assertEquals(testList, response);
+ finishTestAndReset();
+ }
+ });
}
public void testPrimitiveListBigIntegerAsParameter() {
@@ -1996,22 +1935,20 @@
testList.add(new BigInteger("12345") {
// This is an anonymous subtype
});
- simpleFooRequest().processBigIntegerList(testList).fire(
- new Receiver<List<BigInteger>>() {
- @Override
- public void onSuccess(List<BigInteger> response) {
- // Check upcasted values only
- assertEquals(testList, response);
- finishTestAndReset();
- }
- });
+ simpleFooRequest().processBigIntegerList(testList).fire(new Receiver<List<BigInteger>>() {
+ @Override
+ public void onSuccess(List<BigInteger> response) {
+ // Check upcasted values only
+ assertEquals(testList, response);
+ finishTestAndReset();
+ }
+ });
}
public void testPrimitiveListBooleanAsParameter() {
delayTestFinish(DELAY_TEST_FINISH);
- Request<Boolean> procReq = simpleFooRequest().processBooleanList(
- Arrays.asList(true, false));
+ Request<Boolean> procReq = simpleFooRequest().processBooleanList(Arrays.asList(true, false));
procReq.fire(new Receiver<Boolean>() {
@Override
@@ -2031,29 +1968,26 @@
java.sql.Date sqlDate = new java.sql.Date(90, 0, 2);
Time sqlTime = new Time(1, 2, 3);
Timestamp sqlTimestamp = new Timestamp(12345L);
- final List<Date> testList = Arrays.asList(date, sqlDate, sqlTime,
- sqlTimestamp);
- simpleFooRequest().processDateList(testList).fire(
- new Receiver<List<Date>>() {
- @Override
- public void onSuccess(List<Date> response) {
- // Check upcasted values only
- assertEquals(testList.size(), response.size());
- Iterator<Date> expected = testList.iterator();
- Iterator<Date> actual = response.iterator();
- while (expected.hasNext()) {
- assertEquals(expected.next().getTime(), actual.next().getTime());
- }
- finishTestAndReset();
- }
- });
+ final List<Date> testList = Arrays.asList(date, sqlDate, sqlTime, sqlTimestamp);
+ simpleFooRequest().processDateList(testList).fire(new Receiver<List<Date>>() {
+ @Override
+ public void onSuccess(List<Date> response) {
+ // Check upcasted values only
+ assertEquals(testList.size(), response.size());
+ Iterator<Date> expected = testList.iterator();
+ Iterator<Date> actual = response.iterator();
+ while (expected.hasNext()) {
+ assertEquals(expected.next().getTime(), actual.next().getTime());
+ }
+ finishTestAndReset();
+ }
+ });
}
public void testPrimitiveListEnumAsParameter() {
delayTestFinish(DELAY_TEST_FINISH);
- Request<SimpleEnum> procReq = simpleFooRequest().processEnumList(
- Arrays.asList(SimpleEnum.BAR));
+ Request<SimpleEnum> procReq = simpleFooRequest().processEnumList(Arrays.asList(SimpleEnum.BAR));
procReq.fire(new Receiver<SimpleEnum>() {
@Override
@@ -2105,8 +2039,8 @@
public void testProxyList() {
delayTestFinish(DELAY_TEST_FINISH);
- final Request<SimpleFooProxy> fooReq = simpleFooRequest().findSimpleFooById(
- 999L).with("oneToManyField");
+ final Request<SimpleFooProxy> fooReq =
+ simpleFooRequest().findSimpleFooById(999L).with("oneToManyField");
fooReq.fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
@@ -2123,14 +2057,14 @@
public void testProxyListAsParameter() {
delayTestFinish(DELAY_TEST_FINISH);
- final Request<SimpleFooProxy> fooReq = simpleFooRequest().findSimpleFooById(
- 999L).with("selfOneToManyField");
+ final Request<SimpleFooProxy> fooReq =
+ simpleFooRequest().findSimpleFooById(999L).with("selfOneToManyField");
fooReq.fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
final SimpleFooProxy fooProxy = checkSerialization(response);
- final Request<String> procReq = simpleFooRequest().processList(
- fooProxy.getSelfOneToManyField()).using(fooProxy);
+ final Request<String> procReq =
+ simpleFooRequest().processList(fooProxy.getSelfOneToManyField()).using(fooProxy);
procReq.fire(new Receiver<String>() {
@Override
public void onSuccess(String response) {
@@ -2144,25 +2078,24 @@
public void testProxysAsInstanceMethodParams() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().findSimpleFooById(999L).fire(
- new Receiver<SimpleFooProxy>() {
+ simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ SimpleFooRequest context = simpleFooRequest();
+ SimpleBarProxy bar = context.create(SimpleBarProxy.class);
+ Request<String> helloReq = context.hello(bar).using(response);
+ bar = context.edit(bar);
+ bar.setUserName("BAR");
+ helloReq.fire(new Receiver<String>() {
@Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- SimpleFooRequest context = simpleFooRequest();
- SimpleBarProxy bar = context.create(SimpleBarProxy.class);
- Request<String> helloReq = context.hello(bar).using(response);
- bar = context.edit(bar);
- bar.setUserName("BAR");
- helloReq.fire(new Receiver<String>() {
- @Override
- public void onSuccess(String response) {
- assertEquals("Greetings BAR from GWT", response);
- finishTestAndReset();
- }
- });
+ public void onSuccess(String response) {
+ assertEquals("Greetings BAR from GWT", response);
+ finishTestAndReset();
}
});
+ }
+ });
}
public void testServerFailureCheckedException() {
@@ -2170,8 +2103,7 @@
SimpleFooRequest context = simpleFooRequest();
SimpleFooProxy newFoo = context.create(SimpleFooProxy.class);
- final Request<SimpleFooProxy> persistRequest = context.persistAndReturnSelf().using(
- newFoo);
+ final Request<SimpleFooProxy> persistRequest = context.persistAndReturnSelf().using(newFoo);
final SimpleFooProxy mutableFoo = context.edit(newFoo);
// 43 is the crash causing magic number for a checked exception
mutableFoo.setPleaseCrash(43);
@@ -2182,8 +2114,7 @@
delayTestFinish(DELAY_TEST_FINISH);
SimpleFooRequest context = simpleFooRequest();
SimpleFooProxy newFoo = context.create(SimpleFooProxy.class);
- final Request<SimpleFooProxy> persistRequest = context.persistAndReturnSelf().using(
- newFoo);
+ final Request<SimpleFooProxy> persistRequest = context.persistAndReturnSelf().using(newFoo);
final SimpleFooProxy mutableFoo = context.edit(newFoo);
// 42 is the crash causing magic number for a runtime exception
mutableFoo.setPleaseCrash(42);
@@ -2297,8 +2228,7 @@
checkStableIdEquals(foo, returned);
checkStableIdEquals(newFoo, returned);
SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> editRequest = context.persistAndReturnSelf().using(
- returned);
+ Request<SimpleFooProxy> editRequest = context.persistAndReturnSelf().using(returned);
final SimpleFooProxy editableFoo = context.edit(returned);
editableFoo.setUserName("GWT power user");
editRequest.fire(new Receiver<SimpleFooProxy>() {
@@ -2320,8 +2250,7 @@
* Test that a proxy only referenced via a parameterization is available.
*/
public void testOnlyUsedInList() {
- OnlyUsedInListProxy proxy = simpleFooRequest().create(
- OnlyUsedInListProxy.class);
+ OnlyUsedInListProxy proxy = simpleFooRequest().create(OnlyUsedInListProxy.class);
assertNotNull(proxy);
}
@@ -2330,29 +2259,28 @@
*/
public void testUnpersistedEchoComplexGraph() {
delayTestFinish(DELAY_TEST_FINISH);
- final SimpleFooEventHandler<SimpleFooProxy> handler = new SimpleFooEventHandler<SimpleFooProxy>();
- EntityProxyChange.registerForProxyType(req.getEventBus(),
- SimpleFooProxy.class, handler);
+ final SimpleFooEventHandler<SimpleFooProxy> handler =
+ new SimpleFooEventHandler<SimpleFooProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleFooProxy.class, handler);
SimpleFooRequest context = req.simpleFooRequest();
final SimpleBarProxy simpleBar = context.create(SimpleBarProxy.class);
simpleBar.setUnpersisted(true);
final SimpleFooProxy simpleFoo = context.create(SimpleFooProxy.class);
simpleFoo.setUnpersisted(true);
simpleFoo.setBarField(simpleBar);
- context.echoComplex(simpleFoo, simpleBar).with("barField").fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- // The reconstituted object may not have the same stable id
- checkStableIdEquals(simpleBar, response.getBarField());
- response = checkSerialization(response);
- assertEquals(0, handler.totalEventCount);
- checkStableIdEquals(simpleFoo, response);
- SimpleBarProxy responseBar = response.getBarField();
- assertNotNull(responseBar);
- finishTestAndReset();
- }
- });
+ context.echoComplex(simpleFoo, simpleBar).with("barField").fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ // The reconstituted object may not have the same stable id
+ checkStableIdEquals(simpleBar, response.getBarField());
+ response = checkSerialization(response);
+ assertEquals(0, handler.totalEventCount);
+ checkStableIdEquals(simpleFoo, response);
+ SimpleBarProxy responseBar = response.getBarField();
+ assertNotNull(responseBar);
+ finishTestAndReset();
+ }
+ });
}
/**
@@ -2360,9 +2288,9 @@
*/
public void testUnpersistedEchoObject() {
delayTestFinish(DELAY_TEST_FINISH);
- final SimpleFooEventHandler<SimpleFooProxy> handler = new SimpleFooEventHandler<SimpleFooProxy>();
- EntityProxyChange.registerForProxyType(req.getEventBus(),
- SimpleFooProxy.class, handler);
+ final SimpleFooEventHandler<SimpleFooProxy> handler =
+ new SimpleFooEventHandler<SimpleFooProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleFooProxy.class, handler);
SimpleFooRequest context = req.simpleFooRequest();
final SimpleFooProxy simpleFoo = context.create(SimpleFooProxy.class);
simpleFoo.setUnpersisted(true);
@@ -2382,26 +2310,24 @@
*/
public void testUnpersistedObjectFetch() {
delayTestFinish(DELAY_TEST_FINISH);
- req.simpleFooRequest().getUnpersistedInstance().fire(
- new Receiver<SimpleFooProxy>() {
+ req.simpleFooRequest().getUnpersistedInstance().fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ final SimpleFooProxy created = checkSerialization(response);
+ assertNotNull(created);
+ assertTrue(created.getUnpersisted());
+ req.simpleFooRequest().echo(created).fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
- final SimpleFooProxy created = checkSerialization(response);
- assertNotNull(created);
- assertTrue(created.getUnpersisted());
- req.simpleFooRequest().echo(created).fire(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertNotNull(response);
- assertEquals(created.stableId(), response.stableId());
- assertTrue(response.getUnpersisted());
- finishTestAndReset();
- }
- });
+ response = checkSerialization(response);
+ assertNotNull(response);
+ assertEquals(created.stableId(), response.stableId());
+ assertTrue(response.getUnpersisted());
+ finishTestAndReset();
}
});
+ }
+ });
}
/**
@@ -2416,53 +2342,49 @@
willDelete.setUserName("A");
// Persist the newly-created object
- context.persistAndReturnSelf().using(willDelete).fire(
- new Receiver<SimpleBarProxy>() {
+ context.persistAndReturnSelf().using(willDelete).fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onSuccess(SimpleBarProxy response) {
+ response = checkSerialization(response);
+ assertEquals("A", response.getUserName());
+ // Mark the object as deleted
+ SimpleBarRequest context = simpleBarRequest();
+ response = context.edit(response);
+ response.setFindFails(true);
+ response.setUserName("B");
+ context.persistAndReturnSelf().using(response).fire(new Receiver<SimpleBarProxy>() {
+
@Override
public void onSuccess(SimpleBarProxy response) {
response = checkSerialization(response);
- assertEquals("A", response.getUserName());
- // Mark the object as deleted
+ // The last-known state should be returned
+ assertNotNull(response);
+ assertEquals("B", response.getUserName());
+
SimpleBarRequest context = simpleBarRequest();
+ // Ensure attempts to mutate deleted objects don't blow up
response = context.edit(response);
- response.setFindFails(true);
- response.setUserName("B");
- context.persistAndReturnSelf().using(response).fire(
- new Receiver<SimpleBarProxy>() {
+ response.setUserName("C");
- @Override
- public void onSuccess(SimpleBarProxy response) {
- response = checkSerialization(response);
- // The last-known state should be returned
- assertNotNull(response);
- assertEquals("B", response.getUserName());
+ // Attempting to use the now-deleted object should fail
+ context.persistAndReturnSelf().using(response).fire(new Receiver<SimpleBarProxy>() {
+ @Override
+ public void onFailure(ServerFailure error) {
+ assertTrue(error.getMessage().contains(
+ "The requested entity is not available on" + " the server"));
+ finishTestAndReset();
+ }
- SimpleBarRequest context = simpleBarRequest();
- // Ensure attempts to mutate deleted objects don't blow up
- response = context.edit(response);
- response.setUserName("C");
-
- // Attempting to use the now-deleted object should fail
- context.persistAndReturnSelf().using(response).fire(
- new Receiver<SimpleBarProxy>() {
- @Override
- public void onFailure(ServerFailure error) {
- assertTrue(error.getMessage().contains(
- "The requested entity is not available on"
- + " the server"));
- finishTestAndReset();
- }
-
- @Override
- public void onSuccess(SimpleBarProxy response) {
- response = checkSerialization(response);
- fail();
- }
- });
- }
- });
+ @Override
+ public void onSuccess(SimpleBarProxy response) {
+ response = checkSerialization(response);
+ fail();
+ }
+ });
}
});
+ }
+ });
}
public void testValueMethodInvocation() {
@@ -2501,40 +2423,39 @@
response.setSimpleValue(created);
// Retrieve
- req.persistAndReturnSelf().using(response).with(
- "simpleValue.simpleFoo", "simpleValue.simpleValue").to(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- SimpleValueProxy value = response.getSimpleValue();
- assertEquals(42, value.getNumber());
- assertEquals("Hello world!", value.getString());
- assertSame(response, value.getSimpleFoo());
- assertSame(value, value.getSimpleValue().get(0));
+ req.persistAndReturnSelf().using(response).with("simpleValue.simpleFoo",
+ "simpleValue.simpleValue").to(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ SimpleValueProxy value = response.getSimpleValue();
+ assertEquals(42, value.getNumber());
+ assertEquals("Hello world!", value.getString());
+ assertSame(response, value.getSimpleFoo());
+ assertSame(value, value.getSimpleValue().get(0));
- try {
- // Require owning object to be editable
- response.getSimpleValue().setNumber(43);
- fail("Should have thrown exception");
- } catch (IllegalStateException expected) {
- }
+ try {
+ // Require owning object to be editable
+ response.getSimpleValue().setNumber(43);
+ fail("Should have thrown exception");
+ } catch (IllegalStateException expected) {
+ }
- // Update
- SimpleFooRequest req = simpleFooRequest();
- response = req.edit(response);
- response.getSimpleValue().setNumber(43);
- req.persistAndReturnSelf().using(response).with("simpleValue").to(
- new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- response = checkSerialization(response);
- assertEquals(43, response.getSimpleValue().getNumber());
- finishTestAndReset();
- }
- }).fire();
- }
- }).fire();
+ // Update
+ SimpleFooRequest req = simpleFooRequest();
+ response = req.edit(response);
+ response.getSimpleValue().setNumber(43);
+ req.persistAndReturnSelf().using(response).with("simpleValue").to(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ response = checkSerialization(response);
+ assertEquals(43, response.getSimpleValue().getNumber());
+ finishTestAndReset();
+ }
+ }).fire();
+ }
+ }).fire();
}
});
}
@@ -2583,8 +2504,7 @@
@Override
public void onSuccess(SimpleFooProxy response) {
response = checkSerialization(response);
- assertEquals(43,
- response.getSimpleValues().get(0).getNumber());
+ assertEquals(43, response.getSimpleValues().get(0).getNumber());
finishTestAndReset();
}
}).fire();
@@ -2626,40 +2546,39 @@
*/
public void testValueObjectReturnedFromRequestIsImmutable() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().returnValueProxy().fire(
- new Receiver<SimpleValueProxy>() {
+ simpleFooRequest().returnValueProxy().fire(new Receiver<SimpleValueProxy>() {
+ @Override
+ public void onSuccess(SimpleValueProxy a) {
+ a = checkSerialization(a);
+ try {
+ a.setNumber(77);
+ fail();
+ } catch (IllegalStateException expected) {
+ }
+ try {
+ // Ensure Dates comply with ValueProxy mutation behaviors
+ a.getDate().setTime(1);
+ fail();
+ } catch (IllegalStateException expected) {
+ }
+ SimpleFooRequest ctx = simpleFooRequest();
+ final SimpleValueProxy toCheck = ctx.edit(a);
+ toCheck.setNumber(77);
+ toCheck.getDate().setTime(1);
+ ctx.returnValueProxy().fire(new Receiver<SimpleValueProxy>() {
@Override
- public void onSuccess(SimpleValueProxy a) {
- a = checkSerialization(a);
- try {
- a.setNumber(77);
- fail();
- } catch (IllegalStateException expected) {
- }
- try {
- // Ensure Dates comply with ValueProxy mutation behaviors
- a.getDate().setTime(1);
- fail();
- } catch (IllegalStateException expected) {
- }
- SimpleFooRequest ctx = simpleFooRequest();
- final SimpleValueProxy toCheck = ctx.edit(a);
- toCheck.setNumber(77);
- toCheck.getDate().setTime(1);
- ctx.returnValueProxy().fire(new Receiver<SimpleValueProxy>() {
- @Override
- public void onSuccess(SimpleValueProxy b) {
- b = checkSerialization(b);
- b = simpleFooRequest().edit(b);
- // Now check that same value is equal across contexts
- b.setNumber(77);
- b.setDate(new Date(1));
- checkEqualityAndHashcode(toCheck, b);
- finishTestAndReset();
- }
- });
+ public void onSuccess(SimpleValueProxy b) {
+ b = checkSerialization(b);
+ b = simpleFooRequest().edit(b);
+ // Now check that same value is equal across contexts
+ b.setNumber(77);
+ b.setDate(new Date(1));
+ checkEqualityAndHashcode(toCheck, b);
+ finishTestAndReset();
}
});
+ }
+ });
}
public void testValueObjectViolationsOnCreate() {
@@ -2672,14 +2591,26 @@
foo.setSimpleValue(value);
req.echo(foo).fire(new Receiver<SimpleFooProxy>() {
@Override
+ public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
+ assertEquals(1, errors.size());
+ ConstraintViolation<?> v = errors.iterator().next();
+ assertEquals(value, v.getRootBean());
+ assertEquals(value, v.getLeafBean());
+ assertEquals("shouldBeNull", v.getPropertyPath().toString());
+ // Forward to onViolation()
+ super.onConstraintViolation(errors);
+ }
+
+ @Override
public void onSuccess(SimpleFooProxy response) {
fail();
}
+ @SuppressWarnings("deprecation")
@Override
- public void onViolation(Set<Violation> errors) {
+ public void onViolation(Set<com.google.web.bindery.requestfactory.shared.Violation> errors) {
assertEquals(1, errors.size());
- Violation v = errors.iterator().next();
+ com.google.web.bindery.requestfactory.shared.Violation v = errors.iterator().next();
assertEquals(value, v.getInvalidProxy());
assertNull(v.getOriginalProxy());
assertEquals("shouldBeNull", v.getPath());
@@ -2691,35 +2622,47 @@
public void testValueObjectViolationsOnEdit() {
delayTestFinish(DELAY_TEST_FINISH);
- simpleFooRequest().returnValueProxy().fire(
- new Receiver<SimpleValueProxy>() {
+ simpleFooRequest().returnValueProxy().fire(new Receiver<SimpleValueProxy>() {
+ @Override
+ public void onSuccess(SimpleValueProxy response) {
+ final SimpleValueProxy original = checkSerialization(response);
+ SimpleFooRequest req = simpleFooRequest();
+ final SimpleValueProxy value = req.edit(response);
+ value.setShouldBeNull("Hello world");
+ SimpleFooProxy foo = req.create(SimpleFooProxy.class);
+ foo.setSimpleValue(value);
+ req.echo(foo).fire(new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleValueProxy response) {
- final SimpleValueProxy original = checkSerialization(response);
- SimpleFooRequest req = simpleFooRequest();
- final SimpleValueProxy value = req.edit(response);
- value.setShouldBeNull("Hello world");
- SimpleFooProxy foo = req.create(SimpleFooProxy.class);
- foo.setSimpleValue(value);
- req.echo(foo).fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- fail();
- }
+ public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
+ assertEquals(1, errors.size());
+ ConstraintViolation<?> v = errors.iterator().next();
+ assertEquals(value, v.getRootBean());
+ assertEquals(value, v.getLeafBean());
+ assertEquals("shouldBeNull", v.getPropertyPath().toString());
+
+ // Forward to onViolation()
+ super.onConstraintViolation(errors);
+ }
- @Override
- public void onViolation(Set<Violation> errors) {
- assertEquals(1, errors.size());
- Violation v = errors.iterator().next();
- assertEquals(value, v.getInvalidProxy());
- assertEquals(original, v.getOriginalProxy());
- assertEquals("shouldBeNull", v.getPath());
- assertNull(v.getProxyId());
- finishTestAndReset();
- }
- });
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ fail();
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void onViolation(Set<com.google.web.bindery.requestfactory.shared.Violation> errors) {
+ assertEquals(1, errors.size());
+ com.google.web.bindery.requestfactory.shared.Violation v = errors.iterator().next();
+ assertEquals(value, v.getInvalidProxy());
+ assertEquals(original, v.getOriginalProxy());
+ assertEquals("shouldBeNull", v.getPath());
+ assertNull(v.getProxyId());
+ finishTestAndReset();
}
});
+ }
+ });
}
public void testViolationAbsent() {
@@ -2745,8 +2688,7 @@
SimpleFooRequest context = simpleFooRequest();
SimpleFooProxy newFoo = context.create(SimpleFooProxy.class);
- final Request<SimpleFooProxy> create = context.persistAndReturnSelf().using(
- newFoo);
+ final Request<SimpleFooProxy> create = context.persistAndReturnSelf().using(newFoo);
new FailFixAndRefire<SimpleFooProxy>(newFoo, context, create).doTest();
}
@@ -2767,8 +2709,7 @@
public void onSuccess(SimpleFooProxy returned) {
returned = checkSerialization(returned);
SimpleFooRequest context = simpleFooRequest();
- Request<SimpleFooProxy> editRequest = context.persistAndReturnSelf().using(
- returned);
+ Request<SimpleFooProxy> editRequest = context.persistAndReturnSelf().using(returned);
new FailFixAndRefire<SimpleFooProxy>(returned, context, editRequest).doTest();
}
});
@@ -2813,8 +2754,7 @@
private Request<SimpleFooProxy> fooCreationRequest() {
SimpleFooRequest context = simpleFooRequest();
SimpleFooProxy originalFoo = context.create(SimpleFooProxy.class);
- final Request<SimpleFooProxy> fooReq = context.persistAndReturnSelf().using(
- originalFoo);
+ final Request<SimpleFooProxy> fooReq = context.persistAndReturnSelf().using(originalFoo);
originalFoo = context.edit(originalFoo);
originalFoo.setUserName("GWT User");
return fooReq;
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java
index 66b8cc2..963b694 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java
@@ -35,12 +35,13 @@
import com.google.web.bindery.requestfactory.shared.SimpleBarProxy;
import com.google.web.bindery.requestfactory.shared.SimpleFooProxy;
import com.google.web.bindery.requestfactory.shared.SimpleFooRequest;
-import com.google.web.bindery.requestfactory.shared.Violation;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
+import javax.validation.ConstraintViolation;
+
/**
* Integration test of the Editor framework. Only tests for
* RequestFactory-specific features belong here; all other tests should use the
@@ -51,8 +52,7 @@
* DO NOT USE finishTest(). Instead, call finishTestAndReset();
*/
- static class SimpleBarEditor implements Editor<SimpleBarProxy>,
- HasRequestContext<SimpleBarProxy> {
+ static class SimpleBarEditor implements Editor<SimpleBarProxy>, HasRequestContext<SimpleBarProxy> {
protected final SimpleEditor<String> userName = SimpleEditor.of();
RequestContext ctx;
@@ -69,8 +69,7 @@
final SimpleEditor<String> barName = SimpleEditor.of();
}
- interface SimpleFooDriver extends
- RequestFactoryEditorDriver<SimpleFooProxy, SimpleFooEditor> {
+ interface SimpleFooDriver extends RequestFactoryEditorDriver<SimpleFooProxy, SimpleFooEditor> {
}
static class SimpleFooEditor implements HasEditorErrors<SimpleFooProxy> {
@@ -85,12 +84,13 @@
@Path("barField.userName")
final SimpleEditor<String> barName = SimpleEditor.of();
- final ListEditor<SimpleFooProxy, SimpleFooBarNameOnlyEditor> selfOneToManyField = ListEditor.of(new EditorSource<SimpleFooBarNameOnlyEditor>() {
- @Override
- public SimpleFooBarNameOnlyEditor create(int index) {
- return new SimpleFooBarNameOnlyEditor();
- }
- });
+ final ListEditor<SimpleFooProxy, SimpleFooBarNameOnlyEditor> selfOneToManyField = ListEditor
+ .of(new EditorSource<SimpleFooBarNameOnlyEditor>() {
+ @Override
+ public SimpleFooBarNameOnlyEditor create(int index) {
+ return new SimpleFooBarNameOnlyEditor();
+ }
+ });
private final SimpleBarEditor barEditor = new SimpleBarEditor();
@@ -132,36 +132,80 @@
final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
driver.initialize(req, editor);
final String[] paths = driver.getPaths();
- assertEquals(Arrays.asList("barField", "selfOneToManyField",
- "selfOneToManyField.barField"), Arrays.asList(paths));
+ assertEquals(Arrays.asList("barField", "selfOneToManyField", "selfOneToManyField.barField"),
+ Arrays.asList(paths));
- req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(
+ req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+
+ SimpleFooRequest context = req.simpleFooRequest();
+ driver.edit(response, context);
+ assertSame(context, editor.barEditor().ctx);
+ context.persistAndReturnSelf().using(response).with(paths).to(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ assertEquals("EditorFooTest", response.getUserName());
+ assertEquals("EditorBarTest", response.getBarField().getUserName());
+ finishTestAndReset();
+ }
+ });
+ assertEquals("GWT", editor.userName.getValue());
+ assertEquals("FOO", editor.barEditor().userName.getValue());
+ assertEquals("FOO", editor.barName.getValue());
+ editor.userName.setValue("EditorFooTest");
+ // When there are duplicate paths, last declared editor wins
+ editor.barEditor().userName.setValue("EditorBarTest");
+ editor.barName.setValue("ignored 1");
+ editor.selfOneToManyField.getEditors().get(0).barName.setValue("ignored 2");
+ driver.flush().fire();
+ }
+ });
+ }
+
+ public void testConstraintViolations() {
+ delayTestFinish(TEST_TIMEOUT);
+ final SimpleFooEditor editor = new SimpleFooEditor();
+
+ final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
+ driver.initialize(req, editor);
+
+ req.simpleFooRequest().findSimpleFooById(1L).with(driver.getPaths()).fire(
new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
SimpleFooRequest context = req.simpleFooRequest();
driver.edit(response, context);
- assertSame(context, editor.barEditor().ctx);
- context.persistAndReturnSelf().using(response).with(paths).to(
+ context.persistAndReturnSelf().using(response).with(driver.getPaths()).to(
new Receiver<SimpleFooProxy>() {
@Override
- public void onSuccess(SimpleFooProxy response) {
- assertEquals("EditorFooTest", response.getUserName());
- assertEquals("EditorBarTest",
- response.getBarField().getUserName());
+ public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
+ assertEquals(1, errors.size());
+ ConstraintViolation<?> v = errors.iterator().next();
+
+ driver.setConstraintViolations(errors);
+ assertEquals(1, editor.errors.size());
+ EditorError error = editor.errors.get(0);
+ assertEquals("userName", error.getAbsolutePath());
+ assertSame(editor.userName, error.getEditor());
+ assertTrue(error.getMessage().length() > 0);
+ assertEquals("userName", error.getPath());
+ assertSame(v, error.getUserData());
+ assertNull(error.getValue());
finishTestAndReset();
}
+
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ fail("Expected errors. You may be missing jars, see "
+ + "the comment in RequestFactoryTest.ShouldNotSucceedReceiver.onSuccess");
+ }
});
- assertEquals("GWT", editor.userName.getValue());
- assertEquals("FOO", editor.barEditor().userName.getValue());
- assertEquals("FOO", editor.barName.getValue());
- editor.userName.setValue("EditorFooTest");
- // When there are duplicate paths, last declared editor wins
- editor.barEditor().userName.setValue("EditorBarTest");
- editor.barName.setValue("ignored 1");
- editor.selfOneToManyField.getEditors().get(0).barName.setValue(
- "ignored 2");
+ // Set to an illegal value
+ editor.userName.setValue("");
+
driver.flush().fire();
}
});
@@ -202,18 +246,18 @@
SimpleFooRequest context = req.simpleFooRequest();
driver.edit(response, context);
editor.userName.setValue("One");
- context.persistAndReturnSelf().using(response).with(
- driver.getPaths()).to(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- assertEquals("One", response.getUserName());
- // just testing that it doesn't throw (see issue 5752)
- driver.edit(response, req.simpleFooRequest());
- editor.userName.setValue("Two");
- driver.flush();
- finishTestAndReset();
- }
- });
+ context.persistAndReturnSelf().using(response).with(driver.getPaths()).to(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ assertEquals("One", response.getUserName());
+ // just testing that it doesn't throw (see issue 5752)
+ driver.edit(response, req.simpleFooRequest());
+ editor.userName.setValue("Two");
+ driver.flush();
+ finishTestAndReset();
+ }
+ });
// The fire() will freeze the proxies and lock the context
driver.flush().fire();
}
@@ -228,48 +272,45 @@
driver.initialize(req, editor);
String[] paths = driver.getPaths();
- assertEquals(Arrays.asList("barField", "selfOneToManyField",
- "selfOneToManyField.barField"), Arrays.asList(paths));
+ assertEquals(Arrays.asList("barField", "selfOneToManyField", "selfOneToManyField.barField"),
+ Arrays.asList(paths));
- req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(
- new Receiver<SimpleFooProxy>() {
+ req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ // Set up driver in read-only mode
+ driver.edit(response, null);
+ assertNotNull(editor.delegate.subscribe());
+
+ // Simulate edits occurring elsewhere in the module
+ SimpleFooRequest context = req.simpleFooRequest();
+ Request<SimpleFooProxy> request = context.persistAndReturnSelf().using(response);
+ SimpleBarProxy newBar = context.create(SimpleBarProxy.class);
+ newBar = context.edit(newBar);
+ newBar.setUserName("newBar");
+ response = context.edit(response);
+ response.setBarField(newBar);
+ response.setUserName("updated");
+
+ request.fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy response) {
- // Set up driver in read-only mode
- driver.edit(response, null);
- assertNotNull(editor.delegate.subscribe());
-
- // Simulate edits occurring elsewhere in the module
- SimpleFooRequest context = req.simpleFooRequest();
- Request<SimpleFooProxy> request = context.persistAndReturnSelf().using(
- response);
- SimpleBarProxy newBar = context.create(SimpleBarProxy.class);
- newBar = context.edit(newBar);
- newBar.setUserName("newBar");
- response = context.edit(response);
- response.setBarField(newBar);
- response.setUserName("updated");
-
- request.fire(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- // EventBus notifications occur after the onSuccess()
- Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
- public boolean execute() {
- if ("updated".equals(editor.userName.getValue())) {
- assertEquals("updated", editor.userName.getValue());
- assertEquals("newBar",
- editor.barEditor().userName.getValue());
- finishTestAndReset();
- return false;
- }
- return true;
- }
- }, 50);
+ // EventBus notifications occur after the onSuccess()
+ Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
+ public boolean execute() {
+ if ("updated".equals(editor.userName.getValue())) {
+ assertEquals("updated", editor.userName.getValue());
+ assertEquals("newBar", editor.barEditor().userName.getValue());
+ finishTestAndReset();
+ return false;
+ }
+ return true;
}
- });
+ }, 50);
}
});
+ }
+ });
}
public void testViolations() {
@@ -286,31 +327,32 @@
SimpleFooRequest context = req.simpleFooRequest();
driver.edit(response, context);
- context.persistAndReturnSelf().using(response).with(
- driver.getPaths()).to(new Receiver<SimpleFooProxy>() {
- @Override
- public void onSuccess(SimpleFooProxy response) {
- fail("Expected errors. You may be missing jars, see "
- + "the comment in RequestFactoryTest.ShouldNotSucceedReceiver.onSuccess");
- }
+ context.persistAndReturnSelf().using(response).with(driver.getPaths()).to(
+ new Receiver<SimpleFooProxy>() {
+ @Override
+ public void onSuccess(SimpleFooProxy response) {
+ fail("Expected errors. You may be missing jars, see "
+ + "the comment in RequestFactoryTest.ShouldNotSucceedReceiver.onSuccess");
+ }
- @Override
- public void onViolation(Set<Violation> errors) {
- assertEquals(1, errors.size());
- Violation v = errors.iterator().next();
+ @SuppressWarnings("deprecation")
+ @Override
+ public void onViolation(Set<com.google.web.bindery.requestfactory.shared.Violation> errors) {
+ assertEquals(1, errors.size());
+ com.google.web.bindery.requestfactory.shared.Violation v = errors.iterator().next();
- driver.setViolations(errors);
- assertEquals(1, editor.errors.size());
- EditorError error = editor.errors.get(0);
- assertEquals("userName", error.getAbsolutePath());
- assertSame(editor.userName, error.getEditor());
- assertTrue(error.getMessage().length() > 0);
- assertEquals("userName", error.getPath());
- assertSame(v, error.getUserData());
- assertNull(error.getValue());
- finishTestAndReset();
- }
- });
+ driver.setViolations(errors);
+ assertEquals(1, editor.errors.size());
+ EditorError error = editor.errors.get(0);
+ assertEquals("userName", error.getAbsolutePath());
+ assertSame(editor.userName, error.getEditor());
+ assertTrue(error.getMessage().length() > 0);
+ assertEquals("userName", error.getPath());
+ assertSame(v, error.getUserData());
+ assertNull(error.getValue());
+ finishTestAndReset();
+ }
+ });
// Set to an illegal value
editor.userName.setValue("");