Revision: 9309
Author: [email protected]
Date: Tue Nov 30 09:13:06 2010
Log: Ensure RequestFactory is UTF-8 clean.
Refactor existing RPC Unicode tests to allow re-use by RequestFactory.
Issue 5474.
Patch by: bobv, tbroyer
Review by: rchandia
Reported by: diego.dupin

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

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

Added:
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryUnicodeEscapingTest.java /trunk/user/test/com/google/gwt/requestfactory/server/RequestFactoryUnicodeEscapingJreTest.java /trunk/user/test/com/google/gwt/requestfactory/shared/UnicodeTestRequest.java
Modified:
 /trunk/user/src/com/google/gwt/autobean/shared/impl/StringQuoter.java
/trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
 /trunk/user/test/com/google/gwt/requestfactory/RequestFactoryJreSuite.java
 /trunk/user/test/com/google/gwt/requestfactory/RequestFactorySuite.java
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java
 /trunk/user/test/com/google/gwt/user/client/rpc/UnicodeEscapingTest.java

=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryUnicodeEscapingTest.java Tue Nov 30 09:13:06 2010
@@ -0,0 +1,142 @@
+/*
+ * 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.client;
+
+import com.google.gwt.requestfactory.shared.Receiver;
+import com.google.gwt.requestfactory.shared.ServerFailure;
+import com.google.gwt.user.client.rpc.UnicodeEscapingService.InvalidCharacterException;
+import com.google.gwt.user.client.rpc.UnicodeEscapingTest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Runs through a portion of the Basic Multilingual Plane.
+ */
+public class RequestFactoryUnicodeEscapingTest extends RequestFactoryTestBase {
+  private static final int TEST_FINISH_DELAY_MS = 5000;
+  private final UnicodeEscapingTest test = new UnicodeEscapingTest() {
+
+    @Override
+    protected void clientToServerVerifyRange(int start, final int end,
+        final int size, final int step) throws InvalidCharacterException {
+      current = start;
+      int blockEnd = Math.min(end, current + size);
+ req.unicodeTestRequest().verifyStringContainingCharacterRange(current, + blockEnd, getStringContainingCharacterRange(start, blockEnd)).fire(
+          new Receiver<Void>() {
+            List<ServerFailure> fails = new ArrayList<ServerFailure>();
+
+            @Override
+            public void onFailure(ServerFailure error) {
+              fails.add(error);
+              onSuccess(null);
+            }
+
+            @Override
+            public void onSuccess(Void response) {
+              current += step;
+              if (current < end) {
+                delayTestFinish(TEST_FINISH_DELAY_MS);
+                int blockEnd = Math.min(end, current + size);
+ req.unicodeTestRequest().verifyStringContainingCharacterRange(
+                    current, blockEnd,
+ getStringContainingCharacterRange(current, blockEnd)).fire(
+                    this);
+              } else if (!fails.isEmpty()) {
+                StringBuilder msg = new StringBuilder();
+                for (ServerFailure error : fails) {
+                  msg.append(error.getMessage()).append("\n");
+                }
+                throw new RuntimeException(msg.toString());
+              } else {
+                finishTest();
+              }
+            }
+          });
+    }
+
+    @Override
+    protected void serverToClientVerify(int start, final int end,
+        final int size, final int step) {
+      current = start;
+      req.unicodeTestRequest().getStringContainingCharacterRange(start,
+          Math.min(end, current + size)).fire(new Receiver<String>() {
+        List<ServerFailure> fails = new ArrayList<ServerFailure>();
+
+        @Override
+        public void onFailure(ServerFailure error) {
+          fails.add(error);
+          nextBatch();
+        }
+
+        @Override
+        public void onSuccess(String response) {
+          try {
+            verifyStringContainingCharacterRange(current,
+                Math.min(end, current + size), response);
+          } catch (InvalidCharacterException e) {
+            fails.add(new ServerFailure(e.getMessage(), null, null));
+          }
+          nextBatch();
+        }
+
+        private void nextBatch() {
+          current += step;
+          if (current < end) {
+            delayTestFinish(TEST_FINISH_DELAY_MS);
+ req.unicodeTestRequest().getStringContainingCharacterRange(current,
+                Math.min(end, current + size)).fire(this);
+          } else if (!fails.isEmpty()) {
+            StringBuilder msg = new StringBuilder();
+            for (ServerFailure t : fails) {
+              msg.append(t.getMessage()).append("\n");
+            }
+            throw new RuntimeException(msg.toString());
+          } else {
+            finishTest();
+          }
+        }
+      });
+    }
+  };
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.requestfactory.RequestFactorySuite";
+  }
+
+ public void testClientToServerBMPHigh() throws InvalidCharacterException {
+    test.testClientToServerBMPHigh();
+  }
+
+  public void testClientToServerBMPLow() throws InvalidCharacterException {
+    test.testClientToServerBMPLow();
+  }
+
+  public void testClientToServerNonBMP() throws InvalidCharacterException {
+    test.testClientToServerNonBMP();
+  }
+
+  public void testServerToClientBMP() {
+    test.testServerToClientBMP();
+  }
+
+  public void testServerToClientNonBMP() {
+    test.testServerToClientNonBMP();
+  }
+
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/requestfactory/server/RequestFactoryUnicodeEscapingJreTest.java Tue Nov 30 09:13:06 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.server;
+
+import com.google.gwt.requestfactory.client.RequestFactoryUnicodeEscapingTest;
+import com.google.gwt.requestfactory.shared.SimpleRequestFactory;
+
+/**
+ * A JRE implementation of {...@link RequestFactoryUnicodeEscapingTest}.
+ */
+public class RequestFactoryUnicodeEscapingJreTest extends
+    RequestFactoryUnicodeEscapingTest {
+  @Override
+  public String getModuleName() {
+    return null;
+  }
+
+  @Override
+  protected SimpleRequestFactory createFactory() {
+ return RequestFactoryJreTest.createInProcess(SimpleRequestFactory.class);
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/requestfactory/shared/UnicodeTestRequest.java Tue Nov 30 09:13:06 2010
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.requestfactory.shared;
+
+import com.google.gwt.user.client.rpc.UnicodeEscapingTest;
+
+/**
+ * Provides access to the static test methods in {...@link UnicodeEscapingTes}.
+ */
+...@service(UnicodeEscapingTest.class)
+public interface UnicodeTestRequest extends RequestContext {
+  Request<String> getStringContainingCharacterRange(int start, int end);
+
+  Request<Void> verifyStringContainingCharacterRange(int start, int end,
+      String str);
+}
=======================================
--- /trunk/user/src/com/google/gwt/autobean/shared/impl/StringQuoter.java Fri Nov 5 04:25:19 2010 +++ /trunk/user/src/com/google/gwt/autobean/shared/impl/StringQuoter.java Tue Nov 30 09:13:06 2010
@@ -17,7 +17,8 @@

 import com.google.gwt.autobean.server.impl.JsonSplittable;
 import com.google.gwt.autobean.shared.Splittable;
-import com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter;
+
+import org.json.JSONObject;

 /**
  * This class has a super-source version with a client-only implementation.
@@ -27,7 +28,7 @@
    * Create a quoted JSON string.
    */
   public static String quote(String raw) {
-    return ServerSerializationStreamWriter.escapeString(raw);
+    return JSONObject.quote(raw);
   }

   public static Splittable split(String payload) {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java Mon Nov 22 08:01:19 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java Tue Nov 30 09:13:06 2010
@@ -130,7 +130,6 @@
       if (DUMP_PAYLOAD) {
         System.out.println(">>> " + jsonRequestString);
       }
-      PrintWriter writer = response.getWriter();

       try {
         // Check that user is logged in before proceeding
@@ -146,6 +145,8 @@
response.setHeader("userId", String.format("%s", userInfo.getId()));
           response.setStatus(HttpServletResponse.SC_OK);
           response.setContentType(RequestFactory.JSON_CONTENT_TYPE_UTF8);
+          // The Writer must be obtained after setting the content type
+          PrintWriter writer = response.getWriter();
           writer.print(payload);
           writer.flush();
         }
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/RequestFactoryJreSuite.java Mon Nov 22 08:01:19 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/RequestFactoryJreSuite.java Tue Nov 30 09:13:06 2010
@@ -21,6 +21,7 @@
 import com.google.gwt.requestfactory.server.LocatorJreTest;
import com.google.gwt.requestfactory.server.RequestFactoryInterfaceValidatorTest;
 import com.google.gwt.requestfactory.server.RequestFactoryJreTest;
+import com.google.gwt.requestfactory.server.RequestFactoryUnicodeEscapingJreTest;
 import com.google.gwt.requestfactory.shared.impl.SimpleEntityProxyIdTest;

 import junit.framework.Test;
@@ -40,6 +41,7 @@
     suite.addTestSuite(SimpleEntityProxyIdTest.class);
     suite.addTestSuite(RequestFactoryInterfaceValidatorTest.class);
     suite.addTestSuite(RequestFactoryModelTest.class);
+    suite.addTestSuite(RequestFactoryUnicodeEscapingJreTest.class);
     return suite;
   }
 }
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/RequestFactorySuite.java Mon Nov 22 08:01:19 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/RequestFactorySuite.java Tue Nov 30 09:13:06 2010
@@ -20,6 +20,7 @@
import com.google.gwt.requestfactory.client.RequestFactoryExceptionHandlerTest;
 import com.google.gwt.requestfactory.client.RequestFactoryPolymorphicTest;
 import com.google.gwt.requestfactory.client.RequestFactoryTest;
+import com.google.gwt.requestfactory.client.RequestFactoryUnicodeEscapingTest;
 import com.google.gwt.requestfactory.client.ui.EditorTest;
 import com.google.gwt.requestfactory.shared.ComplexKeysTest;
 import com.google.gwt.requestfactory.shared.LocatorTest;
@@ -40,6 +41,7 @@
     suite.addTestSuite(RequestFactoryTest.class);
     suite.addTestSuite(RequestFactoryExceptionHandlerTest.class);
     suite.addTestSuite(RequestFactoryPolymorphicTest.class);
+    suite.addTestSuite(RequestFactoryUnicodeEscapingTest.class);
     return suite;
   }
 }
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Wed Nov 24 12:33:58 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Tue Nov 30 09:13:06 2010
@@ -730,6 +730,7 @@
    * Make sure our stock RF logging service keeps receiving.
    */
   public void testLoggingService() {
+    delayTestFinish(DELAY_TEST_FINISH);
     String logRecordJson = new StringBuilder("{") //
     .append("\"level\": \"ALL\", ") //
     .append("\"loggerName\": \"logger\", ") //
@@ -2041,6 +2042,7 @@
    * in a static method on UserInformation).
    */
   public void testUserInfo() {
+    delayTestFinish(DELAY_TEST_FINISH);
     req.userInformationRequest().getCurrentUserInformation("").fire(
         new Receiver<UserInformationProxy>() {
           @Override
@@ -2050,6 +2052,7 @@
             assertEquals("Dummy User", response.getName());
             assertEquals("", response.getLoginUrl());
             assertEquals("", response.getLogoutUrl());
+            finishTestAndReset();
           }
         });
   }
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java Mon Nov 22 11:42:05 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java Tue Nov 30 09:13:06 2010
@@ -24,4 +24,6 @@
   SimpleBarRequest simpleBarRequest();

   SimpleFooRequest simpleFooRequest();
-}
+
+  UnicodeTestRequest unicodeTestRequest();
+}
=======================================
--- /trunk/user/test/com/google/gwt/user/client/rpc/UnicodeEscapingTest.java Thu Apr 1 18:18:56 2010 +++ /trunk/user/test/com/google/gwt/user/client/rpc/UnicodeEscapingTest.java Tue Nov 30 09:13:06 2010
@@ -108,7 +108,7 @@
   }

   /** start of current block being tested. */
-  private int current;
+  protected int current;

   @Override
   public String getModuleName() {
@@ -234,7 +234,7 @@
         NON_BMP_TEST_INCREMENT);
   }

-  private void clientToServerVerifyRange(final int start, final int end,
+  protected void clientToServerVerifyRange(final int start, final int end,
       final int size, final int step) throws InvalidCharacterException {
     current = start;
     int blockEnd = Math.min(end, current + size);
@@ -274,7 +274,7 @@
         });
   }

-  private void serverToClientVerify(final int start, final int end,
+  protected void serverToClientVerify(final int start, final int end,
       final int size, final int step) {
     current = start;
     getService().getStringContainingCharacterRange(start,

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

Reply via email to