KickJava   Java API By Example, From Geeks To Geeks.

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


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_TxAttributeEntity.java,v 1.6 2003/09/17 08:56:40 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas.jtests.clients.transaction;
28
29 import java.rmi.RemoteException JavaDoc;
30 import javax.transaction.TransactionRequiredException JavaDoc;
31 import org.objectweb.jonas.jtests.beans.transacted.Simple;
32 import org.objectweb.jonas.jtests.beans.transacted.SimpleEHome;
33
34
35 /**
36  * Here are found transactional attribute tests
37  * common but specific for all type of entity beans (BMP, CMP1.1, CMP2.0)
38  * Tests on finder and create methods
39  * @author Philippe Durieux (jonas team)
40  */

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

47     public A_TxAttributeEntity(String JavaDoc name) {
48         super(name);
49     }
50
51     /**
52      * return SimpleHome, that can be either BMP, CMP1, or CMP2 bean.
53      */

54     protected abstract SimpleEHome getHome();
55
56     // -----------------------------------------------------------------
57
// tests on Create methods
58
// -----------------------------------------------------------------
59

60     /**
61      * Test Required transactional attributes on create method
62      * the create method xith required is called outside TX
63      *
64      */

65     public void testCreateRequired() throws Exception JavaDoc {
66         long i = 10;
67         Simple entity = getHome().createForRequired(i);
68         entity.remove();
69     }
70
71     /**
72      * Test Required transactional attributes on create method
73      * the create method xith required is called inside TX
74      *
75      */

76     public void testCreateRequiredTx() throws Exception JavaDoc {
77         utx.begin();
78         long i = 11;
79         Simple entity = null;
80         try {
81             entity = getHome().createForRequired(i);
82         } finally {
83             utx.rollback();
84         }
85
86     }
87     /**
88      * Test NotSupported transactional attributes on create method
89      * the create method xith required is called outside TX
90      *
91      */

92     public void testCreateNotSupported() throws Exception JavaDoc {
93         int i = 12;
94         Simple entity = getHome().create(i);
95         entity.remove();
96     }
97
98     /**
99      * Test NotSupported transactional attributes on create method
100      * the create method xith required is called inside TX
101      *
102      */

103     public void testCreateNotSupportedTx() throws Exception JavaDoc {
104         utx.begin();
105         int i = 13;
106         Simple entity = null;
107         try {
108             entity = getHome().create(i);
109         } finally {
110             utx.rollback();
111             entity.remove();
112         }
113     }
114
115     /**
116      * Test Never transactional attributes on create method
117      * the create method xith required is called outside TX
118      *
119      */

120     public void testCreateNever() throws Exception JavaDoc {
121         short i = 14;
122         Simple entity = getHome().createForNever(i);
123         entity.remove();
124     }
125
126     /**
127      * Test Never transactional attributes on create method
128      * the create method xith required is called inside TX
129      *
130      */

131     public void testCreateNeverTx() throws Exception JavaDoc {
132         utx.begin();
133         short i = 15;
134         Simple entity = null;
135         try {
136             entity = getHome().createForNever(i);
137             entity.remove();
138             fail("never: should raise exception");
139         } catch (java.rmi.RemoteException JavaDoc e) {
140         } finally {
141             utx.rollback();
142
143         }
144         
145     }
146
147     /**
148      * Test RequiresNew transactional attributes on create method
149      * the create method xith required is called outside TX
150      *
151      */

152     public void testCreateRequiresNew() throws Exception JavaDoc {
153         String JavaDoc s = "16";
154         Simple entity = getHome().createForRequiresNew(s);
155         entity.remove();
156     }
157
158     /**
159      * Test RequiresNew transactional attributes on create method
160      * the create method xith required is called inside TX
161      *
162      */

163     public void testCreateRequiresNewTx() throws Exception JavaDoc {
164         utx.begin();
165         String JavaDoc s = "17";
166         Simple entity = null;
167         try {
168             entity = getHome().createForRequiresNew(s);
169         } finally {
170             utx.rollback();
171             entity.remove();
172         }
173     }
174
175
176     /**
177      * Test Mandatory transactional attributes on create method
178      * the create method xith required is called outside TX
179      *
180      */

181     public void testCreateMandatory() throws Exception JavaDoc {
182         char c = 'a';
183         try {
184             Simple entity = getHome().createForMandatory(c);
185             entity.remove();
186             fail("mandatory: should raise exception");
187         } catch (javax.transaction.TransactionRequiredException JavaDoc e) {
188         } catch (java.rmi.RemoteException JavaDoc e) {
189             assertTrue(e.detail instanceof javax.transaction.TransactionRequiredException JavaDoc);
190         }
191     }
192
193     /**
194      * Test Mandatory transactional attributes on create method
195      * the create method xith required is called inside TX
196      *
197      */

198     public void testCreateMandatoryTx() throws Exception JavaDoc {
199         utx.begin();
200         char c = 'b';
201         Simple entity = null;
202         try {
203             entity = getHome().createForMandatory(c);
204         } finally {
205             utx.rollback();
206             
207         }
208     }
209
210
211     /**
212      * Test Supports transactional attributes on create method
213      * the create method xith required is called outside TX
214      *
215      */

216     public void testCreateSupports() throws Exception JavaDoc {
217
218         Simple entity = getHome().createForSupports(false);
219         entity.remove();
220     }
221
222     /**
223      * Test Supports transactional attributes on create method
224      * the create method xith required is called inside TX
225      *
226      */

227     public void testCreateSupportsTx() throws Exception JavaDoc {
228         utx.begin();
229         Simple entity = null;
230         try {
231             entity = getHome().createForSupports(true);
232         } finally {
233             utx.rollback();
234  
235         }
236     }
237
238     // -----------------------------------------------------------------
239
// tests on Home methods
240
// -----------------------------------------------------------------
241

242     /**
243      * Test of NotSupported attribute
244      * A home method with NotSupported is called outside TX
245      * this method returns if the thread is associated to a transaction
246      *
247      * the expected value is false
248      */

249     public void testHomeNotSupported() throws Exception JavaDoc {
250         assertEquals(false, getHome().opwith_notsupported());
251     }
252
253     /**
254      * Test of RequiresNew attribute
255      * A home method with RequiresNew is called outside TX
256      * this method returns if the thread is associated to a transaction
257      *
258      * the expected value is true
259      */

260     public void testHomeRequiresNew() throws Exception JavaDoc {
261         assertEquals(true, getHome().opwith_requires_new());
262     }
263
264     /**
265      * Test of Required attribute
266      * A home method with Required is called outside TX
267      * this method returns if the thread is associated to a transaction
268      *
269      * the expected value is true
270      */

271     public void testHomeRequired() throws Exception JavaDoc {
272         assertEquals(true, getHome().opwith_required());
273     }
274
275     /**
276      * Test of Mandatory attribute
277      * A home method with Mandatory is called outside TX
278      * this method returns if the thread is associated to a transaction
279      *
280      * A javax.transaction.TransactionRequiredException must be received
281      */

282
283     public void testHomeMandatory() throws Exception JavaDoc {
284         try {
285             getHome().opwith_mandatory();
286             fail("mandatory: should raise exception");
287         } catch (javax.transaction.TransactionRequiredException JavaDoc e) {
288         } catch (RemoteException JavaDoc e) {
289             assertTrue(e.detail instanceof TransactionRequiredException JavaDoc);
290         }
291     }
292
293     /**
294      * Test of Never attribute
295      * A home method with Never is called outside TX
296      * this method returns if the thread is associated to a transaction
297      *
298      * the expected value is false
299      */

300     public void testHomeNever() throws Exception JavaDoc {
301         assertEquals(false, getHome().opwith_never());
302     }
303
304
305     /**
306      * Test of Supports attribute
307      * A home method with Supports is called outside TX
308      * this method returns if the thread is associated to a transaction
309      *
310      * the expected value is false
311      */

312     public void testHomeSupports() throws Exception JavaDoc {
313         assertEquals(false, getHome().opwith_supports());
314     }
315
316     /**
317      * Test of NotSupported attribute
318      * A home method with NotSupported is called inside TX
319      * this method returns if the thread is associated to a transaction
320      *
321      * the expected value is false
322      */

323     public void testHomeNotSupportedTx() throws Exception JavaDoc {
324         utx.begin();
325         try {
326             assertEquals(false, getHome().opwith_notsupported());
327         } finally {
328             utx.rollback();
329         }
330     }
331
332     /**
333      * Test of RequiresNew attribute
334      * A home method with RequiresNew is called inside TX
335      * this method returns if the thread is associated to a transaction
336      *
337      * the expected value is true
338      */

339     public void testHomeRequiresNewTx() throws Exception JavaDoc {
340         utx.begin();
341         try {
342             assertEquals(true, getHome().opwith_requires_new());
343         } finally {
344             utx.rollback();
345         }
346     }
347
348     /**
349      * Test of Required attribute
350      * A home method with Required is called inside TX
351      * this method returns if the thread is associated to a transaction
352      *
353      * the expected value is true
354      */

355     public void testHomeRequiredTx() throws Exception JavaDoc {
356         utx.begin();
357         try {
358             assertEquals(true, getHome().opwith_required());
359         } finally {
360             utx.rollback();
361         }
362
363     }
364
365     /**
366      * Test of Mandatory attribute
367      * A home method with Mandatory is called inside TX
368      * this method returns if the thread is associated to a transaction
369      *
370      * the expected value is true
371      */

372     public void testHomeMandatoryTx() throws Exception JavaDoc {
373         utx.begin();
374         try {
375             assertEquals(true, getHome().opwith_mandatory());
376         } finally {
377             utx.rollback();
378         }
379     }
380
381
382
383
384     /**
385      * Test of Never attribute
386      * A home method with Mandatory is called inside TX
387      * this method returns if the thread is associated to a transaction
388      *
389      * A java.rmi.RemoteException must be received
390      */

391     public void testHomeNeverTx() throws Exception JavaDoc {
392         utx.begin();
393         try {
394             getHome().opwith_never();
395             fail("never: should raise exception");
396         } catch (RemoteException JavaDoc e) {
397         } finally {
398             utx.rollback();
399         }
400     }
401
402     /**
403      * Test of Supports attribute
404      * A home method with Supports is called inside TX
405      * this method returns if the thread is associated to a transaction
406      *
407      * the expected value is true
408      */

409     public void testHomeSupportsTx() throws Exception JavaDoc {
410         utx.begin();
411         try {
412             assertEquals(true, getHome().opwith_supports());
413         } finally {
414             utx.rollback();
415         }
416     
417     }
418
419     /**
420      * Test the sequence of several calls to home methods
421      * with different transactional contexts
422      */

423     public void testHomeNoTx() throws Exception JavaDoc {
424         assertEquals(false, getHome().opwith_notsupported());
425         assertEquals(true, getHome().opwith_requires_new());
426         assertEquals(true, getHome().opwith_required());
427         assertEquals(false, getHome().opwith_never());
428         assertEquals(false, getHome().opwith_supports());
429     }
430
431  
432 }
433
Popular Tags