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.stateless;
017:
018: public class StatelessPojoRemoteIntrfcTests extends
019: BasicStatelessTestClient {
020:
021: public StatelessPojoRemoteIntrfcTests() {
022: super ("PojoRemoteIntfc.");
023: }
024:
025: protected void setUp() throws Exception {
026: super .setUp();
027: Object obj = initialContext
028: .lookup("client/tests/stateless/BasicStatelessPojoHome");
029: ejbHome = (BasicStatelessHome) javax.rmi.PortableRemoteObject
030: .narrow(obj, BasicStatelessHome.class);
031: ejbObject = ejbHome.createObject();
032: }
033:
034: //=================================
035: // Test remote interface methods
036: //
037: public void test01_businessMethod() {
038: try {
039: String expected = "Success";
040: String actual = ejbObject.businessMethod("sseccuS");
041: assertEquals(expected, actual);
042: } catch (Exception e) {
043: fail("Received Exception " + e.getClass() + " : "
044: + e.getMessage());
045: }
046: }
047:
048: /**
049: * Throw an application exception and make sure the exception
050: * reaches the bean nicely.
051: */
052: public void test02_throwApplicationException() {
053: try {
054: ejbObject.throwApplicationException();
055: } catch (org.apache.openejb.test.ApplicationException e) {
056: assertTrue(true);
057: return;
058: } catch (Throwable e) {
059: fail("Received Exception " + e.getClass() + " : "
060: + e.getMessage());
061: }
062: fail("An ApplicationException should have been thrown.");
063: }
064:
065: /**
066: * After an application exception we should still be able to
067: * use our bean
068: */
069: public void test03_invokeAfterApplicationException() {
070: try {
071: String expected = "Success";
072: String actual = ejbObject.businessMethod("sseccuS");
073: assertEquals(expected, actual);
074: } catch (Throwable e) {
075: fail("Received Exception " + e.getClass() + " : "
076: + e.getMessage());
077: }
078: }
079:
080: public void test04_throwSystemException() {
081: try {
082: ejbObject.throwSystemException_NullPointer();
083: } catch (java.rmi.RemoteException e) {
084: //Good, so far.
085: Throwable n = e.detail;
086: assertNotNull("Nested exception should not be is null", n);
087: assertTrue(
088: "Nested exception should be an instance of NullPointerException, but exception is "
089: + n.getClass().getName(),
090: (n instanceof NullPointerException));
091: return;
092: } catch (Throwable e) {
093: fail("Received Exception " + e.getClass() + " : "
094: + e.getMessage());
095: }
096: fail("A NullPointerException should have been thrown.");
097: }
098:
099: /**
100: * After a system exception the intance should be garbage collected
101: * but this is invisible to the client as it will just use another
102: * stateless session object. All the stateless session objects are
103: * equal. Refer 4.5.3 in EJB 3.0 core specification.
104: *
105: */
106:
107: public void test05_invokeAfterSystemException() {
108: try {
109: String expected = "Success";
110: String actual = ejbObject.businessMethod("sseccuS");
111: assertEquals(expected, actual);
112:
113: } catch (Exception e) {
114: fail("The business method should have been executed.");
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: }
|