Source Code Cross Referenced for TestContainerTransactionException.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » tests » transaction » containermanaged » base » 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 » ow2 easybeans » org.ow2.easybeans.tests.transaction.containermanaged.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2006 Bull S.A.S.
004:         * Contact: easybeans@ow2.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: TestContainerTransactionException.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.tests.transaction.containermanaged.base;
025:
026:        import static org.testng.Assert.fail;
027:
028:        import javax.ejb.EJBException;
029:
030:        import org.ow2.easybeans.tests.common.ejbs.base.transaction.ItfContainerTransaction;
031:        import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.transaction.ItfTransactionMisc00;
032:        import org.ow2.easybeans.tests.common.helper.EJBHelper;
033:        import org.ow2.easybeans.tests.common.helper.EmbeddedHelper;
034:        import org.ow2.util.log.Log;
035:        import org.ow2.util.log.LogFactory;
036:
037:        /**
038:         * Verifies if the container manages well the runtime exception and the transaction among the beans.
039:         * @author Gisele Pinheiro Souza
040:         * @author Eduardo Studzinski Estima de Castro
041:         */
042:        public abstract class TestContainerTransactionException {
043:
044:            /**
045:             * Constant that defines the first database name.
046:             */
047:            protected static final String DATABASE_1 = "jdbc_1";
048:
049:            /**
050:             * Constant that defines the second database name.
051:             */
052:            protected static final String DATABASE_2 = "jdbc_2";
053:
054:            /**
055:             * Bean used during the tests that throws a runtime exception.
056:             */
057:            private ItfContainerTransaction sfsbContainerTransactionRuntime = null;
058:
059:            /**
060:             * Logger.
061:             */
062:            private static Log logger = LogFactory
063:                    .getLog(TestContainerTransactionException.class);
064:
065:            /**
066:             * Initiates all things needed to execute the tests.
067:             * @throws Exception if an error occurs.
068:             */
069:            public void setup() throws Exception {
070:                // Inserts all database before execute the test
071:                // used because the container does not provide this feature yet
072:                EmbeddedHelper.bindDatasource();
073:                // creates the bean used to manages the databse in the server site.
074:                //cleans the transaction active in other test
075:                ExceptionHandleUtil.cleanTransaction();
076:                //creates the bean used during the tests
077:                createBeanRuntime();
078:                //deletes all tables
079:                deleteTable();
080:            }
081:
082:            /**
083:             * Gets a new instance of the bean used in the runtime exception tests.
084:             * @param beanClass the bean class name used to make the lookup.
085:             * @throws Exception if a lookup error occurs.
086:             */
087:            public void createBeanRuntime(final Class beanClass)
088:                    throws Exception {
089:                sfsbContainerTransactionRuntime = EJBHelper
090:                        .getBeanRemoteInstance(beanClass,
091:                                ItfContainerTransaction.class);
092:            }
093:
094:            /**
095:             * Gets a new instance of the bean used in the runtime exception tests.
096:             * @throws Exception if a lookup error occurs.
097:             */
098:            public abstract void createBeanRuntime() throws Exception;
099:
100:            /**
101:             * Verifies if the container manages the transaction among divers beans.The
102:             * first bean creates a table in the first database and calls other
103:             * bean(with transaction attribute REQUIRED) to insert a table in the second
104:             * database. After the both insertions, the first bean throws a RuntimeException
105:             * exception. Also, verifies if the container throws an EJBException, discards the bean and does the rollback in
106:             * this case(if the transaction atttribute of the first bean has a
107:             * transaction context).
108:             * @throws Exception if an error during the tests occurs.
109:             */
110:            public void testCallOtherBeanReq() throws Exception {
111:                try {
112:                    sfsbContainerTransactionRuntime
113:                            .insertTablesUsingAuxBeanReq(DATABASE_1, DATABASE_2);
114:                    fail("The container did not throw the EJBException.");
115:                } catch (EJBException e) {
116:                    logger
117:                            .debug(
118:                                    "The bean threw an expected error during the execution {0}",
119:                                    e);
120:                }
121:                // verifies if the container discarded the instance.
122:                if (!ExceptionHandleUtil
123:                        .isDiscarded(sfsbContainerTransactionRuntime)) {
124:                    fail("The bean was not discarded.");
125:                }
126:
127:                // TODO - verifies if the container log the error.
128:            }
129:
130:            /**
131:             * Verifies if the container manages the transaction among divers beans.The
132:             * first bean creates a table in the first database and calls other
133:             * bean(with transaction attribute NOT_SUPPORTS) to insert a table in the second
134:             * database. After the both insertions, the first bean throws a RuntimeException
135:             * exception. Also, verifies if the container throws an EJBException, discards the bean and does the rollback in
136:             * this case(if the transaction atttribute of the first bean has a
137:             * transaction context).
138:             * @throws Exception if an error during the tests occurs.
139:             */
140:            public void testCallOtherBeanNotSup() throws Exception {
141:                try {
142:                    sfsbContainerTransactionRuntime
143:                            .insertTablesUsingAuxBeanNotSup(DATABASE_1,
144:                                    DATABASE_2);
145:                    fail("The container did not throw the EJBException.");
146:                } catch (EJBException e) {
147:                    logger
148:                            .debug(
149:                                    "The bean threw an expected error during the execution {0}",
150:                                    e);
151:                }
152:                // verifies if the container discarded the instance.
153:                if (!ExceptionHandleUtil
154:                        .isDiscarded(sfsbContainerTransactionRuntime)) {
155:                    fail("The bean was not discarded.");
156:                }
157:
158:                // TODO - verifies if the container log the error.
159:            }
160:
161:            /**
162:             * Returns the bean that throws a runtime exception.
163:             * @return the bean.
164:             */
165:            public ItfContainerTransaction getRuntimeBean() {
166:                return sfsbContainerTransactionRuntime;
167:            }
168:
169:            /**
170:             * Deletes the tables created during test.
171:             * @throws Exception if a lookup error occurs.
172:             *
173:             */
174:            public void deleteTable() throws Exception {
175:                // deletes the table after each test to avoid errors.
176:                ExceptionHandleUtil.deleteTable(DATABASE_1,
177:                        ItfContainerTransaction.TABLE);
178:                ExceptionHandleUtil.deleteTable(DATABASE_2,
179:                        ItfContainerTransaction.TABLE);
180:                // deletes the auxiliar bean table
181:                ExceptionHandleUtil.deleteTable(DATABASE_1,
182:                        ItfTransactionMisc00.TABLE);
183:                ExceptionHandleUtil.deleteTable(DATABASE_2,
184:                        ItfTransactionMisc00.TABLE);
185:            }
186:
187:        }
w__w_w___.__j_av_a___2s__.___c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.