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: /**
022: * [5] Should be run as the fifth test suite of the BasicCmpTestClients
023: */
024: public class Complex2RemoteIntfcTests extends ComplexCmp2TestClient {
025:
026: public Complex2RemoteIntfcTests() {
027: super ("RemoteIntfc.");
028: }
029:
030: protected void setUp() throws Exception {
031: super .setUp();
032: Object obj = initialContext
033: .lookup("client/tests/entity/cmp2/ComplexCmpHome");
034: ejbHome = (ComplexCmpHome) javax.rmi.PortableRemoteObject
035: .narrow(obj, ComplexCmpHome.class);
036: ejbObject = ejbHome.createObject("Forth Bean");
037: }
038:
039: //=================================
040: // Test remote interface methods
041: //
042: public void test01_businessMethod() {
043: try {
044: String expected = "Success";
045: String actual = ejbObject.businessMethod("sseccuS");
046: assertEquals(expected, actual);
047: } catch (Exception e) {
048: fail("Received Exception " + e.getClass() + " : "
049: + e.getMessage());
050: }
051: }
052:
053: /**
054: * Throw an application exception and make sure the exception
055: * reaches the bean nicely.
056: */
057: public void test02_throwApplicationException() {
058: try {
059: ejbObject.throwApplicationException();
060: } catch (org.apache.openejb.test.ApplicationException e) {
061: //Good. This is the correct behaviour
062: return;
063: } catch (Throwable e) {
064: fail("Received Exception " + e.getClass() + " : "
065: + e.getMessage());
066: }
067: fail("An ApplicationException should have been thrown.");
068: }
069:
070: /**
071: * After an application exception we should still be able to
072: * use our bean
073: */
074: public void test03_invokeAfterApplicationException() {
075: try {
076: String expected = "Success";
077: String actual = ejbObject.businessMethod("sseccuS");
078: assertEquals(expected, actual);
079: } catch (Throwable e) {
080: fail("Received Exception " + e.getClass() + " : "
081: + e.getMessage());
082: }
083: }
084:
085: public void test04_throwSystemException() {
086: try {
087: ejbObject.throwSystemException_NullPointer();
088: } catch (java.rmi.RemoteException e) {
089: //Good, so far.
090: Throwable n = e.detail;
091: assertNotNull("Nested exception should not be is null", n);
092: assertTrue(
093: "Nested exception should be an instance of NullPointerException, but exception is "
094: + n.getClass().getName(),
095: (n instanceof NullPointerException));
096: return;
097: } catch (Throwable e) {
098: fail("Received Exception " + e.getClass() + " : "
099: + e.getMessage());
100: }
101: fail("A NullPointerException should have been thrown.");
102: }
103:
104: /**
105: * After a system exception the intance should be garbage collected
106: * and the remote reference should be invalidated.
107: * <p/>
108: * The Remote Server fails this one, that should be fixed.
109: */
110: public void BUG_test05_invokeAfterSystemException() {
111: try {
112: ejbObject.businessMethod("This refernce is invalid");
113: fail("A java.rmi.NoSuchObjectException should have been thrown.");
114: } catch (java.rmi.NoSuchObjectException e) {
115: // Good.
116: } catch (Throwable e) {
117: fail("Received Exception " + e.getClass() + " : "
118: + e.getMessage());
119: }
120: }
121:
122: //
123: // Test remote interface methods
124: //=================================
125:
126: protected void tearDown() throws Exception {
127: super.tearDown();
128: }
129: }
|