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.test.entity.cmp2;
17:
18: import java.rmi.MarshalledObject;
19: import java.io.ByteArrayOutputStream;
20: import java.io.ObjectOutputStream;
21: import java.io.ByteArrayInputStream;
22: import java.io.ObjectInputStream;
23: import javax.ejb.EJBHome;
24: import javax.ejb.HomeHandle;
25:
26: import org.apache.openejb.test.entity.cmp.BasicCmpHome;
27:
28: /**
29: * [6] Should be run as the sixth test suite of the BasicCmpTestClients
30: */
31: public class Cmp2HomeHandleTests extends BasicCmp2TestClient {
32:
33: public Cmp2HomeHandleTests() {
34: super ("HomeHandle.");
35: }
36:
37: protected void setUp() throws Exception {
38: super .setUp();
39: Object obj = initialContext
40: .lookup("client/tests/entity/cmp2/BasicCmpHome");
41: ejbHome = (BasicCmpHome) javax.rmi.PortableRemoteObject.narrow(
42: obj, BasicCmpHome.class);
43: ejbHomeHandle = ejbHome.getHomeHandle();
44: }
45:
46: //=================================
47: // Test home handle methods
48: //
49: public void test01_getEJBHome() {
50: try {
51: EJBHome home = ejbHomeHandle.getEJBHome();
52: assertNotNull("The EJBHome is null", home);
53: } catch (Exception e) {
54: fail("Received Exception " + e.getClass() + " : "
55: + e.getMessage());
56: }
57: }
58:
59: public void Xtest02_copyHandleByMarshalledObject() {
60: try {
61: MarshalledObject obj = new MarshalledObject(ejbHomeHandle);
62: HomeHandle copy = (HomeHandle) obj.get();
63:
64: assertNotNull("The HomeHandle copy is null", copy);
65: EJBHome home = copy.getEJBHome();
66: assertNotNull("The EJBHome is null", home);
67: } catch (Exception e) {
68: fail("Received Exception " + e.getClass() + " : "
69: + e.getMessage());
70: }
71: }
72:
73: public void Xtest03_copyHandleBySerialize() {
74: try {
75: ByteArrayOutputStream baos = new ByteArrayOutputStream();
76: ObjectOutputStream oos = new ObjectOutputStream(baos);
77: oos.writeObject(ejbHomeHandle);
78: oos.flush();
79: oos.close();
80: ByteArrayInputStream bais = new ByteArrayInputStream(baos
81: .toByteArray());
82: ObjectInputStream ois = new ObjectInputStream(bais);
83: HomeHandle copy = (HomeHandle) ois.readObject();
84:
85: assertNotNull("The HomeHandle copy is null", copy);
86: EJBHome home = copy.getEJBHome();
87: assertNotNull("The EJBHome is null", home);
88: } catch (Exception e) {
89: fail("Received Exception " + e.getClass() + " : "
90: + e.getMessage());
91: }
92: }
93: //
94: // Test home handle methods
95: //=================================
96:
97: }
|