01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.rmi.server;
19:
20: import java.io.Serializable;
21: import java.rmi.server.ExportException;
22:
23: import org.apache.harmony.testframework.serialization.SerializationTest;
24: import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
25:
26: public class ExportExceptionTest extends junit.framework.TestCase {
27:
28: private String errorMessage;
29:
30: private String causeMessage;
31:
32: private Exception cause;
33:
34: /**
35: * Sets up the fixture, for example, open a network connection. This method
36: * is called before a test is executed.
37: */
38: @Override
39: protected void setUp() {
40: errorMessage = "Connectin Error";
41: causeMessage = "Caused Exception";
42: cause = new ExportException(causeMessage);
43: }
44:
45: /**
46: * @tests java.rmi.server.ExportException#ExportException(String)
47: */
48: public void test_Constructor_String() {
49: ExportException e = new ExportException(errorMessage);
50: assertTrue(e instanceof java.rmi.RemoteException);
51: assertEquals(errorMessage, e.getMessage());
52: }
53:
54: /**
55: * @tests java.rmi.server.ExportException#ExportException(String,Exception)
56: */
57: public void test_Constructor_String_Exception() {
58: ExportException e = new ExportException(errorMessage, cause);
59: assertEquals(cause.getMessage(), e.getCause().getMessage());
60: }
61:
62: // comparator for ExportException objects
63: private static final SerializableAssert comparator = new SerializableAssert() {
64: public void assertDeserialized(Serializable initial,
65: Serializable deserialized) {
66:
67: SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(
68: initial, deserialized);
69:
70: ExportException initEx = (ExportException) initial;
71: ExportException desrEx = (ExportException) deserialized;
72:
73: assertEquals(initEx.getMessage(), desrEx.getMessage());
74: assertEquals(initEx.getCause().getMessage(), desrEx
75: .getCause().getMessage());
76: }
77: };
78:
79: /**
80: * @tests serialization/deserialization.
81: */
82: public void testSerializationSelf() throws Exception {
83:
84: SerializationTest.verifySelf(new ExportException(errorMessage,
85: cause), comparator);
86: }
87:
88: /**
89: * @tests serialization/deserialization compatibility with RI.
90: */
91: public void testSerializationCompatibility() throws Exception {
92:
93: SerializationTest.verifyGolden(this , new ExportException(
94: errorMessage, cause), comparator);
95: }
96:
97: }
|