KickJava   Java API By Example, From Geeks To Geeks.

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


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

25
26 package org.objectweb.jonas.jtests.clients.transaction;
27
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32 import org.objectweb.jonas.jtests.beans.transacted.Simple;
33 import org.objectweb.jonas.jtests.beans.transacted.SimpleEHome;
34
35 /**
36  * TxAttribute tests on on entity bean
37  */

38 public class F_TxAttributeEB extends A_TxAttributeEntity {
39
40     private static String JavaDoc BEAN_HOME = "transactedSimpleEBHome";
41     protected static SimpleEHome home = null;
42
43     public F_TxAttributeEB(String JavaDoc name) {
44         super(name);
45     }
46
47
48     // --------------------------------------------------------------------
49
// tests on finder methods
50
// These tests are specific to BMP because there is no ejb<Find> methods
51
// in CMP.
52
// ---------------------------------------------------------------------
53

54     /**
55      * Test NotSupported transactional attributes on finder method
56      * the finder method is called outside TX
57      */

58     public void testFinderNotSupported() throws Exception JavaDoc {
59
60         getHome().finder_notsupported();
61     }
62
63     /**
64      * Test NotSupported transactional attributes on finder method
65      * the finder method is called inside TX
66      */

67     public void testFinderNotSupportedTx() throws Exception JavaDoc {
68
69         utx.begin();
70         try {
71             getHome().finder_notsupported();
72         } finally {
73             utx.rollback();
74         }
75     }
76
77
78     /**
79      * Test required transactional attributes on finder method
80      * the finder method is called outside TX
81      */

82     public void testFinderRequired() throws Exception JavaDoc {
83
84         getHome().finder_required();
85     }
86
87     /**
88      * Test Required transactional attributes on finder method
89      * the finder method is called inside TX
90      */

91     public void testFinderRequiredTx() throws Exception JavaDoc {
92
93         utx.begin();
94         try {
95             getHome().finder_required();
96         } finally {
97             utx.rollback();
98         }
99     }
100
101     /**
102      * Test supports transactional attributes on finder method
103      * the finder method is called outside TX
104      * the finder method is called with false that mean that the method must not be associated
105      * to a transaction
106      */

107     public void testFinderSupports() throws Exception JavaDoc {
108
109         getHome().finder_supports(false);
110     }
111
112
113     /**
114      * Test supports transactional attributes on finder method
115      * the finder method is called inside TX
116      * the finder method is called with true that mean that the method must be associated
117      * to a transaction
118      */

119     public void testFinderSupportsTx() throws Exception JavaDoc {
120         utx.begin();
121         try {
122             getHome().finder_supports(true);
123         } finally {
124             utx.rollback();
125         }
126     }
127
128     /**
129      * Test requiresNew transactional attributes on finder method
130      * the finder method is called outside TX
131      */

132     public void testFinderRequiresNew() throws Exception JavaDoc {
133
134         getHome().finder_requiresnew();
135     }
136
137     /**
138      * Test RequiresNew transactional attributes on finder method
139      * the finder method is called inside TX
140      */

141     public void testFinderRequiresNewTx() throws Exception JavaDoc {
142
143         utx.begin();
144         try {
145             getHome().finder_requiresnew();
146         } finally {
147             utx.rollback();
148         }
149     }
150
151
152     /**
153      * Test Mandatory transactional attributes on finder method
154      * the finder method is called outside TX
155      * TransactionRequiredException must be received
156      */

157     public void testFinderMandatory() throws Exception JavaDoc {
158         try {
159             getHome().finder_mandatory();
160             fail("mandatory: should raise exception");
161         } catch (javax.transaction.TransactionRequiredException JavaDoc e) {
162         } catch (java.rmi.RemoteException JavaDoc e) {
163             assertTrue(e.detail instanceof javax.transaction.TransactionRequiredException JavaDoc);
164         }
165     }
166
167     /**
168      * Test Mandatory transactional attributes on finder method
169      * the finder method is called inside TX
170      */

171     public void testFinderMandatoryTx() throws Exception JavaDoc {
172
173         utx.begin();
174         try {
175             getHome().finder_mandatory();
176         } finally {
177             utx.rollback();
178         }
179     }
180
181     /**
182      * Test Never transactional attributes on finder method
183      * the finder method is called outside TX
184      */

185     public void testFinderNever() throws Exception JavaDoc {
186
187         getHome().finder_never();
188     }
189
190     /**
191      * Test Never transactional attributes on finder method
192      * the finder method is called inside TX
193      */

194     public void testFinderNeverTx() throws Exception JavaDoc {
195         utx.begin();
196         try {
197             getHome().finder_never();
198             fail("never: should raise exception");
199         } catch (java.rmi.RemoteException JavaDoc e) {
200         } finally {
201             utx.rollback();
202         }
203     }
204
205
206     // -----------------------------------------------------------------
207
// Methods for Suite handling
208
// -----------------------------------------------------------------
209

210     protected SimpleEHome getHome() {
211         if (home == null) {
212             try {
213                 home = (SimpleEHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), SimpleEHome.class);
214             } catch (NamingException JavaDoc e) {
215                 fail("Cannot get bean home");
216             }
217         }
218         return home;
219     }
220
221
222     /**
223      * Create a bean and return it.
224      */

225     public Simple getSimple(int i) throws Exception JavaDoc {
226         return getHome().create(i);
227     }
228
229     /**
230      * This suite is all BMP test cases
231      */

232     public static Test suite() {
233         return new TestSuite(F_TxAttributeEB.class);
234     }
235
236     public static void main (String JavaDoc args[]) {
237         String JavaDoc testtorun = null;
238         // Get args
239
for (int argn = 0; argn < args.length; argn++) {
240             String JavaDoc sarg = args[argn];
241             if (sarg.equals("-n")) {
242                 testtorun = args[++argn];
243             }
244         }
245         if (testtorun == null) {
246             junit.textui.TestRunner.run(suite());
247         } else {
248             junit.textui.TestRunner.run(new F_TxAttributeEB(testtorun));
249         }
250     }
251 }
252
Popular Tags