Source Code Cross Referenced for ExceptionUnitTestCase.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » exception » 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 » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.exception 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.exception;
023:
024:        import java.rmi.RemoteException;
025:        import java.rmi.AccessException;
026:        import java.security.GeneralSecurityException;
027:        import java.security.InvalidKeyException;
028:        import javax.ejb.EJBException;
029:        import javax.ejb.TransactionRolledbackLocalException;
030:        import javax.ejb.AccessLocalException;
031:        import javax.ejb.CreateException;
032:        import javax.naming.InitialContext;
033:        import javax.transaction.TransactionRolledbackException;
034:
035:        import junit.framework.Test;
036:        import org.jboss.logging.Logger;
037:        import org.jboss.test.JBossTestCase;
038:        import org.jboss.test.util.ejb.EJBTestCase;
039:
040:        /**
041:         * Test ejb exception propagation
042:         *  
043:         * @author Scott.Stark@jboss.org
044:         * @version $Revision: 57211 $
045:         */
046:        public class ExceptionUnitTestCase extends EJBTestCase {
047:            static Logger log = Logger.getLogger(ExceptionUnitTestCase.class);
048:
049:            public static Test suite() throws Exception {
050:                return JBossTestCase.getDeploySetup(
051:                        ExceptionUnitTestCase.class, "exception.jar");
052:            }
053:
054:            public ExceptionUnitTestCase(String name) {
055:                super (name);
056:            }
057:
058:            private ExceptionTesterHome exceptionTesterHome;
059:            private ExceptionTesterLocalHome exceptionTesterLocalHome;
060:
061:            /**
062:             * Looks up all of the home interfaces and creates the initial data. Looking
063:             * up objects in JNDI is expensive, so it should be done once and cached.
064:             * @throws Exception if a problem occures while finding the home interfaces,
065:             * or if an problem occures while createing the initial data
066:             */
067:            public void setUp() throws Exception {
068:                InitialContext jndi = new InitialContext();
069:                exceptionTesterHome = (ExceptionTesterHome) jndi
070:                        .lookup("exception/ExceptionTester");
071:                exceptionTesterLocalHome = (ExceptionTesterLocalHome) jndi
072:                        .lookup("exception/ExceptionTesterLocal");
073:            }
074:
075:            public void testSessionEjbCreateException() throws Exception {
076:                log.info("+++ testSessionEjbCreateException");
077:                InitialContext ctx = new InitialContext();
078:                ExceptionTesterHome home = (ExceptionTesterHome) ctx
079:                        .lookup("exception/CreateExceptionTesterEJB");
080:                try {
081:                    ExceptionTester bean = home.create();
082:                    fail("Expected CreateException on ExceptionTesterHome.create(), bean="
083:                            + bean);
084:                } catch (CreateException e) {
085:                    log.info("Saw CreateException via remote as expected", e);
086:                }
087:
088:                ExceptionTesterLocalHome lhome = (ExceptionTesterLocalHome) ctx
089:                        .lookup("exception/CreateExceptionTesterLocalEJB");
090:                try {
091:                    ExceptionTesterLocal bean = lhome.create();
092:                    fail("Expected CreateException on ExceptionTesterLocalHome.create(), bean="
093:                            + bean);
094:                } catch (CreateException e) {
095:                    log.info("Saw CreateException via local as expected", e);
096:                }
097:            }
098:
099:            public void testApplicationExceptionInTx_remote() throws Exception {
100:                ExceptionTester exceptionTester = null;
101:                try {
102:                    exceptionTester = exceptionTesterHome.create();
103:
104:                    exceptionTester.applicationExceptionInTx();
105:
106:                    fail("Expected application exception to be thrown");
107:
108:                } catch (ApplicationException e) {
109:                    // good this was expected
110:                } catch (Exception e) {
111:                    fail("Expected ApplicationException but got " + e);
112:                } finally {
113:                    if (exceptionTester != null) {
114:                        exceptionTester.remove();
115:                    }
116:                }
117:            }
118:
119:            public void testApplicationErrorInTx_remote() throws Exception {
120:                ExceptionTester exceptionTester = null;
121:                try {
122:                    exceptionTester = exceptionTesterHome.create();
123:
124:                    exceptionTester.applicationErrorInTx();
125:
126:                    fail("Expected transaction rolled back exception to be thrown");
127:
128:                } catch (TransactionRolledbackException e) {
129:                    // good this was expected
130:                    assertNotNull(
131:                            "TransactionRolledbackException.detail should not be null",
132:                            e.detail);
133:
134:                    assertEquals(
135:                            "TransactionRolledbackException.detail should "
136:                                    + "be a ApplicationError",
137:                            ApplicationError.class, e.detail.getClass());
138:
139:                } catch (Exception e) {
140:                    fail("Expected TransactionRolledbackException but got " + e);
141:                } finally {
142:                    if (exceptionTester != null) {
143:                        exceptionTester.remove();
144:                    }
145:                }
146:            }
147:
148:            public void testEJBExceptionInTx_remote() throws Exception {
149:                ExceptionTester exceptionTester = null;
150:                try {
151:                    exceptionTester = exceptionTesterHome.create();
152:
153:                    exceptionTester.ejbExceptionInTx();
154:
155:                    fail("Expected transaction rolled back exception to be thrown");
156:
157:                } catch (TransactionRolledbackException e) {
158:                    // good this was expected
159:                    assertNotNull(
160:                            "TransactionRolledbackException.detail should not be null",
161:                            e.detail);
162:                    assertEquals(
163:                            "TransactionRolledbackException.detail should "
164:                                    + "be an EJBException", EJBException.class,
165:                            e.detail.getClass());
166:
167:                } catch (Exception e) {
168:                    fail("Expected TransactionRolledbackException but got " + e);
169:                } finally {
170:                    if (exceptionTester != null) {
171:                        exceptionTester.remove();
172:                    }
173:                }
174:            }
175:
176:            public void testRuntimeExceptionInTx_remote() throws Exception {
177:                ExceptionTester exceptionTester = null;
178:                try {
179:                    exceptionTester = exceptionTesterHome.create();
180:
181:                    exceptionTester.runtimeExceptionInTx();
182:
183:                    fail("Expected transaction rolled back exception to be thrown");
184:
185:                } catch (TransactionRolledbackException e) {
186:                    // good this was expected
187:                    assertNotNull(
188:                            "TransactionRolledbackException.detail should not be null",
189:                            e.detail);
190:
191:                    assertEquals(
192:                            "TransactionRolledbackException.detail should "
193:                                    + "be a RuntimeException",
194:                            RuntimeException.class, e.detail.getClass());
195:
196:                } catch (Exception e) {
197:                    fail("Expected TransactionRolledbackException but got " + e);
198:                } finally {
199:                    if (exceptionTester != null) {
200:                        exceptionTester.remove();
201:                    }
202:                }
203:            }
204:
205:            public void testRemoteExceptionInTx_remote() throws Exception {
206:                ExceptionTester exceptionTester = null;
207:                try {
208:                    exceptionTester = exceptionTesterHome.create();
209:
210:                    exceptionTester.remoteExceptionInTx();
211:
212:                    fail("Expected transaction rolled back exception to be thrown");
213:
214:                } catch (TransactionRolledbackException e) {
215:                    // good this was expected
216:                    assertNotNull(
217:                            "TransactionRolledbackException.detail should not be null",
218:                            e.detail);
219:                    assertEquals(
220:                            "TransactionRolledbackException.detail should "
221:                                    + "be a RemoteException",
222:                            RemoteException.class, e.detail.getClass());
223:
224:                } catch (Exception e) {
225:                    fail("Expected TransactionRolledbackException but got " + e);
226:                } finally {
227:                    if (exceptionTester != null) {
228:                        exceptionTester.remove();
229:                    }
230:                }
231:            }
232:
233:            public void testApplicationExceptionNewTx_remote() throws Exception {
234:                ExceptionTester exceptionTester = null;
235:                try {
236:                    exceptionTester = exceptionTesterHome.create();
237:
238:                    exceptionTester.applicationExceptionNewTx();
239:
240:                    fail("Expected application exception to be thrown");
241:
242:                } catch (ApplicationException e) {
243:                    // good this was expected
244:                } catch (Exception e) {
245:                    fail("Expected ApplicationException but got " + e);
246:                } finally {
247:                    if (exceptionTester != null) {
248:                        exceptionTester.remove();
249:                    }
250:                }
251:            }
252:
253:            public void testApplicationErrorNewTx_remote() throws Exception {
254:                ExceptionTester exceptionTester = null;
255:                try {
256:                    exceptionTester = exceptionTesterHome.create();
257:
258:                    exceptionTester.applicationErrorNewTx();
259:
260:                    fail("Expected RemoteException to be thrown");
261:
262:                } catch (RemoteException e) {
263:                    // good this was expected
264:                    assertNotNull("RemoteException.detail should not be null",
265:                            e.detail);
266:
267:                    assertEquals(
268:                            "RemoteException.detail should be a ApplicationError",
269:                            ApplicationError.class, e.detail.getClass());
270:                } catch (Exception e) {
271:                    fail("Expected RemoteException but got " + e);
272:                } finally {
273:                    if (exceptionTester != null) {
274:                        exceptionTester.remove();
275:                    }
276:                }
277:            }
278:
279:            public void testEJBExceptionNewTx_remote() throws Exception {
280:                ExceptionTester exceptionTester = null;
281:                try {
282:                    exceptionTester = exceptionTesterHome.create();
283:
284:                    exceptionTester.ejbExceptionNewTx();
285:
286:                    fail("Expected RemoteException to be thrown");
287:
288:                } catch (RemoteException e) {
289:                    // good this was expected
290:                    assertNotNull("RemoteException.detail should not be null",
291:                            e.detail);
292:
293:                    assertEquals(
294:                            "RemoteException.detail should be a EJBException",
295:                            EJBException.class, e.detail.getClass());
296:                } catch (Exception e) {
297:                    fail("Expected RemoteException but got " + e);
298:                } finally {
299:                    if (exceptionTester != null) {
300:                        exceptionTester.remove();
301:                    }
302:                }
303:            }
304:
305:            public void testRuntimeExceptionNewTx_remote() throws Exception {
306:                ExceptionTester exceptionTester = null;
307:                try {
308:                    exceptionTester = exceptionTesterHome.create();
309:
310:                    exceptionTester.runtimeExceptionNewTx();
311:
312:                    fail("Expected RemoteException to be thrown");
313:
314:                } catch (RemoteException e) {
315:                    // good this was expected
316:                    assertNotNull("RemoteException.detail should not be null",
317:                            e.detail);
318:
319:                    assertEquals(
320:                            "RemoteException.detail should be a RuntimeException",
321:                            RuntimeException.class, e.detail.getClass());
322:
323:                } catch (Exception e) {
324:                    fail("Expected RemoteException but got " + e);
325:                } finally {
326:                    if (exceptionTester != null) {
327:                        exceptionTester.remove();
328:                    }
329:                }
330:            }
331:
332:            public void testRemoteExceptionNewTx_remote() throws Exception {
333:                ExceptionTester exceptionTester = null;
334:                try {
335:                    exceptionTester = exceptionTesterHome.create();
336:
337:                    exceptionTester.remoteExceptionNewTx();
338:
339:                    fail("Expected RemoteException to be thrown");
340:
341:                } catch (RemoteException e) {
342:                    // good this was expected
343:                } catch (Exception e) {
344:                    fail("Expected RemoteException but got " + e);
345:                } finally {
346:                    if (exceptionTester != null) {
347:                        exceptionTester.remove();
348:                    }
349:                }
350:            }
351:
352:            public void testApplicationExceptionNoTx_remote() throws Exception {
353:                ExceptionTester exceptionTester = null;
354:                try {
355:                    exceptionTester = exceptionTesterHome.create();
356:
357:                    exceptionTester.applicationExceptionNoTx();
358:
359:                    fail("Expected application exception to be thrown");
360:
361:                } catch (ApplicationException e) {
362:                    // good this was expected
363:                } catch (Exception e) {
364:                    fail("Expected ApplicationException but got " + e);
365:                } finally {
366:                    if (exceptionTester != null) {
367:                        exceptionTester.remove();
368:                    }
369:                }
370:            }
371:
372:            public void testApplicationErrorNoTx_remote() throws Exception {
373:                ExceptionTester exceptionTester = null;
374:                try {
375:                    exceptionTester = exceptionTesterHome.create();
376:
377:                    exceptionTester.applicationErrorNoTx();
378:
379:                    fail("Expected RemoteException to be thrown");
380:
381:                } catch (RemoteException e) {
382:                    // good this was expected
383:                    assertNotNull("RemoteException.detail should not be null",
384:                            e.detail);
385:
386:                    assertEquals(
387:                            "RemoteException.detail should be a ApplicationError",
388:                            ApplicationError.class, e.detail.getClass());
389:                } catch (Exception e) {
390:                    fail("Expected RemoteException but got " + e);
391:                } finally {
392:                    if (exceptionTester != null) {
393:                        exceptionTester.remove();
394:                    }
395:                }
396:            }
397:
398:            public void testEJBExceptionNoTx_remote() throws Exception {
399:                ExceptionTester exceptionTester = null;
400:                try {
401:                    exceptionTester = exceptionTesterHome.create();
402:
403:                    exceptionTester.ejbExceptionNoTx();
404:
405:                    fail("Expected RemoteException to be thrown");
406:
407:                } catch (RemoteException e) {
408:                    // good this was expected
409:                    assertNotNull("RemoteException.detail should not be null",
410:                            e.detail);
411:
412:                    assertEquals(
413:                            "RemoteException.detail should be a EJBException",
414:                            EJBException.class, e.detail.getClass());
415:                } catch (Exception e) {
416:                    fail("Expected RemoteException but got " + e);
417:                } finally {
418:                    if (exceptionTester != null) {
419:                        exceptionTester.remove();
420:                    }
421:                }
422:            }
423:
424:            public void testRuntimeExceptionNoTx_remote() throws Exception {
425:                ExceptionTester exceptionTester = null;
426:                try {
427:                    exceptionTester = exceptionTesterHome.create();
428:
429:                    exceptionTester.runtimeExceptionNoTx();
430:
431:                    fail("Expected RemoteException to be thrown");
432:
433:                } catch (RemoteException e) {
434:                    // good this was expected
435:                    assertNotNull("RemoteException.detail should not be null",
436:                            e.detail);
437:
438:                    assertEquals(
439:                            "RemoteException.detail should be a RuntimeException",
440:                            RuntimeException.class, e.detail.getClass());
441:
442:                } catch (Exception e) {
443:                    fail("Expected RemoteException but got " + e);
444:                } finally {
445:                    if (exceptionTester != null) {
446:                        exceptionTester.remove();
447:                    }
448:                }
449:            }
450:
451:            public void testRemoteExceptionNoTx_remote() throws Exception {
452:                ExceptionTester exceptionTester = null;
453:                try {
454:                    exceptionTester = exceptionTesterHome.create();
455:
456:                    exceptionTester.remoteExceptionNoTx();
457:
458:                    fail("Expected RemoteException to be thrown");
459:
460:                } catch (RemoteException e) {
461:                    // good this was expected
462:                } catch (Exception e) {
463:                    fail("Expected RemoteException but got " + e);
464:                } finally {
465:                    if (exceptionTester != null) {
466:                        exceptionTester.remove();
467:                    }
468:                }
469:            }
470:
471:            public void testSecurityException_remote() throws Exception {
472:                ExceptionTester exceptionTester = null;
473:                try {
474:                    InitialContext jndi = new InitialContext();
475:                    ExceptionTesterHome exTesterHome = (ExceptionTesterHome) jndi
476:                            .lookup("exception/SecuredExceptionTester");
477:                    exceptionTester = exTesterHome.create();
478:                    exceptionTester.securityExceptionNoTx();
479:
480:                    fail("Expected AccessException to be thrown");
481:
482:                } catch (AccessException e) {
483:                    // good this was expected
484:                } catch (Exception e) {
485:                    fail("Expected AccessException but got " + e);
486:                } finally {
487:                    if (exceptionTester != null) {
488:                        exceptionTester.remove();
489:                    }
490:                }
491:            }
492:
493:            public void testSecurityExceptionByAppNoTx_remote()
494:                    throws Exception {
495:                ExceptionTester exceptionTester = null;
496:                try {
497:                    InitialContext jndi = new InitialContext();
498:                    ExceptionTesterHome exTesterHome = (ExceptionTesterHome) jndi
499:                            .lookup("exception/ExceptionTester");
500:                    exceptionTester = exTesterHome.create();
501:                    exceptionTester.securityExceptionByAppNoTx();
502:
503:                    fail("Expected InvalidKeyException to be thrown");
504:
505:                } catch (InvalidKeyException e) {
506:                    // good this was expected
507:                } catch (Exception e) {
508:                    fail("Expected InvalidKeyException but got " + e);
509:                } finally {
510:                    if (exceptionTester != null) {
511:                        exceptionTester.remove();
512:                    }
513:                }
514:            }
515:
516:            public void testApplicationExceptionInTx_local() throws Exception {
517:                ExceptionTesterLocal exceptionTester = null;
518:                try {
519:                    exceptionTester = exceptionTesterLocalHome.create();
520:
521:                    exceptionTester.applicationExceptionInTx();
522:
523:                    fail("Expected ApplicationException to be thrown");
524:
525:                } catch (ApplicationException e) {
526:                    // good this was expected
527:                } catch (Exception e) {
528:                    fail("Expected ApplicationException but got " + e);
529:                } finally {
530:                    if (exceptionTester != null) {
531:                        exceptionTester.remove();
532:                    }
533:                }
534:            }
535:
536:            public void testApplicationErrorInTx_local() throws Exception {
537:                ExceptionTesterLocal exceptionTester = null;
538:                try {
539:                    exceptionTester = exceptionTesterLocalHome.create();
540:
541:                    exceptionTester.applicationErrorInTx();
542:
543:                    fail("Expected TransactionRolledbackLocalException to be thrown");
544:
545:                } catch (TransactionRolledbackLocalException e) {
546:                    // good this was expected
547:                    assertNotNull(
548:                            "TransactionRolledbackLocalException.getCausedByException() "
549:                                    + "should not be null", e
550:                                    .getCausedByException());
551:
552:                    assertEquals(
553:                            "TransactionRolledbackLocalException.getCausedByExcption() "
554:                                    + "should be an EJBException",
555:                            EJBException.class, e.getCausedByException()
556:                                    .getClass());
557:                } catch (Exception e) {
558:                    fail("Expected TransactionRolledbackLocalException but got "
559:                            + e);
560:                } finally {
561:                    if (exceptionTester != null) {
562:                        exceptionTester.remove();
563:                    }
564:                }
565:            }
566:
567:            public void testEJBExceptionInTx_local() throws Exception {
568:                ExceptionTesterLocal exceptionTester = null;
569:                try {
570:                    exceptionTester = exceptionTesterLocalHome.create();
571:
572:                    exceptionTester.ejbExceptionInTx();
573:
574:                    fail("Expected TransactionRolledbackLocalException to be thrown");
575:
576:                } catch (TransactionRolledbackLocalException e) {
577:                    // good this was expected
578:                    assertNotNull(
579:                            "TransactionRolledbackLocalException.getCausedByException() "
580:                                    + "should not be null", e
581:                                    .getCausedByException());
582:
583:                    assertEquals(
584:                            "TransactionRolledbackLocalException.getCausedByException() "
585:                                    + "should be an EJBException",
586:                            EJBException.class, e.getCausedByException()
587:                                    .getClass());
588:
589:                } catch (Exception e) {
590:                    fail("Expected TransactionRolledbackLocalException but got "
591:                            + e);
592:                } finally {
593:                    if (exceptionTester != null) {
594:                        exceptionTester.remove();
595:                    }
596:                }
597:            }
598:
599:            public void testRuntimeExceptionInTx_local() throws Exception {
600:                ExceptionTesterLocal exceptionTester = null;
601:                try {
602:                    exceptionTester = exceptionTesterLocalHome.create();
603:
604:                    exceptionTester.runtimeExceptionInTx();
605:
606:                    fail("Expected TransactionRolledbackLocalException to be thrown");
607:
608:                } catch (TransactionRolledbackLocalException e) {
609:                    // good this was expected
610:                    assertNotNull(
611:                            "TransactionRolledbackLocalException.getCausedByException() "
612:                                    + "should not be null", e
613:                                    .getCausedByException());
614:
615:                    assertEquals(
616:                            "TransactionRolledbackLocalException.getCausedByException() "
617:                                    + "should be a RuntimeException",
618:                            RuntimeException.class, e.getCausedByException()
619:                                    .getClass());
620:
621:                } catch (Exception e) {
622:                    fail("Expected TransactionRolledbackLocalException but got "
623:                            + e);
624:                } finally {
625:                    if (exceptionTester != null) {
626:                        exceptionTester.remove();
627:                    }
628:                }
629:            }
630:
631:            public void testApplicationExceptionNewTx_local() throws Exception {
632:                ExceptionTesterLocal exceptionTester = null;
633:                try {
634:                    exceptionTester = exceptionTesterLocalHome.create();
635:
636:                    exceptionTester.applicationExceptionNewTx();
637:
638:                    fail("Expected ApplicationException to be thrown");
639:
640:                } catch (ApplicationException e) {
641:                    // good this was expected
642:                } catch (Exception e) {
643:                    fail("Expected ApplicationException but got " + e);
644:                } finally {
645:                    if (exceptionTester != null) {
646:                        exceptionTester.remove();
647:                    }
648:                }
649:            }
650:
651:            public void testApplicationErrorNewTx_local() throws Exception {
652:                ExceptionTesterLocal exceptionTester = null;
653:                try {
654:                    exceptionTester = exceptionTesterLocalHome.create();
655:
656:                    exceptionTester.applicationErrorNewTx();
657:
658:                    fail("Expected EJBException to be thrown");
659:
660:                } catch (EJBException e) {
661:                    // good this was expected
662:                    assertNull(
663:                            "EJBException.getCausedByException() should be null",
664:                            e.getCausedByException());
665:                } catch (Exception e) {
666:                    fail("Expected EJBException but got " + e);
667:                } finally {
668:                    if (exceptionTester != null) {
669:                        exceptionTester.remove();
670:                    }
671:                }
672:            }
673:
674:            public void testEJBExceptionNewTx_local() throws Exception {
675:                ExceptionTesterLocal exceptionTester = null;
676:                try {
677:                    exceptionTester = exceptionTesterLocalHome.create();
678:
679:                    exceptionTester.ejbExceptionNewTx();
680:
681:                    fail("Expected EJBException to be thrown");
682:
683:                } catch (EJBException e) {
684:                    // good this was expected
685:                    assertNull(
686:                            "EJBException.getCausedByException() should be null",
687:                            e.getCausedByException());
688:                } catch (Exception e) {
689:                    fail("Expected EJBException but got " + e);
690:                } finally {
691:                    if (exceptionTester != null) {
692:                        exceptionTester.remove();
693:                    }
694:                }
695:            }
696:
697:            public void testRuntimeExceptionNewTx_local() throws Exception {
698:                ExceptionTesterLocal exceptionTester = null;
699:                try {
700:                    exceptionTester = exceptionTesterLocalHome.create();
701:
702:                    exceptionTester.runtimeExceptionNewTx();
703:
704:                    fail("Expected EJBException to be thrown");
705:
706:                } catch (EJBException e) {
707:                    // good this was expected
708:                    assertNotNull(
709:                            "EJBException.getCausedByException() should not be null",
710:                            e.getCausedByException());
711:
712:                    assertEquals(
713:                            "EJBException.getCausedByException() should be "
714:                                    + "a RuntimeException",
715:                            RuntimeException.class, e.getCausedByException()
716:                                    .getClass());
717:
718:                } catch (Exception e) {
719:                    fail("Expected EJBException but got " + e);
720:                } finally {
721:                    if (exceptionTester != null) {
722:                        exceptionTester.remove();
723:                    }
724:                }
725:            }
726:
727:            public void testApplicationExceptionNoTx_local() throws Exception {
728:                ExceptionTesterLocal exceptionTester = null;
729:                try {
730:                    exceptionTester = exceptionTesterLocalHome.create();
731:
732:                    exceptionTester.applicationExceptionNoTx();
733:
734:                    fail("Expected application exception to be thrown");
735:
736:                } catch (ApplicationException e) {
737:                    // good this was expected
738:                } catch (Exception e) {
739:                    fail("Expected ApplicationException but got " + e);
740:                } finally {
741:                    if (exceptionTester != null) {
742:                        exceptionTester.remove();
743:                    }
744:                }
745:            }
746:
747:            public void testApplicationErrorNoTx_local() throws Exception {
748:                ExceptionTesterLocal exceptionTester = null;
749:                try {
750:                    exceptionTester = exceptionTesterLocalHome.create();
751:
752:                    exceptionTester.applicationErrorNoTx();
753:
754:                    fail("Expected EJBException to be thrown");
755:
756:                } catch (EJBException e) {
757:                    // good this was expected
758:                    assertNull(
759:                            "EJBException.getCausedByException() should be null",
760:                            e.getCausedByException());
761:                } catch (Exception e) {
762:                    fail("Expected EJBException but got " + e);
763:                } finally {
764:                    if (exceptionTester != null) {
765:                        exceptionTester.remove();
766:                    }
767:                }
768:            }
769:
770:            public void testEJBExceptionNoTx_local() throws Exception {
771:                ExceptionTesterLocal exceptionTester = null;
772:                try {
773:                    exceptionTester = exceptionTesterLocalHome.create();
774:
775:                    exceptionTester.ejbExceptionNoTx();
776:
777:                    fail("Expected EJBException to be thrown");
778:
779:                } catch (EJBException e) {
780:                    // good this was expected
781:                    assertNull(
782:                            "EJBException.getCausedByException() should be null",
783:                            e.getCausedByException());
784:                } catch (Exception e) {
785:                    fail("Expected EJBException but got " + e);
786:                } finally {
787:                    if (exceptionTester != null) {
788:                        exceptionTester.remove();
789:                    }
790:                }
791:            }
792:
793:            public void testRuntimeExceptionNoTx_local() throws Exception {
794:                ExceptionTesterLocal exceptionTester = null;
795:                try {
796:                    exceptionTester = exceptionTesterLocalHome.create();
797:
798:                    exceptionTester.runtimeExceptionNoTx();
799:
800:                    fail("Expected EJBException to be thrown");
801:
802:                } catch (EJBException e) {
803:                    // good this was expected
804:                    assertNotNull(
805:                            "EJBException.getCausedByException() should not be null",
806:                            e.getCausedByException());
807:
808:                    assertEquals(
809:                            "EJBException.getCausedByException() should be "
810:                                    + "a RuntimeException",
811:                            RuntimeException.class, e.getCausedByException()
812:                                    .getClass());
813:
814:                } catch (Exception e) {
815:                    fail("Expected EJBException but got " + e);
816:                } finally {
817:                    if (exceptionTester != null) {
818:                        exceptionTester.remove();
819:                    }
820:                }
821:            }
822:
823:            public void testSecurityException_local() throws Exception {
824:                ExceptionTesterLocal exceptionTester = null;
825:                try {
826:                    InitialContext jndi = new InitialContext();
827:                    ExceptionTesterLocalHome exTesterLocalHome = (ExceptionTesterLocalHome) jndi
828:                            .lookup("exception/SecuredExceptionTesterLocal");
829:                    exceptionTester = exTesterLocalHome.create();
830:
831:                    exceptionTester.securityExceptionNoTx();
832:
833:                    fail("Expected AccessLocalException to be thrown");
834:
835:                } catch (AccessLocalException e) {
836:                    // good this was expected
837:                    assertNotNull(
838:                            "AccessLocalException.getCausedByException() should not be null",
839:                            e.getCausedByException());
840:
841:                    Exception ex = e.getCausedByException();
842:                    boolean isSecurityException = ex instanceof  SecurityException
843:                            || ex instanceof  GeneralSecurityException;
844:                    assertTrue(
845:                            "AccessLocalException.getCausedByException() should be "
846:                                    + "a security exception",
847:                            isSecurityException);
848:                } catch (Exception e) {
849:                    fail("Expected EJBException but got " + e);
850:                } finally {
851:                    if (exceptionTester != null) {
852:                        exceptionTester.remove();
853:                    }
854:                }
855:            }
856:
857:            public void testSecurityExceptionByAppNoTx_local() throws Exception {
858:                ExceptionTesterLocal exceptionTester = null;
859:                try {
860:                    InitialContext jndi = new InitialContext();
861:                    ExceptionTesterLocalHome exTesterLocalHome = (ExceptionTesterLocalHome) jndi
862:                            .lookup("exception/ExceptionTesterLocal");
863:                    exceptionTester = exTesterLocalHome.create();
864:
865:                    exceptionTester.securityExceptionByAppNoTx();
866:
867:                    fail("Expected InvalidKeyException to be thrown");
868:
869:                } catch (InvalidKeyException e) {
870:                    // good this was expected
871:                } catch (Exception e) {
872:                    fail("Expected InvalidKeyException but got " + e);
873:                } finally {
874:                    if (exceptionTester != null) {
875:                        exceptionTester.remove();
876:                    }
877:                }
878:            }
879:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.