1 22 package org.jboss.test.exception; 23 24 import java.rmi.RemoteException ; 25 26 import javax.ejb.EJBException ; 27 import javax.ejb.FinderException ; 28 import javax.ejb.TransactionRolledbackLocalException ; 29 import javax.naming.InitialContext ; 30 import javax.transaction.TransactionRolledbackException ; 31 32 import junit.framework.Test; 33 import junit.framework.TestSuite; 34 35 import org.jboss.test.JBossTestCase; 36 import org.jboss.test.util.ejb.EJBTestCase; 37 38 public class EntityExceptionUnitTestCase extends EJBTestCase 39 { 40 public static Test suite() throws Exception 41 { 42 TestSuite suite = new TestSuite(); 45 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionInTx_remote")); 46 suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionInTx_remote")); 47 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionInTxMarkRollback_remote")); 48 suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorInTx_remote")); 49 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorInTx_remote")); 50 suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionInTx_remote")); 51 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionInTx_remote")); 52 suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionInTx_remote")); 53 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionInTx_remote")); 54 suite.addTest(new EntityExceptionUnitTestCase("testRemoteExceptionInTx_remote")); 55 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRemoteExceptionInTx_remote")); 56 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNewTx_remote")); 57 suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNewTx_remote")); 58 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNewTxMarkRollback_remote")); 59 suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorNewTx_remote")); 61 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorNewTx_remote")); 62 suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionNewTx_remote")); 63 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionNewTx_remote")); 64 suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionNewTx_remote")); 65 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionNewTx_remote")); 66 suite.addTest(new EntityExceptionUnitTestCase("testRemoteExceptionNewTx_remote")); 67 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRemoteExceptionNewTx_remote")); 68 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNoTx_remote")); 69 suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNoTx_remote")); 70 suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorNoTx_remote")); 71 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorNoTx_remote")); 72 suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionNoTx_remote")); 73 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionNoTx_remote")); 74 suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionNoTx_remote")); 75 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionNoTx_remote")); 76 suite.addTest(new EntityExceptionUnitTestCase("testRemoteExceptionNoTx_remote")); 77 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRemoteExceptionNoTx_remote")); 78 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionInTx_local")); 79 suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionInTx_local")); 80 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionInTxMarkRollback_local")); 81 suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorInTx_local")); 83 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorInTx_local")); 84 suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionInTx_local")); 85 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionInTx_local")); 86 suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionInTx_local")); 87 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionInTx_local")); 88 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNewTx_local")); 89 suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNewTx_local")); 90 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNewTxMarkRollback_local")); 91 suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorNewTx_local")); 93 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorNewTx_local")); 94 suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionNewTx_local")); 95 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionNewTx_local")); 96 suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionNewTx_local")); 97 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionNewTx_local")); 98 suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNoTx_local")); 99 suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNoTx_local")); 100 suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorNoTx_local")); 101 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorNoTx_local")); 102 suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionNoTx_local")); 103 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionNoTx_local")); 104 suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionNoTx_local")); 105 suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionNoTx_local")); 106 107 return JBossTestCase.getDeploySetup(suite, "exception.jar"); 108 } 109 110 public EntityExceptionUnitTestCase(String name) 111 { 112 super(name); 113 } 114 115 private EntityExceptionTesterHome exceptionTesterHome; 116 117 private EntityExceptionTesterLocalHome exceptionTesterLocalHome; 118 119 126 public void setUp() throws Exception 127 { 128 InitialContext jndi = new InitialContext (); 129 exceptionTesterHome = (EntityExceptionTesterHome) jndi.lookup("exception/EntityExceptionTester"); 130 exceptionTesterLocalHome = (EntityExceptionTesterLocalHome) jndi.lookup("exception/EntityExceptionTesterLocal"); 131 } 132 133 public void testApplicationExceptionInTx_remote() throws Exception 134 { 135 EntityExceptionTester exceptionTester = null; 136 try 137 { 138 exceptionTester = exceptionTesterHome.create(getName()); 139 exceptionTester.applicationExceptionInTx(); 140 fail("Expected application exception to be thrown"); 141 } 142 catch (ApplicationException e) 143 { 144 } 146 catch (Exception e) 147 { 148 fail("Expected ApplicationException but got " + e); 149 } 150 } 151 152 public void testNotDiscardedApplicationExceptionInTx_remote() throws Exception 153 { 154 exceptionTesterHome.findByPrimaryKey("testApplicationExceptionInTx_remote"); 155 } 156 157 public void testApplicationExceptionInTxMarkRollback_remote() throws Exception 158 { 159 EntityExceptionTester exceptionTester = null; 160 try 161 { 162 exceptionTester = exceptionTesterHome.create(getName()); 163 exceptionTester.applicationExceptionInTxMarkRollback(); 164 fail("Expected application exception to be thrown"); 165 } 166 catch (ApplicationException e) 167 { 168 } 170 catch (Exception e) 171 { 172 fail("Expected ApplicationException but got " + e); 173 } 174 } 175 176 184 public void testApplicationErrorInTx_remote() throws Exception 185 { 186 EntityExceptionTester exceptionTester = null; 187 try 188 { 189 exceptionTester = exceptionTesterHome.create(getName()); 190 exceptionTester.applicationErrorInTx(); 191 fail("Expected transaction rolled back exception to be thrown"); 192 } 193 catch (TransactionRolledbackException e) 194 { 195 assertNotNull("TransactionRolledbackException.detail should not be null", e.detail); 197 assertEquals("TransactionRolledbackException.detail should " + "be a ApplicationError", 198 ApplicationError.class, e.detail.getClass()); 199 } 200 catch (Exception e) 201 { 202 fail("Expected TransactionRolledbackException but got " + e); 203 } 204 } 205 206 public void testDiscardedApplicationErrorInTx_remote() throws Exception 207 { 208 boolean caught = false; 209 try 210 { 211 exceptionTesterHome.findByPrimaryKey("testApplicationErrorInTx_remote"); 212 } 213 catch (FinderException expected) 214 { 215 caught = true; 216 } 217 assertTrue("Instance not discarded " + getName(), caught); 218 } 219 220 public void testEJBExceptionInTx_remote() throws Exception 221 { 222 EntityExceptionTester exceptionTester = null; 223 try 224 { 225 exceptionTester = exceptionTesterHome.create(getName()); 226 exceptionTester.ejbExceptionInTx(); 227 fail("Expected transaction rolled back exception to be thrown"); 228 } 229 catch (TransactionRolledbackException e) 230 { 231 assertNotNull("TransactionRolledbackException.detail should not be null", e.detail); 233 assertEquals("TransactionRolledbackException.detail should " + "be an EJBException", EJBException .class, 234 e.detail.getClass()); 235 } 236 catch (Exception e) 237 { 238 fail("Expected TransactionRolledbackException but got " + e); 239 } 240 } 241 242 public void testDiscardedEJBExceptionInTx_remote() throws Exception 243 { 244 boolean caught = false; 245 try 246 { 247 exceptionTesterHome.findByPrimaryKey("testEJBExceptionInTx_remote"); 248 } 249 catch (FinderException expected) 250 { 251 caught = true; 252 } 253 assertTrue("Instance not discarded " + getName(), caught); 254 } 255 256 public void testRuntimeExceptionInTx_remote() throws Exception 257 { 258 EntityExceptionTester exceptionTester = null; 259 try 260 { 261 exceptionTester = exceptionTesterHome.create(getName()); 262 exceptionTester.runtimeExceptionInTx(); 263 fail("Expected transaction rolled back exception to be thrown"); 264 } 265 catch (TransactionRolledbackException e) 266 { 267 assertNotNull("TransactionRolledbackException.detail should not be null", e.detail); 269 assertEquals("TransactionRolledbackException.detail should " + "be a RuntimeException", 270 RuntimeException .class, e.detail.getClass()); 271 } 272 catch (Exception e) 273 { 274 fail("Expected TransactionRolledbackException but got " + e); 275 } 276 } 277 278 public void testDiscardedRuntimeExceptionInTx_remote() throws Exception 279 { 280 boolean caught = false; 281 try 282 { 283 exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionInTx_remote"); 284 } 285 catch (FinderException expected) 286 { 287 caught = true; 288 } 289 assertTrue("Instance not discarded " + getName(), caught); 290 } 291 292 public void testRemoteExceptionInTx_remote() throws Exception 293 { 294 EntityExceptionTester exceptionTester = null; 295 try 296 { 297 exceptionTester = exceptionTesterHome.create(getName()); 298 exceptionTester.remoteExceptionInTx(); 299 fail("Expected transaction rolled back exception to be thrown"); 300 } 301 catch (TransactionRolledbackException e) 302 { 303 assertNotNull("TransactionRolledbackException.detail should not be null", e.detail); 305 assertEquals("TransactionRolledbackException.detail should " + "be a RemoteException", RemoteException .class, 306 e.detail.getClass()); 307 } 308 catch (Exception e) 309 { 310 fail("Expected TransactionRolledbackException but got " + e); 311 } 312 } 313 314 public void testDiscardedRemoteExceptionInTx_remote() throws Exception 315 { 316 boolean caught = false; 317 try 318 { 319 exceptionTesterHome.findByPrimaryKey("testRemoteExceptionInTx_remote"); 320 } 321 catch (FinderException expected) 322 { 323 caught = true; 324 } 325 assertTrue("Instance not discarded " + getName(), caught); 326 } 327 328 public void testApplicationExceptionNewTx_remote() throws Exception 329 { 330 EntityExceptionTester exceptionTester = null; 331 try 332 { 333 exceptionTester = exceptionTesterHome.create(getName()); 334 exceptionTester.applicationExceptionNewTx(); 335 fail("Expected application exception to be thrown"); 336 } 337 catch (ApplicationException e) 338 { 339 } 341 catch (Exception e) 342 { 343 fail("Expected ApplicationException but got " + e); 344 } 345 } 346 347 public void testNotDiscardedApplicationExceptionNewTx_remote() throws Exception 348 { 349 exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNewTx_remote"); 350 } 351 352 public void testApplicationExceptionNewTxMarkRollback_remote() throws Exception 353 { 354 EntityExceptionTester exceptionTester = null; 355 try 356 { 357 exceptionTester = exceptionTesterHome.create(getName()); 358 exceptionTester.applicationExceptionNewTxMarkRollback(); 359 fail("Expected application exception to be thrown"); 360 } 361 catch (ApplicationException e) 362 { 363 } 365 catch (Exception e) 366 { 367 fail("Expected ApplicationException but got " + e); 368 } 369 } 370 371 379 public void testApplicationErrorNewTx_remote() throws Exception 380 { 381 EntityExceptionTester exceptionTester = null; 382 try 383 { 384 exceptionTester = exceptionTesterHome.create(getName()); 385 exceptionTester.applicationErrorNewTx(); 386 fail("Expected RemoteException to be thrown"); 387 } 388 catch (RemoteException e) 389 { 390 assertNotNull("RemoteException.detail should not be null", e.detail); 392 assertEquals("RemoteException.detail should be a ApplicationError", ApplicationError.class, e.detail 393 .getClass()); 394 } 395 catch (Exception e) 396 { 397 fail("Expected RemoteException but got " + e); 398 } 399 } 400 401 public void testDiscardedApplicationErrorNewTx_remote() throws Exception 402 { 403 boolean caught = false; 404 try 405 { 406 exceptionTesterHome.findByPrimaryKey("testApplicationErrorNewTx_remote"); 407 } 408 catch (FinderException expected) 409 { 410 caught = true; 411 } 412 assertTrue("Instance not discarded " + getName(), caught); 413 } 414 415 public void testEJBExceptionNewTx_remote() throws Exception 416 { 417 EntityExceptionTester exceptionTester = null; 418 try 419 { 420 exceptionTester = exceptionTesterHome.create(getName()); 421 exceptionTester.ejbExceptionNewTx(); 422 fail("Expected RemoteException to be thrown"); 423 } 424 catch (RemoteException e) 425 { 426 assertNotNull("RemoteException.detail should not be null", e.detail); 428 assertEquals("RemoteException.detail should be a EJBException", EJBException .class, e.detail.getClass()); 429 } 430 catch (Exception e) 431 { 432 fail("Expected RemoteException but got " + e); 433 } 434 } 435 436 public void testDiscardedEJBExceptionNewTx_remote() throws Exception 437 { 438 boolean caught = false; 439 try 440 { 441 exceptionTesterHome.findByPrimaryKey("testEJBExceptionNewTx_remote"); 442 } 443 catch (FinderException expected) 444 { 445 caught = true; 446 } 447 assertTrue("Instance not discarded " + getName(), caught); 448 } 449 450 public void testRuntimeExceptionNewTx_remote() throws Exception 451 { 452 EntityExceptionTester exceptionTester = null; 453 try 454 { 455 exceptionTester = exceptionTesterHome.create(getName()); 456 exceptionTester.runtimeExceptionNewTx(); 457 fail("Expected RemoteException to be thrown"); 458 } 459 catch (RemoteException e) 460 { 461 assertNotNull("RemoteException.detail should not be null", e.detail); 463 assertEquals("RemoteException.detail should be a RuntimeException", RuntimeException .class, e.detail 464 .getClass()); 465 } 466 catch (Exception e) 467 { 468 fail("Expected RemoteException but got " + e); 469 } 470 } 471 472 public void testDiscardedRuntimeExceptionNewTx_remote() throws Exception 473 { 474 boolean caught = false; 475 try 476 { 477 exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionNewTx_remote"); 478 } 479 catch (FinderException expected) 480 { 481 caught = true; 482 } 483 assertTrue("Instance not discarded " + getName(), caught); 484 } 485 486 public void testRemoteExceptionNewTx_remote() throws Exception 487 { 488 EntityExceptionTester exceptionTester = null; 489 try 490 { 491 exceptionTester = exceptionTesterHome.create(getName()); 492 exceptionTester.remoteExceptionNewTx(); 493 fail("Expected RemoteException to be thrown"); 494 } 495 catch (RemoteException e) 496 { 497 } 499 catch (Exception e) 500 { 501 fail("Expected RemoteException but got " + e); 502 } 503 } 504 505 public void testDiscardedRemoteExceptionNewTx_remote() throws Exception 506 { 507 boolean caught = false; 508 try 509 { 510 exceptionTesterHome.findByPrimaryKey("testRemoteExceptionNewTx_remote"); 511 } 512 catch (FinderException expected) 513 { 514 caught = true; 515 } 516 assertTrue("Instance not discarded " + getName(), caught); 517 } 518 519 public void testApplicationExceptionNoTx_remote() throws Exception 520 { 521 EntityExceptionTester exceptionTester = null; 522 try 523 { 524 exceptionTester = exceptionTesterHome.create(getName()); 525 exceptionTester.applicationExceptionNoTx(); 526 fail("Expected application exception to be thrown"); 527 } 528 catch (ApplicationException e) 529 { 530 } 532 catch (Exception e) 533 { 534 fail("Expected ApplicationException but got " + e); 535 } 536 } 537 538 public void testNotDiscardedApplicationExceptionNoTx_remote() throws Exception 539 { 540 exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNoTx_remote"); 541 } 542 543 public void testApplicationErrorNoTx_remote() throws Exception 544 { 545 EntityExceptionTester exceptionTester = null; 546 try 547 { 548 exceptionTester = exceptionTesterHome.create(getName()); 549 exceptionTester.applicationErrorNoTx(); 550 fail("Expected RemoteException to be thrown"); 551 } 552 catch (RemoteException e) 553 { 554 assertNotNull("RemoteException.detail should not be null", e.detail); 556 assertEquals("RemoteException.detail should be a ApplicationError", ApplicationError.class, e.detail 557 .getClass()); 558 } 559 catch (Exception e) 560 { 561 fail("Expected RemoteException but got " + e); 562 } 563 } 564 565 public void testDiscardedApplicationErrorNoTx_remote() throws Exception 566 { 567 boolean caught = false; 568 try 569 { 570 exceptionTesterHome.findByPrimaryKey("testApplicationErrorNoTx_remote"); 571 } 572 catch (FinderException expected) 573 { 574 caught = true; 575 } 576 assertTrue("Instance not discarded " + getName(), caught); 577 } 578 579 public void testEJBExceptionNoTx_remote() throws Exception 580 { 581 EntityExceptionTester exceptionTester = null; 582 try 583 { 584 exceptionTester = exceptionTesterHome.create(getName()); 585 exceptionTester.ejbExceptionNoTx(); 586 fail("Expected RemoteException to be thrown"); 587 } 588 catch (RemoteException e) 589 { 590 assertNotNull("RemoteException.detail should not be null", e.detail); 592 assertEquals("RemoteException.detail should be a EJBException", EJBException .class, e.detail.getClass()); 593 } 594 catch (Exception e) 595 { 596 fail("Expected RemoteException but got " + e); 597 } 598 } 599 600 public void testDiscardedEJBExceptionNoTx_remote() throws Exception 601 { 602 boolean caught = false; 603 try 604 { 605 exceptionTesterHome.findByPrimaryKey("testEJBExceptionNoTx_remote"); 606 } 607 catch (FinderException expected) 608 { 609 caught = true; 610 } 611 assertTrue("Instance not discarded " + getName(), caught); 612 } 613 614 public void testRuntimeExceptionNoTx_remote() throws Exception 615 { 616 EntityExceptionTester exceptionTester = null; 617 try 618 { 619 exceptionTester = exceptionTesterHome.create(getName()); 620 exceptionTester.runtimeExceptionNoTx(); 621 fail("Expected RemoteException to be thrown"); 622 } 623 catch (RemoteException e) 624 { 625 assertNotNull("RemoteException.detail should not be null", e.detail); 627 assertEquals("RemoteException.detail should be a RuntimeException", RuntimeException .class, e.detail 628 .getClass()); 629 } 630 catch (Exception e) 631 { 632 fail("Expected RemoteException but got " + e); 633 } 634 } 635 636 public void testDiscardedRuntimeExceptionNoTx_remote() throws Exception 637 { 638 boolean caught = false; 639 try 640 { 641 exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionNoTx_remote"); 642 } 643 catch (FinderException expected) 644 { 645 caught = true; 646 } 647 assertTrue("Instance not discarded " + getName(), caught); 648 } 649 650 public void testRemoteExceptionNoTx_remote() throws Exception 651 { 652 EntityExceptionTester exceptionTester = null; 653 try 654 { 655 exceptionTester = exceptionTesterHome.create(getName()); 656 exceptionTester.remoteExceptionNoTx(); 657 fail("Expected RemoteException to be thrown"); 658 } 659 catch (RemoteException e) 660 { 661 } 663 catch (Exception e) 664 { 665 fail("Expected RemoteException but got " + e); 666 } 667 } 668 669 public void testDiscardedRemoteExceptionNoTx_remote() throws Exception 670 { 671 boolean caught = false; 672 try 673 { 674 exceptionTesterHome.findByPrimaryKey("testRemoteExceptionNoTx_remote"); 675 } 676 catch (FinderException expected) 677 { 678 caught = true; 679 } 680 assertTrue("Instance not discarded " + getName(), caught); 681 } 682 683 public void testApplicationExceptionInTx_local() throws Exception 684 { 685 EntityExceptionTesterLocal exceptionTester = null; 686 try 687 { 688 exceptionTester = exceptionTesterLocalHome.create(getName()); 689 exceptionTester.applicationExceptionInTx(); 690 fail("Expected ApplicationException to be thrown"); 691 } 692 catch (ApplicationException e) 693 { 694 } 696 catch (Exception e) 697 { 698 fail("Expected ApplicationException but got " + e); 699 } 700 } 701 702 public void testNotDiscardedApplicationExceptionInTx_local() throws Exception 703 { 704 exceptionTesterHome.findByPrimaryKey("testApplicationExceptionInTx_local"); 705 } 706 707 public void testApplicationExceptionInTxMarkRollback_local() throws Exception 708 { 709 EntityExceptionTesterLocal exceptionTester = null; 710 try 711 { 712 exceptionTester = exceptionTesterLocalHome.create(getName()); 713 exceptionTester.applicationExceptionInTxMarkRollback(); 714 fail("Expected ApplicationException to be thrown"); 715 } 716 catch (ApplicationException e) 717 { 718 } 720 catch (Exception e) 721 { 722 fail("Expected ApplicationException but got " + e); 723 } 724 } 725 726 734 public void testApplicationErrorInTx_local() throws Exception 735 { 736 EntityExceptionTesterLocal exceptionTester = null; 737 try 738 { 739 exceptionTester = exceptionTesterLocalHome.create(getName()); 740 exceptionTester.applicationErrorInTx(); 741 fail("Expected TransactionRolledbackLocalException to be thrown"); 742 } 743 catch (TransactionRolledbackLocalException e) 744 { 745 assertNotNull("TransactionRolledbackLocalException.getCausedByException() " + "should not be null", e 747 .getCausedByException()); 748 assertEquals("TransactionRolledbackLocalException.getCausedByExcption() " + "should be an EJBException", 749 EJBException .class, e.getCausedByException().getClass()); 750 } 751 catch (Exception e) 752 { 753 fail("Expected TransactionRolledbackLocalException but got " + e); 754 } 755 } 756 757 public void testDiscardedApplicationErrorInTx_local() throws Exception 758 { 759 boolean caught = false; 760 try 761 { 762 exceptionTesterHome.findByPrimaryKey("testApplicationErrorInTx_local"); 763 } 764 catch (FinderException expected) 765 { 766 caught = true; 767 } 768 assertTrue("Instance not discarded " + getName(), caught); 769 } 770 771 public void testEJBExceptionInTx_local() throws Exception 772 { 773 EntityExceptionTesterLocal exceptionTester = null; 774 try 775 { 776 exceptionTester = exceptionTesterLocalHome.create(getName()); 777 exceptionTester.ejbExceptionInTx(); 778 fail("Expected TransactionRolledbackLocalException to be thrown"); 779 } 780 catch (TransactionRolledbackLocalException e) 781 { 782 assertNotNull("TransactionRolledbackLocalException.getCausedByException() " + "should not be null", e 784 .getCausedByException()); 785 assertEquals("TransactionRolledbackLocalException.getCausedByException() " + "should be an EJBException", 786 EJBException .class, e.getCausedByException().getClass()); 787 } 788 catch (Exception e) 789 { 790 fail("Expected TransactionRolledbackLocalException but got " + e); 791 } 792 } 793 794 public void testDiscardedEJBExceptionInTx_local() throws Exception 795 { 796 boolean caught = false; 797 try 798 { 799 exceptionTesterHome.findByPrimaryKey("testEJBExceptionInTx_local"); 800 } 801 catch (FinderException expected) 802 { 803 caught = true; 804 } 805 assertTrue("Instance not discarded " + getName(), caught); 806 } 807 808 public void testRuntimeExceptionInTx_local() throws Exception 809 { 810 EntityExceptionTesterLocal exceptionTester = null; 811 try 812 { 813 exceptionTester = exceptionTesterLocalHome.create(getName()); 814 exceptionTester.runtimeExceptionInTx(); 815 fail("Expected TransactionRolledbackLocalException to be thrown"); 816 } 817 catch (TransactionRolledbackLocalException e) 818 { 819 assertNotNull("TransactionRolledbackLocalException.getCausedByException() " + "should not be null", e 821 .getCausedByException()); 822 assertEquals("TransactionRolledbackLocalException.getCausedByException() " + "should be a RuntimeException", 823 RuntimeException .class, e.getCausedByException().getClass()); 824 } 825 catch (Exception e) 826 { 827 fail("Expected TransactionRolledbackLocalException but got " + e); 828 } 829 } 830 831 public void testDiscardedRuntimeExceptionInTx_local() throws Exception 832 { 833 boolean caught = false; 834 try 835 { 836 exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionInTx_local"); 837 } 838 catch (FinderException expected) 839 { 840 caught = true; 841 } 842 assertTrue("Instance not discarded " + getName(), caught); 843 } 844 845 public void testApplicationExceptionNewTx_local() throws Exception 846 { 847 EntityExceptionTesterLocal exceptionTester = null; 848 try 849 { 850 exceptionTester = exceptionTesterLocalHome.create(getName()); 851 exceptionTester.applicationExceptionNewTx(); 852 fail("Expected ApplicationException to be thrown"); 853 } 854 catch (ApplicationException e) 855 { 856 } 858 catch (Exception e) 859 { 860 fail("Expected ApplicationException but got " + e); 861 } 862 } 863 864 public void testNotDiscardedApplicationExceptionNewTx_local() throws Exception 865 { 866 exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNewTx_local"); 867 } 868 869 public void testApplicationExceptionNewTxMarkRollback_local() throws Exception 870 { 871 EntityExceptionTesterLocal exceptionTester = null; 872 try 873 { 874 exceptionTester = exceptionTesterLocalHome.create(getName()); 875 exceptionTester.applicationExceptionNewTxMarkRollback(); 876 fail("Expected ApplicationException to be thrown"); 877 } 878 catch (ApplicationException e) 879 { 880 } 882 catch (Exception e) 883 { 884 fail("Expected ApplicationException but got " + e); 885 } 886 } 887 888 896 public void testApplicationErrorNewTx_local() throws Exception 897 { 898 EntityExceptionTesterLocal exceptionTester = null; 899 try 900 { 901 exceptionTester = exceptionTesterLocalHome.create(getName()); 902 exceptionTester.applicationErrorNewTx(); 903 fail("Expected EJBException to be thrown"); 904 } 905 catch (EJBException e) 906 { 907 assertNull("EJBException.getCausedByException() should be null", e.getCausedByException()); 909 } 910 catch (Exception e) 911 { 912 fail("Expected EJBException but got " + e); 913 } 914 } 915 916 public void testDiscardedApplicationErrorNewTx_local() throws Exception 917 { 918 boolean caught = false; 919 try 920 { 921 exceptionTesterHome.findByPrimaryKey("testApplicationErrorNewTx_local"); 922 } 923 catch (FinderException expected) 924 { 925 caught = true; 926 } 927 assertTrue("Instance not discarded " + getName(), caught); 928 } 929 930 public void testEJBExceptionNewTx_local() throws Exception 931 { 932 EntityExceptionTesterLocal exceptionTester = null; 933 try 934 { 935 exceptionTester = exceptionTesterLocalHome.create(getName()); 936 exceptionTester.ejbExceptionNewTx(); 937 fail("Expected EJBException to be thrown"); 938 } 939 catch (EJBException e) 940 { 941 assertNull("EJBException.getCausedByException() should be null", e.getCausedByException()); 943 } 944 catch (Exception e) 945 { 946 fail("Expected EJBException but got " + e); 947 } 948 } 949 950 public void testDiscardedEJBExceptionNewTx_local() throws Exception 951 { 952 boolean caught = false; 953 try 954 { 955 exceptionTesterHome.findByPrimaryKey("testEJBExceptionNewTx_local"); 956 } 957 catch (FinderException expected) 958 { 959 caught = true; 960 } 961 assertTrue("Instance not discarded " + getName(), caught); 962 } 963 964 public void testRuntimeExceptionNewTx_local() throws Exception 965 { 966 EntityExceptionTesterLocal exceptionTester = null; 967 try 968 { 969 exceptionTester = exceptionTesterLocalHome.create(getName()); 970 exceptionTester.runtimeExceptionNewTx(); 971 fail("Expected EJBException to be thrown"); 972 } 973 catch (EJBException e) 974 { 975 assertNotNull("EJBException.getCausedByException() should not be null", e.getCausedByException()); 977 assertEquals("EJBException.getCausedByException() should be " + "a RuntimeException", RuntimeException .class, 978 e.getCausedByException().getClass()); 979 } 980 catch (Exception e) 981 { 982 fail("Expected EJBException but got " + e); 983 } 984 } 985 986 public void testDiscardedRuntimeExceptionNewTx_local() throws Exception 987 { 988 boolean caught = false; 989 try 990 { 991 exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionNewTx_local"); 992 } 993 catch (FinderException expected) 994 { 995 caught = true; 996 } 997 assertTrue("Instance not discarded " + getName(), caught); 998 } 999 1000 public void testApplicationExceptionNoTx_local() throws Exception 1001 { 1002 EntityExceptionTesterLocal exceptionTester = null; 1003 try 1004 { 1005 exceptionTester = exceptionTesterLocalHome.create(getName()); 1006 exceptionTester.applicationExceptionNoTx(); 1007 fail("Expected application exception to be thrown"); 1008 } 1009 catch (ApplicationException e) 1010 { 1011 } 1013 catch (Exception e) 1014 { 1015 fail("Expected ApplicationException but got " + e); 1016 } 1017 } 1018 1019 public void testNotDiscardedApplicationExceptionNoTx_local() throws Exception 1020 { 1021 exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNoTx_local"); 1022 } 1023 1024 public void testApplicationErrorNoTx_local() throws Exception 1025 { 1026 EntityExceptionTesterLocal exceptionTester = null; 1027 try 1028 { 1029 exceptionTester = exceptionTesterLocalHome.create(getName()); 1030 exceptionTester.applicationErrorNoTx(); 1031 fail("Expected EJBException to be thrown"); 1032 } 1033 catch (EJBException e) 1034 { 1035 assertNull("EJBException.getCausedByException() should be null", e.getCausedByException()); 1037 } 1038 catch (Exception e) 1039 { 1040 fail("Expected EJBException but got " + e); 1041 } 1042 } 1043 1044 public void testDiscardedApplicationErrorNoTx_local() throws Exception 1045 { 1046 boolean caught = false; 1047 try 1048 { 1049 exceptionTesterHome.findByPrimaryKey("testApplicationErrorNoTx_local"); 1050 } 1051 catch (FinderException expected) 1052 { 1053 caught = true; 1054 } 1055 assertTrue("Instance not discarded " + getName(), caught); 1056 } 1057 1058 public void testEJBExceptionNoTx_local() throws Exception 1059 { 1060 EntityExceptionTesterLocal exceptionTester = null; 1061 try 1062 { 1063 exceptionTester = exceptionTesterLocalHome.create(getName()); 1064 exceptionTester.ejbExceptionNoTx(); 1065 fail("Expected EJBException to be thrown"); 1066 } 1067 catch (EJBException e) 1068 { 1069 assertNull("EJBException.getCausedByException() should be null", e.getCausedByException()); 1071 } 1072 catch (Exception e) 1073 { 1074 fail("Expected EJBException but got " + e); 1075 } 1076 } 1077 1078 public void testDiscardedEJBExceptionNoTx_local() throws Exception 1079 { 1080 boolean caught = false; 1081 try 1082 { 1083 exceptionTesterHome.findByPrimaryKey("testEJBExceptionNoTx_local"); 1084 } 1085 catch (FinderException expected) 1086 { 1087 caught = true; 1088 } 1089 assertTrue("Instance not discarded " + getName(), caught); 1090 } 1091 1092 public void testRuntimeExceptionNoTx_local() throws Exception 1093 { 1094 EntityExceptionTesterLocal exceptionTester = null; 1095 try 1096 { 1097 exceptionTester = exceptionTesterLocalHome.create(getName()); 1098 exceptionTester.runtimeExceptionNoTx(); 1099 fail("Expected EJBException to be thrown"); 1100 } 1101 catch (EJBException e) 1102 { 1103 assertNotNull("EJBException.getCausedByException() should not be null", e.getCausedByException()); 1105 assertEquals("EJBException.getCausedByException() should be " + "a RuntimeException", RuntimeException .class, 1106 e.getCausedByException().getClass()); 1107 } 1108 catch (Exception e) 1109 { 1110 fail("Expected EJBException but got " + e); 1111 } 1112 } 1113 1114 public void testDiscardedRuntimeExceptionNoTx_local() throws Exception 1115 { 1116 boolean caught = false; 1117 try 1118 { 1119 exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionNoTx_local"); 1120 } 1121 catch (FinderException expected) 1122 { 1123 caught = true; 1124 } 1125 assertTrue("Instance not discarded " + getName(), caught); 1126 } 1127} | Popular Tags |