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: */package org.apache.openejb.client;
17:
18: import junit.framework.TestCase;
19:
20: import java.io.ByteArrayInputStream;
21: import java.io.ByteArrayOutputStream;
22: import java.io.Externalizable;
23: import java.io.IOException;
24: import java.io.ObjectInputStream;
25: import java.io.ObjectOutputStream;
26:
27: /**
28: * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $
29: */
30: public class JndiRequestTest extends TestCase {
31:
32: public void testExternalize() throws Exception {
33: JNDIRequest expected = new JNDIRequest(
34: RequestMethodConstants.JNDI_LOOKUP,
35: "this/is/a/jndi/name");
36: JNDIRequest actual = new JNDIRequest();
37:
38: externalize(expected, actual);
39:
40: assertEquals("Request method not the same", expected
41: .getRequestMethod(), actual.getRequestMethod());
42: assertEquals("ModuleId not the same", expected.getModuleId(),
43: actual.getModuleId());
44: assertEquals("JNDI Name not the same", expected
45: .getRequestString(), actual.getRequestString());
46: }
47:
48: public void testExternalize2() throws Exception {
49: JNDIRequest expected = new JNDIRequest(
50: RequestMethodConstants.JNDI_LOOKUP,
51: "this/is/a/jndi/name");
52: expected.setModuleId("foobar");
53: JNDIRequest actual = new JNDIRequest();
54:
55: externalize(expected, actual);
56:
57: assertEquals("Request method not the same", expected
58: .getRequestMethod(), actual.getRequestMethod());
59: assertEquals("ModuleId not the same", expected.getModuleId(),
60: actual.getModuleId());
61: assertEquals("JNDI Name not the same", expected
62: .getRequestString(), actual.getRequestString());
63: }
64:
65: private void externalize(Externalizable original,
66: Externalizable copy) throws IOException,
67: ClassNotFoundException {
68: ByteArrayOutputStream baos = new ByteArrayOutputStream();
69: ObjectOutputStream out = new ObjectOutputStream(baos);
70:
71: original.writeExternal(out);
72: out.close();
73:
74: ByteArrayInputStream bais = new ByteArrayInputStream(baos
75: .toByteArray());
76: ObjectInputStream in = new ObjectInputStream(bais);
77:
78: copy.readExternal(in);
79: }
80: }
|