KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > jca15 > F_transactionTest


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_transactionTest.java,v 1.1 2004/04/15 17:09:34 bobkruse Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.jca15;
27
28 import junit.framework.*;
29 import java.io.BufferedReader JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.InputStreamReader JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.lang.String JavaDoc;
34 import java.rmi.RemoteException JavaDoc;
35 import javax.rmi.PortableRemoteObject JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.Enumeration JavaDoc;
38 import java.util.Hashtable JavaDoc;
39 import java.util.Properties JavaDoc;
40 import javax.ejb.FinderException JavaDoc;
41 import javax.ejb.RemoveException JavaDoc;
42 import javax.naming.Context JavaDoc;
43 import javax.naming.InitialContext JavaDoc;
44 import javax.naming.NamingException JavaDoc;
45
46 import org.objectweb.jonas.jtests.beans.jca15.TransactedCA;
47 import org.objectweb.jonas.jtests.beans.jca15.TransactedCAHome;
48 import org.objectweb.jonas.jtests.util.JTestCase;
49 import org.objectweb.jonas.jtests.clients.jca15.F_securityTest;
50
51 /**
52  * Tests Jonas Connector Architecture Local Transaction.
53  * F_transactionTests tests Jonas CA Local Transaction
54  */

55
56 public class F_transactionTest extends JTestCase {
57
58     static Context JavaDoc ctx = null;
59
60     // Lookup bean home
61

62     protected static String JavaDoc BEAN_HOME = "TransactedCAHome";
63     protected static TransactedCAHome home = null;
64     private static final String JavaDoc RAR_JNDI_NAME = "eis/ErsatzLoTransaction";
65     final public int CLOSE_HANDLE = 0;
66     final public int CLOSE_PHYSICAL = 1;
67     public int CloseType = 0;
68     static TransactedCA bean = null;
69     public String JavaDoc UseBeans="jca15";
70     
71     public F_transactionTest(String JavaDoc name) {
72         super(name);
73     }
74
75     protected void setUp() {
76         super.setUp();
77         try {
78             // get JNDI initial context
79

80             if (ctx == null) {
81                 ctx = new InitialContext JavaDoc();
82             }
83
84             if (home == null) {
85                 useBeans(UseBeans, false);
86             }
87             getBean();
88             assertTrue (6 == 6);
89
90         } catch (Exception JavaDoc e) {
91             fail("Cannot do setUp: " +e);
92         }
93     }
94     private void getBean() throws Exception JavaDoc {
95         // Connecting to TransactedCAHome thru JNDI
96

97         if (home == null) {
98             home = (TransactedCAHome)PortableRemoteObject.narrow(
99                                 ctx.lookup(BEAN_HOME),
100                                 TransactedCAHome.class);
101             bean = home.create();
102         }
103     }
104     protected void tearDown() throws Exception JavaDoc {
105         //bean.closeUp(CloseType);
106
}
107     protected void startUp(String JavaDoc testName) {
108         try {
109             bean.method1(RAR_JNDI_NAME, testName);
110         } catch (Exception JavaDoc ee) {
111             ee.printStackTrace();
112             System.exit(2);
113         }
114     }
115
116 // test list ****************************************************
117

118     /**
119     Test Local Transaction with component-managed demarcation.
120     
121     The application component uses a transaction demarcation API specific
122     to an EIS. The resource adapter needs to notify the application server of
123     the events (transaction begin, commit, and rollback) related to the local
124     transaction. An application server uses this part of the contract.
125
126      */

127     public void testTransaction1() {
128         CloseType=CLOSE_PHYSICAL;
129         startUp("testTransaction1");
130         try {
131             bean.beginLoTransaction();
132             assertTrue (6 == 6);
133             bean.closeUp(CloseType);
134             bean.commitLoTransaction();
135             assertTrue (6 == 6);
136         } catch (Exception JavaDoc e) {
137             assertTrue(6==7);
138         }
139     }
140
141     public void testTransaction2() {
142         CloseType=CLOSE_PHYSICAL;
143         startUp("testTransaction2");
144         try {
145             bean.closeUp(CloseType);
146             bean.commitLoTransaction();
147             assertTrue (6 == 7);
148         } catch (Exception JavaDoc e) {
149             assertTrue(6==6); // should get here
150
}
151     }
152
153     public static Test suite() {
154         return new TestSuite(F_transactionTest.class);
155     }
156
157     public static void main (String JavaDoc args[]) {
158
159         String JavaDoc testtorun = null;
160
161         // Get args
162

163         for (int argn = 0; argn < args.length; argn++) {
164
165             String JavaDoc s_arg = args[argn];
166             Integer JavaDoc i_arg;
167
168             if (s_arg.equals("-n")) {
169                 testtorun = args[++argn];
170             }
171         }
172
173         if (testtorun == null) {
174             junit.textui.TestRunner.run(suite());
175         } else {
176             junit.textui.TestRunner.run(new F_transactionTest(testtorun));
177         }
178     }
179 }
180
Popular Tags