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