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.bmp;
017:
018: /**
019: * [5] Should be run as the fifth test suite of the BasicBmpTestClients
020: *
021: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
022: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
023: */
024: public class BmpRemoteIntfcTests extends BasicBmpTestClient {
025:
026: public BmpRemoteIntfcTests() {
027: super ("RemoteIntfc.");
028: }
029:
030: protected void setUp() throws Exception {
031: super .setUp();
032: Object obj = initialContext
033: .lookup("client/tests/entity/bmp/BasicBmpHome");
034: ejbHome = (BasicBmpHome) javax.rmi.PortableRemoteObject.narrow(
035: obj, BasicBmpHome.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: *
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: }
|