Revision: 10175
Author:   [email protected]
Date:     Wed May 11 08:32:59 2011
Log: Adding additional testing for GWT RPC. Some custom serialized objects
were previously untested, at least explicitly. Testing put in
place now provides coverage to test future changes.

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

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=10175

Added:
 /trunk/user/test/com/google/gwt/user/client/rpc/CoreJavaTest.java
 /trunk/user/test/com/google/gwt/user/client/rpc/CoreJavaTestService.java
/trunk/user/test/com/google/gwt/user/client/rpc/CoreJavaTestServiceAsync.java /trunk/user/test/com/google/gwt/user/server/rpc/CoreJavaTestServiceImpl.java
Modified:
 /trunk/user/test/com/google/gwt/user/RPCSuite.gwt.xml
 /trunk/user/test/com/google/gwt/user/RPCSuite.java
/trunk/user/test/com/google/gwt/user/client/rpc/CustomFieldSerializerTest.java

=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/user/client/rpc/CoreJavaTest.java Wed May 11 08:32:59 2011
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2011 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.user.client.rpc;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.logging.impl.LevelImplRegular;
+
+import java.math.MathContext;
+import java.math.RoundingMode;
+import java.util.logging.LogRecord;
+
+/**
+ * Test cases for Generic Collections in GWT RPC.
+ *
+ */
+public class CoreJavaTest extends RpcTestBase {
+
+  private static final LogRecord expectedLogRecord = createLogRecord();
+
+  public static boolean isValid(LogRecord value, boolean compareTrace) {
+ if (!expectedLogRecord.getLevel().toString().equals(value.getLevel().toString())) {
+      return false;
+    }
+
+    if (!expectedLogRecord.getMessage().equals(value.getMessage())) {
+      return false;
+    }
+
+    if (expectedLogRecord.getMillis() != value.getMillis()) {
+      return false;
+    }
+
+    if (!expectedLogRecord.getLoggerName().equals(value.getLoggerName())) {
+      return false;
+    }
+
+    Throwable expectedCause = expectedLogRecord.getThrown();
+    Throwable valueCause = value.getThrown();
+    while (expectedCause != null) {
+      if (valueCause == null) {
+        return false;
+      }
+
+      if (!expectedCause.getMessage().equals(valueCause.getMessage())) {
+        return false;
+      }
+
+      if (compareTrace) {
+        StackTraceElement[] expectedTrace = expectedCause.getStackTrace();
+        StackTraceElement[] valueTrace = valueCause.getStackTrace();
+        if ((expectedTrace == null) != (valueTrace == null)) {
+          return false;
+        }
+        if (expectedTrace != null) {
+          if (expectedTrace.length != valueTrace.length) {
+            return false;
+          }
+          for (int i = 0; i < expectedTrace.length; ++i) {
+            StackTraceElement expectedElement = expectedTrace[i];
+            StackTraceElement valueElement = valueTrace[i];
+
+            if (!expectedElement.equals(valueElement)) {
+              return false;
+            }
+          }
+        }
+      }
+
+      expectedCause = expectedCause.getCause();
+      valueCause = valueCause.getCause();
+    }
+    if (valueCause != null) {
+      return false;
+    }
+
+    return true;
+  }
+
+  public static boolean isValid(MathContext value) {
+    return createMathContext().equals(value);
+  }
+
+  private static LogRecord createLogRecord() {
+    /*
+     * A LevelImplRegular log level is created here in order to circumvent
+ * normal logging system behavior. Without this, the Level is null unless
+     * logging is active, which we do not want for testing. Standard usage
+     * is new LogRecord(Level.INFO, "Test Log Record");
+     */
+    LevelImplRegular logLevel = new LevelImplRegular();
+    LogRecord result = new LogRecord(logLevel.info(), "Test Log Record");
+
+    // Only set serialized fields.
+
+    result.setLoggerName("Test Logger Name");
+    result.setMillis(1234567);
+
+    Throwable thrown = new Throwable("Test LogRecord Throwable 1");
+    thrown.initCause(new Throwable("Test LogRecord Throwable cause"));
+    result.setThrown(thrown);
+
+    return result;
+  }
+
+  private static MathContext createMathContext() {
+    return new MathContext(5, RoundingMode.CEILING);
+  }
+
+  private CoreJavaTestServiceAsync coreJavaTestService;
+
+  public void testLogRecord() {
+    CoreJavaTestServiceAsync service = getServiceAsync();
+    delayTestFinishForRpc();
+ service.echoLogRecord(expectedLogRecord, new AsyncCallback<LogRecord>() {
+      public void onFailure(Throwable caught) {
+        TestSetValidator.rethrowException(caught);
+      }
+
+      public void onSuccess(LogRecord result) {
+        assertNotNull(result);
+        assertTrue(isValid(result, true));
+        finishTest();
+      }
+    });
+    finishTest();
+  }
+
+  public void testMathContext() {
+    CoreJavaTestServiceAsync service = getServiceAsync();
+    final MathContext expected = createMathContext();
+
+    delayTestFinishForRpc();
+    service.echoMathContext(expected, new AsyncCallback<MathContext>() {
+      public void onFailure(Throwable caught) {
+        TestSetValidator.rethrowException(caught);
+      }
+
+      public void onSuccess(MathContext result) {
+        assertNotNull(result);
+        assertTrue(isValid(result));
+        finishTest();
+      }
+    });
+  }
+
+  private CoreJavaTestServiceAsync getServiceAsync() {
+    if (coreJavaTestService == null) {
+ coreJavaTestService = (CoreJavaTestServiceAsync) GWT.create(CoreJavaTestService.class);
+    }
+    return coreJavaTestService;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/user/client/rpc/CoreJavaTestService.java Wed May 11 08:32:59 2011
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011 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.user.client.rpc;
+
+import java.math.MathContext;
+import java.util.logging.LogRecord;
+
+/**
+ * Test service for serialization of GWT core.java emulations.
+ */
+@RemoteServiceRelativePath("corejava")
+public interface CoreJavaTestService extends RemoteService {
+  /**
+   * A custom exception for the CoreJava test.
+   */
+  final class CoreJavaTestServiceException extends Exception {
+    public CoreJavaTestServiceException() {
+    }
+
+    public CoreJavaTestServiceException(String msg) {
+      super(msg);
+    }
+  }
+
+ LogRecord echoLogRecord(LogRecord value) throws CoreJavaTestServiceException;
+
+ MathContext echoMathContext(MathContext value) throws CoreJavaTestServiceException;
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/user/client/rpc/CoreJavaTestServiceAsync.java Wed May 11 08:32:59 2011
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2011 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.user.client.rpc;
+
+import java.math.MathContext;
+import java.util.logging.LogRecord;
+
+/**
+ * Async interface for serialization of GWT core.java emulations.
+ */
+public interface CoreJavaTestServiceAsync {
+
+  void echoLogRecord(LogRecord value, AsyncCallback<LogRecord> callback);
+
+ void echoMathContext(MathContext expected, AsyncCallback<MathContext> asyncCallback);
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/user/server/rpc/CoreJavaTestServiceImpl.java Wed May 11 08:32:59 2011
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2011 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.user.server.rpc;
+
+import com.google.gwt.user.client.rpc.CoreJavaTest;
+import com.google.gwt.user.client.rpc.CoreJavaTestService;
+
+import java.math.MathContext;
+import java.util.logging.LogRecord;
+
+/**
+ * Remote service implementation for serialization of GWT core.java emulations.
+ */
+public class CoreJavaTestServiceImpl extends HybridServiceServlet implements CoreJavaTestService {
+
+ public LogRecord echoLogRecord(LogRecord value) throws CoreJavaTestServiceException {
+    /*
+ * Don't check the stack trace on the server side, because the expected result + * it is comparing against came from a server-side instance of CoreJavaTest, and
+     * hence has a different stack trace from the streamed version.
+     */
+    if (!CoreJavaTest.isValid(value, false)) {
+      throw new CoreJavaTestServiceException();
+    }
+
+    return value;
+  }
+
+ public MathContext echoMathContext(MathContext value) throws CoreJavaTestServiceException {
+    if (!CoreJavaTest.isValid(value)) {
+      throw new CoreJavaTestServiceException();
+    }
+
+    return value;
+  }
+}
=======================================
--- /trunk/user/test/com/google/gwt/user/RPCSuite.gwt.xml Mon Apr 18 08:45:48 2011 +++ /trunk/user/test/com/google/gwt/user/RPCSuite.gwt.xml Wed May 11 08:32:59 2011
@@ -21,6 +21,8 @@
<servlet path='/echo' class='com.google.gwt.user.server.rpc.MixedSerializableEchoServiceImpl' />
   <servlet path='/collections'
     class='com.google.gwt.user.server.rpc.CollectionsTestServiceImpl' />
+  <servlet path='/corejava'
+    class='com.google.gwt.user.server.rpc.CoreJavaTestServiceImpl' />
   <servlet path='/customfieldserializers'
class='com.google.gwt.user.server.rpc.CustomFieldSerializerTestServiceImpl' />
   <servlet path='/enums'
=======================================
--- /trunk/user/test/com/google/gwt/user/RPCSuite.java Wed Apr 13 06:21:31 2011 +++ /trunk/user/test/com/google/gwt/user/RPCSuite.java Wed May 11 08:32:59 2011
@@ -28,6 +28,7 @@
 import com.google.gwt.rpc.client.RpcValueTypesTest;
 import com.google.gwt.user.client.rpc.CollectionsTest;
 import com.google.gwt.user.client.rpc.CollectionsTestWithTypeObfuscation;
+import com.google.gwt.user.client.rpc.CoreJavaTest;
 import com.google.gwt.user.client.rpc.CustomFieldSerializerTest;
import com.google.gwt.user.client.rpc.CustomFieldSerializerTestWithTypeObfuscation;
 import com.google.gwt.user.client.rpc.EnumsTest;
@@ -102,6 +103,7 @@
     suite.addTestSuite(EnumsTest.class);
     suite.addTestSuite(InheritanceTest.class);
     suite.addTestSuite(CollectionsTest.class);
+    suite.addTestSuite(CoreJavaTest.class);
     suite.addTestSuite(CustomFieldSerializerTest.class);
     suite.addTestSuite(ExceptionsTest.class);
     suite.addTestSuite(ObjectGraphTest.class);
=======================================
--- /trunk/user/test/com/google/gwt/user/client/rpc/CustomFieldSerializerTest.java Wed Nov 4 13:03:23 2009 +++ /trunk/user/test/com/google/gwt/user/client/rpc/CustomFieldSerializerTest.java Wed May 11 08:32:59 2011
@@ -57,7 +57,9 @@
   }

   /**
-   * Tests that the custom field serializers are actually called.
+   * Tests that the custom field serializers are actually called when the
+   * custom field serializer does not derive from
+   * {@link CustomFieldSerializer}
    */
   public void testCustomFieldSerialization() {
     CustomFieldSerializerTestServiceAsync service = getServiceAsync();
@@ -83,6 +85,9 @@
   /**
* Test that custom serializers that call readObject() inside instantiate (as
    * is required for most immutable classes) work.
+   *
+   * This also checks that custom <code>instantiate</code> works when the
+   * custom serializer does not implement {@link CustomFieldSerializer}.
    */
   public void testSerializableImmutables() {
     CustomFieldSerializerTestServiceAsync service = getServiceAsync();

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

Reply via email to