1 24 25 package org.objectweb.jonas.jtests.clients.entity; 26 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 30 import javax.naming.NamingException ; 31 import javax.rmi.PortableRemoteObject ; 32 33 import junit.framework.Assert; 34 import junit.framework.Test; 35 import junit.framework.TestSuite; 36 37 import org.objectweb.jonas.jtests.beans.relation.family.People; 38 import org.objectweb.jonas.jtests.beans.relation.family.PeopleHome; 39 import org.objectweb.jonas.jtests.util.JTestCase; 40 41 49 public class F_FamilyEC2 extends JTestCase { 50 51 54 private static PeopleHome home = null; 55 56 59 public F_FamilyEC2(String name) { 60 super(name); 61 } 62 63 protected static boolean isInit = false; 64 65 69 protected void setUp() { 70 super.setUp(); 71 if (!isInit) { 72 useBeans("family", false); 73 try { 74 home = (PeopleHome) PortableRemoteObject.narrow(ictx.lookup("FamilyHome"), 75 PeopleHome.class); 76 } catch (NamingException e) { 77 fail("Cannot get bean home: " + e.getMessage()); 78 } 79 isInit = true; 80 } 81 } 82 83 89 protected void tearDown() throws Exception { 90 cleanall(); 91 } 92 93 98 private void cleanall() throws Exception { 99 debug("remove all beans"); 100 101 try { 104 utx.begin(); 105 } catch (Exception e) { 106 debug("rollback first and start a new tx"); 107 utx.rollback(); 108 utx.begin(); 109 } 110 111 try { 114 Collection c = home.findAll(); 115 for (Iterator i = c.iterator(); i.hasNext(); ) { 116 People p = (People) PortableRemoteObject.narrow(i.next(), People.class); 117 debug("removing " + p.getName()); 118 p.remove(); 119 } 120 utx.commit(); 121 } catch (Exception e) { 122 error("Exception in cleanup: " + e); 123 try { 124 utx.rollback(); 125 } catch (Exception f) { 126 error("Exception during rollback: " + f); 127 } finally { 128 unloadBeans("family"); 129 isInit = false; 130 } 131 } 132 } 133 134 138 142 public void testRemoveHTCreateIT() throws Exception { 143 home.create("Edouard", null, null); 144 home.create("Philomene", null, null); 145 home.remove("Edouard"); 146 utx.begin(); 147 home.create("Edouard", null, null); 148 home.union("Edouard", "Philomene"); 149 utx.commit(); 150 } 151 152 156 public void testRemoveHTCreateIT1() throws Exception { 157 home.create("Edouard", null, null); 158 home.remove("Edouard"); 159 utx.begin(); 160 home.create("Edouard", null, null); 161 utx.commit(); 162 } 163 164 167 public void testRemoveFatherTx() throws Exception { 168 build1920(); 169 People p1 = home.create("Edouard2", "Edouard", "Philomene"); 170 utx.begin(); 171 home.remove("Edouard"); 172 utx.commit(); 173 Assert.assertTrue("Edouard2 has no father", p1.hasNoFather()); 174 } 175 176 179 public void testRemoveFather() throws Exception { 180 build1920(); 181 People p1 = home.create("Edouard2", "Edouard", "Philomene"); 182 home.remove("Edouard"); 183 Assert.assertTrue("Edouard2 has no father", p1.hasNoFather()); 184 } 185 186 189 public void testRemoveMother() throws Exception { 190 build1920(); 191 People p1 = home.create("Sylvain", "Edouard", "Philomene"); 192 home.remove("Edouard"); 193 home.remove("Philomene"); 194 Assert.assertTrue("Sylvain is orphan", p1.isOrphan()); 195 } 196 197 200 public void testRemoveMotherTx() throws Exception { 201 utx.begin(); 202 build1920(); 203 People p1 = home.create("Sylvain", "Edouard", "Philomene"); 204 home.remove("Edouard"); 205 home.remove("Philomene"); 206 utx.commit(); 207 Assert.assertTrue("Sylvain is orphan", p1.isOrphan()); 208 } 209 210 215 public void testManChildren() throws Exception { 216 build1920(); 217 build1940(); 218 People p3 = home.findByPrimaryKey("Ernest"); 219 Assert.assertEquals("Ernest's children", 3, p3.kidNumber()); 220 } 221 222 225 public void testRollbackUnion() throws Exception { 226 home.create("Ernest", null, null); 227 home.create("Simone", null, null); 228 home.create("Monette", "Ernest", "Simone"); 229 home.create("Sylvain", null, null); 230 utx.begin(); 231 home.union("Sylvain", "Monette"); 232 utx.rollback(); 233 People p3 = home.findByPrimaryKey("Monette"); 234 Assert.assertTrue("Monette not orphan", !p3.isOrphan()); 235 } 236 237 240 public void testRollbackDivorce() throws Exception { 241 home.create("Ernest", null, null); 242 home.create("Simone", null, null); 243 home.create("Monette", "Ernest", "Simone"); 244 home.create("Sylvain", null, null); 245 home.union("Sylvain", "Monette"); 246 People p3 = home.create("Philippe", "Sylvain", "Monette"); 247 People p1 = home.create("Sylvie", null, null); 248 home.union("Philippe", "Sylvie"); 249 utx.begin(); 250 home.divorce("Philippe", "Sylvie"); 251 utx.rollback(); 252 Assert.assertTrue("Philippe not orphan", !p3.isOrphan()); 253 Assert.assertTrue("Philippe not single", !p3.isSingle()); 254 Assert.assertTrue("Sylvie not single", !p1.isSingle()); 255 } 256 257 260 public void testDivorce() throws Exception { 261 home.create("Sylvain", null, null); 262 home.create("Simone", null, null); 263 People p2 = home.create("Philippe", "Sylvain", "Simone"); 264 People p6 = home.create("Pascale", "Sylvain", "Simone"); 265 People p5 = home.create("Sylvie", null, null); 266 People p4 = home.create("Catherine", null, null); 267 home.union("Philippe", "Sylvie"); 268 People p3 = home.create("Thomas", "Philippe", "Sylvie"); 269 home.divorce("Philippe", "Sylvie"); 270 People p1 = home.create("Nathan", "Philippe", "Catherine"); 271 Assert.assertTrue("Philippe single", p2.isSingle()); 272 Assert.assertTrue("Sylvie single", p5.isSingle()); 273 Assert.assertTrue("Nathan son of Philippe", p1.myFather().getName().equals("Philippe")); 274 Assert.assertTrue("Nathan son of Catherine", p1.myMother().getName().equals("Catherine")); 275 Assert.assertTrue("Nathan and Thomas", p3.brotherSisterOf("Nathan")); 276 Assert.assertTrue("Philippe and Pascale", p2.brotherSisterOf("Pascale")); 277 } 278 279 282 public void testRemoveRb() throws Exception { 283 home.create("Ernest", null, null); 284 home.create("Monette", "Ernest", null); 285 home.create("Philippe", null, "Monette"); 286 utx.begin(); 287 home.remove("Ernest"); 288 utx.rollback(); 289 People p2 = home.findByPrimaryKey("Monette"); 290 Assert.assertEquals("Monette's children", 1, p2.kidNumber()); 291 } 292 293 296 public void testRemoveRb2() throws Exception { 297 home.create("Ernest", null, null); 298 home.create("Monette", "Ernest", null); 299 home.create("Philippe", null, "Monette"); 300 utx.begin(); 301 home.remove("Monette"); 302 utx.rollback(); 303 People p2 = home.findByPrimaryKey("Monette"); 304 Assert.assertEquals("Monette's children", 1, p2.kidNumber()); 305 } 306 307 310 public void testRemoveRb3() throws Exception { 311 home.create("Ernest", null, null); 312 home.create("Monette", "Ernest", null); 313 home.create("Philippe", null, "Monette"); 314 utx.begin(); 315 home.remove("Philippe"); 316 utx.rollback(); 317 People p2 = home.findByPrimaryKey("Monette"); 318 Assert.assertEquals("Monette's children", 1, p2.kidNumber()); 319 } 320 321 325 public void testRemoveRbSync() throws Exception { 326 home.create("Ernest", null, null); 327 home.create("Monette", "Ernest", null); 328 home.create("Philippe", null, "Monette"); 329 sync(false); 330 utx.begin(); 331 home.remove("Ernest"); 332 utx.rollback(); 333 People p2 = home.findByPrimaryKey("Monette"); 334 Assert.assertEquals("Monette's children", 1, p2.kidNumber()); 335 } 336 337 341 public void testCreateHomeRB() throws Exception { 342 home.create("Lucien", null, null); 343 utx.begin(); 344 home.create("Odette", null, null); 345 home.union("Lucien", "Odette"); 346 utx.rollback(); 347 home.create("Odette", null, null); 348 } 349 350 357 public void test1920() throws Exception { 358 build1920(); 359 check1920(); 360 } 361 362 public void test1920co() throws Exception { 363 utx.begin(); 364 build1920(); 365 utx.commit(); 366 check1920(); 367 } 368 369 public void test1920rb() throws Exception { 370 utx.begin(); 371 build1920(); 372 utx.rollback(); 373 build1920(); 374 check1920(); 375 } 376 377 public void test1920rb1() throws Exception { 378 build1920(); 379 utx.begin(); 380 build1940(); 381 utx.rollback(); 382 check1920(); 383 } 384 385 public void test1920rb2() throws Exception { 386 build1920(); 387 utx.begin(); 388 build1940(); 389 build1960(); 390 build1980(); 391 build1990(); 392 utx.rollback(); 393 check1920(); 394 } 395 396 public void test1940() throws Exception { 397 build1920(); 398 build1940(); 399 check1940(); 400 } 401 402 public void test1940co() throws Exception { 403 utx.begin(); 404 build1920(); 405 build1940(); 406 utx.commit(); 407 check1940(); 408 } 409 410 public void test1940co2() throws Exception { 411 build1920(); 412 utx.begin(); 413 build1940(); 414 utx.commit(); 415 check1940(); 416 } 417 418 public void test1940rb() throws Exception { 419 build1920(); 420 build1940(); 421 utx.begin(); 422 build1960(); 423 utx.rollback(); 424 check1940(); 425 } 426 427 public void test1940rb2() throws Exception { 428 utx.begin(); 429 build1920(); 430 build1940(); 431 utx.commit(); 432 utx.begin(); 433 build1960(); 434 utx.rollback(); 435 check1940(); 436 } 437 438 public void test1940rb3() throws Exception { 439 build1920(); 440 utx.begin(); 441 build1940(); 442 utx.commit(); 443 utx.begin(); 444 build1960(); 445 build1980(); 446 build1990(); 447 utx.rollback(); 448 check1940(); 449 } 450 451 public void test1940rb4() throws Exception { 452 utx.begin(); 453 build1920(); 454 utx.rollback(); 455 build1920(); 456 check1920(); 457 utx.begin(); 458 build1940(); 459 utx.rollback(); 460 check1920(); 461 build1940(); 462 check1940(); 463 } 464 465 public void test1960() throws Exception { 466 build1920(); 467 build1940(); 468 build1960(); 469 check1960(); 470 } 471 472 public void test1960co() throws Exception { 473 utx.begin(); 474 build1920(); 475 build1940(); 476 build1960(); 477 utx.commit(); 478 check1960(); 479 } 480 481 public void test1960co1() throws Exception { 482 build1920(); 483 utx.begin(); 484 build1940(); 485 build1960(); 486 utx.commit(); 487 check1960(); 488 } 489 490 public void test1960co2() throws Exception { 491 build1920(); 492 utx.begin(); 493 build1940(); 494 utx.commit(); 495 build1960(); 496 check1960(); 497 } 498 499 public void test1960rb() throws Exception { 500 build1920(); 501 utx.begin(); 502 build1940(); 503 utx.commit(); 504 utx.begin(); 505 build1960(); 506 build1980(); 507 utx.rollback(); 508 build1960(); 509 check1960(); 510 } 511 512 public void test1960rb1() throws Exception { 513 build1920(); 514 build1940(); 515 build1960(); 516 utx.begin(); 517 build1980(); 518 utx.rollback(); 519 check1960(); 520 } 521 522 public void test1960rb2() throws Exception { 523 build1920(); 524 utx.begin(); 525 build1940(); 526 build1960(); 527 utx.commit(); 528 utx.begin(); 529 build1980(); 530 utx.rollback(); 531 check1960(); 532 } 533 534 public void test1960rb3() throws Exception { 535 utx.begin(); 536 build1920(); 537 build1940(); 538 utx.commit(); 539 build1960(); 540 utx.begin(); 541 build1980(); 542 utx.rollback(); 543 check1960(); 544 } 545 546 public void test1960rb4() throws Exception { 547 build1920(); 548 utx.begin(); 549 build1940(); 550 build1960(); 551 utx.commit(); 552 utx.begin(); 553 build1980(); 554 build1990(); 555 utx.rollback(); 556 check1960(); 557 } 558 559 public void test1980() throws Exception { 560 build1920(); 561 build1940(); 562 build1960(); 563 build1980(); 564 check1980(); 565 } 566 567 public void test1980co() throws Exception { 568 utx.begin(); 569 build1920(); 570 build1940(); 571 build1960(); 572 build1980(); 573 utx.commit(); 574 check1980(); 575 } 576 577 public void test1980co1() throws Exception { 578 build1920(); 579 build1940(); 580 utx.begin(); 581 build1960(); 582 utx.commit(); 583 build1980(); 584 check1980(); 585 } 586 587 public void test1980co2() throws Exception { 588 build1920(); 589 utx.begin(); 590 build1940(); 591 build1960(); 592 utx.commit(); 593 build1980(); 594 check1980(); 595 } 596 597 public void test1980rb() throws Exception { 598 build1920(); 599 build1940(); 600 build1960(); 601 build1980(); 602 utx.begin(); 603 build1990(); 604 utx.rollback(); 605 check1980(); 606 } 607 608 public void test1980rb2() throws Exception { 609 build1920(); 610 build1940(); 611 utx.begin(); 612 build1960(); 613 utx.commit(); 614 build1980(); 615 utx.begin(); 616 build1990(); 617 utx.rollback(); 618 check1980(); 619 } 620 621 public void test1980rb3() throws Exception { 622 build1920(); 623 utx.begin(); 624 build1940(); 625 build1960(); 626 build1980(); 627 utx.commit(); 628 utx.begin(); 629 build1990(); 630 utx.rollback(); 631 check1980(); 632 } 633 634 public void test1980rb4() throws Exception { 635 build1920(); 636 build1940(); 637 build1960(); 638 utx.begin(); 639 build1980(); 640 utx.commit(); 641 utx.begin(); 642 build1990(); 643 utx.rollback(); 644 check1980(); 645 } 646 647 public void test1980rb5() throws Exception { 648 build1920(); 649 build1940(); 650 build1960(); 651 build1980(); 652 utx.begin(); 653 build1990(); 654 build2000(); 655 utx.rollback(); 656 check1980(); 657 } 658 659 public void test1980rb5s() throws Exception { 660 build1920(); 661 build1940(); 662 build1960(); 663 build1980(); 664 sync(false); 665 utx.begin(); 666 build1990(); 667 build2000(); 668 utx.rollback(); 669 check1980(); 670 } 671 672 public void test1980rb5s2() throws Exception { 673 build1920(); 674 build1940(); 675 build1960(); 676 sync(false); 677 build1980(); 678 utx.begin(); 679 build1990(); 680 build2000(); 681 utx.rollback(); 682 check1980(); 683 } 684 685 public void test1980rb5s3() throws Exception { 686 build1920(); 687 build1940(); 688 build1960(); 689 build1980(); 690 utx.begin(); 691 build1990(); 692 sync(false); 693 build2000(); 694 utx.rollback(); 695 check1980(); 696 } 697 698 public void test1990() throws Exception { 699 build1920(); 700 build1940(); 701 build1960(); 702 build1980(); 703 build1990(); 704 check1990(); 705 } 706 707 public void test1990co() throws Exception { 708 utx.begin(); 709 build1920(); 710 build1940(); 711 build1960(); 712 build1980(); 713 build1990(); 714 utx.commit(); 715 check1990(); 716 } 717 718 public void test1990co1() throws Exception { 719 build1920(); 720 build1940(); 721 utx.begin(); 722 build1960(); 723 build1980(); 724 build1990(); 725 utx.commit(); 726 check1990(); 727 } 728 729 public void test1990co2() throws Exception { 730 build1920(); 731 utx.begin(); 732 build1940(); 733 build1960(); 734 utx.commit(); 735 build1980(); 736 build1990(); 737 check1990(); 738 } 739 740 public void test1990co3() throws Exception { 741 utx.begin(); 742 build1920(); 743 build1940(); 744 utx.commit(); 745 build1960(); 746 build1980(); 747 build1990(); 748 check1990(); 749 } 750 751 public void test1990rb() throws Exception { 752 build1920(); 753 build1940(); 754 build1960(); 755 build1980(); 756 build1990(); 757 utx.begin(); 758 build2000(); 759 utx.rollback(); 760 check1990(); 761 } 762 763 public void test1990rb2() throws Exception { 764 build1920(); 765 build1940(); 766 build1960(); 767 build1980(); 768 utx.begin(); 769 build1990(); 770 utx.commit(); 771 utx.begin(); 772 build2000(); 773 utx.rollback(); 774 check1990(); 775 } 776 777 public void test1990rb3() throws Exception { 778 build1920(); 779 build1940(); 780 utx.begin(); 781 build1960(); 782 build1980(); 783 utx.commit(); 784 build1990(); 785 utx.begin(); 786 build2000(); 787 utx.rollback(); 788 check1990(); 789 } 790 791 public void test2000() throws Exception { 792 build1920(); 793 build1940(); 794 build1960(); 795 build1980(); 796 build1990(); 797 build2000(); 798 check2000(); 799 } 800 801 public void test2000co() throws Exception { 802 utx.begin(); 803 build1920(); 804 build1940(); 805 build1960(); 806 build1980(); 807 build1990(); 808 build2000(); 809 utx.commit(); 810 check2000(); 811 } 812 813 public void test2000co2() throws Exception { 814 build1920(); 815 build1940(); 816 utx.begin(); 817 build1960(); 818 build1980(); 819 build1990(); 820 build2000(); 821 utx.commit(); 822 check2000(); 823 } 824 825 public void test2000co3() throws Exception { 826 build1920(); 827 build1940(); 828 utx.begin(); 829 build1960(); 830 build1980(); 831 build1990(); 832 utx.commit(); 833 build2000(); 834 check2000(); 835 } 836 837 public void test2000co4() throws Exception { 838 utx.begin(); 839 build1920(); 840 utx.commit(); 841 build1940(); 842 utx.begin(); 843 build1960(); 844 build1980(); 845 build1990(); 846 utx.commit(); 847 build2000(); 848 check2000(); 849 } 850 851 public void test2000co5() throws Exception { 852 utx.begin(); 853 build1920(); 854 utx.commit(); 855 build1940(); 856 build1960(); 857 utx.begin(); 858 build1980(); 859 utx.commit(); 860 build1990(); 861 build2000(); 862 check2000(); 863 } 864 865 869 public void vtestP1() throws Exception { 870 build1920(); 871 build1940(); 872 printAncestors(home.findByPrimaryKey("Sylvain")); 873 } 874 875 public void vtestP2() throws Exception { 876 build1920(); 877 build1940(); 878 build1960(); 879 printAncestors(home.findByPrimaryKey("Philippe")); 880 } 881 882 public void vtestP3() throws Exception { 883 build1920(); 884 build1940(); 885 build1960(); 886 build1980(); 887 printAncestors(home.findByPrimaryKey("Isabelle")); 888 } 889 890 894 private void build1920() throws Exception { 895 debug("Build 1920"); 896 home.create("Edouard", null, null); 897 home.create("Philomene", null, null); 898 home.create("Ernest", null, null); 899 home.create("Simone", null, null); 900 home.create("Lucienne", null, null); 901 } 902 903 private void check1920() throws Exception { 904 debug("Check 1920"); 905 People p1 = home.findByPrimaryKey("Edouard"); 906 Assert.assertTrue("Edouard is single", p1.isSingle()); 907 People p2 = home.findByPrimaryKey("Ernest"); 908 Assert.assertTrue("Ernest is single", p2.isSingle()); 909 People p3 = home.findByPrimaryKey("Philomene"); 910 Assert.assertTrue("Philomene is single", p3.isSingle()); 911 People p4 = home.findByPrimaryKey("Simone"); 912 Assert.assertTrue("Simone is single", p4.isSingle()); 913 } 914 915 916 private void build1940() throws Exception { 917 debug("Build 1940"); 918 home.union("Edouard", "Philomene"); 919 home.union("Ernest", "Simone"); 920 home.create("Edouard2", "Edouard", "Philomene"); 921 home.create("Genevieve", null, null); 922 home.create("Odette", "Edouard", "Philomene"); 923 home.create("Lucien", null, null); 924 home.create("Blanche", "Edouard", "Philomene"); 925 home.create("Paul", null, null); 926 home.create("Sylvain", "Edouard", "Philomene"); 927 home.create("Tines", "Ernest", "Simone"); 928 home.create("Suzanne", null, null); 929 home.create("Monette", "Ernest", "Simone"); 930 home.create("Francis", null, null); 931 home.create("Marose", "Ernest", "Simone"); 932 } 933 934 private void check1940() throws Exception { 935 debug("Check 1940"); 936 People p1 = home.findByPrimaryKey("Edouard"); 937 People p2 = p1.mySpouse(); 938 People p3 = home.findByPrimaryKey("Ernest"); 939 People p4 = p3.mySpouse(); 940 Assert.assertTrue("Edouard is married", p2.getName().equals("Philomene")); 941 Assert.assertTrue("Philomene is married", p2.mySpouse().getName().equals("Edouard")); 942 Assert.assertEquals("Simone's children", 3, p4.kidNumber()); 943 } 944 945 private void build1960() throws Exception { 946 debug("Build 1960"); 947 home.create("Pierre", "Ernest", "Simone"); 948 home.union("Lucien", "Odette"); 949 home.union("Paul", "Blanche"); 950 home.union("Sylvain", "Monette"); 951 home.union("Tines", "Suzanne"); 952 home.union("Francis", "Marose"); 953 home.create("Jean Paul", null, null); 954 home.create("Chantal", "Edouard2", "Genevieve"); 955 home.create("Daniel", "Lucien", "Odette"); 956 home.create("Genevieve2", "Edouard2", "Genevieve"); 957 home.create("Marie Paule", "Paul", "Blanche"); 958 home.create("Emmanuel", null, null); 959 home.create("Dominique", null, null); 960 home.create("Philippe", "Sylvain", "Monette"); 961 home.create("Michel", "Edouard2", "Genevieve"); 962 home.create("Pascale", "Sylvain", "Monette"); 963 home.create("Veronique", "Francis", "Marose"); 964 home.create("Francois", "Tines", "Suzanne"); 965 home.create("Monique", null, null); 966 home.create("Roch", null, null); 967 home.create("Florence", "Francis", "Marose"); 968 home.create("Sylvie", null, null); 969 home.create("Catherine", null, "Lucienne"); 970 } 971 972 private void check1960() throws Exception { 973 debug("Check 1960"); 974 People p1 = home.findByPrimaryKey("Ernest"); 975 People p2 = home.findByPrimaryKey("Monette"); 976 People p3 = home.findByPrimaryKey("Francois"); 977 Assert.assertTrue("Monette is married", p2.mySpouse().getName().equals("Sylvain")); 978 Assert.assertEquals("Monette's children", 2, p2.kidNumber()); 979 Assert.assertTrue("Monette has a father", p2.myFather().getName().equals("Ernest")); 980 Assert.assertTrue("Francois has a mother", p3.myMother().getName().equals("Suzanne")); 981 } 982 983 private void build1980() throws Exception { 984 debug("Build 1980"); 985 home.create("Thierry", "Tines", "Suzanne"); 986 home.create("Valerie", "Francis", "Marose"); 987 home.create("Jerome", "Francis", "Marose"); 988 home.union("Pierre", "Chantal"); 989 home.remove("Edouard"); 990 home.remove("Philomene"); 991 home.remove("Simone"); 992 home.union("Jean Paul", "Veronique"); 993 home.union("Dominique", "Genevieve2"); 994 home.create("Isabelle", "Pierre", "Chantal"); 995 home.create("Wilfried", "Pierre", "Chantal"); 996 home.union("Roch", "Florence"); 997 } 998 999 private void check1980() throws Exception { 1000 debug("Check 1980"); 1001 People p1 = home.findByPrimaryKey("Marose"); 1002 People p2 = home.findByPrimaryKey("Sylvain"); 1003 People p3 = home.findByPrimaryKey("Philippe"); 1004 People p4 = home.findByPrimaryKey("Jerome"); 1005 People p5 = home.findByPrimaryKey("Ernest"); 1006 Assert.assertEquals("Marose's children", 4, p1.kidNumber()); 1007 Assert.assertTrue("Sylvain is orphan", p2.isOrphan()); 1008 Assert.assertTrue("Philippe and Pascale", p3.brotherSisterOf("Pascale")); 1009 Assert.assertTrue("Jerome and Veronique", p4.brotherSisterOf("Veronique")); 1010 Assert.assertTrue("Ernest single", p5.isSingle()); 1011 } 1012 1013 private void build1990() throws Exception { 1014 debug("Build 1990"); 1015 home.union("Emmanuel", "Pascale"); 1016 home.union("Philippe", "Sylvie"); 1017 home.union("Francois", "Monique"); 1018 home.create("Lucie", "Jean Paul", "Veronique"); 1019 home.create("Amandine", "Emmanuel", "Pascale"); 1020 home.create("Julien", "Emmanuel", "Pascale"); 1021 home.create("Thomas", "Philippe", "Sylvie"); 1022 home.create("Florent", "Philippe", "Sylvie"); 1023 home.create("Fanny", "Emmanuel", "Pascale"); 1024 home.divorce("Roch", "Florence"); 1025 home.create("Charles Guillaume", "Francois", "Monique"); 1026 home.create("Pierre Olivier", "Francois", "Monique"); 1027 } 1028 1029 private void check1990() throws Exception { 1030 debug("Check 1990"); 1031 People p2 = home.findByPrimaryKey("Monette"); 1032 People p3 = home.findByPrimaryKey("Pascale"); 1033 Assert.assertEquals("Monette's children", 2, p2.kidNumber()); 1034 Assert.assertEquals("Pascale's children", 3, p3.kidNumber()); 1035 } 1036 1037 private void build2000() throws Exception { 1038 debug("Build 2000"); 1039 home.divorce("Philippe", "Sylvie"); 1040 home.divorce("Jean Paul", "Veronique"); 1041 home.remove("Ernest"); 1042 home.create("Nathan", "Philippe", "Catherine"); 1043 } 1044 1045 private void check2000() throws Exception { 1046 debug("Check 2000"); 1047 People p1 = home.findByPrimaryKey("Nathan"); 1048 People p2 = home.findByPrimaryKey("Philippe"); 1049 People p3 = home.findByPrimaryKey("Thomas"); 1050 People p4 = home.findByPrimaryKey("Catherine"); 1051 People p5 = home.findByPrimaryKey("Sylvie"); 1052 People p6 = home.findByPrimaryKey("Pascale"); 1053 People p7 = home.findByPrimaryKey("Monette"); 1054 Assert.assertTrue("Philippe single", p2.isSingle()); 1055 Assert.assertTrue("Sylvie single", p5.isSingle()); 1056 Assert.assertTrue("Nathan son of Philippe", p1.myFather().getName().equals("Philippe")); 1057 Assert.assertTrue("Nathan son of Catherine", p1.myMother().getName().equals("Catherine")); 1058 Assert.assertTrue("Nathan and Thomas", p3.brotherSisterOf("Nathan")); 1059 Assert.assertTrue("Monette orphan", p7.isOrphan()); 1060 Assert.assertTrue("Philippe and Pascale", p2.brotherSisterOf("Pascale")); 1061 } 1062 1063 private void printParents(People p) throws Exception { 1064 People father = p.myFather(); 1065 People mother = p.myMother(); 1066 System.out.print(p.getName() + "\t--->\t"); 1067 System.out.print(father != null ? father.getName() : "-"); 1068 System.out.print("\t"); 1069 System.out.println(mother != null ? mother.getName() : "-"); 1070 } 1071 1072 private void printAncestors(People p) throws Exception { 1073 if (p != null) { 1074 printParents(p); 1075 printAncestors(p.myFather()); 1076 printAncestors(p.myMother()); 1077 } 1078 } 1079 1080 protected static void callTest(String testname) throws Exception { 1081 JTestCase.callTest("entity.F_FamilyEC2", testname); 1082 } 1083 1084 1087 protected static void perfs() throws Exception { 1088 callTest("testEmpty"); 1089 callTest("test1920"); 1090 callTest("test1940"); 1091 callTest("test1960"); 1092 callTest("test1980"); 1093 callTest("test1990"); 1094 callTest("test2000"); 1095 callTest("test1920co"); 1096 callTest("test1940co"); 1097 callTest("test1960co"); 1098 callTest("test1980co"); 1099 callTest("test1990co"); 1100 callTest("test2000co"); 1101 } 1102 1103 1107 public static Test suite2() { 1108 TestSuite suite = new TestSuite(); 1109 suite.addTest(new F_FamilyEC2("testF6")); 1110 suite.addTest(new F_FamilyEC2("testF8")); 1111 suite.addTest(new F_FamilyEC2("testF9")); 1112 suite.addTest(new F_FamilyEC2("testF10")); 1113 return suite; 1114 } 1115 1116 1119 public static Test suite1() { 1120 TestSuite suite = new TestSuite(); 1121 suite.addTest(new F_FamilyEC2("testF11")); 1122 suite.addTest(new F_FamilyEC2("testF12")); 1123 suite.addTest(new F_FamilyEC2("testF13")); 1124 suite.addTest(new F_FamilyEC2("testF14")); 1125 suite.addTest(new F_FamilyEC2("testF15")); 1126 suite.addTest(new F_FamilyEC2("testF16")); 1127 suite.addTest(new F_FamilyEC2("testF17")); 1128 suite.addTest(new F_FamilyEC2("testF18")); 1129 suite.addTest(new F_FamilyEC2("testF19")); 1130 return suite; 1131 } 1132 1133 1136 public static Test suite() { 1137 return new TestSuite(F_FamilyEC2.class); 1138 } 1139 1140 public static void main(String args[]) throws Exception { 1141 String testtorun = null; 1142 1143 for (int argn = 0; argn < args.length; argn++) { 1145 String sarg = args[argn]; 1146 if (sarg.equals("-n")) { 1147 testtorun = args[++argn]; 1148 } 1149 } 1150 if (testtorun == null) { 1151 junit.textui.TestRunner.run(suite()); 1152 } else { 1153 if (testtorun.equals("perfs")) { 1154 perfs(); 1155 } else if (testtorun.equals("suite1")) { 1156 junit.textui.TestRunner.run(suite1()); 1157 } else if (testtorun.equals("suite2")) { 1158 junit.textui.TestRunner.run(suite2()); 1159 } else { 1160 junit.textui.TestRunner.run(new F_FamilyEC2(testtorun)); 1161 } 1162 } 1163 } 1164 1165} 1166 | Popular Tags |