KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > exception > A_Catcher


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: A_Catcher.java,v 1.4 2004/09/23 08:23:20 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.exception;
27
28 import java.rmi.RemoteException JavaDoc;
29
30 import javax.transaction.Status JavaDoc;
31 import javax.transaction.TransactionRolledbackException JavaDoc;
32
33 import org.objectweb.jonas.jtests.beans.beanexc.AccountS;
34 import org.objectweb.jonas.jtests.beans.beanexc.AppException;
35 import org.objectweb.jonas.jtests.util.JTestCase;
36
37 /**
38  * Exception test cases common for all type of beans (Entity/Session)
39  * @author Ph.Coq
40  */

41 public abstract class A_Catcher extends JTestCase {
42
43     public A_Catcher(String JavaDoc name) {
44         super(name);
45     }
46
47     protected void setUp() {
48         super.setUp();
49         useBeans("beanexc", true);
50     }
51
52     /**
53      * This method depends on the home used to get it. AccountS is the base
54      * interface of Account (common to Session/Entity)
55      */

56     public abstract AccountS getAccountS(int i);
57
58     // -----------------------------------------------------
59
// ApplicationException
60
// -----------------------------------------------------
61

62     /**
63      * Test business method throwing an Application exception. It must be caught
64      * by the client. The business method has NotSupported attribute. Spec 2.0
65      * page 376 (table15)
66      */

67     public void testApplicationNoTx() throws Exception JavaDoc {
68         AccountS acs = getAccountS(83);
69         try {
70             acs.doAppException_3();
71             fail("No AppException");
72         } catch (AppException e) {
73         }
74     }
75
76     /**
77      * Test business method throwing an Application exception. It must be caught
78      * by the client. The business method has NotSupported attribute. Test that
79      * the transaction has not been marked rollback. Spec 2.0 page 376 (table15)
80      */

81     public void testApplicationNotTx() throws Exception JavaDoc {
82         AccountS acs = getAccountS(83);
83         utx.begin();
84         try {
85             acs.doAppException_3();
86             fail("No AppException");
87         } catch (AppException e) {
88             assertTrue(utx.getStatus() == Status.STATUS_ACTIVE);
89         } finally {
90             utx.rollback();
91         }
92     }
93
94     /**
95      * Test business method throwing an Application exception. It must be caught
96      * by the client. A transaction is started in the container. (RequiresNew)
97      * Bean does NOT call setRollbackOnly Test that the AppException has been
98      * caught. Spec 2.0 page 376 (table15)
99      */

100     public void testApplicationContTx1() throws Exception JavaDoc {
101         AccountS acs = getAccountS(82);
102         try {
103             // the instance doesn't call setRollbackOnly
104
acs.doAppException_2(false);
105             fail("No AppException");
106         } catch (AppException e) {
107
108         }
109     }
110
111     /**
112      * Test business method throwing an Application exception. It must be caught
113      * by the client. A transaction is started in the container. (RequiresNew)
114      * Bean calls setRollbackOnly Test that the AppException has been caught.
115      * Spec 2.0 page 376 (table15)
116      */

117     public void testApplicationContTxRb1() throws Exception JavaDoc {
118         AccountS acs = getAccountS(82);
119         try {
120             // the instance calls setRollbackOnly
121
acs.doAppException_2(true);
122             fail("No AppException");
123         } catch (AppException e) {
124         }
125     }
126
127     /**
128      * Test business method throwing an Application exception. It must be caught
129      * by the client. Methods runs in the context of the caller's transaction
130      * The business method has Mandatory attribute. Test that the transaction
131      * has not been marked rollback. Spec 2.0 page 375 (table15)
132      */

133     public void testApplicationCallerTx1() throws Exception JavaDoc {
134         AccountS acs = getAccountS(81);
135         utx.begin();
136         try {
137             acs.doAppException_1();
138             fail("No AppException");
139         } catch (AppException e) {
140             assertTrue(utx.getStatus() == Status.STATUS_ACTIVE);
141         } finally {
142             utx.rollback();
143         }
144     }
145
146     // -----------------------------------------------------
147
// UncheckedException
148
// -----------------------------------------------------
149

150     /**
151      * Test business method throwing an unchecked exception. Methods runs in the
152      * context of the caller's transaction TransactionRolledbackException must
153      * be caught by the client. The business method has Mandatory attribute. See
154      * EJB2.0 specs page 375 (table 15)
155      */

156     public void testUncheckedCallerTx() throws Exception JavaDoc {
157         AccountS acs = getAccountS(85);
158         utx.begin();
159         try {
160             acs.doUncheckedException_1();
161             fail("No RemoteException");
162         } catch (RemoteException JavaDoc e) {
163             assertTrue((e.detail instanceof TransactionRolledbackException JavaDoc)
164                     || (e instanceof TransactionRolledbackException JavaDoc));
165         } finally {
166             utx.rollback();
167         }
168     }
169
170     /**
171      * Test business method throwing an unchecked exception. Called inside a
172      * containertransaction. The client must receive RemoteException See EJB2.0
173      * specs page 376 (table 15)
174      */

175     public void testUncheckedContTx() throws Exception JavaDoc {
176         AccountS acs = getAccountS(84);
177         try {
178             acs.doUncheckedException_2(); // RequiresNew
179
fail("No RemoteException");
180         } catch (RemoteException JavaDoc e) {
181         }
182
183     }
184
185     /**
186      * Test business method throwing an unchecked exception. Method runs with an
187      * unspecified transaction context (NotSupported) The client must receive
188      * RemoteException See EJB2.0 specs page 376 (table 15)
189      */

190     public void testUncheckedNoTx() throws Exception JavaDoc {
191         AccountS acs = getAccountS(84);
192         try {
193             acs.doUncheckedException_3(); // NotSupported
194
fail("No RemoteException");
195         } catch (RemoteException JavaDoc e) {
196         }
197     }
198
199     // -----------------------------------------------------
200
// EJBException
201
// -----------------------------------------------------
202

203     /**
204      * Test business method throwing an EJBException Called inside a
205      * containertransaction (RequiresNew). The client must receive
206      * RemoteException See EJB2.0 specs page 376 (table 15)
207      */

208     public void testEJBContTx() throws Exception JavaDoc {
209         AccountS acs = getAccountS(84);
210         try {
211             acs.doEJBException_1(); // RequiresNew
212
fail("No RemoteException");
213         } catch (RemoteException JavaDoc e) {
214         }
215     }
216
217     // -----------------------------------------------------
218
// RemoteException
219
// -----------------------------------------------------
220

221     /**
222      * Test business method throwing a RemoteException. Methods runs in the
223      * context of the caller's transaction The bean method is TxMandatory The
224      * client must receive TransactionRolledbackException See EJB2.0 specs page
225      * 375 (table 15)
226      */

227     public void testRemoteCallerTx() throws Exception JavaDoc {
228         AccountS acs = getAccountS(86);
229         utx.begin();
230         acs.ping(); // avoid another bug with RMI
231
try {
232             acs.doRemoteException_1(); // TxMandatory
233
fail("No RemoteException");
234         } catch (RemoteException JavaDoc e) {
235             assertTrue((e.detail instanceof TransactionRolledbackException JavaDoc)
236                     || (e instanceof TransactionRolledbackException JavaDoc));
237         } finally {
238             utx.rollback();
239         }
240     }
241
242 }
Popular Tags