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: import javax.ejb.EJBException;
019:
020: /**
021: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
022: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
023: * @author <a href="mailto:manu.t.george@gmail.com">Manu George</a>
024: */
025: public class StatelessLocalIntfcTests extends
026: BasicStatelessLocalTestClient {
027:
028: public StatelessLocalIntfcTests() {
029: super ("LocalIntfc.");
030: }
031:
032: protected void setUp() throws Exception {
033: super .setUp();
034: Object obj = initialContext
035: .lookup("client/tests/stateless/BasicStatelessPojoHomeLocal");
036: ejbLocalHome = (BasicStatelessLocalHome) obj;
037: ejbLocalObject = ejbLocalHome.create();
038: }
039:
040: //=================================
041: // Test local interface methods
042: //
043: public void test01_businessMethod() {
044: try {
045: String expected = "Success";
046: String actual = ejbLocalObject.businessMethod("sseccuS");
047: assertEquals(expected, actual);
048: } catch (Exception e) {
049: fail("Received Exception " + e.getClass() + " : "
050: + e.getMessage());
051: }
052: }
053:
054: /**
055: * Throw an application exception in the bean and make sure the exception
056: * reaches the client nicely.
057: */
058: public void test02_throwApplicationException() {
059: try {
060: ejbLocalObject.throwApplicationException();
061: } catch (org.apache.openejb.test.ApplicationException e) {
062: //Good. This is the correct behaviour
063: return;
064: } catch (Throwable e) {
065: fail("Received Exception " + e.getClass() + " : "
066: + e.getMessage());
067: }
068: fail("An ApplicationException should have been thrown.");
069: }
070:
071: /**
072: * After an application exception we should still be able to
073: * use our bean
074: */
075: public void test03_invokeAfterApplicationException() {
076: try {
077: String expected = "Success";
078: String actual = ejbLocalObject.businessMethod("sseccuS");
079: assertEquals(expected, actual);
080: } catch (Throwable e) {
081: fail("Received Exception " + e.getClass() + " : "
082: + e.getMessage());
083: }
084: }
085:
086: public void test04_throwSystemException() {
087: try {
088: ejbLocalObject.throwSystemException_NullPointer();
089: } catch (EJBException e) {
090: //Good, so far.
091:
092: assertNotNull("Nested exception should not be is null", e);
093: assertTrue(
094: "Nested exception should be an instance of NullPointerException, but exception is "
095: + e.getCausedByException().getClass()
096: .getName(),
097: (e.getCausedByException() instanceof NullPointerException));
098: return;
099: } catch (Throwable e) {
100: fail("Received Exception " + e.getClass() + " : "
101: + e.getMessage());
102: }
103: fail("An EJBException encapsulating a NullPointerException should have been thrown.");
104: }
105:
106: /**
107: * After a system exception the intance should be garbage collected
108: * but this is invisible to the client as it will just use another
109: * stateless session object. All the stateless session objects are
110: * equal. Refer 4.5.3 in EJB 3.0 core specification.
111: * This one seems to fail. we should double-check the spec on this.
112: */
113: public void test05_invokeAfterSystemException() {
114: try {
115: String expected = "Success";
116: String actual = ejbLocalObject.businessMethod("sseccuS");
117: assertEquals(expected, actual);
118:
119: } catch (Exception e) {
120: fail("The business method should have been executed.");
121: } catch (Throwable e) {
122: fail("Received Exception " + e.getClass() + " : "
123: + e.getMessage());
124: }
125: }
126:
127: //
128: // Test remote interface methods
129: //=================================
130:
131: protected void tearDown() throws Exception {
132: super .tearDown();
133: }
134:
135: //TODO Tests for the below conditions need to be added.
136: /* Test an Application Exception that is a runtime exception
137: * Throwing an application exception within a transaction
138: * will rollback only if that method is marked for rollback
139: * Also FinderException, CreateException and RemoveException
140: * are application exceptions.
141: */
142: }
|