Source Code Cross Referenced for TestSessionSynchronization.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » tests » transaction » containermanaged » stateful » 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.stateful 
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: TestSessionSynchronization.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.tests.transaction.containermanaged.stateful;
025:
026:        import static org.testng.Assert.assertTrue;
027:        import static org.testng.Assert.fail;
028:
029:        import java.sql.SQLException;
030:
031:        import javax.transaction.UserTransaction;
032:
033:        import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.transaction.ItfSessionSync;
034:        import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.transaction.SFSBSessionSync;
035:        import org.ow2.easybeans.tests.common.helper.EJBHelper;
036:        import org.ow2.easybeans.tests.transaction.containermanaged.base.TestContainerTransactionBase;
037:        import org.ow2.util.log.Log;
038:        import org.ow2.util.log.LogFactory;
039:        import org.testng.annotations.BeforeClass;
040:        import org.testng.annotations.BeforeMethod;
041:        import org.testng.annotations.Test;
042:
043:        /**
044:         * Verifies if the container-managed transaction in the stateful bean is
045:         * following the JSR 220.The test verifies if the SessionSynchronization Callbacks are working properly.
046:         * The items covered in this test are: 12.6.2.11.
047:         * @reference JSR 220-PROPOSED FINAL
048:         * @requirement Application Server must be running; the bean
049:         *              org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.SFSBSessionSync
050:         *              must be deployed.
051:         * @setup gets the reference of SFSBSessionSync and binds the
052:         *        databases specified in the EmbeddedTest.
053:         * @author Gisele Pinheiro Souza
054:         * @author Eduardo Studzinski Estima de Castro
055:         */
056:        public class TestSessionSynchronization extends
057:                TestContainerTransactionBase {
058:
059:            /**
060:             * Bean used during the tests.
061:             */
062:            private ItfSessionSync sfsbSessionSync;
063:
064:            /**
065:             * Logger.
066:             */
067:            private static Log logger = LogFactory
068:                    .getLog(TestSessionSynchronization.class);
069:
070:            /**
071:             * Creates the bean before each test to avoid errors during the tests.
072:             * @throws Exception if an error during the bean creation occurs.
073:             */
074:            @BeforeMethod
075:            public void createBean() throws Exception {
076:                sfsbSessionSync = EJBHelper.getBeanRemoteInstance(
077:                        SFSBSessionSync.class, ItfSessionSync.class);
078:                sfsbSessionSync.startup(DATABASE_1, DATABASE_2);
079:            }
080:
081:            /**
082:             * Binds the databases used.
083:             * @throws Exception if an error during the test startup occurs.
084:             */
085:            @BeforeClass
086:            @Override
087:            public void setup() throws Exception {
088:                super .setup();
089:            }
090:
091:            /**
092:             * Verifies if the callback methods were called correctly. The afterbegin,
093:             * before completion must stay in the same transaction that the method
094:             * called. The beforeCompletation calls a setRollbackOnly, so the table
095:             * created in the afterBegin must to be deleted and the afterCompletation
096:             * must receive that the transaction was not commited.
097:             * @throws Exception if an unexpected error occurs during the test.
098:             */
099:            private void verifyCallbacks() throws Exception {
100:                // verifies if the table was created in the DATABASE_1
101:                // the afterBegin method inserts the table in this database.
102:                try {
103:                    verifyTable(DATABASE_1, ItfSessionSync.TABLE);
104:                    fail("The beforeCompletion method was not called "
105:                            + " or the afterBegin method and the method called were not in the same transaction.");
106:                } catch (SQLException e) {
107:                    logger.debug("The method threw an expected exception {0}",
108:                            e);
109:                }
110:
111:                // verifies if the table was created in the DATABASE_2
112:                // the insertTableRequired method inserts the table in this database.
113:                try {
114:                    verifyTable(DATABASE_2, ItfSessionSync.TABLE);
115:                    fail("The beforeCompletion method was not called.");
116:                } catch (SQLException e) {
117:                    logger.debug("The method threw an expected exception {0}",
118:                            e);
119:                }
120:                // the after completion method inserts the value in this variable,
121:                // so it tests if the afterCompletion is called.
122:                assertTrue(sfsbSessionSync.isRolledback());
123:            }
124:
125:            /**
126:             * Verifies if the table created by the afterBegin method is created when a
127:             * method that does not support transaction is called.Also, this method
128:             * verifies if the table in the method was create properly.
129:             * @throws Exception if an unexpected error occurs during the test.
130:             */
131:            private void verifyTablesWithouCallbacks() throws Exception {
132:                // verifies if the table was created in the DATABASE_1
133:                // the afterTransaction method inserts the table in this database.
134:                try {
135:                    verifyTable(DATABASE_1, ItfSessionSync.TABLE);
136:                    fail("The method afterbegin was called, but it is not correct in this case.");
137:                } catch (SQLException e) {
138:                    logger.debug("The method threw an expected exception {0}",
139:                            e);
140:                }
141:                // verifies if the table was created in the DATABASE_?
142:                // the method CALLED inserts the table in this database.
143:                try {
144:                    verifyTable(DATABASE_2, ItfSessionSync.TABLE);
145:                    logger.debug("The table was inserted correctly.");
146:                } catch (SQLException e) {
147:                    fail("The container rolled back the transaction, but there is not transaction associated.");
148:                }
149:            }
150:
151:            /**
152:             * Calls the method that uses the required attribute.The bean implements the
153:             * SessionSynchronization interface, so the methods afterBegin,
154:             * beforeCompletion and afterCompletion must be called. The method
155:             * beforeCompletion calls setRollbackOnly, so the transaction must be rolled
156:             * back.
157:             * @input -
158:             * @output the tables not created because the transaction rolled back.
159:             * @throws Exception if an error occurs during the tests.
160:             */
161:            @Test(dependsOnMethods={"testSessionSyncWithUserTransAndSupports"})
162:            public void testSessionSyncWithRequired() throws Exception {
163:                sfsbSessionSync.insertTableRequired();
164:                verifyCallbacks();
165:            }
166:
167:            /**
168:             * Calls the method that uses the requires_new attribute.The bean implements the
169:             * SessionSynchronization interface, so the methods afterBegin,
170:             * beforeCompletion and afterCompletion must be called. The method
171:             * beforeCompletion calls setRollbackOnly, so the transaction must be
172:             * rolled back.
173:             * @input -
174:             * @output the tables not created because the transaction rolled back.
175:             * @throws Exception if an error occurs during the tests.
176:             */
177:            @Test
178:            public void testSessionSyncWithRequiresNew() throws Exception {
179:                sfsbSessionSync.insertTableRequiredNew();
180:                verifyCallbacks();
181:            }
182:
183:            /**
184:             * Calls the method that uses the mandatory attribute.The bean implements the
185:             * SessionSynchronization interface, so the methods afterBegin,
186:             * beforeCompletion and afterCompletion must be called. The method
187:             * beforeCompletion calls setRollbackOnly, so the transaction must be
188:             * rolled back.
189:             * @input -
190:             * @output the tables not created because the transaction rolled back.
191:             * @throws Exception if an error occurs during the tests.
192:             */
193:            @Test
194:            public void testSessionSyncWithMandatory() throws Exception {
195:                UserTransaction utx = getUserTransaction();
196:                utx.begin();
197:                sfsbSessionSync.insertTableMandatory();
198:                try {
199:                    utx.commit();
200:                } catch (Exception e) {
201:                    logger.debug("The method threw an expected exception {e}",
202:                            e);
203:                }
204:                verifyCallbacks();
205:            }
206:
207:            /**
208:             * Calls the method with transaction attribute supports and verifies if the
209:             * methods callback are called. The transaction attribute supports must to
210:             * have the same behaviour that the required.
211:             * @input -
212:             * @output the databases without tables, because the container made a
213:             *         rollback.
214:             * @throws Exception if an error occurs during the tests.
215:             */
216:            @Test
217:            public void testSessionSyncWithUserTransAndSupports()
218:                    throws Exception {
219:                UserTransaction utx = getUserTransaction();
220:                utx.begin();
221:                sfsbSessionSync.insertTableSupports();
222:                try {
223:                    utx.commit();
224:                } catch (Exception e) {
225:                    logger.debug("The method threw an expected exception {e}",
226:                            e);
227:                }
228:                verifyCallbacks();
229:            }
230:
231:            /**
232:             * Calls the method with transaction attribute supports and verifies if the
233:             * container did not call the callbacks methdos from SessionSynchronization
234:             * interface. The container must no call this methods, because the method is
235:             * not in a transaction context.
236:             * @throws Exception if an error occurs during the tests.
237:             */
238:            @Test
239:            public void testSessionSyncWithOnlySupports() throws Exception {
240:                sfsbSessionSync.insertTableSupports();
241:                verifyTablesWithouCallbacks();
242:            }
243:
244:            /**
245:             * Calls the method with transaction attribute not_supported and verifies if the
246:             * container did not call the callbacks methdos from SessionSynchronization
247:             * interface. The container must no call this methods, because the method is
248:             * not in a transaction context.
249:             * @throws Exception if an error occurs during the tests.
250:             */
251:            @Test
252:            public void testSessionSyncWithNotSupported() throws Exception {
253:                sfsbSessionSync.insertTableNotSupported();
254:                verifyTablesWithouCallbacks();
255:            }
256:
257:            /**
258:             * Calls the method with transaction attribute never and verifies if the
259:             * container did not call the callbacks methdos from SessionSynchronization
260:             * interface. The container must no call this methods, because the method is
261:             * not in a transaction context.
262:             * @throws Exception if an error occurs during the tests.
263:             */
264:            @Test
265:            public void testSessionSyncWithNever() throws Exception {
266:                sfsbSessionSync.insertTableNever();
267:                verifyTablesWithouCallbacks();
268:            }
269:
270:            /**
271:             * Deletes the table before each test to avoid errors in each test.
272:             */
273:            @BeforeMethod
274:            @Override
275:            public void deleteTable() {
276:                deleteTable(DATABASE_1, ItfSessionSync.TABLE);
277:                deleteTable(DATABASE_2, ItfSessionSync.TABLE);
278:            }
279:
280:            /**
281:             * Makes a rollback in the transaction actives.
282:             * @throws Exception if a transaction exception occurs.
283:             */
284:            @BeforeMethod
285:            @Override
286:            public void cleanTransaction() throws Exception {
287:                super.cleanTransaction();
288:            }
289:
290:        }
w_w__w__.___j___av___a_2__s__.___c_o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.