Source Code Cross Referenced for F_xatransactionTest.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » clients » jca15 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.jtests.clients.jca15 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         * 
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         * 
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         * 
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: F_xatransactionTest.java 4604 2004-04-15 17:15:45Z bobkruse $
023:         * --------------------------------------------------------------------------
024:         */
025:
026:        package org.objectweb.jonas.jtests.clients.jca15;
027:
028:        import junit.framework.*;
029:        import java.io.BufferedReader;
030:        import java.io.FileInputStream;
031:        import java.io.InputStreamReader;
032:        import java.io.IOException;
033:        import java.lang.String;
034:        import java.rmi.RemoteException;
035:        import javax.rmi.PortableRemoteObject;
036:        import java.util.Collection;
037:        import java.util.Enumeration;
038:        import java.util.Hashtable;
039:        import java.util.Properties;
040:        import javax.ejb.FinderException;
041:        import javax.ejb.RemoveException;
042:        import javax.naming.Context;
043:        import javax.naming.InitialContext;
044:        import javax.naming.NamingException;
045:        import javax.transaction.UserTransaction;
046:        import javax.transaction.SystemException;
047:
048:        import org.objectweb.jonas.jtests.beans.jca15.TransactedCA;
049:        import org.objectweb.jonas.jtests.beans.jca15.TransactedCAHome;
050:        import org.objectweb.jonas.jtests.beans.jca15.Utility;
051:        import org.objectweb.jonas.jtests.util.JTestCase;
052:        import org.objectweb.jonas.jtests.clients.jca15.F_securityTest;
053:
054:        /**
055:         * F_xatransactionTests tests JOnAS Connection Architecture XA Transaction
056:         */
057:
058:        public class F_xatransactionTest extends JTestCase {
059:
060:            static Context ctx = null;
061:
062:            // Lookup bean home
063:
064:            protected static String BEAN_HOME = "TransactedCAHome";
065:            protected static TransactedCAHome home = null;
066:            private static final String RAR_JNDI_NAME = "eis/ErsatzXATransaction";
067:            final public int CLOSE_HANDLE = 0;
068:            final public int CLOSE_PHYSICAL = 1;
069:            public int CloseType = 0;
070:            static TransactedCA bean = null;
071:            public String UseBeans = "jca15";
072:            String err = "";
073:
074:            public F_xatransactionTest(String name) {
075:                super (name);
076:            }
077:
078:            protected void setUp() {
079:                super .setUp();
080:                try {
081:                    // get JNDI initial context
082:
083:                    if (ctx == null) {
084:                        err = "InitialContext()";
085:                        ctx = new InitialContext();
086:                    }
087:                    //
088:                    // We want to start transactions for client: get UserTransaction
089:                    //
090:                    if (utx == null) {
091:                        err = "lookup(javax.transaction.UserTransaction)";
092:                        utx = (UserTransaction) ctx
093:                                .lookup(Utility.USER_TRANSACTION);
094:                    }
095:                    if (home == null) {
096:                        useBeans(UseBeans, false);
097:                    }
098:                    getBean();
099:                    assertTrue(6 == 6);
100:
101:                } catch (SystemException se1) {
102:                    String s = "setUp error: Unable to " + err
103:                            + " SystemException=" + se1;
104:                    fail(s);
105:                } catch (Exception e) {
106:                    fail("Cannot do setUp. Error on " + err + " Exception=" + e);
107:                }
108:            }
109:
110:            private void getBean() throws Exception {
111:                // Connecting to TransactedCAHome thru JNDI
112:
113:                if (home == null) {
114:                    home = (TransactedCAHome) PortableRemoteObject.narrow(ctx
115:                            .lookup(BEAN_HOME), TransactedCAHome.class);
116:                    bean = home.create();
117:                }
118:            }
119:
120:            protected void tearDown() throws Exception {
121:                //bean.closeUp(CloseType);
122:            }
123:
124:            protected void startUp(String testName) {
125:                try {
126:                    bean.method1(RAR_JNDI_NAME, testName);
127:                } catch (Exception ee) {
128:                    ee.printStackTrace();
129:                    System.exit(2);
130:                }
131:            }
132:
133:            // test list ****************************************************
134:
135:            /**
136:             * The application server invokes the ManagedConnection.getXAResource method
137:             * to get the XAResource instance associated with the ManagedConnection instance.
138:             * Then, application server calls the TM, which in turn calls the 
139:             * XAResourceImpl.start() method.
140:             * 
141:             * This test verifies the existence of the instance, assigned Xid, and start()
142:             */
143:            public void testIsXaresource() {
144:                CloseType = CLOSE_PHYSICAL;
145:
146:                try {
147:                    startUp("testIsXaresource");
148:                    assertTrue(5 == 5);
149:                    String ans = bean.getXid();
150:                    assertTrue(5 == 5);
151:                    assertEquals("OK", ans);
152:                    bean.closeUp(CloseType);
153:                    assertTrue(5 == 5);
154:                } catch (Exception e) {
155:                    System.err
156:                            .println("XatransactionTest: Exception in TransactedCASLR");
157:                    e.printStackTrace();
158:                } catch (Throwable t) {
159:                    System.err
160:                            .println("XatransactionTest: Exception in TransactedCASLR");
161:                    t.printStackTrace();
162:                }
163:            }
164:
165:            /**
166:             *  At connection close, the application server performs "transactional" cleanup.
167:             *  The application server dissociates the XAResource instance (corresponding 
168:             *  to the ManagedConnection "mc" instance) from the transaction manager.
169:             *  The transaction manager calls XAResource.end(Xid, flag)
170:             * <p>
171:             *  The ConnectionEvent is CLOSE_CONNECTION. This test verifies that application 
172:             *  server called TM which in turn called XAResource.end(). 
173:             *  
174:             *
175:             */
176:            public void testIsXAend1() {
177:                CloseType = CLOSE_HANDLE; // leave physical connection open
178:
179:                try {
180:                    startUp("testIsXAend1");
181:                    assertTrue(5 == 5);
182:                    assertTrue(bean.getCMInstance()); // is physical connection o.k.
183:                    bean.closeUp(CloseType);
184:                    assertTrue(bean.getCMInstance()); // should still be o.k.
185:                    assertTrue(5 == 5);
186:                } catch (Exception e) {
187:                    System.err
188:                            .println("testIsXAend1: Exception in TransactedCASLR");
189:                    e.printStackTrace();
190:                } catch (Throwable t) {
191:                    System.err
192:                            .println("testIsXAend1: Exception in TransactedCASLR");
193:                    t.printStackTrace();
194:                }
195:            }
196:
197:            /**
198:             *  At connection close, the application server performs "transactional" cleanup.
199:             *  The application server dissociates the XAResource instance (corresponding 
200:             *  to the ManagedConnection "mc" instance) from the transaction manager.
201:             *  The transaction manager calls XAResource.end(Xid, flag)
202:             * <p>
203:             *  The ConnectionEvent is CONNECTION_ERROR_OCCURRED to force a physical close.
204:             *  verifies mc.XAR reference is null
205:             *
206:             */
207:            public void testIsXAend2() {
208:                CloseType = CLOSE_PHYSICAL;
209:
210:                try {
211:                    startUp("testIsXAend2");
212:                    String ans = bean.getXid();
213:                    assertEquals("FAIL", ans); // XAR is dissociated, should FAIL
214:                    // testIsXAend2 should not work. end() not called by TM-
215:                } catch (Exception e) {
216:                    System.err
217:                            .println("testIsXAend2: Exception in TransactedCASLR");
218:                    e.printStackTrace();
219:                } catch (Throwable t) {
220:                    System.err
221:                            .println("testIsXAend2: Exception in TransactedCASLR");
222:                    t.printStackTrace();
223:                }
224:            }
225:
226:            public static Test suite() {
227:                return new TestSuite(F_xatransactionTest.class);
228:            }
229:
230:            public static void main(String args[]) {
231:
232:                String testtorun = null;
233:
234:                // Get args
235:
236:                for (int argn = 0; argn < args.length; argn++) {
237:
238:                    String s_arg = args[argn];
239:                    Integer i_arg;
240:
241:                    if (s_arg.equals("-n")) {
242:                        testtorun = args[++argn];
243:                    }
244:                }
245:
246:                if (testtorun == null) {
247:                    junit.textui.TestRunner.run(suite());
248:                } else {
249:                    junit.textui.TestRunner.run(new F_xatransactionTest(
250:                            testtorun));
251:                }
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.