KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > transaction > A_TxAttribute


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 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_TxAttribute.java,v 1.6 2004/03/19 11:57:16 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.transaction;
27
28 import java.rmi.RemoteException JavaDoc;
29
30 import javax.transaction.TransactionRequiredException JavaDoc;
31
32 import org.objectweb.jonas.jtests.beans.transacted.Simple;
33 import org.objectweb.jonas.jtests.util.JTestCase;
34
35 /**
36  * Transactional attribute test cases
37  * tests here are common to entity and session beans.
38  * beans used : transacted
39  * @author Ph.Coq, Ph.Durieux (jonas team)
40  */

41 public abstract class A_TxAttribute extends JTestCase {
42
43     /**
44      * constructor
45      * @param name name of the test suite.
46      */

47     public A_TxAttribute(String JavaDoc name) {
48         super(name);
49     }
50
51     /**
52      * Sets up the fixture, here load the beans if not loaded yet.
53      * This method is called before a test is executed.
54      */

55     protected void setUp() {
56         super.setUp();
57         useBeans("transacted", true);
58     }
59
60     /**
61      * Get an instance of the bean.
62      * This method depends on the home used to get it.
63      * For entity bean, the arg is used to get a particular instance.
64      * For session beans, we get any session bean from the pool.
65      */

66     public abstract Simple getSimple(int i) throws Exception JavaDoc;
67
68
69     // --------------------------------------------------------------------
70
// test cases
71
// --------------------------------------------------------------------
72

73     /**
74      * Test of NotSupported attribute
75      * A business method with NotSupported is called outside TX
76      * this method returns if the thread is associated to a transaction
77      *
78      * the expected value is false
79      */

80     public void testNotSupported() throws Exception JavaDoc {
81
82         Simple s = getSimple(10);
83         assertEquals(false, s.opwith_notsupported());
84         s.remove();
85     }
86
87     /**
88      * Test of RequiresNew attribute
89      * A business method with RequiresNew is called outside TX
90      * this method returns if the thread is associated to a transaction
91      *
92      * the expected value is true
93      */

94     public void testRequiresNew() throws Exception JavaDoc {
95
96         Simple s = getSimple(11);
97         assertEquals(true, s.opwith_requires_new());
98         s.remove();
99     }
100
101     /**
102      * Test of Required attribute
103      * A business method with Required is called outside TX
104      * this method returns if the thread is associated to a transaction
105      *
106      * the expected value is true
107      */

108     public void testRequired() throws Exception JavaDoc {
109
110         Simple s = getSimple(12);
111         assertEquals(true, s.opwith_required());
112         s.remove();
113     }
114
115     /**
116      * Test a "Required" method calling a "Requires_new" method.
117      * the expected value is true
118      */

119     public void testRequiredRequiresNew() throws Exception JavaDoc {
120
121         Simple s = getSimple(12);
122         assertEquals(true, s.required_call_requires_new());
123         s.remove();
124     }
125
126     /**
127      * Test a "Required" method calling a "Requires_new" method on
128      * another bean instance.
129      * the expected value is true
130      */

131     public void testRequiredRequiresNew2() throws Exception JavaDoc {
132
133         Simple s = getSimple(20);
134         Simple s2 = getSimple(21);
135         assertEquals(true, s.call_requires_new_on(s2));
136         s2.remove();
137         s.remove();
138     }
139
140     /**
141      * Test of Mandatory attribute
142      * A business method with Mandatory is called outside TX
143      * this method returns if the thread is associated to a transaction
144      *
145      * A javax.transaction.TransactionRequiredException must be received
146      */

147
148     public void testMandatory() throws Exception JavaDoc {
149
150         Simple s = getSimple(13);
151         try {
152             s.opwith_mandatory();
153             fail("mandatory: should raise exception");
154         } catch (javax.transaction.TransactionRequiredException JavaDoc e) {
155         } catch (RemoteException JavaDoc e) {
156             assertTrue(e.detail instanceof TransactionRequiredException JavaDoc);
157         }
158         s.remove();
159     }
160
161     /**
162      * Test of Never attribute
163      * A business method with Never is called outside TX
164      * this method returns if the thread is associated to a transaction
165      *
166      * the expected value is false
167      */

168     public void testNever() throws Exception JavaDoc {
169
170         Simple s = getSimple(14);
171         assertEquals(false, s.opwith_never());
172         s.remove();
173     }
174
175
176     /**
177      * Test of Supports attribute
178      * A business method with Supports is called outside TX
179      * this method returns if the thread is associated to a transaction
180      *
181      * the expected value is false
182      */

183     public void testSupports() throws Exception JavaDoc {
184
185         Simple s = getSimple(15);
186         assertEquals(false, s.opwith_supports());
187         s.remove();
188     }
189
190     /**
191      * Test of NotSupported attribute
192      * A business method with NotSupported is called inside TX
193      * this method returns if the thread is associated to a transaction
194      *
195      * the expected value is false
196      */

197     public void testNotSupportedTx() throws Exception JavaDoc {
198
199         Simple s = getSimple(20);
200         utx.begin();
201         try {
202             assertEquals(false, s.opwith_notsupported());
203         } finally {
204             utx.rollback();
205             s.remove();
206         }
207     }
208
209     /**
210      * Test of RequiresNew attribute
211      * A business method with RequiresNew is called inside TX
212      * this method returns if the thread is associated to a transaction
213      *
214      * the expected value is true
215      */

216     public void testRequiresNewTx() throws Exception JavaDoc {
217         Simple s = getSimple(21);
218         utx.begin();
219         try {
220             assertEquals(true, s.opwith_requires_new());
221         } finally {
222             utx.rollback();
223             s.remove();
224         }
225     }
226
227     /**
228      * Test of Required attribute
229      * A business method with Required is called inside TX
230      * this method returns if the thread is associated to a transaction
231      *
232      * the expected value is true
233      */

234     public void testRequiredTx() throws Exception JavaDoc {
235
236         Simple s = getSimple(22);
237         utx.begin();
238         try {
239             assertEquals(true, s.opwith_required());
240         } finally {
241             utx.rollback();
242             s.remove();
243         }
244
245     }
246
247     /**
248      * Test of Mandatory attribute
249      * A business method with Mandatory is called inside TX
250      * this method returns if the thread is associated to a transaction
251      *
252      * the expected value is true
253      */

254     public void testMandatoryTx() throws Exception JavaDoc {
255
256         Simple s = getSimple(23);
257         utx.begin();
258         try {
259             assertEquals(true, s.opwith_mandatory());
260         } finally {
261             utx.rollback();
262             s.remove();
263         }
264     }
265
266
267
268
269     /**
270      * Test of Never attribute
271      * A business method with Mandatory is called inside TX
272      * this method returns if the thread is associated to a transaction
273      *
274      * A java.rmi.RemoteException must be received
275      */

276     public void testNeverTx() throws Exception JavaDoc {
277
278         Simple s = getSimple(24);
279         utx.begin();
280         try {
281             s.opwith_never();
282             fail("never: should raise exception");
283         } catch (RemoteException JavaDoc e) {
284         } finally {
285             utx.rollback();
286             s.remove();
287         }
288     }
289
290     /**
291      * Test of Supports attribute
292      * A business method with Supports is called inside TX
293      * this method returns if the thread is associated to a transaction
294      *
295      * the expected value is true
296      */

297     public void testSupportsTx() throws Exception JavaDoc {
298
299         Simple s = getSimple(25);
300         utx.begin();
301         try {
302             assertEquals(true, s.opwith_supports());
303         } finally {
304             utx.rollback();
305             s.remove();
306         }
307     
308     }
309
310     /**
311      * Test the sequence of several calls to methods
312      * with different transactional contexts
313      */

314     public void testNoTx() throws Exception JavaDoc {
315
316         Simple s = getSimple(1);
317         assertEquals(false, s.opwith_notsupported());
318         assertEquals(true, s.opwith_requires_new());
319         assertEquals(true, s.opwith_required());
320         assertEquals(false, s.opwith_never());
321         assertEquals(false, s.opwith_supports());
322         s.remove();
323     }
324
325 }
326
Popular Tags