KickJava   Java API By Example, From Geeks To Geeks.

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


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_ContManagedTx.java,v 1.3 2005/03/17 15:21:44 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 javax.transaction.RollbackException JavaDoc;
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33 import org.objectweb.jonas.jtests.beans.transacted.Simple;
34 import org.objectweb.jonas.jtests.beans.transacted.SimpleSHome;
35 import org.objectweb.jonas.jtests.beans.transacted.SynchroSimple;
36 import org.objectweb.jonas.jtests.util.JTestCase;
37
38 /**
39  * Test for Bean Managed Transaction beans
40  */

41 public class F_ContManagedTx extends JTestCase {
42
43     private static String JavaDoc BEAN_HOME = "transactedSimpleSYHome";
44     protected static SimpleSHome home = null;
45
46     public F_ContManagedTx(String JavaDoc name) {
47         super(name);
48     }
49
50     protected void setUp() {
51         super.setUp();
52         useBeans("transacted", true);
53         if (home == null) {
54             try {
55                 home = (SimpleSHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), SimpleSHome.class);
56             } catch (NamingException JavaDoc e) {
57                 fail("Cannot get Home:" + e);
58             }
59         }
60     }
61
62     /**
63      * Test rollback only in beforeCompletion
64      * See EJB 2.1 spec 7.5.4
65      */

66     public void testRollBackInBeforeCompletion() throws Exception JavaDoc {
67         SynchroSimple ss = (SynchroSimple) PortableRemoteObject.narrow(home.create(), SynchroSimple.class);
68         
69         utx.begin();
70         ss.setRollbackOnly();
71         try {
72             utx.commit();
73             fail("transaction should be rolled back");
74         } catch (RollbackException JavaDoc e) {
75         } finally {
76             ss.remove(); // cleaning
77
}
78     }
79
80     public static Test suite() {
81         return new TestSuite(F_ContManagedTx.class);
82     }
83
84     public static void main (String JavaDoc args[]) {
85         String JavaDoc testtorun = null;
86         // Get args
87
for (int argn = 0; argn < args.length; argn++) {
88             String JavaDoc sarg = args[argn];
89             if (sarg.equals("-n")) {
90                 testtorun = args[++argn];
91             }
92         }
93         if (testtorun == null) {
94             junit.textui.TestRunner.run(suite());
95         } else {
96             junit.textui.TestRunner.run(new F_ContManagedTx(testtorun));
97         }
98     }
99 }
100
Popular Tags