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