001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: A_Catcher.java 5486 2004-09-23 08:23:20Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.clients.exception;
025:
026: import java.rmi.RemoteException;
027:
028: import javax.transaction.Status;
029: import javax.transaction.TransactionRolledbackException;
030:
031: import org.objectweb.jonas.jtests.beans.beanexc.AccountS;
032: import org.objectweb.jonas.jtests.beans.beanexc.AppException;
033: import org.objectweb.jonas.jtests.util.JTestCase;
034:
035: /**
036: * Exception test cases common for all type of beans (Entity/Session)
037: * @author Ph.Coq
038: */
039: public abstract class A_Catcher extends JTestCase {
040:
041: public A_Catcher(String name) {
042: super (name);
043: }
044:
045: protected void setUp() {
046: super .setUp();
047: useBeans("beanexc", true);
048: }
049:
050: /**
051: * This method depends on the home used to get it. AccountS is the base
052: * interface of Account (common to Session/Entity)
053: */
054: public abstract AccountS getAccountS(int i);
055:
056: // -----------------------------------------------------
057: // ApplicationException
058: // -----------------------------------------------------
059:
060: /**
061: * Test business method throwing an Application exception. It must be caught
062: * by the client. The business method has NotSupported attribute. Spec 2.0
063: * page 376 (table15)
064: */
065: public void testApplicationNoTx() throws Exception {
066: AccountS acs = getAccountS(83);
067: try {
068: acs.doAppException_3();
069: fail("No AppException");
070: } catch (AppException e) {
071: }
072: }
073:
074: /**
075: * Test business method throwing an Application exception. It must be caught
076: * by the client. The business method has NotSupported attribute. Test that
077: * the transaction has not been marked rollback. Spec 2.0 page 376 (table15)
078: */
079: public void testApplicationNotTx() throws Exception {
080: AccountS acs = getAccountS(83);
081: utx.begin();
082: try {
083: acs.doAppException_3();
084: fail("No AppException");
085: } catch (AppException e) {
086: assertTrue(utx.getStatus() == Status.STATUS_ACTIVE);
087: } finally {
088: utx.rollback();
089: }
090: }
091:
092: /**
093: * Test business method throwing an Application exception. It must be caught
094: * by the client. A transaction is started in the container. (RequiresNew)
095: * Bean does NOT call setRollbackOnly Test that the AppException has been
096: * caught. Spec 2.0 page 376 (table15)
097: */
098: public void testApplicationContTx1() throws Exception {
099: AccountS acs = getAccountS(82);
100: try {
101: // the instance doesn't call setRollbackOnly
102: acs.doAppException_2(false);
103: fail("No AppException");
104: } catch (AppException e) {
105:
106: }
107: }
108:
109: /**
110: * Test business method throwing an Application exception. It must be caught
111: * by the client. A transaction is started in the container. (RequiresNew)
112: * Bean calls setRollbackOnly Test that the AppException has been caught.
113: * Spec 2.0 page 376 (table15)
114: */
115: public void testApplicationContTxRb1() throws Exception {
116: AccountS acs = getAccountS(82);
117: try {
118: // the instance calls setRollbackOnly
119: acs.doAppException_2(true);
120: fail("No AppException");
121: } catch (AppException e) {
122: }
123: }
124:
125: /**
126: * Test business method throwing an Application exception. It must be caught
127: * by the client. Methods runs in the context of the caller's transaction
128: * The business method has Mandatory attribute. Test that the transaction
129: * has not been marked rollback. Spec 2.0 page 375 (table15)
130: */
131: public void testApplicationCallerTx1() throws Exception {
132: AccountS acs = getAccountS(81);
133: utx.begin();
134: try {
135: acs.doAppException_1();
136: fail("No AppException");
137: } catch (AppException e) {
138: assertTrue(utx.getStatus() == Status.STATUS_ACTIVE);
139: } finally {
140: utx.rollback();
141: }
142: }
143:
144: // -----------------------------------------------------
145: // UncheckedException
146: // -----------------------------------------------------
147:
148: /**
149: * Test business method throwing an unchecked exception. Methods runs in the
150: * context of the caller's transaction TransactionRolledbackException must
151: * be caught by the client. The business method has Mandatory attribute. See
152: * EJB2.0 specs page 375 (table 15)
153: */
154: public void testUncheckedCallerTx() throws Exception {
155: AccountS acs = getAccountS(85);
156: utx.begin();
157: try {
158: acs.doUncheckedException_1();
159: fail("No RemoteException");
160: } catch (RemoteException e) {
161: assertTrue((e.detail instanceof TransactionRolledbackException)
162: || (e instanceof TransactionRolledbackException));
163: } finally {
164: utx.rollback();
165: }
166: }
167:
168: /**
169: * Test business method throwing an unchecked exception. Called inside a
170: * containertransaction. The client must receive RemoteException See EJB2.0
171: * specs page 376 (table 15)
172: */
173: public void testUncheckedContTx() throws Exception {
174: AccountS acs = getAccountS(84);
175: try {
176: acs.doUncheckedException_2(); // RequiresNew
177: fail("No RemoteException");
178: } catch (RemoteException e) {
179: }
180:
181: }
182:
183: /**
184: * Test business method throwing an unchecked exception. Method runs with an
185: * unspecified transaction context (NotSupported) The client must receive
186: * RemoteException See EJB2.0 specs page 376 (table 15)
187: */
188: public void testUncheckedNoTx() throws Exception {
189: AccountS acs = getAccountS(84);
190: try {
191: acs.doUncheckedException_3(); // NotSupported
192: fail("No RemoteException");
193: } catch (RemoteException e) {
194: }
195: }
196:
197: // -----------------------------------------------------
198: // EJBException
199: // -----------------------------------------------------
200:
201: /**
202: * Test business method throwing an EJBException Called inside a
203: * containertransaction (RequiresNew). The client must receive
204: * RemoteException See EJB2.0 specs page 376 (table 15)
205: */
206: public void testEJBContTx() throws Exception {
207: AccountS acs = getAccountS(84);
208: try {
209: acs.doEJBException_1(); // RequiresNew
210: fail("No RemoteException");
211: } catch (RemoteException e) {
212: }
213: }
214:
215: // -----------------------------------------------------
216: // RemoteException
217: // -----------------------------------------------------
218:
219: /**
220: * Test business method throwing a RemoteException. Methods runs in the
221: * context of the caller's transaction The bean method is TxMandatory The
222: * client must receive TransactionRolledbackException See EJB2.0 specs page
223: * 375 (table 15)
224: */
225: public void testRemoteCallerTx() throws Exception {
226: AccountS acs = getAccountS(86);
227: utx.begin();
228: acs.ping(); // avoid another bug with RMI
229: try {
230: acs.doRemoteException_1(); // TxMandatory
231: fail("No RemoteException");
232: } catch (RemoteException e) {
233: assertTrue((e.detail instanceof TransactionRolledbackException)
234: || (e instanceof TransactionRolledbackException));
235: } finally {
236: utx.rollback();
237: }
238: }
239:
240: }
|