Source Code Cross Referenced for SFSBTransAttributeTester.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » tests » common » ejbs » stateful » containermanaged » xmldescriptor » 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.common.ejbs.stateful.containermanaged.xmldescriptor 
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: SFSBTransAttributeTester.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.xmldescriptor;
025:
026:        import static org.testng.Assert.fail;
027:
028:        import java.sql.SQLException;
029:
030:        import javax.ejb.EJB;
031:        import javax.ejb.EJBException;
032:        import javax.ejb.Remote;
033:        import javax.ejb.Stateful;
034:        import javax.naming.NamingException;
035:        import javax.transaction.UserTransaction;
036:
037:        import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.ItfDatabaseManager;
038:        import org.ow2.easybeans.tests.common.helper.TransactionHelper;
039:        import org.ow2.util.log.Log;
040:        import org.ow2.util.log.LogFactory;
041:
042:        /**
043:         * Verifies if the container sets all types of transaction attributes that are
044:         * defined by the deployment descriptor.
045:         * @author Gisele Pinheiro Souza
046:         * @author Eduardo Studzinski Estima de Castro
047:         */
048:        @Stateful
049:        @Remote(ItfTransAttributeTester.class)
050:        public class SFSBTransAttributeTester implements 
051:                ItfTransAttributeTester {
052:
053:            /**
054:             * Bean that has the transaction attribute mandatory defined in the
055:             * deployment descriptor.
056:             */
057:            @EJB(beanName="SFSBTransAttributeDefMandatory")
058:            private ItfTransAttributeDefinition beanMandatory;
059:
060:            /**
061:             * Bean that has the transaction attribute required defined in the
062:             * deployment descriptor.
063:             */
064:            @EJB(beanName="SFSBTransAttributeDefRequired")
065:            private ItfTransAttributeDefinition beanRequired;
066:
067:            /**
068:             * Bean that has the transaction attribute requires_new defined in the
069:             * deployment descriptor.
070:             */
071:            @EJB(beanName="SFSBTransAttributeDefRequiresNew")
072:            private ItfTransAttributeDefinition beanRequiresNew;
073:
074:            /**
075:             * Bean that has the transaction attribute supports defined in the
076:             * deployment descriptor.
077:             */
078:            @EJB(beanName="SFSBTransAttributeDefSupports")
079:            private ItfTransAttributeDefinition beanSupports;
080:
081:            /**
082:             * Bean that has the transaction attribute not supported  defined in the
083:             * deployment descriptor.
084:             */
085:            @EJB(beanName="SFSBTransAttributeDefNotSupported")
086:            private ItfTransAttributeDefinition beanNotSupported;
087:
088:            /**
089:             * Bean that has the transaction attribute never defined in the
090:             * deployment descriptor.
091:             */
092:            @EJB(beanName="SFSBTransAttributeDefNever")
093:            private ItfTransAttributeDefinition beanNever;
094:
095:            /**
096:             * Used to manipulate the data in the database.
097:             */
098:            @EJB
099:            private ItfDatabaseManager slsbDatabaseManager;
100:
101:            /**
102:             * Logger.
103:             */
104:            private static Log logger = LogFactory
105:                    .getLog(SFSBTransAttributeTester.class);
106:
107:            /**
108:             * Verifies if the client use the same transaction that the bean. Creates a
109:             * transaction, call a bean method that acess the JDBC and after makes a
110:             * rollback. If the bean uses the same transaction, the data in the database
111:             * must be rolled back.
112:             * @param bean the bean that is verified.
113:             * @return true if the bean uses the same transaction that the client, false otherwise.
114:             * @throws Exception if an error occurs.
115:             */
116:            private boolean usesClientTransaction(
117:                    final ItfTransAttributeDefinition bean) throws Exception {
118:                UserTransaction utx = TransactionHelper
119:                        .getInternalUserTransaction();
120:                try {
121:                    utx.begin();
122:                    bean.insertTableCorrectMandatory(DB_NAME, TABLE_NAME);
123:                } finally {
124:                    utx.rollback();
125:                }
126:                try {
127:                    slsbDatabaseManager.verifyTable(DB_NAME, TABLE_NAME);
128:                    return false;
129:                } catch (SQLException e) {
130:                    return true;
131:                }
132:            }
133:
134:            /**
135:             * Verifies if the bean has a transaction context.
136:             * @param bean the bean that is verified.
137:             * @return true if the bean uses a transaction, false otherwise.
138:             * @throws Exception if an error occurs.
139:             */
140:            private boolean hasTransaction(
141:                    final ItfTransAttributeDefinition bean) throws Exception {
142:                bean.insertTableErrorMandatory(DB_NAME, TABLE_NAME);
143:                try {
144:                    slsbDatabaseManager.verifyTable(DB_NAME, TABLE_NAME);
145:                    return false;
146:                } catch (SQLException e) {
147:                    return true;
148:                }
149:            }
150:
151:            /**
152:             * Verifies if the deployment descriptor overrides the default transaction
153:             * attribute value. Also, verifies if the transaction attribute type is really mandatory.
154:             * @throws Exception if an error occurs.
155:             */
156:            public void testMandatory() throws Exception {
157:                //cleans the database to avoid errors.
158:                deleteTable(DB_NAME, TABLE_NAME);
159:
160:                UserTransaction utx = TransactionHelper.getUserTransaction();
161:                try {
162:                    utx.begin();
163:                    beanMandatory.insertTableCorrect(DB_NAME, TABLE_NAME);
164:                } finally {
165:                    utx.rollback();
166:                }
167:                try {
168:                    slsbDatabaseManager.verifyTable(DB_NAME, TABLE_NAME);
169:                    fail("The deployment descriptor did not override the "
170:                            + "annotation. The bean did not use the client transaction in mandatory mode.");
171:                } catch (SQLException e) {
172:                    logger.debug("The bean thron an expected exception{0}", e);
173:                }
174:
175:                //cleans the database to avoid errors.
176:                deleteTable(DB_NAME, TABLE_NAME);
177:
178:                try {
179:                    beanMandatory.insertTableCorrect(DB_NAME, TABLE_NAME);
180:                } catch (EJBException e) {
181:                    logger.debug("The bean thron an expected exception{0}", e);
182:                    fail("The deployment descriptor did not override the annotation. "
183:                            + "The bean was called withou a transaction context in a mandatory mode and there was not exception.");
184:                }
185:            }
186:
187:            /**
188:             * Verifies if the deployment descriptor overrides the transaction
189:             * attribute mandatory. Also, verifies if the transaction attribute type is really required.
190:             * @throws Exception if an error occurs.
191:             */
192:            public void testRequired() throws Exception {
193:                //cleans the database to avoid errors.
194:                deleteTable(DB_NAME, TABLE_NAME);
195:                boolean bolClientTransaction = usesClientTransaction(beanRequired);
196:                //cleans the database to avoid errors.
197:                deleteTable(DB_NAME, TABLE_NAME);
198:                boolean bolHasTransaction = hasTransaction(beanRequired);
199:                if (!(bolClientTransaction && bolHasTransaction)) {
200:                    fail("The container did not override the transaction attribute for REQUIRED");
201:                }
202:            }
203:
204:            /**
205:             * Verifies if the deployment descriptor overrides the transaction
206:             * attribute mandatory. Also, verifies if the transaction attribute type is really requireds new.
207:             * @throws Exception if an error occurs.
208:             */
209:            public void testRequiresNew() throws Exception {
210:                //cleans the database to avoid errors.
211:                deleteTable(DB_NAME, TABLE_NAME);
212:                boolean bolClientTransaction = usesClientTransaction(beanRequiresNew);
213:                //cleans the database to avoid errors.
214:                deleteTable(DB_NAME, TABLE_NAME);
215:                boolean bolHasTransaction = hasTransaction(beanRequiresNew);
216:                if (!(!bolClientTransaction && bolHasTransaction)) {
217:                    fail("The container did not override the transaction attribute for REQUIRES_NEW");
218:                }
219:            }
220:
221:            /**
222:             * Verifies if the deployment descriptor overrides the transaction
223:             * attribute mandatory. Also, verifies if the transaction attribute type is really supports.
224:             * @throws Exception if an error occurs.
225:             */
226:            public void testSupports() throws Exception {
227:                //cleans the database to avoid errors.
228:                deleteTable(DB_NAME, TABLE_NAME);
229:                boolean bolClientTransaction = usesClientTransaction(beanSupports);
230:                //cleans the database to avoid errors.
231:                deleteTable(DB_NAME, TABLE_NAME);
232:                boolean bolHasTransaction = hasTransaction(beanSupports);
233:                if (!(bolClientTransaction && !bolHasTransaction)) {
234:                    fail("The container did not override the transaction attribute for SUPPORTS");
235:                }
236:            }
237:
238:            /**
239:             * Verifies if the deployment descriptor overrides the transaction
240:             * attribute mandatory. Also, verifies if the transaction attribute type is really not supported.
241:             * @throws Exception if an error occurs.
242:             */
243:            public void testNotSupported() throws Exception {
244:                //cleans the database to avoid errors.
245:                deleteTable(DB_NAME, TABLE_NAME);
246:                boolean bolClientTransaction = usesClientTransaction(beanNotSupported);
247:                //cleans the database to avoid errors.
248:                deleteTable(DB_NAME, TABLE_NAME);
249:                boolean bolHasTransaction = hasTransaction(beanNotSupported);
250:                if (bolClientTransaction || bolHasTransaction) {
251:                    fail("The container did not override the transaction attribute for NOT_SUPPORTED");
252:                }
253:            }
254:
255:            /**
256:             * Verifies if the deployment descriptor overrides the transaction
257:             * attribute mandatory. Also, verifies if the transaction attribute type is really never.
258:             * @throws Exception if an error occurs.
259:             */
260:            public void testNever() throws Exception {
261:                //cleans the database to avoid errors.
262:                deleteTable(DB_NAME, TABLE_NAME);
263:                boolean bolClientTransaction = true;
264:                try {
265:                    usesClientTransaction(beanNever);
266:                } catch (EJBException e) {
267:                    bolClientTransaction = false;
268:                }
269:                //cleans the database to avoid errors.
270:                deleteTable(DB_NAME, TABLE_NAME);
271:                boolean bolHasTransaction = hasTransaction(beanNever);
272:                if (bolClientTransaction || bolHasTransaction) {
273:                    fail("The container did not override the transaction attribute for NEVER");
274:                }
275:            }
276:
277:            /**
278:             * Deletes the table in the database.
279:             * @param dbName the database name in the registry.
280:             * @param tableName the table name.
281:             */
282:            protected void deleteTable(final String dbName,
283:                    final String tableName) {
284:                // deletes the table after each test to avoid errors.
285:                try {
286:                    slsbDatabaseManager.deleteTable(dbName, tableName);
287:                } catch (SQLException e) {
288:                    logger
289:                            .debug(
290:                                    "The table delete threw an error during the execution {0}",
291:                                    e);
292:                } catch (NamingException e) {
293:                    logger
294:                            .debug(
295:                                    "The table delete threw an error during the execution {0}",
296:                                    e);
297:                }
298:            }
299:
300:        }
w__w__w_.___ja__v___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.