Revision: 10261
Author: [email protected]
Date: Wed Jun 1 11:09:25 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/1441804
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=10261
Added:
/trunk/user/test/com/google/gwt/user/LoggingRPCSuite.gwt.xml
/trunk/user/test/com/google/gwt/user/LoggingRPCSuite.java
/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/client/rpc/LoggingRPCTest.java
/trunk/user/test/com/google/gwt/user/client/rpc/LoggingRPCTestService.java
/trunk/user/test/com/google/gwt/user/client/rpc/LoggingRPCTestServiceAsync.java
/trunk/user/test/com/google/gwt/user/server/rpc/CoreJavaTestServiceImpl.java
/trunk/user/test/com/google/gwt/user/server/rpc/LoggingRPCTestServiceImpl.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/LoggingRPCSuite.gwt.xml Wed Jun 1
11:09:25 2011
@@ -0,0 +1,25 @@
+<!--
-->
+<!-- Copyright 2007 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 -->
+<!-- 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. License for the specific language governing permissions
and -->
+<!-- limitations under the
License. -->
+
+<module>
+ <inherits name='com.google.gwt.user.User' />
+ <inherits name="com.google.gwt.logging.Logging"/>
+
+ <define-property name='rpc.enforceTypeVersioning' values="true, false" />
+ <set-property name='rpc.enforceTypeVersioning' value='true' />
+
+ <servlet path='/loggingrpc'
+ class='com.google.gwt.user.server.rpc.LoggingRPCTestServiceImpl' />
+
+</module>
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/user/LoggingRPCSuite.java Wed Jun 1
11:09:25 2011
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import com.google.gwt.dev.BootStrapPlatform;
+import com.google.gwt.junit.tools.GWTTestSuite;
+import com.google.gwt.user.client.rpc.LoggingRPCTest;
+
+
+import junit.framework.Test;
+
+/**
+ * A collection of TestCases for the RPC system.
+ */
+public class LoggingRPCSuite {
+
+ static {
+ /*
+ * Required for OS X Leopard. This call ensures we have a valid context
+ * ClassLoader. Many of the tests test low-level RPC mechanisms and
rely on
+ * a ClassLoader to resolve classes and resources.
+ */
+ BootStrapPlatform.applyPlatformHacks();
+ }
+
+ public static Test suite() {
+ GWTTestSuite suite = new GWTTestSuite(
+ "Test for com.google.gwt.user.client.rpc.core.java.util.logging");
+
+ // GWTTestCases
+ suite.addTestSuite(LoggingRPCTest.class);
+
+ return suite;
+ }
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/user/client/rpc/CoreJavaTest.java Wed
Jun 1 11:09:25 2011
@@ -0,0 +1,67 @@
+/*
+ * 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 java.math.MathContext;
+import java.math.RoundingMode;
+
+/**
+ * Test cases for Java core emulation classes in GWT RPC.
+ *
+ * Logging is tested in a separate suite because it requires logging
enabled
+ * in gwt.xml. Otherwise, only MathContext has non-trivial content for RPC.
+ *
+ */
+public class CoreJavaTest extends RpcTestBase {
+
+ public static boolean isValid(MathContext value) {
+ return createMathContext().equals(value);
+ }
+
+ private static MathContext createMathContext() {
+ return new MathContext(5, RoundingMode.CEILING);
+ }
+
+ private CoreJavaTestServiceAsync coreJavaTestService;
+
+ 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 Jun 1 11:09:25 2011
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * Test service for serialization of GWT core.java.util.logging 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);
+ }
+ }
+
+ MathContext echoMathContext(MathContext value) throws
CoreJavaTestServiceException;
+}
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/user/client/rpc/CoreJavaTestServiceAsync.java
Wed Jun 1 11:09:25 2011
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+/**
+ * Async interface for serialization of GWT core.java.util.logging
emulations.
+ */
+public interface CoreJavaTestServiceAsync {
+
+ void echoMathContext(MathContext expected, AsyncCallback<MathContext>
asyncCallback);
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/user/client/rpc/LoggingRPCTest.java Wed
Jun 1 11:09:25 2011
@@ -0,0 +1,118 @@
+/*
+ * 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.junit.client.GWTTestCase;
+
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+/**
+ * Test cases for Generic Collections in GWT RPC.
+ *
+ */
+public class LoggingRPCTest extends GWTTestCase {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.user.LoggingRPCSuite";
+ }
+
+ private static final LogRecord expectedLogRecord = createLogRecord();
+
+ public static boolean isValid(LogRecord value) {
+ 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;
+ }
+
+ // Do not compare trace as it is not stable across RPC.
+
+ expectedCause = expectedCause.getCause();
+ valueCause = valueCause.getCause();
+ }
+ if (valueCause != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private static LogRecord createLogRecord() {
+ LogRecord result = new LogRecord(Level.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 LoggingRPCTestServiceAsync loggingRPCTestService;
+
+ public void testLogRecord() {
+ LoggingRPCTestServiceAsync service = getServiceAsync();
+ delayTestFinish(15000);
+ service.echoLogRecord(expectedLogRecord, new
AsyncCallback<LogRecord>() {
+ public void onFailure(Throwable caught) {
+ TestSetValidator.rethrowException(caught);
+ }
+
+ public void onSuccess(LogRecord result) {
+ assertNotNull(result);
+ assertTrue(isValid(result));
+ finishTest();
+ }
+ });
+ finishTest();
+ }
+
+ private LoggingRPCTestServiceAsync getServiceAsync() {
+ if (loggingRPCTestService == null) {
+ loggingRPCTestService = (LoggingRPCTestServiceAsync)
GWT.create(LoggingRPCTestService.class);
+ }
+ return loggingRPCTestService;
+ }
+}
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/user/client/rpc/LoggingRPCTestService.java
Wed Jun 1 11:09:25 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.util.logging.LogRecord;
+
+/**
+ * Test service for serialization of GWT core.java.util.logging emulations.
+ */
+@RemoteServiceRelativePath("loggingrpc")
+public interface LoggingRPCTestService extends RemoteService {
+ /**
+ * A custom exception for the LoggingRPC test.
+ */
+ final class LoggingRPCTestServiceException extends Exception {
+ public LoggingRPCTestServiceException() {
+ }
+
+ public LoggingRPCTestServiceException(String msg) {
+ super(msg);
+ }
+ }
+
+ LogRecord echoLogRecord(LogRecord value) throws
LoggingRPCTestServiceException;
+}
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/user/client/rpc/LoggingRPCTestServiceAsync.java
Wed Jun 1 11:09:25 2011
@@ -0,0 +1,28 @@
+/*
+ * 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.util.logging.LogRecord;
+
+/**
+ * Async interface for serialization of GWT core.java emulations.
+ */
+public interface LoggingRPCTestServiceAsync {
+
+ void echoLogRecord(LogRecord value, AsyncCallback<LogRecord> callback);
+}
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/user/server/rpc/CoreJavaTestServiceImpl.java
Wed Jun 1 11:09:25 2011
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * Remote service implementation for serialization of GWT core.java
emulations.
+ */
+public class CoreJavaTestServiceImpl extends HybridServiceServlet
implements CoreJavaTestService {
+
+ public MathContext echoMathContext(MathContext value) throws
CoreJavaTestServiceException {
+ if (!CoreJavaTest.isValid(value)) {
+ throw new CoreJavaTestServiceException();
+ }
+
+ return value;
+ }
+}
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/user/server/rpc/LoggingRPCTestServiceImpl.java
Wed Jun 1 11:09:25 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.LoggingRPCTest;
+import com.google.gwt.user.client.rpc.LoggingRPCTestService;
+
+import java.util.logging.LogRecord;
+
+/**
+ * Remote service implementation for serialization of GWT
core.java.util.logging
+ * emulations.
+ */
+public class LoggingRPCTestServiceImpl extends HybridServiceServlet
implements
+ LoggingRPCTestService {
+
+ public LogRecord echoLogRecord(LogRecord value) throws
LoggingRPCTestServiceException {
+ /*
+ * 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
+ * LoggingRPCTest, and hence has a different stack trace from the
streamed
+ * version.
+ */
+ if (!LoggingRPCTest.isValid(value)) {
+ throw new LoggingRPCTestServiceException();
+ }
+
+ return value;
+ }
+}
=======================================
--- /trunk/user/test/com/google/gwt/user/RPCSuite.gwt.xml Wed May 11
11:14:46 2011
+++ /trunk/user/test/com/google/gwt/user/RPCSuite.gwt.xml Wed Jun 1
11:09:25 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 May 11 11:14:46
2011
+++ /trunk/user/test/com/google/gwt/user/RPCSuite.java Wed Jun 1 11:09:25
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 May 11 11:14:46 2011
+++
/trunk/user/test/com/google/gwt/user/client/rpc/CustomFieldSerializerTest.java
Wed Jun 1 11:09:25 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