KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > transaction > B_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:
23  * --------------------------------------------------------------------------
24  */

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

39 public abstract class B_TxAttribute extends JTestCase {
40
41     /**
42      * constructor
43      * @param name name of the test suite.
44      */

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

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

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

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

78     public void testSimpleOptNotSupportedRemove() throws Exception JavaDoc {
79
80         Simple s = getSimple(10);
81         assertEquals(false, s.opwith_notsupported());
82         s.remove();
83       
84         
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 testGetSimpleOptRequiresNewRemove() throws Exception JavaDoc {
95
96         Simple s = getSimple(11);
97         assertEquals(true, s.opwith_requires_new());
98         s.remove();
99  
100     }
101
102     /**
103      * Test of Required attribute
104      * A business method with Required is called outside TX
105      * this method returns if the thread is associated to a transaction
106      *
107      * the expected value is true
108      */

109     public void testGetSimpleOptRequiredRemove() throws Exception JavaDoc {
110
111         Simple s = getSimple(12);
112         assertEquals(true, s.opwith_required());
113         s.remove();
114     }
115
116    
117     /**
118      * Test of RequiresNew attribute
119      * A business method with RequiresNew is called inside TX
120      * this method returns if the thread is associated to a transaction
121      *
122      * the expected value is true
123      */

124     public void testGetSimpleOptRequiresNewRemoveInTx() throws Exception JavaDoc {
125         Simple s = getSimple(21);
126         utx.begin();
127         try {
128             assertEquals(true, s.opwith_requires_new());
129         } finally {
130             utx.rollback();
131             s.remove();
132         }
133     }
134
135     /**
136      * Test of Required attribute
137      * A business method with Required is called inside TX
138      * this method returns if the thread is associated to a transaction
139      *
140      * the expected value is true
141      */

142     public void testGetSimpleOptRequiredRemoveInTx() throws Exception JavaDoc {
143
144         Simple s = getSimple(22);
145         utx.begin();
146         try {
147             assertEquals(true, s.opwith_required());
148         } finally {
149             utx.rollback();
150             s.remove();
151         }
152
153     }
154
155     /**
156      * Test of Mandatory attribute
157      * A business method with Mandatory is called inside TX
158      * this method returns if the thread is associated to a transaction
159      *
160      * the expected value is true
161      */

162     public void testMandatoryTx() throws Exception JavaDoc {
163
164         Simple s = getSimple(23);
165         utx.begin();
166         try {
167             assertEquals(true, s.opwith_mandatory());
168         } finally {
169             utx.rollback();
170             s.remove();
171         }
172     }
173
174
175
176
177     /**
178      * Test of Never attribute
179      * A business method with Mandatory is called inside TX
180      * this method returns if the thread is associated to a transaction
181      *
182      * A java.rmi.RemoteException must be received
183      */

184     public void testNeverTx() throws Exception JavaDoc {
185
186         Simple s = getSimple(24);
187         utx.begin();
188         try {
189             s.opwith_never();
190             fail("never: should raise exception");
191         } catch (RemoteException JavaDoc e) {
192         } finally {
193             utx.rollback();
194             s.remove();
195         }
196     }
197
198     /**
199      * Test of Supports attribute
200      * A business method with Supports is called inside TX
201      * this method returns if the thread is associated to a transaction
202      *
203      * the expected value is true
204      */

205     public void testSupportsTx() throws Exception JavaDoc {
206
207         Simple s = getSimple(25);
208         utx.begin();
209         try {
210             assertEquals(true, s.opwith_supports());
211         } finally {
212             utx.rollback();
213             s.remove();
214         }
215     
216     }
217
218     /**
219      * Test the sequence of several calls to methods
220      * with different transactional contexts
221      */

222     public void testNoTx() throws Exception JavaDoc {
223
224         Simple s = getSimple(1);
225         assertEquals(false, s.opwith_notsupported());
226         assertEquals(true, s.opwith_requires_new());
227         assertEquals(true, s.opwith_required());
228         assertEquals(false, s.opwith_never());
229         assertEquals(false, s.opwith_supports());
230         s.remove();
231     }
232
233 }
234
Popular Tags