01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.server.rpc.impl;
17:
18: import com.google.gwt.user.client.rpc.IsSerializable;
19: import com.google.gwt.user.client.rpc.SerializationException;
20: import com.google.gwt.user.server.rpc.SerializationPolicy;
21:
22: import junit.framework.TestCase;
23:
24: import java.io.Serializable;
25:
26: /**
27: * Tests {@link LegacySerializationPolicy}.
28: */
29: public class LegacySerializationPolicyTest extends TestCase {
30:
31: private static class Bar implements Serializable {
32: }
33:
34: private static class Baz {
35: }
36:
37: private static class Foo implements IsSerializable {
38: }
39:
40: public void testSerializability() throws SerializationException {
41:
42: SerializationPolicy serializationPolicy = LegacySerializationPolicy
43: .getInstance();
44:
45: assertDeserializeFields(serializationPolicy, Foo.class);
46: assertValidDeserialize(serializationPolicy, Foo.class);
47:
48: assertDeserializeFields(serializationPolicy, Bar.class);
49: assertNotValidDeserialize(serializationPolicy, Bar.class);
50:
51: assertNotDeserializeFields(serializationPolicy, Baz.class);
52: assertNotValidDeserialize(serializationPolicy, Baz.class);
53: }
54:
55: private void assertDeserializeFields(SerializationPolicy policy,
56: Class clazz) {
57: assertTrue(policy.shouldDeserializeFields(clazz));
58: }
59:
60: private void assertNotDeserializeFields(SerializationPolicy policy,
61: Class clazz) {
62: assertFalse(policy.shouldDeserializeFields(clazz));
63: }
64:
65: private void assertNotValidDeserialize(SerializationPolicy policy,
66: Class clazz) {
67: try {
68: policy.validateDeserialize(clazz);
69: fail("assertNotValidDeserialize: " + clazz.getName()
70: + " failed to throw an exception");
71: } catch (SerializationException e) {
72: // expected
73: }
74: }
75:
76: private void assertValidDeserialize(SerializationPolicy policy,
77: Class clazz) throws SerializationException {
78: policy.validateDeserialize(clazz);
79: }
80: }
|