001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.server.rpc.impl;
017:
018: import com.google.gwt.user.client.rpc.SerializationException;
019:
020: import junit.framework.TestCase;
021:
022: import java.util.HashMap;
023:
024: /**
025: * Tests for the {@link StandardSerializationPolicy} class.
026: */
027: public class StandardSerializationPolicyTest extends TestCase {
028:
029: // This type will be included
030: class A {
031: // purposely empty
032: }
033:
034: // This type will not be included
035: class B {
036: // purposely empty
037: }
038:
039: // This type is serializable but not instantiable
040: class C {
041: // purposely empty
042: }
043:
044: /**
045: * Test method for
046: * {@link com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy#shouldDeserializeFields(java.lang.Class)}.
047: */
048: public void testShouldDerializeFields() {
049: StandardSerializationPolicy ssp = getStandardSerializationPolicy();
050: assertTrue(ssp.shouldDeserializeFields(A.class));
051: assertFalse(ssp.shouldDeserializeFields(B.class));
052: assertTrue(ssp.shouldDeserializeFields(C.class));
053: }
054:
055: /**
056: * Test method for
057: * {@link com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy#shouldSerializeFields(java.lang.Class)}.
058: */
059: public void testShouldSerializeFields() {
060: StandardSerializationPolicy ssp = getStandardSerializationPolicy();
061: assertTrue(ssp.shouldSerializeFields(A.class));
062: assertFalse(ssp.shouldSerializeFields(B.class));
063: assertTrue(ssp.shouldSerializeFields(C.class));
064: }
065:
066: /**
067: * Test method for
068: * {@link com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy#validateDeserialize(java.lang.Class)}.
069: *
070: * @throws SerializationException
071: */
072: public void testValidateDeserialize() throws SerializationException {
073: StandardSerializationPolicy ssp = getStandardSerializationPolicy();
074:
075: ssp.validateDeserialize(A.class);
076:
077: try {
078: ssp.validateDeserialize(B.class);
079: fail("Expected SerializationException");
080: } catch (SerializationException e) {
081: // should get here
082: }
083:
084: try {
085: ssp.validateDeserialize(C.class);
086: fail("Expected SerializationException");
087: } catch (SerializationException e) {
088: // should get here
089: }
090: }
091:
092: /**
093: * Test method for
094: * {@link com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy#validateSerialize(java.lang.Class)}.
095: *
096: * @throws SerializationException
097: */
098: public void testValidateSerialize() throws SerializationException {
099: StandardSerializationPolicy ssp = getStandardSerializationPolicy();
100:
101: ssp.validateSerialize(A.class);
102:
103: try {
104: ssp.validateSerialize(B.class);
105: fail("Expected SerializationException");
106: } catch (SerializationException e) {
107: // should get here
108: }
109:
110: try {
111: ssp.validateSerialize(C.class);
112: fail("Expected SerializationException");
113: } catch (SerializationException e) {
114: // should get here
115: }
116: }
117:
118: StandardSerializationPolicy getStandardSerializationPolicy() {
119: java.util.Map map = new HashMap();
120: map.put(A.class, Boolean.TRUE);
121: map.put(C.class, Boolean.FALSE);
122: return new StandardSerializationPolicy(map);
123: }
124: }
|