Source Code Cross Referenced for EntityExceptionUnitTestCase.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) 


0001:        /*
0002:         * JBoss, Home of Professional Open Source.
0003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
0004:         * as indicated by the @author tags. See the copyright.txt file in the
0005:         * distribution for a full listing of individual contributors.
0006:         *
0007:         * This is free software; you can redistribute it and/or modify it
0008:         * under the terms of the GNU Lesser General Public License as
0009:         * published by the Free Software Foundation; either version 2.1 of
0010:         * the License, or (at your option) any later version.
0011:         *
0012:         * This software is distributed in the hope that it will be useful,
0013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015:         * Lesser General Public License for more details.
0016:         *
0017:         * You should have received a copy of the GNU Lesser General Public
0018:         * License along with this software; if not, write to the Free
0019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
0021:         */
0022:        package org.jboss.test.exception;
0023:
0024:        import java.rmi.RemoteException;
0025:
0026:        import javax.ejb.EJBException;
0027:        import javax.ejb.FinderException;
0028:        import javax.ejb.TransactionRolledbackLocalException;
0029:        import javax.naming.InitialContext;
0030:        import javax.transaction.TransactionRolledbackException;
0031:
0032:        import junit.framework.Test;
0033:        import junit.framework.TestSuite;
0034:
0035:        import org.jboss.test.JBossTestCase;
0036:        import org.jboss.test.util.ejb.EJBTestCase;
0037:
0038:        public class EntityExceptionUnitTestCase extends EJBTestCase {
0039:            public static Test suite() throws Exception {
0040:                // JBAS-3492, the execution order of tests in this test case is important
0041:                // so it must be defined explicitly when running under some JVMs
0042:                TestSuite suite = new TestSuite();
0043:                suite.addTest(new EntityExceptionUnitTestCase(
0044:                        "testApplicationExceptionInTx_remote"));
0045:                suite.addTest(new EntityExceptionUnitTestCase(
0046:                        "testNotDiscardedApplicationExceptionInTx_remote"));
0047:                suite.addTest(new EntityExceptionUnitTestCase(
0048:                        "testApplicationExceptionInTxMarkRollback_remote"));
0049:                suite.addTest(new EntityExceptionUnitTestCase(
0050:                        "testApplicationErrorInTx_remote"));
0051:                suite.addTest(new EntityExceptionUnitTestCase(
0052:                        "testDiscardedApplicationErrorInTx_remote"));
0053:                suite.addTest(new EntityExceptionUnitTestCase(
0054:                        "testEJBExceptionInTx_remote"));
0055:                suite.addTest(new EntityExceptionUnitTestCase(
0056:                        "testDiscardedEJBExceptionInTx_remote"));
0057:                suite.addTest(new EntityExceptionUnitTestCase(
0058:                        "testRuntimeExceptionInTx_remote"));
0059:                suite.addTest(new EntityExceptionUnitTestCase(
0060:                        "testDiscardedRuntimeExceptionInTx_remote"));
0061:                suite.addTest(new EntityExceptionUnitTestCase(
0062:                        "testRemoteExceptionInTx_remote"));
0063:                suite.addTest(new EntityExceptionUnitTestCase(
0064:                        "testDiscardedRemoteExceptionInTx_remote"));
0065:                suite.addTest(new EntityExceptionUnitTestCase(
0066:                        "testApplicationExceptionNewTx_remote"));
0067:                suite.addTest(new EntityExceptionUnitTestCase(
0068:                        "testNotDiscardedApplicationExceptionNewTx_remote"));
0069:                suite.addTest(new EntityExceptionUnitTestCase(
0070:                        "testApplicationExceptionNewTxMarkRollback_remote"));
0071:                //suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNewTxMarkRollback_remote"));
0072:                suite.addTest(new EntityExceptionUnitTestCase(
0073:                        "testApplicationErrorNewTx_remote"));
0074:                suite.addTest(new EntityExceptionUnitTestCase(
0075:                        "testDiscardedApplicationErrorNewTx_remote"));
0076:                suite.addTest(new EntityExceptionUnitTestCase(
0077:                        "testEJBExceptionNewTx_remote"));
0078:                suite.addTest(new EntityExceptionUnitTestCase(
0079:                        "testDiscardedEJBExceptionNewTx_remote"));
0080:                suite.addTest(new EntityExceptionUnitTestCase(
0081:                        "testRuntimeExceptionNewTx_remote"));
0082:                suite.addTest(new EntityExceptionUnitTestCase(
0083:                        "testDiscardedRuntimeExceptionNewTx_remote"));
0084:                suite.addTest(new EntityExceptionUnitTestCase(
0085:                        "testRemoteExceptionNewTx_remote"));
0086:                suite.addTest(new EntityExceptionUnitTestCase(
0087:                        "testDiscardedRemoteExceptionNewTx_remote"));
0088:                suite.addTest(new EntityExceptionUnitTestCase(
0089:                        "testApplicationExceptionNoTx_remote"));
0090:                suite.addTest(new EntityExceptionUnitTestCase(
0091:                        "testNotDiscardedApplicationExceptionNoTx_remote"));
0092:                suite.addTest(new EntityExceptionUnitTestCase(
0093:                        "testApplicationErrorNoTx_remote"));
0094:                suite.addTest(new EntityExceptionUnitTestCase(
0095:                        "testDiscardedApplicationErrorNoTx_remote"));
0096:                suite.addTest(new EntityExceptionUnitTestCase(
0097:                        "testEJBExceptionNoTx_remote"));
0098:                suite.addTest(new EntityExceptionUnitTestCase(
0099:                        "testDiscardedEJBExceptionNoTx_remote"));
0100:                suite.addTest(new EntityExceptionUnitTestCase(
0101:                        "testRuntimeExceptionNoTx_remote"));
0102:                suite.addTest(new EntityExceptionUnitTestCase(
0103:                        "testDiscardedRuntimeExceptionNoTx_remote"));
0104:                suite.addTest(new EntityExceptionUnitTestCase(
0105:                        "testRemoteExceptionNoTx_remote"));
0106:                suite.addTest(new EntityExceptionUnitTestCase(
0107:                        "testDiscardedRemoteExceptionNoTx_remote"));
0108:                suite.addTest(new EntityExceptionUnitTestCase(
0109:                        "testApplicationExceptionInTx_local"));
0110:                suite.addTest(new EntityExceptionUnitTestCase(
0111:                        "testNotDiscardedApplicationExceptionInTx_local"));
0112:                suite.addTest(new EntityExceptionUnitTestCase(
0113:                        "testApplicationExceptionInTxMarkRollback_local"));
0114:                //suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionInTxMarkRollback_local"));
0115:                suite.addTest(new EntityExceptionUnitTestCase(
0116:                        "testApplicationErrorInTx_local"));
0117:                suite.addTest(new EntityExceptionUnitTestCase(
0118:                        "testDiscardedApplicationErrorInTx_local"));
0119:                suite.addTest(new EntityExceptionUnitTestCase(
0120:                        "testEJBExceptionInTx_local"));
0121:                suite.addTest(new EntityExceptionUnitTestCase(
0122:                        "testDiscardedEJBExceptionInTx_local"));
0123:                suite.addTest(new EntityExceptionUnitTestCase(
0124:                        "testRuntimeExceptionInTx_local"));
0125:                suite.addTest(new EntityExceptionUnitTestCase(
0126:                        "testDiscardedRuntimeExceptionInTx_local"));
0127:                suite.addTest(new EntityExceptionUnitTestCase(
0128:                        "testApplicationExceptionNewTx_local"));
0129:                suite.addTest(new EntityExceptionUnitTestCase(
0130:                        "testNotDiscardedApplicationExceptionNewTx_local"));
0131:                suite.addTest(new EntityExceptionUnitTestCase(
0132:                        "testApplicationExceptionNewTxMarkRollback_local"));
0133:                //suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNewTxMarkRollback_local"));
0134:                suite.addTest(new EntityExceptionUnitTestCase(
0135:                        "testApplicationErrorNewTx_local"));
0136:                suite.addTest(new EntityExceptionUnitTestCase(
0137:                        "testDiscardedApplicationErrorNewTx_local"));
0138:                suite.addTest(new EntityExceptionUnitTestCase(
0139:                        "testEJBExceptionNewTx_local"));
0140:                suite.addTest(new EntityExceptionUnitTestCase(
0141:                        "testDiscardedEJBExceptionNewTx_local"));
0142:                suite.addTest(new EntityExceptionUnitTestCase(
0143:                        "testRuntimeExceptionNewTx_local"));
0144:                suite.addTest(new EntityExceptionUnitTestCase(
0145:                        "testDiscardedRuntimeExceptionNewTx_local"));
0146:                suite.addTest(new EntityExceptionUnitTestCase(
0147:                        "testApplicationExceptionNoTx_local"));
0148:                suite.addTest(new EntityExceptionUnitTestCase(
0149:                        "testNotDiscardedApplicationExceptionNoTx_local"));
0150:                suite.addTest(new EntityExceptionUnitTestCase(
0151:                        "testApplicationErrorNoTx_local"));
0152:                suite.addTest(new EntityExceptionUnitTestCase(
0153:                        "testDiscardedApplicationErrorNoTx_local"));
0154:                suite.addTest(new EntityExceptionUnitTestCase(
0155:                        "testEJBExceptionNoTx_local"));
0156:                suite.addTest(new EntityExceptionUnitTestCase(
0157:                        "testDiscardedEJBExceptionNoTx_local"));
0158:                suite.addTest(new EntityExceptionUnitTestCase(
0159:                        "testRuntimeExceptionNoTx_local"));
0160:                suite.addTest(new EntityExceptionUnitTestCase(
0161:                        "testDiscardedRuntimeExceptionNoTx_local"));
0162:
0163:                return JBossTestCase.getDeploySetup(suite, "exception.jar");
0164:            }
0165:
0166:            public EntityExceptionUnitTestCase(String name) {
0167:                super (name);
0168:            }
0169:
0170:            private EntityExceptionTesterHome exceptionTesterHome;
0171:
0172:            private EntityExceptionTesterLocalHome exceptionTesterLocalHome;
0173:
0174:            /**
0175:             * Looks up all of the home interfaces and creates the initial data. 
0176:             * Looking up objects in JNDI is expensive, so it should be done once 
0177:             * and cached.
0178:             * @throws Exception if a problem occures while finding the home interfaces,
0179:             * or if an problem occures while createing the initial data
0180:             */
0181:            public void setUp() throws Exception {
0182:                InitialContext jndi = new InitialContext();
0183:                exceptionTesterHome = (EntityExceptionTesterHome) jndi
0184:                        .lookup("exception/EntityExceptionTester");
0185:                exceptionTesterLocalHome = (EntityExceptionTesterLocalHome) jndi
0186:                        .lookup("exception/EntityExceptionTesterLocal");
0187:            }
0188:
0189:            public void testApplicationExceptionInTx_remote() throws Exception {
0190:                EntityExceptionTester exceptionTester = null;
0191:                try {
0192:                    exceptionTester = exceptionTesterHome.create(getName());
0193:                    exceptionTester.applicationExceptionInTx();
0194:                    fail("Expected application exception to be thrown");
0195:                } catch (ApplicationException e) {
0196:                    // good this was expected
0197:                } catch (Exception e) {
0198:                    fail("Expected ApplicationException but got " + e);
0199:                }
0200:            }
0201:
0202:            public void testNotDiscardedApplicationExceptionInTx_remote()
0203:                    throws Exception {
0204:                exceptionTesterHome
0205:                        .findByPrimaryKey("testApplicationExceptionInTx_remote");
0206:            }
0207:
0208:            public void testApplicationExceptionInTxMarkRollback_remote()
0209:                    throws Exception {
0210:                EntityExceptionTester exceptionTester = null;
0211:                try {
0212:                    exceptionTester = exceptionTesterHome.create(getName());
0213:                    exceptionTester.applicationExceptionInTxMarkRollback();
0214:                    fail("Expected application exception to be thrown");
0215:                } catch (ApplicationException e) {
0216:                    // good this was expected
0217:                } catch (Exception e) {
0218:                    fail("Expected ApplicationException but got " + e);
0219:                }
0220:            }
0221:
0222:            /*
0223:             * It is not clear what the behaviour should be from the spec
0224:             *  
0225:             void testNotDiscardedApplicationExceptionInTxMarkRollback_remote() throws Exception
0226:             {
0227:             exceptionTesterHome.findByPrimaryKey("testApplicationExceptionInTxMarkRollback_remote"); 
0228:             }
0229:             */
0230:            public void testApplicationErrorInTx_remote() throws Exception {
0231:                EntityExceptionTester exceptionTester = null;
0232:                try {
0233:                    exceptionTester = exceptionTesterHome.create(getName());
0234:                    exceptionTester.applicationErrorInTx();
0235:                    fail("Expected transaction rolled back exception to be thrown");
0236:                } catch (TransactionRolledbackException e) {
0237:                    // good this was expected
0238:                    assertNotNull(
0239:                            "TransactionRolledbackException.detail should not be null",
0240:                            e.detail);
0241:                    assertEquals(
0242:                            "TransactionRolledbackException.detail should "
0243:                                    + "be a ApplicationError",
0244:                            ApplicationError.class, e.detail.getClass());
0245:                } catch (Exception e) {
0246:                    fail("Expected TransactionRolledbackException but got " + e);
0247:                }
0248:            }
0249:
0250:            public void testDiscardedApplicationErrorInTx_remote()
0251:                    throws Exception {
0252:                boolean caught = false;
0253:                try {
0254:                    exceptionTesterHome
0255:                            .findByPrimaryKey("testApplicationErrorInTx_remote");
0256:                } catch (FinderException expected) {
0257:                    caught = true;
0258:                }
0259:                assertTrue("Instance not discarded " + getName(), caught);
0260:            }
0261:
0262:            public void testEJBExceptionInTx_remote() throws Exception {
0263:                EntityExceptionTester exceptionTester = null;
0264:                try {
0265:                    exceptionTester = exceptionTesterHome.create(getName());
0266:                    exceptionTester.ejbExceptionInTx();
0267:                    fail("Expected transaction rolled back exception to be thrown");
0268:                } catch (TransactionRolledbackException e) {
0269:                    // good this was expected
0270:                    assertNotNull(
0271:                            "TransactionRolledbackException.detail should not be null",
0272:                            e.detail);
0273:                    assertEquals(
0274:                            "TransactionRolledbackException.detail should "
0275:                                    + "be an EJBException", EJBException.class,
0276:                            e.detail.getClass());
0277:                } catch (Exception e) {
0278:                    fail("Expected TransactionRolledbackException but got " + e);
0279:                }
0280:            }
0281:
0282:            public void testDiscardedEJBExceptionInTx_remote() throws Exception {
0283:                boolean caught = false;
0284:                try {
0285:                    exceptionTesterHome
0286:                            .findByPrimaryKey("testEJBExceptionInTx_remote");
0287:                } catch (FinderException expected) {
0288:                    caught = true;
0289:                }
0290:                assertTrue("Instance not discarded " + getName(), caught);
0291:            }
0292:
0293:            public void testRuntimeExceptionInTx_remote() throws Exception {
0294:                EntityExceptionTester exceptionTester = null;
0295:                try {
0296:                    exceptionTester = exceptionTesterHome.create(getName());
0297:                    exceptionTester.runtimeExceptionInTx();
0298:                    fail("Expected transaction rolled back exception to be thrown");
0299:                } catch (TransactionRolledbackException e) {
0300:                    // good this was expected
0301:                    assertNotNull(
0302:                            "TransactionRolledbackException.detail should not be null",
0303:                            e.detail);
0304:                    assertEquals(
0305:                            "TransactionRolledbackException.detail should "
0306:                                    + "be a RuntimeException",
0307:                            RuntimeException.class, e.detail.getClass());
0308:                } catch (Exception e) {
0309:                    fail("Expected TransactionRolledbackException but got " + e);
0310:                }
0311:            }
0312:
0313:            public void testDiscardedRuntimeExceptionInTx_remote()
0314:                    throws Exception {
0315:                boolean caught = false;
0316:                try {
0317:                    exceptionTesterHome
0318:                            .findByPrimaryKey("testRuntimeExceptionInTx_remote");
0319:                } catch (FinderException expected) {
0320:                    caught = true;
0321:                }
0322:                assertTrue("Instance not discarded " + getName(), caught);
0323:            }
0324:
0325:            public void testRemoteExceptionInTx_remote() throws Exception {
0326:                EntityExceptionTester exceptionTester = null;
0327:                try {
0328:                    exceptionTester = exceptionTesterHome.create(getName());
0329:                    exceptionTester.remoteExceptionInTx();
0330:                    fail("Expected transaction rolled back exception to be thrown");
0331:                } catch (TransactionRolledbackException e) {
0332:                    // good this was expected
0333:                    assertNotNull(
0334:                            "TransactionRolledbackException.detail should not be null",
0335:                            e.detail);
0336:                    assertEquals(
0337:                            "TransactionRolledbackException.detail should "
0338:                                    + "be a RemoteException",
0339:                            RemoteException.class, e.detail.getClass());
0340:                } catch (Exception e) {
0341:                    fail("Expected TransactionRolledbackException but got " + e);
0342:                }
0343:            }
0344:
0345:            public void testDiscardedRemoteExceptionInTx_remote()
0346:                    throws Exception {
0347:                boolean caught = false;
0348:                try {
0349:                    exceptionTesterHome
0350:                            .findByPrimaryKey("testRemoteExceptionInTx_remote");
0351:                } catch (FinderException expected) {
0352:                    caught = true;
0353:                }
0354:                assertTrue("Instance not discarded " + getName(), caught);
0355:            }
0356:
0357:            public void testApplicationExceptionNewTx_remote() throws Exception {
0358:                EntityExceptionTester exceptionTester = null;
0359:                try {
0360:                    exceptionTester = exceptionTesterHome.create(getName());
0361:                    exceptionTester.applicationExceptionNewTx();
0362:                    fail("Expected application exception to be thrown");
0363:                } catch (ApplicationException e) {
0364:                    // good this was expected
0365:                } catch (Exception e) {
0366:                    fail("Expected ApplicationException but got " + e);
0367:                }
0368:            }
0369:
0370:            public void testNotDiscardedApplicationExceptionNewTx_remote()
0371:                    throws Exception {
0372:                exceptionTesterHome
0373:                        .findByPrimaryKey("testApplicationExceptionNewTx_remote");
0374:            }
0375:
0376:            public void testApplicationExceptionNewTxMarkRollback_remote()
0377:                    throws Exception {
0378:                EntityExceptionTester exceptionTester = null;
0379:                try {
0380:                    exceptionTester = exceptionTesterHome.create(getName());
0381:                    exceptionTester.applicationExceptionNewTxMarkRollback();
0382:                    fail("Expected application exception to be thrown");
0383:                } catch (ApplicationException e) {
0384:                    // good this was expected
0385:                } catch (Exception e) {
0386:                    fail("Expected ApplicationException but got " + e);
0387:                }
0388:            }
0389:
0390:            /*
0391:             * It is not clear what the behaviour should be from the spec
0392:             *  
0393:             public void testNotDiscardedApplicationExceptionNewTxMarkRollback_remote() throws Exception
0394:             {
0395:             exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNewTxMarkRollback_remote"); 
0396:             }
0397:             */
0398:            public void testApplicationErrorNewTx_remote() throws Exception {
0399:                EntityExceptionTester exceptionTester = null;
0400:                try {
0401:                    exceptionTester = exceptionTesterHome.create(getName());
0402:                    exceptionTester.applicationErrorNewTx();
0403:                    fail("Expected RemoteException to be thrown");
0404:                } catch (RemoteException e) {
0405:                    // good this was expected
0406:                    assertNotNull("RemoteException.detail should not be null",
0407:                            e.detail);
0408:                    assertEquals(
0409:                            "RemoteException.detail should be a ApplicationError",
0410:                            ApplicationError.class, e.detail.getClass());
0411:                } catch (Exception e) {
0412:                    fail("Expected RemoteException but got " + e);
0413:                }
0414:            }
0415:
0416:            public void testDiscardedApplicationErrorNewTx_remote()
0417:                    throws Exception {
0418:                boolean caught = false;
0419:                try {
0420:                    exceptionTesterHome
0421:                            .findByPrimaryKey("testApplicationErrorNewTx_remote");
0422:                } catch (FinderException expected) {
0423:                    caught = true;
0424:                }
0425:                assertTrue("Instance not discarded " + getName(), caught);
0426:            }
0427:
0428:            public void testEJBExceptionNewTx_remote() throws Exception {
0429:                EntityExceptionTester exceptionTester = null;
0430:                try {
0431:                    exceptionTester = exceptionTesterHome.create(getName());
0432:                    exceptionTester.ejbExceptionNewTx();
0433:                    fail("Expected RemoteException to be thrown");
0434:                } catch (RemoteException e) {
0435:                    // good this was expected
0436:                    assertNotNull("RemoteException.detail should not be null",
0437:                            e.detail);
0438:                    assertEquals(
0439:                            "RemoteException.detail should be a EJBException",
0440:                            EJBException.class, e.detail.getClass());
0441:                } catch (Exception e) {
0442:                    fail("Expected RemoteException but got " + e);
0443:                }
0444:            }
0445:
0446:            public void testDiscardedEJBExceptionNewTx_remote()
0447:                    throws Exception {
0448:                boolean caught = false;
0449:                try {
0450:                    exceptionTesterHome
0451:                            .findByPrimaryKey("testEJBExceptionNewTx_remote");
0452:                } catch (FinderException expected) {
0453:                    caught = true;
0454:                }
0455:                assertTrue("Instance not discarded " + getName(), caught);
0456:            }
0457:
0458:            public void testRuntimeExceptionNewTx_remote() throws Exception {
0459:                EntityExceptionTester exceptionTester = null;
0460:                try {
0461:                    exceptionTester = exceptionTesterHome.create(getName());
0462:                    exceptionTester.runtimeExceptionNewTx();
0463:                    fail("Expected RemoteException to be thrown");
0464:                } catch (RemoteException e) {
0465:                    // good this was expected
0466:                    assertNotNull("RemoteException.detail should not be null",
0467:                            e.detail);
0468:                    assertEquals(
0469:                            "RemoteException.detail should be a RuntimeException",
0470:                            RuntimeException.class, e.detail.getClass());
0471:                } catch (Exception e) {
0472:                    fail("Expected RemoteException but got " + e);
0473:                }
0474:            }
0475:
0476:            public void testDiscardedRuntimeExceptionNewTx_remote()
0477:                    throws Exception {
0478:                boolean caught = false;
0479:                try {
0480:                    exceptionTesterHome
0481:                            .findByPrimaryKey("testRuntimeExceptionNewTx_remote");
0482:                } catch (FinderException expected) {
0483:                    caught = true;
0484:                }
0485:                assertTrue("Instance not discarded " + getName(), caught);
0486:            }
0487:
0488:            public void testRemoteExceptionNewTx_remote() throws Exception {
0489:                EntityExceptionTester exceptionTester = null;
0490:                try {
0491:                    exceptionTester = exceptionTesterHome.create(getName());
0492:                    exceptionTester.remoteExceptionNewTx();
0493:                    fail("Expected RemoteException to be thrown");
0494:                } catch (RemoteException e) {
0495:                    // good this was expected
0496:                } catch (Exception e) {
0497:                    fail("Expected RemoteException but got " + e);
0498:                }
0499:            }
0500:
0501:            public void testDiscardedRemoteExceptionNewTx_remote()
0502:                    throws Exception {
0503:                boolean caught = false;
0504:                try {
0505:                    exceptionTesterHome
0506:                            .findByPrimaryKey("testRemoteExceptionNewTx_remote");
0507:                } catch (FinderException expected) {
0508:                    caught = true;
0509:                }
0510:                assertTrue("Instance not discarded " + getName(), caught);
0511:            }
0512:
0513:            public void testApplicationExceptionNoTx_remote() throws Exception {
0514:                EntityExceptionTester exceptionTester = null;
0515:                try {
0516:                    exceptionTester = exceptionTesterHome.create(getName());
0517:                    exceptionTester.applicationExceptionNoTx();
0518:                    fail("Expected application exception to be thrown");
0519:                } catch (ApplicationException e) {
0520:                    // good this was expected
0521:                } catch (Exception e) {
0522:                    fail("Expected ApplicationException but got " + e);
0523:                }
0524:            }
0525:
0526:            public void testNotDiscardedApplicationExceptionNoTx_remote()
0527:                    throws Exception {
0528:                exceptionTesterHome
0529:                        .findByPrimaryKey("testApplicationExceptionNoTx_remote");
0530:            }
0531:
0532:            public void testApplicationErrorNoTx_remote() throws Exception {
0533:                EntityExceptionTester exceptionTester = null;
0534:                try {
0535:                    exceptionTester = exceptionTesterHome.create(getName());
0536:                    exceptionTester.applicationErrorNoTx();
0537:                    fail("Expected RemoteException to be thrown");
0538:                } catch (RemoteException e) {
0539:                    // good this was expected
0540:                    assertNotNull("RemoteException.detail should not be null",
0541:                            e.detail);
0542:                    assertEquals(
0543:                            "RemoteException.detail should be a ApplicationError",
0544:                            ApplicationError.class, e.detail.getClass());
0545:                } catch (Exception e) {
0546:                    fail("Expected RemoteException but got " + e);
0547:                }
0548:            }
0549:
0550:            public void testDiscardedApplicationErrorNoTx_remote()
0551:                    throws Exception {
0552:                boolean caught = false;
0553:                try {
0554:                    exceptionTesterHome
0555:                            .findByPrimaryKey("testApplicationErrorNoTx_remote");
0556:                } catch (FinderException expected) {
0557:                    caught = true;
0558:                }
0559:                assertTrue("Instance not discarded " + getName(), caught);
0560:            }
0561:
0562:            public void testEJBExceptionNoTx_remote() throws Exception {
0563:                EntityExceptionTester exceptionTester = null;
0564:                try {
0565:                    exceptionTester = exceptionTesterHome.create(getName());
0566:                    exceptionTester.ejbExceptionNoTx();
0567:                    fail("Expected RemoteException to be thrown");
0568:                } catch (RemoteException e) {
0569:                    // good this was expected
0570:                    assertNotNull("RemoteException.detail should not be null",
0571:                            e.detail);
0572:                    assertEquals(
0573:                            "RemoteException.detail should be a EJBException",
0574:                            EJBException.class, e.detail.getClass());
0575:                } catch (Exception e) {
0576:                    fail("Expected RemoteException but got " + e);
0577:                }
0578:            }
0579:
0580:            public void testDiscardedEJBExceptionNoTx_remote() throws Exception {
0581:                boolean caught = false;
0582:                try {
0583:                    exceptionTesterHome
0584:                            .findByPrimaryKey("testEJBExceptionNoTx_remote");
0585:                } catch (FinderException expected) {
0586:                    caught = true;
0587:                }
0588:                assertTrue("Instance not discarded " + getName(), caught);
0589:            }
0590:
0591:            public void testRuntimeExceptionNoTx_remote() throws Exception {
0592:                EntityExceptionTester exceptionTester = null;
0593:                try {
0594:                    exceptionTester = exceptionTesterHome.create(getName());
0595:                    exceptionTester.runtimeExceptionNoTx();
0596:                    fail("Expected RemoteException to be thrown");
0597:                } catch (RemoteException e) {
0598:                    // good this was expected
0599:                    assertNotNull("RemoteException.detail should not be null",
0600:                            e.detail);
0601:                    assertEquals(
0602:                            "RemoteException.detail should be a RuntimeException",
0603:                            RuntimeException.class, e.detail.getClass());
0604:                } catch (Exception e) {
0605:                    fail("Expected RemoteException but got " + e);
0606:                }
0607:            }
0608:
0609:            public void testDiscardedRuntimeExceptionNoTx_remote()
0610:                    throws Exception {
0611:                boolean caught = false;
0612:                try {
0613:                    exceptionTesterHome
0614:                            .findByPrimaryKey("testRuntimeExceptionNoTx_remote");
0615:                } catch (FinderException expected) {
0616:                    caught = true;
0617:                }
0618:                assertTrue("Instance not discarded " + getName(), caught);
0619:            }
0620:
0621:            public void testRemoteExceptionNoTx_remote() throws Exception {
0622:                EntityExceptionTester exceptionTester = null;
0623:                try {
0624:                    exceptionTester = exceptionTesterHome.create(getName());
0625:                    exceptionTester.remoteExceptionNoTx();
0626:                    fail("Expected RemoteException to be thrown");
0627:                } catch (RemoteException e) {
0628:                    // good this was expected
0629:                } catch (Exception e) {
0630:                    fail("Expected RemoteException but got " + e);
0631:                }
0632:            }
0633:
0634:            public void testDiscardedRemoteExceptionNoTx_remote()
0635:                    throws Exception {
0636:                boolean caught = false;
0637:                try {
0638:                    exceptionTesterHome
0639:                            .findByPrimaryKey("testRemoteExceptionNoTx_remote");
0640:                } catch (FinderException expected) {
0641:                    caught = true;
0642:                }
0643:                assertTrue("Instance not discarded " + getName(), caught);
0644:            }
0645:
0646:            public void testApplicationExceptionInTx_local() throws Exception {
0647:                EntityExceptionTesterLocal exceptionTester = null;
0648:                try {
0649:                    exceptionTester = exceptionTesterLocalHome
0650:                            .create(getName());
0651:                    exceptionTester.applicationExceptionInTx();
0652:                    fail("Expected ApplicationException to be thrown");
0653:                } catch (ApplicationException e) {
0654:                    // good this was expected
0655:                } catch (Exception e) {
0656:                    fail("Expected ApplicationException but got " + e);
0657:                }
0658:            }
0659:
0660:            public void testNotDiscardedApplicationExceptionInTx_local()
0661:                    throws Exception {
0662:                exceptionTesterHome
0663:                        .findByPrimaryKey("testApplicationExceptionInTx_local");
0664:            }
0665:
0666:            public void testApplicationExceptionInTxMarkRollback_local()
0667:                    throws Exception {
0668:                EntityExceptionTesterLocal exceptionTester = null;
0669:                try {
0670:                    exceptionTester = exceptionTesterLocalHome
0671:                            .create(getName());
0672:                    exceptionTester.applicationExceptionInTxMarkRollback();
0673:                    fail("Expected ApplicationException to be thrown");
0674:                } catch (ApplicationException e) {
0675:                    // good this was expected
0676:                } catch (Exception e) {
0677:                    fail("Expected ApplicationException but got " + e);
0678:                }
0679:            }
0680:
0681:            /*
0682:             * It is not clear what the behaviour should be from the spec
0683:             *  
0684:             public void testNotDiscardedApplicationExceptionInTxMarkRollback_local() throws Exception
0685:             {
0686:             exceptionTesterHome.findByPrimaryKey("testApplicationExceptionInTxMarkRollback_local"); 
0687:             }
0688:             */
0689:            public void testApplicationErrorInTx_local() throws Exception {
0690:                EntityExceptionTesterLocal exceptionTester = null;
0691:                try {
0692:                    exceptionTester = exceptionTesterLocalHome
0693:                            .create(getName());
0694:                    exceptionTester.applicationErrorInTx();
0695:                    fail("Expected TransactionRolledbackLocalException to be thrown");
0696:                } catch (TransactionRolledbackLocalException e) {
0697:                    // good this was expected
0698:                    assertNotNull(
0699:                            "TransactionRolledbackLocalException.getCausedByException() "
0700:                                    + "should not be null", e
0701:                                    .getCausedByException());
0702:                    assertEquals(
0703:                            "TransactionRolledbackLocalException.getCausedByExcption() "
0704:                                    + "should be an EJBException",
0705:                            EJBException.class, e.getCausedByException()
0706:                                    .getClass());
0707:                } catch (Exception e) {
0708:                    fail("Expected TransactionRolledbackLocalException but got "
0709:                            + e);
0710:                }
0711:            }
0712:
0713:            public void testDiscardedApplicationErrorInTx_local()
0714:                    throws Exception {
0715:                boolean caught = false;
0716:                try {
0717:                    exceptionTesterHome
0718:                            .findByPrimaryKey("testApplicationErrorInTx_local");
0719:                } catch (FinderException expected) {
0720:                    caught = true;
0721:                }
0722:                assertTrue("Instance not discarded " + getName(), caught);
0723:            }
0724:
0725:            public void testEJBExceptionInTx_local() throws Exception {
0726:                EntityExceptionTesterLocal exceptionTester = null;
0727:                try {
0728:                    exceptionTester = exceptionTesterLocalHome
0729:                            .create(getName());
0730:                    exceptionTester.ejbExceptionInTx();
0731:                    fail("Expected TransactionRolledbackLocalException to be thrown");
0732:                } catch (TransactionRolledbackLocalException e) {
0733:                    // good this was expected
0734:                    assertNotNull(
0735:                            "TransactionRolledbackLocalException.getCausedByException() "
0736:                                    + "should not be null", e
0737:                                    .getCausedByException());
0738:                    assertEquals(
0739:                            "TransactionRolledbackLocalException.getCausedByException() "
0740:                                    + "should be an EJBException",
0741:                            EJBException.class, e.getCausedByException()
0742:                                    .getClass());
0743:                } catch (Exception e) {
0744:                    fail("Expected TransactionRolledbackLocalException but got "
0745:                            + e);
0746:                }
0747:            }
0748:
0749:            public void testDiscardedEJBExceptionInTx_local() throws Exception {
0750:                boolean caught = false;
0751:                try {
0752:                    exceptionTesterHome
0753:                            .findByPrimaryKey("testEJBExceptionInTx_local");
0754:                } catch (FinderException expected) {
0755:                    caught = true;
0756:                }
0757:                assertTrue("Instance not discarded " + getName(), caught);
0758:            }
0759:
0760:            public void testRuntimeExceptionInTx_local() throws Exception {
0761:                EntityExceptionTesterLocal exceptionTester = null;
0762:                try {
0763:                    exceptionTester = exceptionTesterLocalHome
0764:                            .create(getName());
0765:                    exceptionTester.runtimeExceptionInTx();
0766:                    fail("Expected TransactionRolledbackLocalException to be thrown");
0767:                } catch (TransactionRolledbackLocalException e) {
0768:                    // good this was expected
0769:                    assertNotNull(
0770:                            "TransactionRolledbackLocalException.getCausedByException() "
0771:                                    + "should not be null", e
0772:                                    .getCausedByException());
0773:                    assertEquals(
0774:                            "TransactionRolledbackLocalException.getCausedByException() "
0775:                                    + "should be a RuntimeException",
0776:                            RuntimeException.class, e.getCausedByException()
0777:                                    .getClass());
0778:                } catch (Exception e) {
0779:                    fail("Expected TransactionRolledbackLocalException but got "
0780:                            + e);
0781:                }
0782:            }
0783:
0784:            public void testDiscardedRuntimeExceptionInTx_local()
0785:                    throws Exception {
0786:                boolean caught = false;
0787:                try {
0788:                    exceptionTesterHome
0789:                            .findByPrimaryKey("testRuntimeExceptionInTx_local");
0790:                } catch (FinderException expected) {
0791:                    caught = true;
0792:                }
0793:                assertTrue("Instance not discarded " + getName(), caught);
0794:            }
0795:
0796:            public void testApplicationExceptionNewTx_local() throws Exception {
0797:                EntityExceptionTesterLocal exceptionTester = null;
0798:                try {
0799:                    exceptionTester = exceptionTesterLocalHome
0800:                            .create(getName());
0801:                    exceptionTester.applicationExceptionNewTx();
0802:                    fail("Expected ApplicationException to be thrown");
0803:                } catch (ApplicationException e) {
0804:                    // good this was expected
0805:                } catch (Exception e) {
0806:                    fail("Expected ApplicationException but got " + e);
0807:                }
0808:            }
0809:
0810:            public void testNotDiscardedApplicationExceptionNewTx_local()
0811:                    throws Exception {
0812:                exceptionTesterHome
0813:                        .findByPrimaryKey("testApplicationExceptionNewTx_local");
0814:            }
0815:
0816:            public void testApplicationExceptionNewTxMarkRollback_local()
0817:                    throws Exception {
0818:                EntityExceptionTesterLocal exceptionTester = null;
0819:                try {
0820:                    exceptionTester = exceptionTesterLocalHome
0821:                            .create(getName());
0822:                    exceptionTester.applicationExceptionNewTxMarkRollback();
0823:                    fail("Expected ApplicationException to be thrown");
0824:                } catch (ApplicationException e) {
0825:                    // good this was expected
0826:                } catch (Exception e) {
0827:                    fail("Expected ApplicationException but got " + e);
0828:                }
0829:            }
0830:
0831:            /*
0832:             * It is not clear what the behaviour should be from the spec
0833:             *  
0834:             public void testNotDiscardedApplicationExceptionNewTxMarkRollback_local() throws Exception
0835:             {
0836:             exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNewTxMarkRollback_local"); 
0837:             }
0838:             */
0839:            public void testApplicationErrorNewTx_local() throws Exception {
0840:                EntityExceptionTesterLocal exceptionTester = null;
0841:                try {
0842:                    exceptionTester = exceptionTesterLocalHome
0843:                            .create(getName());
0844:                    exceptionTester.applicationErrorNewTx();
0845:                    fail("Expected EJBException to be thrown");
0846:                } catch (EJBException e) {
0847:                    // good this was expected
0848:                    assertNull(
0849:                            "EJBException.getCausedByException() should be null",
0850:                            e.getCausedByException());
0851:                } catch (Exception e) {
0852:                    fail("Expected EJBException but got " + e);
0853:                }
0854:            }
0855:
0856:            public void testDiscardedApplicationErrorNewTx_local()
0857:                    throws Exception {
0858:                boolean caught = false;
0859:                try {
0860:                    exceptionTesterHome
0861:                            .findByPrimaryKey("testApplicationErrorNewTx_local");
0862:                } catch (FinderException expected) {
0863:                    caught = true;
0864:                }
0865:                assertTrue("Instance not discarded " + getName(), caught);
0866:            }
0867:
0868:            public void testEJBExceptionNewTx_local() throws Exception {
0869:                EntityExceptionTesterLocal exceptionTester = null;
0870:                try {
0871:                    exceptionTester = exceptionTesterLocalHome
0872:                            .create(getName());
0873:                    exceptionTester.ejbExceptionNewTx();
0874:                    fail("Expected EJBException to be thrown");
0875:                } catch (EJBException e) {
0876:                    // good this was expected
0877:                    assertNull(
0878:                            "EJBException.getCausedByException() should be null",
0879:                            e.getCausedByException());
0880:                } catch (Exception e) {
0881:                    fail("Expected EJBException but got " + e);
0882:                }
0883:            }
0884:
0885:            public void testDiscardedEJBExceptionNewTx_local() throws Exception {
0886:                boolean caught = false;
0887:                try {
0888:                    exceptionTesterHome
0889:                            .findByPrimaryKey("testEJBExceptionNewTx_local");
0890:                } catch (FinderException expected) {
0891:                    caught = true;
0892:                }
0893:                assertTrue("Instance not discarded " + getName(), caught);
0894:            }
0895:
0896:            public void testRuntimeExceptionNewTx_local() throws Exception {
0897:                EntityExceptionTesterLocal exceptionTester = null;
0898:                try {
0899:                    exceptionTester = exceptionTesterLocalHome
0900:                            .create(getName());
0901:                    exceptionTester.runtimeExceptionNewTx();
0902:                    fail("Expected EJBException to be thrown");
0903:                } catch (EJBException e) {
0904:                    // good this was expected
0905:                    assertNotNull(
0906:                            "EJBException.getCausedByException() should not be null",
0907:                            e.getCausedByException());
0908:                    assertEquals(
0909:                            "EJBException.getCausedByException() should be "
0910:                                    + "a RuntimeException",
0911:                            RuntimeException.class, e.getCausedByException()
0912:                                    .getClass());
0913:                } catch (Exception e) {
0914:                    fail("Expected EJBException but got " + e);
0915:                }
0916:            }
0917:
0918:            public void testDiscardedRuntimeExceptionNewTx_local()
0919:                    throws Exception {
0920:                boolean caught = false;
0921:                try {
0922:                    exceptionTesterHome
0923:                            .findByPrimaryKey("testRuntimeExceptionNewTx_local");
0924:                } catch (FinderException expected) {
0925:                    caught = true;
0926:                }
0927:                assertTrue("Instance not discarded " + getName(), caught);
0928:            }
0929:
0930:            public void testApplicationExceptionNoTx_local() throws Exception {
0931:                EntityExceptionTesterLocal exceptionTester = null;
0932:                try {
0933:                    exceptionTester = exceptionTesterLocalHome
0934:                            .create(getName());
0935:                    exceptionTester.applicationExceptionNoTx();
0936:                    fail("Expected application exception to be thrown");
0937:                } catch (ApplicationException e) {
0938:                    // good this was expected
0939:                } catch (Exception e) {
0940:                    fail("Expected ApplicationException but got " + e);
0941:                }
0942:            }
0943:
0944:            public void testNotDiscardedApplicationExceptionNoTx_local()
0945:                    throws Exception {
0946:                exceptionTesterHome
0947:                        .findByPrimaryKey("testApplicationExceptionNoTx_local");
0948:            }
0949:
0950:            public void testApplicationErrorNoTx_local() throws Exception {
0951:                EntityExceptionTesterLocal exceptionTester = null;
0952:                try {
0953:                    exceptionTester = exceptionTesterLocalHome
0954:                            .create(getName());
0955:                    exceptionTester.applicationErrorNoTx();
0956:                    fail("Expected EJBException to be thrown");
0957:                } catch (EJBException e) {
0958:                    // good this was expected
0959:                    assertNull(
0960:                            "EJBException.getCausedByException() should be null",
0961:                            e.getCausedByException());
0962:                } catch (Exception e) {
0963:                    fail("Expected EJBException but got " + e);
0964:                }
0965:            }
0966:
0967:            public void testDiscardedApplicationErrorNoTx_local()
0968:                    throws Exception {
0969:                boolean caught = false;
0970:                try {
0971:                    exceptionTesterHome
0972:                            .findByPrimaryKey("testApplicationErrorNoTx_local");
0973:                } catch (FinderException expected) {
0974:                    caught = true;
0975:                }
0976:                assertTrue("Instance not discarded " + getName(), caught);
0977:            }
0978:
0979:            public void testEJBExceptionNoTx_local() throws Exception {
0980:                EntityExceptionTesterLocal exceptionTester = null;
0981:                try {
0982:                    exceptionTester = exceptionTesterLocalHome
0983:                            .create(getName());
0984:                    exceptionTester.ejbExceptionNoTx();
0985:                    fail("Expected EJBException to be thrown");
0986:                } catch (EJBException e) {
0987:                    // good this was expected
0988:                    assertNull(
0989:                            "EJBException.getCausedByException() should be null",
0990:                            e.getCausedByException());
0991:                } catch (Exception e) {
0992:                    fail("Expected EJBException but got " + e);
0993:                }
0994:            }
0995:
0996:            public void testDiscardedEJBExceptionNoTx_local() throws Exception {
0997:                boolean caught = false;
0998:                try {
0999:                    exceptionTesterHome
1000:                            .findByPrimaryKey("testEJBExceptionNoTx_local");
1001:                } catch (FinderException expected) {
1002:                    caught = true;
1003:                }
1004:                assertTrue("Instance not discarded " + getName(), caught);
1005:            }
1006:
1007:            public void testRuntimeExceptionNoTx_local() throws Exception {
1008:                EntityExceptionTesterLocal exceptionTester = null;
1009:                try {
1010:                    exceptionTester = exceptionTesterLocalHome
1011:                            .create(getName());
1012:                    exceptionTester.runtimeExceptionNoTx();
1013:                    fail("Expected EJBException to be thrown");
1014:                } catch (EJBException e) {
1015:                    // good this was expected
1016:                    assertNotNull(
1017:                            "EJBException.getCausedByException() should not be null",
1018:                            e.getCausedByException());
1019:                    assertEquals(
1020:                            "EJBException.getCausedByException() should be "
1021:                                    + "a RuntimeException",
1022:                            RuntimeException.class, e.getCausedByException()
1023:                                    .getClass());
1024:                } catch (Exception e) {
1025:                    fail("Expected EJBException but got " + e);
1026:                }
1027:            }
1028:
1029:            public void testDiscardedRuntimeExceptionNoTx_local()
1030:                    throws Exception {
1031:                boolean caught = false;
1032:                try {
1033:                    exceptionTesterHome
1034:                            .findByPrimaryKey("testRuntimeExceptionNoTx_local");
1035:                } catch (FinderException expected) {
1036:                    caught = true;
1037:                }
1038:                assertTrue("Instance not discarded " + getName(), caught);
1039:            }
1040:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.