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.mdb;
018:
019: import javax.jms.Destination;
020:
021: /**
022: * [5] Should be run as the fifth test suite of the BasicStatelessTestClients
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 BasicMdbTests extends MdbTestClient {
028: protected BasicMdbObject basicMdbObject;
029:
030: public BasicMdbTests() {
031: super ("BasicMdb.");
032: }
033:
034: protected void setUp() throws Exception {
035: super .setUp();
036: Destination destination = (Destination) initialContext
037: .lookup("client/tests/messagedriven/mdb/BasicMdb");
038: basicMdbObject = MdbProxy.newProxyInstance(
039: BasicMdbObject.class, connectionFactory, destination);
040: }
041:
042: protected void tearDown() throws Exception {
043: MdbProxy.destroyProxy(basicMdbObject);
044: super .tearDown();
045: }
046:
047: //=================================
048: // Test remote interface methods
049: //
050: public void test01_businessMethod() {
051: try {
052: String expected = "Success";
053: String actual = basicMdbObject.businessMethod("sseccuS");
054: assertEquals(expected, actual);
055: } catch (Exception e) {
056: e.printStackTrace();
057: fail("Received Exception " + e.getClass() + " : "
058: + e.getMessage());
059: }
060: }
061:
062: /**
063: * Throw an application exception and make sure the exception
064: * reaches the bean nicely.
065: */
066: public void Xtest02_throwApplicationException() {
067: try {
068: basicMdbObject.throwApplicationException();
069: } catch (org.apache.openejb.test.ApplicationException e) {
070: //Good. This is the correct behaviour
071: return;
072: } catch (Throwable e) {
073: fail("Received Exception " + e.getClass() + " : "
074: + e.getMessage());
075: }
076: fail("An ApplicationException should have been thrown.");
077: }
078:
079: /**
080: * After an application exception we should still be able to
081: * use our bean
082: */
083: public void test03_invokeAfterApplicationException() {
084: try {
085: String expected = "Success";
086: String actual = basicMdbObject.businessMethod("sseccuS");
087: assertEquals(expected, actual);
088: } catch (Throwable e) {
089: e.printStackTrace();
090: fail("Received Exception " + e.getClass() + " : "
091: + e.getMessage());
092: }
093: }
094:
095: public void Xtest04_throwSystemException() {
096: try {
097: basicMdbObject.throwSystemException_NullPointer();
098: } catch (Exception e) {
099: //Good, so far.
100: Throwable n = e.getCause();
101: assertNotNull("Nested exception should not be is null", n);
102: assertTrue(
103: "Nested exception should be an instance of NullPointerException, but exception is "
104: + n.getClass().getName(),
105: (n instanceof NullPointerException));
106: return;
107: } catch (Throwable e) {
108: fail("Received Exception " + e.getClass() + " : "
109: + e.getMessage());
110: }
111: fail("A NullPointerException should have been thrown.");
112: }
113:
114: /**
115: * After a system exception the intance should be garbage collected
116: * and the remote reference should be invalidated.
117: *
118: * This one seems to fail. we should double-check the spec on this.
119: */
120: public void TODO_test05_invokeAfterSystemException() {
121: try {
122: basicMdbObject.businessMethod("This refernce is invalid");
123: fail("A java.rmi.NoSuchObjectException should have been thrown.");
124: } catch (Exception e) {
125: // Good.
126: } catch (Throwable e) {
127: fail("Received Exception " + e.getClass() + " : "
128: + e.getMessage());
129: }
130: }
131: //
132: // Test remote interface methods
133: //=================================
134: }
|