Source Code Cross Referenced for StatefulBeanTxTests.java in  » J2EE » openejb3 » org » apache » openejb » test » 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 » openejb3 » org.apache.openejb.test.stateful 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.openejb.test.stateful;
017:
018:        import java.util.Properties;
019:
020:        import javax.ejb.EJBMetaData;
021:        import javax.ejb.Handle;
022:        import javax.ejb.HomeHandle;
023:        import javax.naming.Context;
024:        import javax.naming.InitialContext;
025:        import javax.transaction.RollbackException;
026:
027:        import org.apache.openejb.test.TestManager;
028:        import org.apache.openejb.test.object.Account;
029:        import org.apache.openejb.test.object.Transaction;
030:
031:        /**
032:         * [1] Should be run as the first test suite of the StatefulTestClients
033:         *
034:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
035:         * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
036:         */
037:        public class StatefulBeanTxTests extends
038:                org.apache.openejb.test.NamedTestCase {
039:
040:            public final static String jndiEJBHomeEntry = "client/tests/stateful/BeanManagedTransactionTests/EJBHome";
041:
042:            protected BeanTxStatefulHome ejbHome;
043:            protected BeanTxStatefulObject ejbObject;
044:
045:            protected EJBMetaData ejbMetaData;
046:            protected HomeHandle ejbHomeHandle;
047:            protected Handle ejbHandle;
048:            protected Integer ejbPrimaryKey;
049:
050:            protected InitialContext initialContext;
051:
052:            public StatefulBeanTxTests() {
053:                super ("Stateful.BeanManagedTransaction.");
054:            }
055:
056:            /**
057:             * Sets up the fixture, for example, open a network connection.
058:             * This method is called before a test is executed.
059:             */
060:            protected void setUp() throws Exception {
061:
062:                Properties properties = TestManager.getServer()
063:                        .getContextEnvironment();
064:                //properties.put(Context.SECURITY_PRINCIPAL, "STATEFUL_test00_CLIENT");
065:                //properties.put(Context.SECURITY_CREDENTIALS, "STATEFUL_test00_CLIENT");
066:
067:                initialContext = new InitialContext(properties);
068:
069:                /*[1] Get bean */
070:                Object obj = initialContext.lookup(jndiEJBHomeEntry);
071:                ejbHome = (BeanTxStatefulHome) javax.rmi.PortableRemoteObject
072:                        .narrow(obj, BeanTxStatefulHome.class);
073:                ejbObject = ejbHome.create("Transaction Bean");
074:
075:                /*[2] Create database table */
076:                TestManager.getDatabase().createAccountTable();
077:            }
078:
079:            /**
080:             * Tears down the fixture, for example, close a network connection.
081:             * This method is called after a test is executed.
082:             */
083:            protected void tearDown() throws Exception {
084:                /*[1] Drop database table */
085:                TestManager.getDatabase().dropAccountTable();
086:            }
087:
088:            /**
089:             * <B>11.6.1 Bean-managed transaction demarcation</B>
090:             * <P>
091:             * The Container must make the javax.transaction.UserTransaction interface available to
092:             * the enterprise bean's business method via the javax.ejb.EJBContext interface and under the
093:             * environment entry java:comp/UserTransaction. When an instance uses the javax.trans-action.
094:             * UserTransaction interface to demarcate a transaction, the Container must enlist all the
095:             * resource managers used by the instance between the begin() and commit(),or rollback(),
096:             * methods with the transaction. When the instance attempts to commit the transaction, the Container is
097:             * responsible for the global coordination of the transaction commit.
098:             * </P>
099:             * <P>--------------------------------------------------------</P>
100:             * <P>
101:             * Check that a javax.transaction.UserTransaction can be obtained from
102:             * the javax.ejb.EJBContext
103:             * </P>
104:             */
105:            public void test01_EJBContext_getUserTransaction() {
106:                try {
107:                    Transaction t = ejbObject.getUserTransaction();
108:                    assertNotNull("UserTransaction is null.", t);
109:                } catch (Exception e) {
110:                    fail("Received Exception " + e.getClass() + " : "
111:                            + e.getMessage());
112:                }
113:            }
114:
115:            /**
116:             *
117:             * <B>11.6.1 Bean-managed transaction demarcation</B>
118:             * <P>
119:             * The Container must make the javax.transaction.UserTransaction interface available to
120:             * the enterprise bean's business method via the javax.ejb.EJBContext interface and under the
121:             * environment entry java:comp/UserTransaction. When an instance uses the javax.trans-action.
122:             * UserTransaction interface to demarcate a transaction, the Container must enlist all the
123:             * resource managers used by the instance between the begin() and commit(),or rollback(),
124:             * methods with the transaction. When the instance attempts to commit the transaction, the Container is
125:             * responsible for the global coordination of the transaction commit.
126:             * </P>
127:             * <P>--------------------------------------------------------</P>
128:             * <P>
129:             * Check that a javax.transaction.UserTransaction can be obtained from
130:             * the environment entry java:comp/UserTransaction
131:             * </P>
132:             */
133:            public void test02_java_comp_UserTransaction() {
134:                try {
135:                    Transaction t = ejbObject.jndiUserTransaction();
136:                    assertNotNull(
137:                            "UserTransaction is null. Could not retreive a UserTransaction from the bean's JNDI namespace.",
138:                            t);
139:                } catch (Exception e) {
140:                    fail("Could not retreive a UserTransaction from the bean's JNDI namespace. Received Exception "
141:                            + e.getClass() + " : " + e.getMessage());
142:                }
143:            }
144:
145:            /**
146:             * <B>11.6.1 Bean-managed transaction demarcation</B>
147:             * <P>
148:             * The Container must throw the java.lang.IllegalStateException if an instance of a bean
149:             * with bean-managed transaction demarcation attempts to invoke the setRollbackOnly() or
150:             * getRollbackOnly() method of the javax.ejb.EJBContext interface.
151:             * </P>
152:             * <P>--------------------------------------------------------</P>
153:             * <P>
154:             * Test that setRollbackOnly() throws a java.lang.IllegalStateException
155:             * </P>
156:             */
157:            public void TODO_test03_EJBContext_setRollbackOnly() {
158:                try {
159:
160:                } catch (Exception e) {
161:                    fail("Received Exception " + e.getClass() + " : "
162:                            + e.getMessage());
163:                }
164:            }
165:
166:            /**
167:             * <B>11.6.1 Bean-managed transaction demarcation</B>
168:             * <P>
169:             * The Container must throw the java.lang.IllegalStateException if an instance of a bean
170:             * with bean-managed transaction demarcation attempts to invoke the setRollbackOnly() or
171:             * getRollbackOnly() method of the javax.ejb.EJBContext interface.
172:             * </P>
173:             * <P>--------------------------------------------------------</P>
174:             * <P>
175:             * Test that getRollbackOnly() throws a java.lang.IllegalStateException
176:             * </P>
177:             */
178:            public void TODO_test04_EJBContext_getRollbackOnly() {
179:                try {
180:
181:                } catch (Exception e) {
182:                    fail("Received Exception " + e.getClass() + " : "
183:                            + e.getMessage());
184:                }
185:            }
186:
187:            /**
188:             *
189:             */
190:            public void test05_singleTransactionCommit() {
191:                try {
192:                    Account expected = new Account("123-45-6789", "Joe",
193:                            "Cool", 40000);
194:                    Account actual = new Account();
195:
196:                    ejbObject.openAccount(expected, new Boolean(false));
197:                    actual = ejbObject.retreiveAccount(expected.getSsn());
198:
199:                    assertNotNull(
200:                            "The transaction was not commited.  The record is null",
201:                            actual);
202:                    assertEquals("The transaction was not commited cleanly.",
203:                            expected, actual);
204:                } catch (RollbackException re) {
205:                    fail("Transaction was rolledback.  Received Exception "
206:                            + re.getClass() + " : " + re.getMessage());
207:                } catch (Exception e) {
208:                    fail("Received Exception " + e.getClass() + " : "
209:                            + e.getMessage());
210:                }
211:            }
212:
213:            /**
214:             * This test does work for the IntraVM Server, but it fails on 
215:             * the Remote Server.  For some reason, when the RollbackException is
216:             * sent to the client, the server blocks.
217:             */
218:            public void BUG_test06_singleTransactionRollback() {
219:                Account expected = new Account("234-56-7890", "Charlie",
220:                        "Brown", 20000);
221:                Account actual = new Account();
222:
223:                // Try and add the account in a transaction.  This should fail and 
224:                // throw a RollbackException
225:                try {
226:                    ejbObject.openAccount(expected, new Boolean(true));
227:                    fail("A javax.transaction.RollbackException should have been thrown.");
228:                } catch (RollbackException re) {
229:                    // Good.
230:                } catch (Exception e) {
231:                    fail("Received Exception " + e.getClass() + " : "
232:                            + e.getMessage());
233:                }
234:
235:                //// Now check that the account really wasn't added.
236:                //try{
237:                //    actual = ejbObject.retreiveAccount( expected.getSsn() );
238:                //    //assertTrue( "The transaction was commited when it should have been rolledback.", !expected.equals(actual) );
239:                //} catch (Exception e){
240:                //    fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
241:                //}
242:            }
243:
244:            /**
245:             * <B>11.6.1 Bean-managed transaction demarcation</B>
246:             * <P>
247:             * The Container must allow the enterprise bean instance to serially perform several transactions in a
248:             * method.
249:             * </P>
250:             */
251:            public void TODO_test07_serialTransactions() {
252:                try {
253:
254:                } catch (Exception e) {
255:                    fail("Received Exception " + e.getClass() + " : "
256:                            + e.getMessage());
257:                }
258:            }
259:
260:            /**
261:             * <B>11.6.1 Bean-managed transaction demarcation</B>
262:             * <P>
263:             * When an instance attempts to start a transaction using the
264:             * begin() method of the javax.transaction.UserTransaction
265:             * interface while the instance has not committed the previous
266:             * transaction, the Container must throw the
267:             * javax.transaction.NotSupportedException in the begin() method.
268:             * </P>
269:             */
270:            public void TODO_test08_nestedTransactions() {
271:                try {
272:
273:                } catch (Exception e) {
274:                    fail("Received Exception " + e.getClass() + " : "
275:                            + e.getMessage());
276:                }
277:            }
278:
279:            /**
280:             * <B>11.6.1 Bean-managed transaction demarcation</B>
281:             * <P>
282:             * In the case of a stateful session bean, it is possible that the
283:             * business method that started a transaction completes without
284:             * committing or rolling back the transaction. In such a case, the
285:             * Container must retain the association between the transaction
286:             * and the instance across multiple client calls until the instance
287:             * commits or rolls back the transaction. When the client invokes
288:             * the next business method, the Container must invoke the business
289:             * method in this transaction context.
290:             * </P>
291:             */
292:            public void TODO_test09_methodSpanningTransactions() {
293:                try {
294:
295:                } catch (Exception e) {
296:                    fail("Received Exception " + e.getClass() + " : "
297:                            + e.getMessage());
298:                }
299:            }
300:
301:            /**
302:             * <B>11.6.1 Bean-managed transaction demarcation</B>
303:             * <P>
304:             * The actions performed by the Container for an instance with bean-managed transaction are summarized
305:             * by the following table. T1 is a transaction associated with a client request, T2 is a transaction that is cur-rently
306:             * associated with the instance (i.e. a transaction that was started but not completed by a previous
307:             * business method).
308:             * </P>
309:             * <PRE>
310:             * =========================================================================
311:             * Container's actions for methods of beans with bean-managed transaction
312:             * =========================================================================
313:             *
314:             *            |      IF     |          AND             |          THEN
315:             *  scenario  |   Client's  | Transaction currently    | Transaction associated
316:             *            | transaction | associated with instance | with the method is
317:             * ___________|_____________|__________________________|________________________
318:             *            |             |                          |
319:             *    1       |  none       |  none                    |  none
320:             * ___________|_____________|__________________________|________________________
321:             *            |             |                          |
322:             *    2       |  T1         |  none                    |  none
323:             * ___________|_____________|__________________________|________________________
324:             *            |             |                          |
325:             *    3       |  none       |  T2                      |  T2
326:             * ___________|_____________|__________________________|________________________
327:             *            |             |                          |
328:             *    4       |  T1         |  T2                      |  T2
329:             * ___________|_____________|__________________________|________________________
330:             * </PRE>
331:             * <P>
332:             * If the client request is not associated with a transaction and the instance is not associated with a
333:             * transaction, the container invokes the instance with an unspecified transaction context.
334:             * </P>
335:             * <P>--------------------------------------------------------</P>
336:             * <P>
337:             * Test scenario 1: none none<BR>
338:             * If the client's transaction is none and the transaction currently
339:             * associated with instance none then the transaction associated with the method is none.
340:             * </P>
341:             */
342:            public void TODO_test10_scenario1_NoneNone() {
343:                try {
344:
345:                } catch (Exception e) {
346:                    fail("Received Exception " + e.getClass() + " : "
347:                            + e.getMessage());
348:                }
349:            }
350:
351:            /**
352:             * <B>11.6.1 Bean-managed transaction demarcation</B>
353:             * <P>
354:             * The actions performed by the Container for an instance with bean-managed transaction are summarized
355:             * by the following table. T1 is a transaction associated with a client request, T2 is a transaction that is cur-rently
356:             * associated with the instance (i.e. a transaction that was started but not completed by a previous
357:             * business method).
358:             * </P>
359:             * <PRE>
360:             * =========================================================================
361:             * Container's actions for methods of beans with bean-managed transaction
362:             * =========================================================================
363:             *
364:             *            |      IF     |          AND             |          THEN
365:             *  scenario  |   Client's  | Transaction currently    | Transaction associated
366:             *            | transaction | associated with instance | with the method is
367:             * ___________|_____________|__________________________|________________________
368:             *            |             |                          |
369:             *    1       |  none       |  none                    |  none
370:             * ___________|_____________|__________________________|________________________
371:             *            |             |                          |
372:             *    2       |  T1         |  none                    |  none
373:             * ___________|_____________|__________________________|________________________
374:             *            |             |                          |
375:             *    3       |  none       |  T2                      |  T2
376:             * ___________|_____________|__________________________|________________________
377:             *            |             |                          |
378:             *    4       |  T1         |  T2                      |  T2
379:             * ___________|_____________|__________________________|________________________
380:             * </PRE>
381:             * <P>
382:             * If the client is associated with a transaction T1, and the instance is not associated with a transaction,
383:             * the container suspends the client's transaction association and invokes the method with
384:             * an unspecified transaction context. The container resumes the client's transaction association
385:             * (T1) when the method completes.
386:             * </P>
387:             * <P>--------------------------------------------------------</P>
388:             * <P>
389:             * Test scenario 2: T1 none<BR>
390:             * </P>
391:             */
392:            public void TODO_test11_scenario2_T1None() {
393:                try {
394:
395:                } catch (Exception e) {
396:                    fail("Received Exception " + e.getClass() + " : "
397:                            + e.getMessage());
398:                }
399:            }
400:
401:            /**
402:             * <B>11.6.1 Bean-managed transaction demarcation</B>
403:             * <P>
404:             * The actions performed by the Container for an instance with bean-managed transaction are summarized
405:             * by the following table. T1 is a transaction associated with a client request, T2 is a transaction that is cur-rently
406:             * associated with the instance (i.e. a transaction that was started but not completed by a previous
407:             * business method).
408:             * </P>
409:             * <PRE>
410:             * =========================================================================
411:             * Container's actions for methods of beans with bean-managed transaction
412:             * =========================================================================
413:             *
414:             *            |      IF     |          AND             |          THEN
415:             *  scenario  |   Client's  | Transaction currently    | Transaction associated
416:             *            | transaction | associated with instance | with the method is
417:             * ___________|_____________|__________________________|________________________
418:             *            |             |                          |
419:             *    1       |  none       |  none                    |  none
420:             * ___________|_____________|__________________________|________________________
421:             *            |             |                          |
422:             *    2       |  T1         |  none                    |  none
423:             * ___________|_____________|__________________________|________________________
424:             *            |             |                          |
425:             *    3       |  none       |  T2                      |  T2
426:             * ___________|_____________|__________________________|________________________
427:             *            |             |                          |
428:             *    4       |  T1         |  T2                      |  T2
429:             * ___________|_____________|__________________________|________________________
430:             * </PRE>
431:             * <P>
432:             * If the client request is not associated with a transaction and the instance is already associated
433:             * with a transaction T2, the container invokes the instance with the transaction that is associated
434:             * with the instance (T2). This case can never happen for a stateless Session Bean.
435:             * </P>
436:             * <P>--------------------------------------------------------</P>
437:             * <P>
438:             * Test scenario 3: none T2<BR>
439:             * </P>
440:             */
441:            public void TODO_test12_scenario3_NoneT2() {
442:                try {
443:
444:                } catch (Exception e) {
445:                    fail("Received Exception " + e.getClass() + " : "
446:                            + e.getMessage());
447:                }
448:            }
449:
450:            /**
451:             * <B>11.6.1 Bean-managed transaction demarcation</B>
452:             * <P>
453:             * The actions performed by the Container for an instance with bean-managed transaction are summarized
454:             * by the following table. T1 is a transaction associated with a client request, T2 is a transaction that is cur-rently
455:             * associated with the instance (i.e. a transaction that was started but not completed by a previous
456:             * business method).
457:             * </P>
458:             * <PRE>
459:             * =========================================================================
460:             * Container's actions for methods of beans with bean-managed transaction
461:             * =========================================================================
462:             *
463:             *            |      IF     |          AND             |          THEN
464:             *  scenario  |   Client's  | Transaction currently    | Transaction associated
465:             *            | transaction | associated with instance | with the method is
466:             * ___________|_____________|__________________________|________________________
467:             *            |             |                          |
468:             *    1       |  none       |  none                    |  none
469:             * ___________|_____________|__________________________|________________________
470:             *            |             |                          |
471:             *    2       |  T1         |  none                    |  none
472:             * ___________|_____________|__________________________|________________________
473:             *            |             |                          |
474:             *    3       |  none       |  T2                      |  T2
475:             * ___________|_____________|__________________________|________________________
476:             *            |             |                          |
477:             *    4       |  T1         |  T2                      |  T2
478:             * ___________|_____________|__________________________|________________________
479:             * </PRE>
480:             * <P>
481:             * If the client is associated with a transaction T1, and the instance is already associated with a
482:             * transaction T2, the container suspends the client's transaction association and invokes the
483:             * method with the transaction context that is associated with the instance (T2). The container
484:             * resumes the client's transaction association (T1) when the method completes. This case can
485:             * never happen for a stateless Session Bean.
486:             * </P>
487:             * <P>--------------------------------------------------------</P>
488:             * <P>
489:             * Test scenario 4: T1 T2<BR>
490:             * </P>
491:             */
492:            public void TODO_test13_scenario4_T1T2() {
493:                try {
494:
495:                } catch (Exception e) {
496:                    fail("Received Exception " + e.getClass() + " : "
497:                            + e.getMessage());
498:                }
499:            }
500:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.