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.stateful;
017:
018: import org.apache.openejb.test.ApplicationException;
019:
020: /**
021: * [5] Should be run as the fifth test suite of the BasicStatefulTestClients
022: *
023: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
024: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
025: */
026: public class StatefulRemoteIntfcTests extends BasicStatefulTestClient {
027:
028: public StatefulRemoteIntfcTests() {
029: super ("RemoteIntfc.");
030: }
031:
032: protected void setUp() throws Exception {
033: super .setUp();
034: Object obj = initialContext
035: .lookup("client/tests/stateful/BasicStatefulHome");
036: ejbHome = (BasicStatefulHome) javax.rmi.PortableRemoteObject
037: .narrow(obj, BasicStatefulHome.class);
038: ejbObject = ejbHome.createObject("Third Bean");
039: }
040:
041: //=================================
042: // Test remote interface methods
043: //
044: public void test01_businessMethod() {
045: try {
046: String expected = "Success";
047: String actual = ejbObject.businessMethod("sseccuS");
048: assertEquals(expected, actual);
049: } catch (Throwable e) {
050: fail("Received Exception " + e.getClass() + " : "
051: + e.getMessage());
052: }
053: }
054:
055: /**
056: * Throw an application exception and make sure the exception
057: * reaches the bean nicely.
058: */
059: public void test02_throwApplicationException() {
060: try {
061: ejbObject.throwApplicationException();
062: } catch (ApplicationException e) {
063: //Good. This is the correct behaviour
064: return;
065: } catch (Throwable e) {
066: fail("Received Exception " + e.getClass() + " : "
067: + e.getMessage());
068: }
069: fail("An ApplicationException should have been thrown.");
070: }
071:
072: /**
073: * After an application exception we should still be able to
074: * use our bean
075: */
076: public void test03_invokeAfterApplicationException() {
077: try {
078: String expected = "Success";
079: String actual = ejbObject.businessMethod("sseccuS");
080: assertEquals(expected, actual);
081: } catch (Throwable e) {
082: fail("Received Exception " + e.getClass() + " : "
083: + e.getMessage());
084: }
085: }
086:
087: public void test04_throwSystemException() {
088: try {
089: ejbObject.throwSystemException_NullPointer();
090: } catch (java.rmi.RemoteException e) {
091: //Good, so far.
092: Throwable n = e.detail;
093: assertNotNull("Nested exception should not be is null", n);
094: assertTrue(
095: "Nested exception should be an instance of NullPointerException, but exception is "
096: + n.getClass().getName(),
097: (n instanceof NullPointerException));
098: return;
099: } catch (Throwable e) {
100: fail("Received Exception " + e.getClass() + " : "
101: + e.getMessage());
102: }
103: fail("A NullPointerException should have been thrown.");
104: }
105:
106: /**
107: * After a system exception the intance should be garbage collected
108: * and the remote reference should be invalidated.
109: */
110: public void 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: }
|