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: /**
019: *
020: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
021: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
022: */
023: public class StatefulLocalBusinessIntfcTests extends StatefulTestClient {
024: private BasicStatefulBusinessLocal businessLocal;
025:
026: public StatefulLocalBusinessIntfcTests() {
027: super ("LocalBusinessIntfc.");
028: }
029:
030: protected void setUp() throws Exception {
031: super .setUp();
032: }
033:
034: //=================================
035: // Test remote interface methods
036: //
037: public void test00_lookupBusinessInterface() throws Exception {
038: Object obj = initialContext
039: .lookup("client/tests/stateful/BasicStatefulPojoHomeBusinessLocal");
040: assertNotNull(obj);
041: assertTrue("instance of BasicStatefulBusinessLocal",
042: obj instanceof BasicStatefulBusinessLocal);
043: businessLocal = (BasicStatefulBusinessLocal) obj;
044: }
045:
046: public void test01_businessMethod() {
047: try {
048: String expected = "Success";
049: String actual = businessLocal.businessMethod("sseccuS");
050: assertEquals(expected, actual);
051: } catch (Exception e) {
052: fail("Received Exception " + e.getClass() + " : "
053: + e.getMessage());
054: }
055:
056: try {
057: Integer expected = new Integer(42);
058: Object actual = businessLocal.echo(expected);
059: assertSame("pass by reference", expected, actual);
060: } catch (Exception e) {
061: fail("Received Exception " + e.getClass() + " : "
062: + e.getMessage());
063: }
064: }
065:
066: /**
067: * Throw an application exception and make sure the exception
068: * reaches the bean nicely.
069: */
070: public void test02_throwApplicationException() {
071: try {
072: businessLocal.throwApplicationException();
073: } catch (org.apache.openejb.test.ApplicationException e) {
074: //Good. This is the correct behaviour
075: return;
076: } catch (Throwable e) {
077: fail("Received Exception " + e.getClass() + " : "
078: + e.getMessage());
079: }
080: fail("An ApplicationException should have been thrown.");
081: }
082:
083: /**
084: * After an application exception we should still be able to
085: * use our bean
086: */
087: public void test03_invokeAfterApplicationException() {
088: try {
089: String expected = "Success";
090: String actual = businessLocal.businessMethod("sseccuS");
091: assertEquals(expected, actual);
092: } catch (Throwable e) {
093: fail("Received Exception " + e.getClass() + " : "
094: + e.getMessage());
095: }
096: }
097:
098: // TODO: check which exception should be thrown
099: public void _test04_throwSystemException() {
100: try {
101: businessLocal.throwSystemException_NullPointer();
102: } catch (Exception e) {
103: //Good, so far.
104: Throwable n = e.getCause();
105: assertNotNull("Nested exception should not be is null", n);
106: assertTrue(
107: "Nested exception should be an instance of NullPointerException, but exception is "
108: + n.getClass().getName(),
109: (n instanceof NullPointerException));
110: return;
111: } catch (Throwable e) {
112: fail("Received Exception " + e.getClass() + " : "
113: + e.getMessage());
114: }
115: fail("A NullPointerException should have been thrown.");
116: }
117:
118: /**
119: * After a system exception the intance should be garbage collected
120: * and the remote reference should be invalidated.
121: *
122: * This one seems to fail. we should double-check the spec on this.
123: */
124: //TODO: implement
125: public void TODO_test05_invokeAfterSystemException() {
126: // try{
127: // businessLocal.businessMethod("This refernce is invalid");
128: // fail("A java.rmi.NoSuchObjectException should have been thrown.");
129: // } catch (java.rmi.NoSuchObjectException e){
130: // // Good.
131: // } catch (Throwable e){
132: // fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
133: // }
134: }
135:
136: //
137: // Test remote interface methods
138: //=================================
139:
140: public void test06_testRemove() {
141: Object obj = businessLocal.remove();
142: assertNotNull(obj);
143: }
144:
145: protected void tearDown() throws Exception {
146: super.tearDown();
147: }
148: }
|