Revision: 8862
Author: [email protected]
Date: Thu Sep 23 21:25:47 2010
Log: Fixes Collection of value types and proxies as parameters to RequestFactory
methods. Also fixes Enum and Date params.

Review at http://gwt-code-reviews.appspot.com/883802

http://code.google.com/p/google-web-toolkit/source/detail?r=8862

Added:
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/HasWireFormatId.java
Modified:
/trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractEnumRequest.java
 /trunk/user/src/com/google/gwt/requestfactory/client/impl/JsoList.java
 /trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyImpl.java
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
 /trunk/user/src/com/google/gwt/requestfactory/shared/impl/RequestData.java
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
 /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java
 /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleFooRequest.java

=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/requestfactory/shared/impl/HasWireFormatId.java Thu Sep 23 21:25:47 2010
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.requestfactory.shared.impl;
+
+/**
+ * <p>
+ * <span style="color:red">Experimental API: This class is still under rapid
+ * development, and is very likely to be deleted. Use it at your own risk.
+ * </span>
+ * </p>
+ * Shared interface for retrieving wireformat id.
+ */
+public interface HasWireFormatId {
+  String wireFormatId();
+}
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractEnumRequest.java Wed Sep 22 07:25:43 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractEnumRequest.java Thu Sep 23 21:25:47 2010
@@ -28,7 +28,7 @@
  * @param <E> an enum type
  */
 public abstract class AbstractEnumRequest<E extends Enum<E>> extends
-    AbstractPrimitiveRequest<Integer, AbstractEnumRequest<E>> {
+    AbstractPrimitiveRequest<E, AbstractEnumRequest<E>> {

   private final E[] enumValues;

@@ -42,7 +42,8 @@
     int ordinal = Integer.valueOf(responseText);
     for (E e : enumValues) {
       if (ordinal == e.ordinal()) {
-        succeed(ordinal);
+        succeed(e);
+        return;
       }
     }
throw new IllegalArgumentException("Invalid enum ordinal value " + ordinal);
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/JsoList.java Wed Sep 22 11:52:53 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/JsoList.java Thu Sep 23 21:25:47 2010
@@ -129,7 +129,8 @@
       }
     } catch (final Exception ex) {
       throw new IllegalStateException(
-          "Index " + i + " has invalid " + " value " + get(jso, i)
+          "Index " + i + " "
+              + "has invalid " + " value " + get(jso, i)
               + " for type " + type);
     }

=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyImpl.java Thu Sep 23 15:15:17 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyImpl.java Thu Sep 23 21:25:47 2010
@@ -16,9 +16,9 @@
 package com.google.gwt.requestfactory.client.impl;

 import com.google.gwt.requestfactory.shared.EntityProxy;
-
 import com.google.gwt.requestfactory.shared.EntityProxyId;
 import com.google.gwt.requestfactory.shared.impl.CollectionProperty;
+import com.google.gwt.requestfactory.shared.impl.HasWireFormatId;
 import com.google.gwt.requestfactory.shared.impl.Property;

 /**
@@ -34,7 +34,7 @@
  * is fixed it might be worth abandoning the instanceof capability, needs
  * thinking.
  */
-public class ProxyImpl implements EntityProxy {
+public class ProxyImpl implements EntityProxy, HasWireFormatId {

   protected static String wireFormatId(String id, boolean isFuture,
       ProxySchema<?> schema) {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java Thu Sep 23 15:15:17 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java Thu Sep 23 21:25:47 2010
@@ -198,7 +198,8 @@
    * contributed from EntityProxy are excluded.
    */
   private List<EntityProperty> computeEntityPropertiesFromProxyType(
-      JClassType publicProxyType) {
+      JClassType publicProxyType, TreeLogger logger)
+      throws UnableToCompleteException {
List<EntityProperty> entityProperties = new ArrayList<EntityProperty>();
     Set<String> propertyNames = new HashSet<String>();

@@ -208,7 +209,7 @@
         continue;
       }

- EntityProperty entityProperty = maybeComputePropertyFromMethod(method); + EntityProperty entityProperty = maybeComputePropertyFromMethod(method, logger);
       if (entityProperty != null) {
         String propertyName = entityProperty.getName();
         if (!propertyNames.contains(propertyName)) {
@@ -222,8 +223,8 @@
   };

   private void ensureProxyType(TreeLogger logger,
-      GeneratorContext generatorContext, String packageName,
-      JClassType publicProxyType) throws UnableToCompleteException {
+      GeneratorContext generatorContext, JClassType publicProxyType)
+      throws UnableToCompleteException {
     TypeOracle typeOracle = generatorContext.getTypeOracle();

     if (!publicProxyType.isAssignableTo(entityProxyType)) {
@@ -236,6 +237,7 @@
     if (generatedProxyTypes.contains(publicProxyType)) {
       return;
     }
+    String packageName = publicProxyType.getPackage().getName();

     String proxyImplTypeName = publicProxyType.getName() + "Impl";
     PrintWriter pw = generatorContext.tryCreate(logger, packageName,
@@ -272,7 +274,7 @@
       f.setSuperclass(ProxyImpl.class.getSimpleName());
       f.addImplementedInterface(publicProxyType.getName());

- List<EntityProperty> entityProperties = computeEntityPropertiesFromProxyType(publicProxyType); + List<EntityProperty> entityProperties = computeEntityPropertiesFromProxyType(publicProxyType, logger);
       for (EntityProperty entityProperty : entityProperties) {
         JType type = entityProperty.getType();
         if (type.isPrimitive() == null) {
@@ -307,7 +309,7 @@
         }
       }

-      printSchema(typeOracle, publicProxyType, proxyImplTypeName, sw);
+ printSchema(typeOracle, publicProxyType, proxyImplTypeName, sw, logger);

       sw.println();
String simpleImplName = publicProxyType.getSimpleSourceName() + "Impl";
@@ -373,8 +375,7 @@
     generatedProxyTypes.add(publicProxyType);
     // ensure generatation of transitive dependencies
     for (JClassType type : transitiveDeps) {
- ensureProxyType(logger, generatorContext, type.getPackage().getName(),
-          type);
+      ensureProxyType(logger, generatorContext, type);
     }
   }

@@ -643,10 +644,17 @@

     // write each method.
     for (JMethod method : selectorInterface.getOverridableMethods()) {
- JClassType returnType = method.getReturnType().isParameterized().getTypeArgs()[0];
-
-      ensureProxyType(logger, generatorContext,
-          returnType.getPackage().getName(), returnType);
+      JParameterizedType parameterizedType = method.getReturnType()
+          .isParameterized();
+      if (parameterizedType == null) {
+        logger.log(TreeLogger.ERROR, String.format(
+ "Illegal return type for %s. Methods of %s must return Request<T>.",
+            method.getName(), selectorInterface.getName()));
+        throw new UnableToCompleteException();
+      }
+      JClassType returnType = parameterizedType.getTypeArgs()[0];
+
+      ensureProxyType(logger, generatorContext, returnType);

       String operationName = selectorInterface.getQualifiedBinaryName()
+ ReflectionBasedOperationRegistry.SCOPE_SEPARATOR + method.getName();
@@ -658,6 +666,20 @@
       String extraArgs = "";
       // TODO: refactor this into some kind of extensible map lookup
       // check for ProxyListRequest<T> or ProxySetRequest<T>
+      if (method.getReturnType().isArray() != null) {
+        logger.log(TreeLogger.ERROR, String.format(
+ "Illegal return type for %s. Methods of %s cannot return array.",
+            method.getName(), selectorInterface.getName()));
+        throw new UnableToCompleteException();
+      }
+      for (JParameter param : method.getParameters()) {
+        if (param.getType().isArray() != null) {
+          logger.log(TreeLogger.ERROR, String.format(
+ "Illegal param type %s for %s. Methods of %s cannot take array parameters.", + param.getName(), method.getName(), selectorInterface.getName()));
+          throw new UnableToCompleteException();
+        }
+      }
       if (isProxyCollectionRequest(typeOracle, requestType)) {
         Class<?> colType = getCollectionType(typeOracle, requestType);
         assert colType != null;
@@ -712,7 +734,8 @@
         requestClassName = AbstractBigIntegerRequest.class.getName();
       } else if (isEnumRequest(typeOracle, requestType)) {
         requestClassName = AbstractEnumRequest.class.getName();
-        extraArgs = ", " + requestType.isParameterized().getTypeArgs()[0]
+ JClassType enumType = requestType.isParameterized().getTypeArgs()[0];
+        extraArgs = ", " + enumType.getQualifiedSourceName()
             + ".values()";
       } else if (isVoidRequest(typeOracle, requestType)) {
         requestClassName = AbstractVoidRequest.class.getName();
@@ -820,10 +843,7 @@
         sb.append("factory.getWireFormat(" + parameter.getName() + ")");
         continue;
       }
-      JParameterizedType params = paramType.isParameterized();
-      if (params != null) {
-        classType = params.getTypeArgs()[0];
-      }
+
       if (classType != null && classType.isAssignableTo(entityProxyType)) {
sb.append("((" + classType.getQualifiedBinaryName() + "Impl" + ")");
       }
@@ -946,18 +966,31 @@
* Returns an {...@link EntityProperty} if the method looks like a bean property
    * accessor or <code>null</code>.
    */
-  private EntityProperty maybeComputePropertyFromMethod(JMethod method) {
+  private EntityProperty maybeComputePropertyFromMethod(JMethod method,
+      TreeLogger logger) throws UnableToCompleteException {
     String propertyName = null;
     JType propertyType = null;
     String methodName = method.getName();
     if (methodName.startsWith("get")) {
       propertyName = Introspector.decapitalize(methodName.substring(3));
       propertyType = method.getReturnType();
+      if (propertyType.isArray() != null) {
+        logger.log(TreeLogger.ERROR, "Method " + methodName
+        + " on " + method.getEnclosingType().getQualifiedSourceName()
+        + " may not return a Java array.");
+        throw new UnableToCompleteException();
+      }
     } else if (methodName.startsWith("set")) {
       propertyName = Introspector.decapitalize(methodName.substring(3));
       JParameter[] parameters = method.getParameters();
       if (parameters.length > 0) {
         propertyType = parameters[parameters.length - 1].getType();
+        if (propertyType.isArray() != null) {
+          logger.log(TreeLogger.ERROR, "Method " + methodName
+          + " on " + method.getEnclosingType().getQualifiedSourceName()
+          + " may accept a Java array as a parameter.");
+          throw new UnableToCompleteException();
+        }
       }
     }

@@ -1009,12 +1042,14 @@
    * @param publicProxyType
    * @param proxyImplTypeName
    * @param sw
+   * @param logger
    * @return
    * @throws UnableToCompleteException
    */

   private JClassType printSchema(TypeOracle typeOracle,
- JClassType publicProxyType, String proxyImplTypeName, SourceWriter sw) { + JClassType publicProxyType, String proxyImplTypeName, SourceWriter sw,
+      TreeLogger logger) throws UnableToCompleteException {
     sw.println(String.format(
         "public static class MySchema extends ProxySchema<%s> {",
         proxyImplTypeName));
@@ -1034,7 +1069,8 @@
       throw new RuntimeException(e);
     }

- List<EntityProperty> entityProperties = computeEntityPropertiesFromProxyType(publicProxyType); + List<EntityProperty> entityProperties = computeEntityPropertiesFromProxyType(publicProxyType,
+        logger);
     for (EntityProperty entityProperty : entityProperties) {
       sw.println(String.format("set.add(%s);", entityProperty.getName()));
     }
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java Thu Sep 23 15:15:17 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java Thu Sep 23 21:25:47 2010
@@ -880,7 +880,7 @@
     } else if (result instanceof Number || result instanceof Enum<?>
         || result instanceof String || result instanceof Date
         || result instanceof Character || result instanceof Boolean) {
-      envelop.put(RESULT_TOKEN, result);
+      envelop.put(RESULT_TOKEN, encodePropertyValue(result));
     } else {
       Class<? extends EntityProxy> returnType = null;
if (operation.getDomainClassName().equals(FindService.class.getName())) {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/impl/RequestData.java Thu Sep 23 15:15:17 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/shared/impl/RequestData.java Thu Sep 23 21:25:47 2010
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.requestfactory.shared.impl;

+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -92,7 +93,7 @@
     if (parameters != null) {
       for (int i = 0; i < parameters.length; i++) {
         Object value = parameters[i];
-        requestMap.put(PARAM_TOKEN + i, value.toString());
+        requestMap.put(PARAM_TOKEN + i, asJsonString(value));
       }
     }
     if (contentData != null) {
@@ -112,4 +113,44 @@
     }
     return requestMap;
   }
-}
+
+  private String asJsonString(Object value) {
+    if (value == null) {
+      return "null";
+    }
+
+    if (value instanceof Iterable) {
+      StringBuffer toReturn = new StringBuffer();
+      toReturn.append('[');
+      boolean first = true;
+      for (Object val : ((Iterable) value)) {
+        if (!first) {
+          toReturn.append(',');
+        } else {
+          first = false;
+        }
+        toReturn.append(asJsonString(val));
+      }
+      toReturn.append(']');
+      return toReturn.toString();
+    }
+
+    if (value instanceof HasWireFormatId) {
+      return "\"" + ((HasWireFormatId) value).wireFormatId() + "\"";
+    }
+
+    /*
+     * Roughly parallels JsonRequestProcessor.encodePropertyValue.
+ * Everything is toString(), except Date and Enum which must become numbers.
+     */
+    if (value instanceof Date) {
+      return asJsonString(((Date) value).getTime());
+    }
+
+    if (value instanceof Enum) {
+      return asJsonString(((Enum) value).ordinal());
+    }
+
+    return value.toString();
+  }
+}
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Thu Sep 23 15:15:17 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Thu Sep 23 21:25:47 2010
@@ -23,12 +23,15 @@
 import com.google.gwt.requestfactory.shared.Request;
 import com.google.gwt.requestfactory.shared.ServerFailure;
 import com.google.gwt.requestfactory.shared.SimpleBarProxy;
+import com.google.gwt.requestfactory.shared.SimpleEnum;
 import com.google.gwt.requestfactory.shared.SimpleFooProxy;
 import com.google.gwt.requestfactory.shared.Violation;

+import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 import java.util.Set;

@@ -92,16 +95,16 @@
         }
       });
     }
-
-    void doVoidTest() {
-      voidReturnExpected = true;
-      doTest();
-    }

     void doTest() {
       proxy.setUserName("a"); // too short
       request.fire(this);
     }
+
+    void doVoidTest() {
+      voidReturnExpected = true;
+      doTest();
+    }
   }

   public <T extends EntityProxy> void assertContains(Collection<T> col,
@@ -188,44 +191,6 @@
       }
     });
   }
-
-  public void testHistoryToken() {
-    delayTestFinish(5000);
-    final SimpleBarProxy foo = req.create(SimpleBarProxy.class);
-    final EntityProxyId<SimpleBarProxy> futureId = foo.stableId();
-    final String futureToken = req.getHistoryToken(futureId);
-
-    // Check that a newly-created object's token can be found
-    assertEquals(futureId, req.getProxyId(futureToken));
-    assertEquals(req.getClass(futureId), req.getClass(futureToken));
-
- Request<SimpleBarProxy> fooReq = req.simpleBarRequest().persistAndReturnSelf(
-        foo);
-    fooReq.fire(new Receiver<SimpleBarProxy>() {
-      @Override
-      public void onSuccess(final SimpleBarProxy returned) {
-        EntityProxyId<SimpleBarProxy> persistedId = returned.stableId();
-        String persistedToken = req.getHistoryToken(returned.stableId());
-
-        // Expect variations after persist
-        assertFalse(futureToken.equals(persistedToken));
-
-        // Make sure the token is stable after persist using the future id
-        assertEquals(persistedToken, req.getHistoryToken(futureId));
-
-        // Check that the persisted object can be found with future token
-        assertEquals(futureId, req.getProxyId(futureToken));
-        assertEquals(futureId, req.getProxyId(persistedToken));
-        assertEquals(req.getClass(futureId), req.getClass(persistedToken));
-
-        assertEquals(persistedId, req.getProxyId(futureToken));
-        assertEquals(persistedId, req.getProxyId(persistedToken));
-        assertEquals(req.getClass(persistedId), req.getClass(futureToken));
-
-        finishTestAndReset();
-      }
-    });
-  }

   public void testFetchEntity() {
     delayTestFinish(5000);
@@ -293,6 +258,24 @@
   public void testGetEventBus() {
     assertEquals(eventBus, req.getEventBus());
   }
+
+  public void testGetListLongId() {
+    delayTestFinish(5000);
+
+    // Long ids
+    req.simpleFooRequest().findAll().with("barField.userName").fire(
+        new Receiver<List<SimpleFooProxy>>() {
+          @Override
+          public void onSuccess(List<SimpleFooProxy> response) {
+            assertEquals(1, response.size());
+            for (SimpleFooProxy foo : response) {
+              assertNotNull(foo.stableId());
+              assertEquals("FOO", foo.getBarField().getUserName());
+            }
+            finishTestAndReset();
+          }
+        });
+  }

   public void testGetListStringId() {
     delayTestFinish(5000);
@@ -311,22 +294,42 @@
     });
   }

-  public void testGetListLongId() {
+  public void testHistoryToken() {
     delayTestFinish(5000);
-
-    // Long ids
-    req.simpleFooRequest().findAll().with("barField.userName").fire(
-        new Receiver<List<SimpleFooProxy>>() {
-          @Override
-          public void onSuccess(List<SimpleFooProxy> response) {
-            assertEquals(1, response.size());
-            for (SimpleFooProxy foo : response) {
-              assertNotNull(foo.stableId());
-              assertEquals("FOO", foo.getBarField().getUserName());
-            }
-            finishTestAndReset();
-          }
-        });
+    final SimpleBarProxy foo = req.create(SimpleBarProxy.class);
+    final EntityProxyId<SimpleBarProxy> futureId = foo.stableId();
+    final String futureToken = req.getHistoryToken(futureId);
+
+    // Check that a newly-created object's token can be found
+    assertEquals(futureId, req.getProxyId(futureToken));
+    assertEquals(req.getClass(futureId), req.getClass(futureToken));
+
+ Request<SimpleBarProxy> fooReq = req.simpleBarRequest().persistAndReturnSelf(
+        foo);
+    fooReq.fire(new Receiver<SimpleBarProxy>() {
+      @Override
+      public void onSuccess(final SimpleBarProxy returned) {
+        EntityProxyId<SimpleBarProxy> persistedId = returned.stableId();
+        String persistedToken = req.getHistoryToken(returned.stableId());
+
+        // Expect variations after persist
+        assertFalse(futureToken.equals(persistedToken));
+
+        // Make sure the token is stable after persist using the future id
+        assertEquals(persistedToken, req.getHistoryToken(futureId));
+
+        // Check that the persisted object can be found with future token
+        assertEquals(futureId, req.getProxyId(futureToken));
+        assertEquals(futureId, req.getProxyId(persistedToken));
+        assertEquals(req.getClass(futureId), req.getClass(persistedToken));
+
+        assertEquals(persistedId, req.getProxyId(futureToken));
+        assertEquals(persistedId, req.getProxyId(persistedToken));
+        assertEquals(req.getClass(persistedId), req.getClass(futureToken));
+
+        finishTestAndReset();
+      }
+    });
   }

   /*
@@ -859,10 +862,11 @@
* TODO: all these tests should check the final values. It will be easy when
   * we have better persistence than the singleton pattern.
   */
-  public void testPersistValueSetAlreadyExists() {
+  public void testPersistValueSetAddNew() {
     delayTestFinish(5000);
-
-    req.simpleBarRequest().findSimpleBarById("1L").fire(
+    SimpleBarProxy newBar = req.create(SimpleBarProxy.class);
+
+    req.simpleBarRequest().persistAndReturnSelf(newBar).fire(
         new Receiver<SimpleBarProxy>() {
           @Override
           public void onSuccess(final SimpleBarProxy barProxy) {
@@ -878,13 +882,12 @@
                     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) {
- assertEquals(response.getOneToManySetField().size(),
-                            listCount);
+                        assertEquals(listCount + 1,
+                            response.getOneToManySetField().size());
                         assertContains(response.getOneToManySetField(),
                             barProxy);
                         finishTestAndReset();
@@ -900,11 +903,10 @@
* TODO: all these tests should check the final values. It will be easy when
   * we have better persistence than the singleton pattern.
   */
-  public void testPersistValueSetAddNew() {
+  public void testPersistValueSetAlreadyExists() {
     delayTestFinish(5000);
-    SimpleBarProxy newBar = req.create(SimpleBarProxy.class);
-
-    req.simpleBarRequest().persistAndReturnSelf(newBar).fire(
+
+    req.simpleBarRequest().findSimpleBarById("1L").fire(
         new Receiver<SimpleBarProxy>() {
           @Override
           public void onSuccess(final SimpleBarProxy barProxy) {
@@ -920,12 +922,13 @@
                     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) {
-                        assertEquals(listCount + 1,
-                            response.getOneToManySetField().size());
+ assertEquals(response.getOneToManySetField().size(),
+                            listCount);
                         assertContains(response.getOneToManySetField(),
                             barProxy);
                         finishTestAndReset();
@@ -993,6 +996,70 @@
       }
     });
   }
+
+  public void testPrimitiveListAsParameter() {
+    delayTestFinish(5000);
+    final Request<SimpleFooProxy> fooReq =
+        req.simpleFooRequest().findSimpleFooById(999L);
+    fooReq.fire(new Receiver<SimpleFooProxy>() {
+      public void onSuccess(SimpleFooProxy response) {
+         final Request<Integer> sumReq = req.simpleFooRequest().sum(
+             response, Arrays.asList(1,2,3));
+         sumReq.fire(new Receiver<Integer>() {
+           @Override
+           public void onSuccess(Integer response) {
+             assertEquals(6, response.intValue());
+             finishTestAndReset();
+           }
+         });
+      }
+    });
+  }
+
+  public void testPrimitiveListBooleanAsParameter() {
+    delayTestFinish(5000);
+
+    Request<Boolean> procReq = req.simpleFooRequest().processBooleanList(
+        Arrays.asList(true, false));
+
+    procReq.fire(new Receiver<Boolean>() {
+      @Override
+      public void onSuccess(Boolean response) {
+        assertEquals(true, (boolean) response);
+        finishTestAndReset();
+      }
+    });
+  }
+
+  public void testPrimitiveListDateAsParameter() {
+    delayTestFinish(5000);
+
+    final Date date = new Date(90, 0, 1);
+    Request<Date> procReq = req.simpleFooRequest().processDateList(
+             Arrays.asList(date));
+    procReq.fire(new Receiver<Date>() {
+      @Override
+      public void onSuccess(Date response) {
+        assertEquals(date, response);
+        finishTestAndReset();
+      }
+    });
+  }
+
+  public void testPrimitiveListEnumAsParameter() {
+    delayTestFinish(5000);
+
+    Request<SimpleEnum> procReq = req.simpleFooRequest().processEnumList(
+        Arrays.asList(SimpleEnum.BAR));
+
+    procReq.fire(new Receiver<SimpleEnum>() {
+      @Override
+      public void onSuccess(SimpleEnum response) {
+        assertEquals(SimpleEnum.BAR, response);
+        finishTestAndReset();
+      }
+    });
+  }

   public void testPrimitiveSet() {
     delayTestFinish(5000);
@@ -1008,6 +1075,19 @@
       }
     });
   }
+
+  public void testPrimitiveString() {
+    delayTestFinish(5000);
+ final String testString = "test\"string\'with\nstring\u2060characters\t"; + final Request<String> fooReq = req.simpleFooRequest().processString(testString);
+    fooReq.fire(new Receiver<String>() {
+      @Override
+      public void onSuccess(String response) {
+        assertEquals(testString, response);
+        finishTestAndReset();
+      }
+    });
+  }

   public void testProxyList() {
     delayTestFinish(5000);
@@ -1020,6 +1100,25 @@
       }
     });
   }
+
+  public void testProxyListAsParameter() {
+    delayTestFinish(5000);
+    final Request<SimpleFooProxy> fooReq =
+ req.simpleFooRequest().findSimpleFooById(999L).with("selfOneToManyField");
+    fooReq.fire(new Receiver<SimpleFooProxy>() {
+      public void onSuccess(final SimpleFooProxy fooProxy) {
+ final Request<String> procReq = req.simpleFooRequest().processList(
+             fooProxy, fooProxy.getSelfOneToManyField());
+         procReq.fire(new Receiver<String>() {
+           @Override
+           public void onSuccess(String response) {
+             assertEquals(fooProxy.getUserName(), response);
+             finishTestAndReset();
+           }
+         });
+      }
+    });
+  }

   public void testProxysAsInstanceMethodParams() {
     delayTestFinish(5000);
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java Thu Sep 23 05:32:15 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java Thu Sep 23 21:25:47 2010
@@ -97,6 +97,22 @@
   public static SimpleFoo getSingleton() {
     return get();
   }
+
+  public static Boolean processBooleanList(List<Boolean> values) {
+    return values.get(0);
+  }
+
+  public static Date processDateList(List<Date> values) {
+    return values.get(0);
+  }
+
+  public static SimpleEnum processEnumList(List<SimpleEnum> values) {
+    return values.get(0);
+  }
+
+  public static String processString(String string) {
+    return string;
+  }

   public static synchronized SimpleFoo reset() {
     SimpleFoo instance = new SimpleFoo();
@@ -264,6 +280,10 @@
   public Long getLongField() {
     return longField;
   }
+
+  public String getNullField() {
+    return nullField;
+  }

   public List<Integer> getNumberListField() {
     return numberListField;
@@ -276,10 +296,6 @@
   public Set<SimpleBar> getOneToManySetField() {
     return oneToManySetField;
   }
-
-  public String getNullField() {
-    return nullField;
-  }

   /**
    * @return the otherBoolField
@@ -335,7 +351,7 @@
     }
     return result;
   }
-
+
   public void setBarField(SimpleBar barField) {
     this.barField = barField;
   }
@@ -413,6 +429,10 @@
   public void setLongField(Long longField) {
     this.longField = longField;
   }
+
+  public void setNullField(String nullField) {
+    this.nullField = nullField;
+  }

   public void setNumberListField(List<Integer> numberListField) {
     this.numberListField = numberListField;
@@ -425,10 +445,6 @@
   public void setOneToManySetField(Set<SimpleBar> oneToManySetField) {
     this.oneToManySetField = oneToManySetField;
   }
-
-  public void setNullField(String nullField) {
-    this.nullField = nullField;
-  }

   /**
    * @param otherBoolField the otherBoolField to set
@@ -436,6 +452,10 @@
   public void setOtherBoolField(Boolean otherBoolField) {
     this.otherBoolField = otherBoolField;
   }
+
+  public void setPassword(String password) {
+    this.password = password;
+  }

   public void setPleaseCrash(Integer crashIf42or43) throws Exception {
     if (crashIf42or43 == 42) {
@@ -446,10 +466,6 @@
     }
     pleaseCrash = crashIf42or43;
   }
-
-  public void setPassword(String password) {
-    this.password = password;
-  }

   public void setSelfOneToManyField(List<SimpleFoo> selfOneToManyField) {
     this.selfOneToManyField = selfOneToManyField;
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleFooRequest.java Wed Sep 22 07:25:43 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleFooRequest.java Thu Sep 23 21:25:47 2010
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.requestfactory.shared;

+import java.util.Date;
 import java.util.List;
 import java.util.Set;

@@ -32,26 +33,34 @@

   ProxyRequest<SimpleFooProxy> findSimpleFooById(Long id);

-  Request<Integer> privateMethod();
-
   Request<List<Integer>> getNumberList();

   Request<Set<Integer>> getNumberSet();

+  @Instance
+  Request<String> hello(SimpleFooProxy instance, SimpleBarProxy proxy);
+
   @Instance
   Request<Void> persist(SimpleFooProxy proxy);

   @Instance
   ProxyRequest<SimpleFooProxy> persistAndReturnSelf(SimpleFooProxy proxy);

-  Request<Void> reset();
-
-  @Instance
-  Request<String> hello(SimpleFooProxy instance, SimpleBarProxy proxy);
-
-  @Instance
-  Request<Integer> sum(SimpleFooProxy instance, List<Integer> values);
+  Request<Integer> privateMethod();
+
+  Request<Boolean> processBooleanList(List<Boolean> values);
+
+  Request<Date> processDateList(List<Date> values);
+
+  Request<SimpleEnum> processEnumList(List<SimpleEnum> values);
+
+  Request<String> processString(String value);

   @Instance
Request<String> processList(SimpleFooProxy instance, List<SimpleFooProxy> values);
-}
+
+  Request<Void> reset();
+
+  @Instance
+  Request<Integer> sum(SimpleFooProxy instance, List<Integer> values);
+}

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to