001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.test.entity.cmp2;
018:
019: import org.apache.openejb.test.entity.cmp.ComplexCmpHome;
020:
021: import javax.ejb.EJBObject;
022: import javax.ejb.Handle;
023: import java.rmi.MarshalledObject;
024: import java.io.ByteArrayOutputStream;
025: import java.io.ObjectOutputStream;
026: import java.io.ByteArrayInputStream;
027: import java.io.ObjectInputStream;
028:
029: /**
030: * [7] Should be run as the seventh test suite of the BasicCmpTestClients
031: */
032: public class Complex2HandleTests extends ComplexCmp2TestClient {
033: public Complex2HandleTests() {
034: super ("Handle.");
035: }
036:
037: protected void setUp() throws Exception {
038: super .setUp();
039: Object obj = initialContext
040: .lookup("client/tests/entity/cmp2/ComplexCmpHome");
041: ejbHome = (ComplexCmpHome) javax.rmi.PortableRemoteObject
042: .narrow(obj, ComplexCmpHome.class);
043: ejbObject = ejbHome.createObject("Fifth Bean");
044: ejbHandle = ejbObject.getHandle();
045: }
046:
047: protected void tearDown() throws Exception {
048: if (ejbObject != null) {
049: ejbObject.remove();
050: }
051: super .tearDown();
052: }
053:
054: //=================================
055: // Test handle methods
056: //
057: public void test01_getEJBObject() {
058:
059: try {
060: EJBObject object = ejbHandle.getEJBObject();
061: assertNotNull("The EJBObject is null", object);
062: // Wait until isIdentical is working.
063: //assertTrue("EJBObjects are not identical", object.isIdentical(ejbObject));
064: } catch (Exception e) {
065: fail("Received Exception " + e.getClass() + " : "
066: + e.getMessage());
067: }
068: }
069:
070: public void Xtest02_copyHandleByMarshalledObject() {
071: try {
072: MarshalledObject obj = new MarshalledObject(ejbHandle);
073: Handle copy = (Handle) obj.get();
074:
075: EJBObject object = copy.getEJBObject();
076: assertNotNull("The EJBObject is null", object);
077: assertTrue("EJBObjects are not identical", object
078: .isIdentical(ejbObject));
079: } catch (Exception e) {
080: fail("Received Exception " + e.getClass() + " : "
081: + e.getMessage());
082: }
083: }
084:
085: public void Xtest03_copyHandleBySerialize() {
086: try {
087: ByteArrayOutputStream baos = new ByteArrayOutputStream();
088: ObjectOutputStream oos = new ObjectOutputStream(baos);
089: oos.writeObject(ejbHandle);
090: oos.flush();
091: oos.close();
092: ByteArrayInputStream bais = new ByteArrayInputStream(baos
093: .toByteArray());
094: ObjectInputStream ois = new ObjectInputStream(bais);
095: Handle copy = (Handle) ois.readObject();
096:
097: EJBObject object = copy.getEJBObject();
098: assertNotNull("The EJBObject is null", object);
099: assertTrue("EJBObjects are not identical", object
100: .isIdentical(ejbObject));
101: } catch (Exception e) {
102: fail("Received Exception " + e.getClass() + " : "
103: + e.getMessage());
104: }
105: }
106:
107: /**
108: * This remove method of the EJBHome is placed hear as it
109: * is more a test on the handle then on the remove method
110: * itself.
111: */
112: public void test04_EJBHome_remove() {
113: try {
114: ejbHome.remove(ejbHandle);
115: try {
116: ejbObject.businessMethod("Should throw an exception");
117: assertTrue(
118: "Calling business method after removing the EJBObject does not throw an exception",
119: false);
120: } catch (Exception e) {
121: assertTrue(true);
122: }
123: } catch (Exception e) {
124: fail("Received Exception " + e.getClass() + " : "
125: + e.getMessage());
126: } finally {
127: ejbObject = null;
128: }
129: }
130:
131: //
132: // Test handle methods
133: //=================================
134: }
|