KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > stateful > StatefulBeanTxTests


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: StatefulBeanTxTests.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb.test.stateful;
46
47 import java.util.Properties JavaDoc;
48
49 import javax.ejb.EJBMetaData JavaDoc;
50 import javax.ejb.Handle JavaDoc;
51 import javax.ejb.HomeHandle JavaDoc;
52 import javax.naming.Context JavaDoc;
53 import javax.naming.InitialContext JavaDoc;
54 import javax.transaction.RollbackException JavaDoc;
55
56 import org.openejb.test.TestManager;
57 import org.openejb.test.object.Account;
58 import org.openejb.test.object.Transaction;
59
60 /**
61  * [1] Should be run as the first test suite of the StatefulTestClients
62  *
63  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
64  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
65  */

66 public class StatefulBeanTxTests extends org.openejb.test.NamedTestCase{
67
68     public final static String JavaDoc jndiEJBHomeEntry = "client/tests/stateful/BeanManagedTransactionTests/EJBHome";
69
70     protected BeanTxStatefulHome ejbHome;
71     protected BeanTxStatefulObject ejbObject;
72
73     protected EJBMetaData JavaDoc ejbMetaData;
74     protected HomeHandle JavaDoc ejbHomeHandle;
75     protected Handle JavaDoc ejbHandle;
76     protected Integer JavaDoc ejbPrimaryKey;
77
78     protected InitialContext JavaDoc initialContext;
79
80     public StatefulBeanTxTests(){
81         super("Stateful.BeanManagedTransaction.");
82     }
83
84     /**
85      * Sets up the fixture, for example, open a network connection.
86      * This method is called before a test is executed.
87      */

88     protected void setUp() throws Exception JavaDoc {
89
90         Properties JavaDoc properties = TestManager.getServer().getContextEnvironment();
91         properties.put(Context.SECURITY_PRINCIPAL, "STATEFUL_test00_CLIENT");
92         properties.put(Context.SECURITY_CREDENTIALS, "STATEFUL_test00_CLIENT");
93
94         initialContext = new InitialContext JavaDoc(properties);
95
96         /*[1] Get bean */
97         Object JavaDoc obj = initialContext.lookup(jndiEJBHomeEntry);
98         ejbHome = (BeanTxStatefulHome)javax.rmi.PortableRemoteObject.narrow( obj, BeanTxStatefulHome.class);
99         ejbObject = ejbHome.create("Transaction Bean");
100
101         /*[2] Create database table */
102         TestManager.getDatabase().createAccountTable();
103     }
104
105     /**
106      * Tears down the fixture, for example, close a network connection.
107      * This method is called after a test is executed.
108      */

109     protected void tearDown() throws Exception JavaDoc {
110         /*[1] Drop database table */
111         TestManager.getDatabase().dropAccountTable();
112     }
113
114
115     /**
116      * <B>11.6.1 Bean-managed transaction demarcation</B>
117      * <P>
118      * The Container must make the javax.transaction.UserTransaction interface available to
119      * the enterprise bean’s business method via the javax.ejb.EJBContext interface and under the
120      * environment entry java:comp/UserTransaction. When an instance uses the javax.trans-action.
121      * UserTransaction interface to demarcate a transaction, the Container must enlist all the
122      * resource managers used by the instance between the begin() and commit()—or rollback()—
123      * methods with the transaction. When the instance attempts to commit the transaction, the Container is
124      * responsible for the global coordination of the transaction commit.
125      * </P>
126      * <P>--------------------------------------------------------</P>
127      * <P>
128      * Check that a javax.transaction.UserTransaction can be obtained from
129      * the javax.ejb.EJBContext
130      * </P>
131      */

132     public void test01_EJBContext_getUserTransaction(){
133         try{
134            Transaction t = ejbObject.getUserTransaction();
135            assertNotNull("UserTransaction is null.", t);
136         } catch (Exception JavaDoc e){
137             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
138         }
139     }
140
141     /**
142      *
143      * <B>11.6.1 Bean-managed transaction demarcation</B>
144      * <P>
145      * The Container must make the javax.transaction.UserTransaction interface available to
146      * the enterprise bean’s business method via the javax.ejb.EJBContext interface and under the
147      * environment entry java:comp/UserTransaction. When an instance uses the javax.trans-action.
148      * UserTransaction interface to demarcate a transaction, the Container must enlist all the
149      * resource managers used by the instance between the begin() and commit()—or rollback()—
150      * methods with the transaction. When the instance attempts to commit the transaction, the Container is
151      * responsible for the global coordination of the transaction commit.
152      * </P>
153      * <P>--------------------------------------------------------</P>
154      * <P>
155      * Check that a javax.transaction.UserTransaction can be obtained from
156      * the environment entry java:comp/UserTransaction
157      * </P>
158      */

159     public void test02_java_comp_UserTransaction(){
160         try{
161             Transaction t = ejbObject.jndiUserTransaction();
162             assertNotNull("UserTransaction is null. Could not retreive a UserTransaction from the bean's JNDI namespace.", t);
163         } catch (Exception JavaDoc e){
164             fail("Could not retreive a UserTransaction from the bean's JNDI namespace. Received Exception "+e.getClass()+ " : "+e.getMessage());
165         }
166     }
167
168     /**
169      * <B>11.6.1 Bean-managed transaction demarcation</B>
170      * <P>
171      * The Container must throw the java.lang.IllegalStateException if an instance of a bean
172      * with bean-managed transaction demarcation attempts to invoke the setRollbackOnly() or
173      * getRollbackOnly() method of the javax.ejb.EJBContext interface.
174      * </P>
175      * <P>--------------------------------------------------------</P>
176      * <P>
177      * Test that setRollbackOnly() throws a java.lang.IllegalStateException
178      * </P>
179      */

180     public void TODO_test03_EJBContext_setRollbackOnly(){
181         try{
182
183         } catch (Exception JavaDoc e){
184             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
185         }
186     }
187
188     /**
189      * <B>11.6.1 Bean-managed transaction demarcation</B>
190      * <P>
191      * The Container must throw the java.lang.IllegalStateException if an instance of a bean
192      * with bean-managed transaction demarcation attempts to invoke the setRollbackOnly() or
193      * getRollbackOnly() method of the javax.ejb.EJBContext interface.
194      * </P>
195      * <P>--------------------------------------------------------</P>
196      * <P>
197      * Test that getRollbackOnly() throws a java.lang.IllegalStateException
198      * </P>
199      */

200     public void TODO_test04_EJBContext_getRollbackOnly(){
201         try{
202
203         } catch (Exception JavaDoc e){
204             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
205         }
206     }
207
208     /**
209      *
210      */

211     public void test05_singleTransactionCommit(){
212         try{
213             Account expected = new Account("123-45-6789","Joe","Cool",40000);
214             Account actual = new Account();
215
216             ejbObject.openAccount(expected, new Boolean JavaDoc(false));
217             actual = ejbObject.retreiveAccount( expected.getSsn() );
218
219             assertNotNull( "The transaction was not commited. The record is null", actual );
220             assertEquals( "The transaction was not commited cleanly.", expected, actual );
221         } catch (RollbackException JavaDoc re){
222             fail("Transaction was rolledback. Received Exception "+re.getClass()+ " : "+re.getMessage());
223         } catch (Exception JavaDoc e){
224             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
225         }
226     }
227
228     /**
229      * This test does work for the IntraVM Server, but it fails on
230      * the Remote Server. For some reason, when the RollbackException is
231      * sent to the client, the server blocks.
232      */

233     public void BUG_test06_singleTransactionRollback(){
234         Account expected = new Account("234-56-7890","Charlie","Brown", 20000);
235         Account actual = new Account();
236
237         // Try and add the account in a transaction. This should fail and
238
// throw a RollbackException
239
try{
240             ejbObject.openAccount(expected, new Boolean JavaDoc(true));
241             fail( "A javax.transaction.RollbackException should have been thrown." );
242         } catch (RollbackException JavaDoc re){
243             // Good.
244
} catch (Exception JavaDoc e){
245             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
246         }
247         
248       //// Now check that the account really wasn't added.
249
//try{
250
// actual = ejbObject.retreiveAccount( expected.getSsn() );
251
// //assertTrue( "The transaction was commited when it should have been rolledback.", !expected.equals(actual) );
252
//} catch (Exception e){
253
// fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
254
//}
255
}
256
257
258     /**
259      * <B>11.6.1 Bean-managed transaction demarcation</B>
260      * <P>
261      * The Container must allow the enterprise bean instance to serially perform several transactions in a
262      * method.
263      * </P>
264      */

265     public void TODO_test07_serialTransactions(){
266         try{
267
268         } catch (Exception JavaDoc e){
269             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
270         }
271     }
272
273     /**
274      * <B>11.6.1 Bean-managed transaction demarcation</B>
275      * <P>
276      * When an instance attempts to start a transaction using the
277      * begin() method of the javax.transaction.UserTransaction
278      * interface while the instance has not committed the previous
279      * transaction, the Container must throw the
280      * javax.transaction.NotSupportedException in the begin() method.
281      * </P>
282      */

283     public void TODO_test08_nestedTransactions(){
284         try{
285
286         } catch (Exception JavaDoc e){
287             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
288         }
289     }
290
291     /**
292      * <B>11.6.1 Bean-managed transaction demarcation</B>
293      * <P>
294      * In the case of a stateful session bean, it is possible that the
295      * business method that started a transaction completes without
296      * committing or rolling back the transaction. In such a case, the
297      * Container must retain the association between the transaction
298      * and the instance across multiple client calls until the instance
299      * commits or rolls back the transaction. When the client invokes
300      * the next business method, the Container must invoke the business
301      * method in this transaction context.
302      * </P>
303      */

304     public void TODO_test09_methodSpanningTransactions(){
305         try{
306
307         } catch (Exception JavaDoc e){
308             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
309         }
310     }
311
312     /**
313      * <B>11.6.1 Bean-managed transaction demarcation</B>
314      * <P>
315      * The actions performed by the Container for an instance with bean-managed transaction are summarized
316      * by the following table. T1 is a transaction associated with a client request, T2 is a transaction that is cur-rently
317      * associated with the instance (i.e. a transaction that was started but not completed by a previous
318      * business method).
319      * </P>
320      * <PRE>
321      * =========================================================================
322      * Container’s actions for methods of beans with bean-managed transaction
323      * =========================================================================
324      *
325      * | IF | AND | THEN
326      * scenario | Client’s | Transaction currently | Transaction associated
327      * | transaction | associated with instance | with the method is
328      * ___________|_____________|__________________________|________________________
329      * | | |
330      * 1 | none | none | none
331      * ___________|_____________|__________________________|________________________
332      * | | |
333      * 2 | T1 | none | none
334      * ___________|_____________|__________________________|________________________
335      * | | |
336      * 3 | none | T2 | T2
337      * ___________|_____________|__________________________|________________________
338      * | | |
339      * 4 | T1 | T2 | T2
340      * ___________|_____________|__________________________|________________________
341      * </PRE>
342      * <P>
343      * If the client request is not associated with a transaction and the instance is not associated with a
344      * transaction, the container invokes the instance with an unspecified transaction context.
345      * </P>
346      * <P>--------------------------------------------------------</P>
347      * <P>
348      * Test scenario 1: none none<BR>
349      * If the client's transaction is none and the transaction currently
350      * associated with instance none then the transaction associated with the method is none.
351      * </P>
352      */

353     public void TODO_test10_scenario1_NoneNone(){
354         try{
355
356         } catch (Exception JavaDoc e){
357             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
358         }
359     }
360
361     /**
362      * <B>11.6.1 Bean-managed transaction demarcation</B>
363      * <P>
364      * The actions performed by the Container for an instance with bean-managed transaction are summarized
365      * by the following table. T1 is a transaction associated with a client request, T2 is a transaction that is cur-rently
366      * associated with the instance (i.e. a transaction that was started but not completed by a previous
367      * business method).
368      * </P>
369      * <PRE>
370      * =========================================================================
371      * Container’s actions for methods of beans with bean-managed transaction
372      * =========================================================================
373      *
374      * | IF | AND | THEN
375      * scenario | Client’s | Transaction currently | Transaction associated
376      * | transaction | associated with instance | with the method is
377      * ___________|_____________|__________________________|________________________
378      * | | |
379      * 1 | none | none | none
380      * ___________|_____________|__________________________|________________________
381      * | | |
382      * 2 | T1 | none | none
383      * ___________|_____________|__________________________|________________________
384      * | | |
385      * 3 | none | T2 | T2
386      * ___________|_____________|__________________________|________________________
387      * | | |
388      * 4 | T1 | T2 | T2
389      * ___________|_____________|__________________________|________________________
390      * </PRE>
391      * <P>
392      * If the client is associated with a transaction T1, and the instance is not associated with a transaction,
393      * the container suspends the client’s transaction association and invokes the method with
394      * an unspecified transaction context. The container resumes the client’s transaction association
395      * (T1) when the method completes.
396      * </P>
397      * <P>--------------------------------------------------------</P>
398      * <P>
399      * Test scenario 2: T1 none<BR>
400      * </P>
401      */

402     public void TODO_test11_scenario2_T1None(){
403         try{
404
405         } catch (Exception JavaDoc e){
406             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
407         }
408     }
409
410     /**
411      * <B>11.6.1 Bean-managed transaction demarcation</B>
412      * <P>
413      * The actions performed by the Container for an instance with bean-managed transaction are summarized
414      * by the following table. T1 is a transaction associated with a client request, T2 is a transaction that is cur-rently
415      * associated with the instance (i.e. a transaction that was started but not completed by a previous
416      * business method).
417      * </P>
418      * <PRE>
419      * =========================================================================
420      * Container’s actions for methods of beans with bean-managed transaction
421      * =========================================================================
422      *
423      * | IF | AND | THEN
424      * scenario | Client’s | Transaction currently | Transaction associated
425      * | transaction | associated with instance | with the method is
426      * ___________|_____________|__________________________|________________________
427      * | | |
428      * 1 | none | none | none
429      * ___________|_____________|__________________________|________________________
430      * | | |
431      * 2 | T1 | none | none
432      * ___________|_____________|__________________________|________________________
433      * | | |
434      * 3 | none | T2 | T2
435      * ___________|_____________|__________________________|________________________
436      * | | |
437      * 4 | T1 | T2 | T2
438      * ___________|_____________|__________________________|________________________
439      * </PRE>
440      * <P>
441      * If the client request is not associated with a transaction and the instance is already associated
442      * with a transaction T2, the container invokes the instance with the transaction that is associated
443      * with the instance (T2). This case can never happen for a stateless Session Bean.
444      * </P>
445      * <P>--------------------------------------------------------</P>
446      * <P>
447      * Test scenario 3: none T2<BR>
448      * </P>
449      */

450     public void TODO_test12_scenario3_NoneT2(){
451         try{
452
453         } catch (Exception JavaDoc e){
454             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
455         }
456     }
457
458     /**
459      * <B>11.6.1 Bean-managed transaction demarcation</B>
460      * <P>
461      * The actions performed by the Container for an instance with bean-managed transaction are summarized
462      * by the following table. T1 is a transaction associated with a client request, T2 is a transaction that is cur-rently
463      * associated with the instance (i.e. a transaction that was started but not completed by a previous
464      * business method).
465      * </P>
466      * <PRE>
467      * =========================================================================
468      * Container’s actions for methods of beans with bean-managed transaction
469      * =========================================================================
470      *
471      * | IF | AND | THEN
472      * scenario | Client’s | Transaction currently | Transaction associated
473      * | transaction | associated with instance | with the method is
474      * ___________|_____________|__________________________|________________________
475      * | | |
476      * 1 | none | none | none
477      * ___________|_____________|__________________________|________________________
478      * | | |
479      * 2 | T1 | none | none
480      * ___________|_____________|__________________________|________________________
481      * | | |
482      * 3 | none | T2 | T2
483      * ___________|_____________|__________________________|________________________
484      * | | |
485      * 4 | T1 | T2 | T2
486      * ___________|_____________|__________________________|________________________
487      * </PRE>
488      * <P>
489      * If the client is associated with a transaction T1, and the instance is already associated with a
490      * transaction T2, the container suspends the client’s transaction association and invokes the
491      * method with the transaction context that is associated with the instance (T2). The container
492      * resumes the client’s transaction association (T1) when the method completes. This case can
493      * never happen for a stateless Session Bean.
494      * </P>
495      * <P>--------------------------------------------------------</P>
496      * <P>
497      * Test scenario 4: T1 T2<BR>
498      * </P>
499      */

500     public void TODO_test13_scenario4_T1T2(){
501         try{
502
503         } catch (Exception JavaDoc e){
504             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
505         }
506     }
507 }
508
Popular Tags