001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.test.entity.cmp2;
017:
018: import org.apache.openejb.test.entity.cmp.BasicCmpHome;
019:
020: /**
021: * [5] Should be run as the fifth test suite of the BasicCmpTestClients
022: */
023: public class Cmp2RemoteIntfcTests extends BasicCmp2TestClient {
024:
025: public Cmp2RemoteIntfcTests() {
026: super ("RemoteIntfc.");
027: }
028:
029: protected void setUp() throws Exception {
030: super .setUp();
031: Object obj = initialContext
032: .lookup("client/tests/entity/cmp/BasicCmpHome");
033: ejbHome = (BasicCmpHome) javax.rmi.PortableRemoteObject.narrow(
034: obj, BasicCmpHome.class);
035: ejbObject = ejbHome.createObject("Forth Bean");
036: }
037:
038: //=================================
039: // Test remote interface methods
040: //
041: public void test01_businessMethod() {
042: try {
043: String expected = "Success";
044: String actual = ejbObject.businessMethod("sseccuS");
045: assertEquals(expected, actual);
046: } catch (Exception e) {
047: fail("Received Exception " + e.getClass() + " : "
048: + e.getMessage());
049: }
050: }
051:
052: /**
053: * Throw an application exception and make sure the exception
054: * reaches the bean nicely.
055: */
056: public void test02_throwApplicationException() {
057: try {
058: ejbObject.throwApplicationException();
059: } catch (org.apache.openejb.test.ApplicationException e) {
060: //Good. This is the correct behaviour
061: return;
062: } catch (Throwable e) {
063: fail("Received Exception " + e.getClass() + " : "
064: + e.getMessage());
065: }
066: fail("An ApplicationException should have been thrown.");
067: }
068:
069: /**
070: * After an application exception we should still be able to
071: * use our bean
072: */
073: public void test03_invokeAfterApplicationException() {
074: try {
075: String expected = "Success";
076: String actual = ejbObject.businessMethod("sseccuS");
077: assertEquals(expected, actual);
078: } catch (Throwable e) {
079: fail("Received Exception " + e.getClass() + " : "
080: + e.getMessage());
081: }
082: }
083:
084: public void test04_throwSystemException() {
085: try {
086: ejbObject.throwSystemException_NullPointer();
087: } catch (java.rmi.RemoteException e) {
088: //Good, so far.
089: Throwable n = e.detail;
090: assertNotNull("Nested exception should not be is null", n);
091: assertTrue(
092: "Nested exception should be an instance of NullPointerException, but exception is "
093: + n.getClass().getName(),
094: (n instanceof NullPointerException));
095: return;
096: } catch (Throwable e) {
097: fail("Received Exception " + e.getClass() + " : "
098: + e.getMessage());
099: }
100: fail("A NullPointerException should have been thrown.");
101: }
102:
103: /**
104: * After a system exception the intance should be garbage collected
105: * and the remote reference should be invalidated.
106: * <p/>
107: * The Remote Server fails this one, that should be fixed.
108: */
109: public void BUG_test05_invokeAfterSystemException() {
110: try {
111: ejbObject.businessMethod("This refernce is invalid");
112: fail("A java.rmi.NoSuchObjectException should have been thrown.");
113: } catch (java.rmi.NoSuchObjectException e) {
114: // Good.
115: } catch (Throwable e) {
116: fail("Received Exception " + e.getClass() + " : "
117: + e.getMessage());
118: }
119: }
120:
121: //
122: // Test remote interface methods
123: //=================================
124:
125: protected void tearDown() throws Exception {
126: super.tearDown();
127: }
128: }
|