1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import junit.framework.Test; 29 import junit.framework.TestSuite; 30 import javax.naming.NamingException ; 31 import javax.rmi.PortableRemoteObject ; 32 import java.util.ArrayList ; 33 import java.util.Collection ; 34 import java.util.Enumeration ; 35 import java.util.Hashtable ; 36 import java.util.Iterator ; 37 38 import org.objectweb.jonas.jtests.beans.relation.omu.AHomeRemote; 39 import org.objectweb.jonas.jtests.beans.relation.omu.ARemote; 40 import org.objectweb.jonas.jtests.beans.relation.omu.BHomeRemote; 41 import org.objectweb.jonas.jtests.beans.relation.omu.BRemote; 42 43 44 48 49 public class F_Relation_omuEC2 extends A_Cmp2Util { 50 51 52 private static String BEAN_HOME_A = "relation_omu_AHome"; 53 protected static AHomeRemote ahome = null; 54 private static String BEAN_HOME_B = "relation_omu_BHome"; 55 protected static BHomeRemote bhome = null; 56 57 static Hashtable tbRelationA2B = new Hashtable (); 58 59 static { 60 tbRelationA2B.put("as0", new String []{}); 61 tbRelationA2B.put("as1", new String []{"bs1_1"}); 62 tbRelationA2B.put("as2", new String []{"bs2_1", "bs2_2", "bs2_3"}); 63 tbRelationA2B.put("a0", new String []{}); 64 tbRelationA2B.put("a1", new String []{"b1_1", "b1_2", "b1_3"}); 65 tbRelationA2B.put("a2", new String []{"b2_1", "b2_2", "b2_3"}); 66 tbRelationA2B.put("a3", new String []{"b3_1"}); 67 for (Enumeration ea = tbRelationA2B.keys(); ea.hasMoreElements();) { 69 String aname = (String ) (ea.nextElement()); 70 String [] tb = (String []) tbRelationA2B.get(aname); 71 ArrayList col = new ArrayList (tb.length); 72 for (int i = 0; i < tb.length; i++) { 73 col.add(tb[i]); 74 } 75 tbRelationA2B.put(aname, col); 76 } 77 } 78 79 public F_Relation_omuEC2(String name) { 80 super(name); 81 debug("F_Relation_omuEC2("+name+")"); 82 } 83 84 protected static boolean isInit = false; 85 86 protected void setUp() { 87 super.setUp(); 88 boolean ok = false; 89 int nbtry = 0; 90 while (!ok && nbtry < 3) { 91 if (!isInit) { 92 useBeans("omu", true); 94 try { 95 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A), 96 AHomeRemote.class); 97 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B), 98 BHomeRemote.class); 99 } catch (NamingException e) { 100 fail("Cannot get bean home: " + e.getMessage()); 101 } 102 try { 104 ahome.findByPrimaryKey("a0"); 105 } catch (Exception e) { 106 try { 107 utx.begin(); 108 bhome.create("bs0"); 109 bhome.create("bs1_1"); 110 bhome.create("bs2_1"); 111 bhome.create("bs2_2"); 112 bhome.create("bs2_3"); 113 bhome.create("bs3"); 114 bhome.create("b0"); 115 bhome.create("b1_1"); 116 bhome.create("b1_2"); 117 bhome.create("b1_3"); 118 bhome.create("b2_1"); 119 bhome.create("b2_2"); 120 bhome.create("b2_3"); 121 bhome.create("b3_1"); 122 ARemote as0 = ahome.create("as0"); 123 ARemote as1 = ahome.create("as1"); 124 ARemote as2 = ahome.create("as2"); 125 ARemote a0 = ahome.create("a0"); 126 ARemote a1 = ahome.create("a1"); 127 ARemote a2 = ahome.create("a2"); 128 ARemote a3 = ahome.create("a3"); 129 as1.assignB((Collection )tbRelationA2B.get("as1")); 130 as2.assignB((Collection )tbRelationA2B.get("as2")); 131 a1.assignB((Collection )tbRelationA2B.get("a1")); 132 a2.assignB((Collection )tbRelationA2B.get("a2")); 133 a3.assignB((Collection )tbRelationA2B.get("a3")); 134 } catch (Exception i) { 135 fail("InitialState creation problem:: "+i); 136 } finally { 137 try { 138 utx.commit(); 139 } catch (Exception ii) { 140 } 141 } 142 } 143 isInit = true; 144 } 145 nbtry++; 148 try { 149 if (initStateOK()) { 150 ok = true; 151 } 152 } catch (Exception e) { 153 } 154 if (!ok) { 155 isInit = false; 156 unloadBeans("omu"); 157 } 158 } 159 } 160 161 165 boolean initStateOK() throws Exception { 166 boolean isOk = true; 167 msgerror = new StringBuffer (); 168 for (Enumeration ea = tbRelationA2B.keys(); ea.hasMoreElements();) { 169 String aname = (String ) (ea.nextElement()); 170 ARemote a = ahome.findByPrimaryKey(aname); 171 Collection colActual = a.retrieveB(); 172 ArrayList colExpected = (ArrayList ) (tbRelationA2B.get(aname)); 173 debug("Relation for " + aname + " :: expected:" + colExpected + ", found:" + colActual ); 174 if (!isCollectionEqual(colExpected, colActual)) { 175 isOk = false; 176 msgerror = msgerror.append("Wrong relation for " + aname 177 + " (expected:" + colExpected 178 + ", found:" + colActual + ")"); 179 } 180 } 181 return isOk; 182 } 183 184 187 public void testReadA() throws Exception { 188 Collection c = ahome.findAll(); 189 for (Iterator i = c.iterator(); i.hasNext(); ) { 190 ARemote a = (ARemote) PortableRemoteObject.narrow(i.next(), ARemote.class); 191 String n = a.getId(); 192 } 193 } 194 195 198 public void _testBasicGetEmpty(int tx) throws Exception { 199 Collection c = null; 200 if ((tx == TX_CALL) || (tx == TX_RB)) { 201 utx.begin(); 202 } 203 ARemote a = ahome.findByPrimaryKey("as0"); 204 if (tx == TX_CONT) { 205 c = a.retrieveBInNewTx(); 206 } else { 207 c = a.retrieveB(); 208 } 209 if (tx == TX_CALL) { 210 utx.commit(); 211 } else if (tx == TX_RB) { 212 utx.rollback(); 213 } 214 checkIsInitialState(); 215 } 216 217 public void testBasicGetEmptyTxNo() throws Exception { 218 _testBasicGetEmpty(TX_NO); 219 } 220 221 public void testBasicGetEmptyTxCall() throws Exception { 222 _testBasicGetEmpty(TX_CALL); 223 } 224 225 public void testBasicGetEmptyTxCont() throws Exception { 226 _testBasicGetEmpty(TX_CONT); 227 } 228 229 232 public void _testBasicGetOne(int tx) throws Exception { 233 234 Collection c = null; 235 if ((tx == TX_CALL) || (tx == TX_RB)) { 236 utx.begin(); 237 } 238 ARemote a = ahome.findByPrimaryKey("as1"); 239 if (tx == TX_CONT) { 240 c = a.retrieveBInNewTx(); 241 } else { 242 c = a.retrieveB(); 243 } 244 if (tx == TX_CALL) { 245 utx.commit(); 246 } else if (tx == TX_RB) { 247 utx.rollback(); 248 } 249 assertEquals("Wrong relations size for as1: ", 1, c.size()); 251 String s = "bs1_1"; 252 assertTrue("Relation missing " + s + " for as1: ", c.contains(s)); 253 checkIsInitialState(); 254 } 255 256 public void testBasicGetOneTxNo() throws Exception { 257 _testBasicGetOne(TX_NO); 258 } 259 260 public void testBasicGetOneTxCall() throws Exception { 261 _testBasicGetOne(TX_CALL); 262 } 263 264 public void testBasicGetOneTxCont() throws Exception { 265 _testBasicGetOne(TX_CONT); 266 } 267 268 public void testBasicGetOneTxRb() throws Exception { 269 _testBasicGetOne(TX_RB); 270 } 271 272 275 public void _testBasicGetMany(int tx) throws Exception { 276 277 Collection c = null; 278 if ((tx == TX_CALL) || (tx == TX_RB)) { 279 utx.begin(); 280 } 281 ARemote a = ahome.findByPrimaryKey("as2"); 282 if (tx == TX_CONT) { 283 c = a.retrieveBInNewTx(); 284 } else { 285 c = a.retrieveB(); 286 } 287 if (tx == TX_CALL) { 288 utx.commit(); 289 } else if (tx == TX_RB) { 290 utx.rollback(); 291 } 292 assertEquals("Relations size of: ", 3, c.size()); 294 String s = "bs2_1"; 295 assertTrue("Relation missing " + s + ": ", c.contains(s)); 296 s = "bs2_2"; 297 assertTrue("Relation missing " + s + ": ", c.contains(s)); 298 s = "bs2_3"; 299 assertTrue("Relation missing " + s + ": ", c.contains(s)); 300 checkIsInitialState(); 301 } 302 303 public void testBasicGetManyTxNo() throws Exception { 304 _testBasicGetMany(TX_NO); 305 } 306 307 public void testBasicGetManyTxCall() throws Exception { 308 _testBasicGetMany(TX_CALL); 309 } 310 311 public void testBasicGetManyTxCont() throws Exception { 312 _testBasicGetMany(TX_CONT); 313 } 314 315 316 321 public void _testBasicSetEmpty(int tx) throws Exception { 322 ArrayList ce = new ArrayList (); 323 if ((tx == TX_CALL) || (tx == TX_RB)) { 324 utx.begin(); 325 } 326 ARemote a = ahome.findByPrimaryKey("as1"); 327 if (tx == TX_CONT) { 328 a.assignBInNewTx(ce); 329 } else { 330 a.assignB(ce); 331 } 332 if (tx == TX_CALL) { 333 utx.commit(); 334 } else if (tx == TX_RB) { 335 utx.rollback(); 336 } 337 Collection ca = a.retrieveB(); 339 if (tx != TX_RB) { 340 assertEquals("Relations size of: ", 0, ca.size()); 341 } else { 342 assertEquals("Relations size of: ", 1, ca.size()); 343 } 344 if (tx != TX_RB) { 346 a.addInB("bs1_1"); 347 ca = a.retrieveB(); 349 assertEquals("After undo, Relations size of: ", 1, ca.size()); 350 } 351 checkIsInitialState(); 352 } 353 354 public void testBasicSetEmptyTxNo() throws Exception { 355 _testBasicSetEmpty(TX_NO); 356 } 357 358 public void testBasicSetEmptyTxCall() throws Exception { 359 _testBasicSetEmpty(TX_CALL); 360 } 361 362 public void testBasicSetEmptyTxCont() throws Exception { 363 _testBasicSetEmpty(TX_CONT); 364 } 365 366 public void testBasicSetEmptyTxRb() throws Exception { 367 _testBasicSetEmpty(TX_RB); 368 } 369 370 371 376 public void _testBasicClear(int tx) throws Exception { 377 ArrayList ce = new ArrayList (); 378 if ((tx == TX_CALL) || (tx == TX_RB)) { 379 utx.begin(); 380 } 381 ARemote a = ahome.findByPrimaryKey("as1"); 382 if (tx == TX_CONT) { 383 a.clearBInNewTx(); 384 } else { 385 a.clearB(); 386 } 387 if (tx == TX_CALL) { 388 utx.commit(); 389 } else if (tx == TX_RB) { 390 utx.rollback(); 391 } 392 Collection ca = a.retrieveB(); 394 if (tx != TX_RB) { 395 assertEquals("Relations size of: ", 0, ca.size()); 396 } else { 397 assertEquals("Relations size of: ", 1, ca.size()); 398 } 399 if (tx != TX_RB) { 401 a.addInB("bs1_1"); 402 ca = a.retrieveB(); 404 assertEquals("After undo, Relations size of: ", 1, ca.size()); 405 } 406 checkIsInitialState(); 407 } 408 409 public void testBasicClearTxNo() throws Exception { 410 _testBasicClear(TX_NO); 411 } 412 413 public void testBasicClearTxCall() throws Exception { 414 _testBasicClear(TX_CALL); 415 } 416 417 public void testBasicClearTxCont() throws Exception { 418 _testBasicClear(TX_CONT); 419 } 420 421 public void testBasicClearTxRb() throws Exception { 422 _testBasicClear(TX_RB); 423 } 424 425 426 432 public void _testBasicSetOne(int tx) throws Exception { 433 ArrayList ce = new ArrayList (); 434 ce.add("b0"); 435 if ((tx == TX_CALL) || (tx == TX_RB)) { 436 utx.begin(); 437 } 438 ARemote a = ahome.findByPrimaryKey("as0"); 439 if (tx == TX_CONT) { 440 a.assignBInNewTx(ce); 441 } else { 442 a.assignB(ce); 443 } 444 if (tx == TX_CALL) { 445 utx.commit(); 446 } else if (tx == TX_RB) { 447 utx.rollback(); 448 } 449 Collection ca = a.retrieveB(); 451 if (tx != TX_RB) { 452 assertTrue("Wrong relations as0 (required:" + ce + ", found:" + ca 453 + ")", isCollectionEqual(ce, ca)); 454 } else { 455 assertEquals("Relations size of: ", 0, ca.size()); 456 } 457 if (tx != TX_RB) { 459 a.assignB(new ArrayList ()); 460 ca = a.retrieveB(); 462 assertEquals("After undo, Relations size of: ", 0, ca.size()); 463 } 464 checkIsInitialState(); 465 } 466 467 public void testBasicSetOneTxNo() throws Exception { 468 _testBasicSetOne(TX_NO); 469 } 470 471 public void testBasicSetOneTxCall() throws Exception { 472 _testBasicSetOne(TX_CALL); 473 } 474 475 public void testBasicSetOneTxCont() throws Exception { 476 _testBasicSetOne(TX_CONT); 477 } 478 479 public void testBasicSetOneTxRb() throws Exception { 480 _testBasicSetOne(TX_RB); 481 } 482 483 484 491 public void _testBasicAddOne(int tx) throws Exception { 492 ArrayList ce = new ArrayList (); 493 ce.add("bs0"); 494 if ((tx == TX_CALL) || (tx == TX_RB)) { 495 utx.begin(); 496 } 497 ARemote a = ahome.findByPrimaryKey("as0"); 498 if (tx == TX_CONT) { 499 a.addInBInNewTx("bs0"); 500 } else { 501 a.addInB("bs0"); 502 } 503 if (tx == TX_CALL) { 504 utx.commit(); 505 } else if (tx == TX_RB) { 506 utx.rollback(); 507 } 508 Collection ca = a.retrieveB(); 510 if (tx != TX_RB) { 511 assertTrue("Wrong relations as0 (required:" + ce + ", found:" + ca 512 + ")", isCollectionEqual(ce, ca)); 513 } else { 514 assertEquals("Relations size of: ", 0, ca.size()); 515 } 516 if (tx != TX_RB) { 518 a.assignB(new ArrayList ()); 519 ca = a.retrieveB(); 521 assertEquals("After undo, Relations size of: ", 0, ca.size()); 522 } 523 checkIsInitialState(); 524 } 525 526 public void testBasicAddOneTxNo() throws Exception { 527 _testBasicAddOne(TX_NO); 528 } 529 530 public void testBasicAddOneTxCall() throws Exception { 531 _testBasicAddOne(TX_CALL); 532 } 533 534 public void testBasicAddOneTxCont() throws Exception { 535 _testBasicAddOne(TX_CONT); 536 } 537 538 public void testBasicAddOneTxRb() throws Exception { 539 _testBasicAddOne(TX_RB); 540 } 541 542 543 553 public void _testBasicSetMulti(int tx) throws Exception { 554 ArrayList ce = new ArrayList (2); 555 ce.add("bs0"); 556 ce.add("bs3"); 557 if ((tx == TX_CALL) || (tx == TX_RB)) { 558 utx.begin(); 559 } 560 ARemote a = ahome.findByPrimaryKey("as1"); 561 Collection co = a.retrieveB(); 562 if (tx == TX_CONT) { 563 a.assignBInNewTx(ce); 564 } else { 565 a.assignB(ce); 566 } 567 if (tx == TX_CALL) { 568 utx.commit(); 569 } else if (tx == TX_RB) { 570 utx.rollback(); 571 } 572 Collection ca = a.retrieveB(); 574 if (tx != TX_RB) { 575 assertTrue("Wrong relations as1 (required:" + ce + ", found:" + ca 576 + ")", isCollectionEqual(ce, ca)); 577 } else { 578 assertTrue("Wrong relations as1 (required:" + co + ", found:" + ca 579 + ")", isCollectionEqual(co, ca)); 580 } 581 if (tx != TX_RB) { 583 a.assignB(co); 584 ca = a.retrieveB(); 586 assertTrue("After undo, wrong relations: ", isCollectionEqual(co, ca)); 587 } 588 checkIsInitialState(); 589 } 590 591 public void testBasicSetMultiTxNo() throws Exception { 592 _testBasicSetMulti(TX_NO); 593 } 594 595 public void testBasicSetMultiTxCall() throws Exception { 596 _testBasicSetMulti(TX_CALL); 597 } 598 599 public void testBasicSetMultiTxCont() throws Exception { 600 _testBasicSetMulti(TX_CONT); 601 } 602 603 public void testBasicSetMultiTxRb() throws Exception { 604 _testBasicSetMulti(TX_RB); 605 } 606 607 608 615 public void _testBasicAddMulti(int tx) throws Exception { 616 ArrayList ce = (ArrayList ) tbRelationA2B.get("as1"); 617 if ((tx == TX_CALL) || (tx == TX_RB)) { 618 utx.begin(); 619 } 620 ARemote a = ahome.findByPrimaryKey("as1"); 621 if (tx == TX_CONT) { 622 a.addInBInNewTx("bs0"); 623 } else { 624 a.addInB("bs0"); 625 } 626 ce.add("bs0"); 627 if (tx == TX_CALL) { 628 utx.commit(); 629 } else if (tx == TX_RB) { 630 utx.rollback(); 631 } 632 Collection ca = a.retrieveB(); 634 if (tx == TX_RB) 635 ce.remove("bs0"); 636 try { 637 assertTrue( 638 "Wrong relations as1 (required:" + ce + ", found:" + ca + ")", 639 isCollectionEqual(ce, ca)); 640 } finally { 641 if (tx != TX_RB) 642 ce.remove("bs0"); 643 } 644 if (tx != TX_RB) { 646 a.removeFromB("bs0"); 647 ca = a.retrieveB(); 649 assertTrue("After undo, wrong relations: (required:" + tbRelationA2B.get("as1") + ", found:" + ca 650 + ")", isCollectionEqual((Collection ) tbRelationA2B.get("as1"), ca)); 651 } 652 checkIsInitialState(); 653 } 654 655 public void testBasicAddMultiTxNo() throws Exception { 656 _testBasicAddMulti(TX_NO); 657 } 658 659 public void testBasicAddMultiTxCall() throws Exception { 660 _testBasicAddMulti(TX_CALL); 661 } 662 663 public void testBasicAddMultiTxCont() throws Exception { 664 _testBasicAddMulti(TX_CONT); 665 } 666 667 public void testBasicAddMultiTxRb() throws Exception { 668 _testBasicAddMulti(TX_RB); 669 } 670 671 679 public void _testBasicRemoveInRel(int tx) throws Exception { 680 String bRemoved = "b3_1"; 681 if ((tx == TX_CALL) || (tx == TX_RB)) { 682 utx.begin(); 683 } 684 ARemote a = ahome.findByPrimaryKey("a3"); 685 if (tx == TX_CONT) { 686 a.removeFromBInNewTx(bRemoved); 687 } else { 688 a.removeFromB(bRemoved); 689 } 690 if (tx == TX_CALL) { 691 utx.commit(); 692 } else if (tx == TX_RB) { 693 utx.rollback(); 694 } 695 Collection ca = a.retrieveB(); 697 if (tx != TX_RB) { 698 assertEquals("Wrong relations size for a3: ", 0, ca.size()); 699 } else { 700 assertEquals("Wrong relations size for a3: ", 1, ca.size()); 701 } 702 703 if (tx != TX_RB) { 705 a.addInB(bRemoved); 706 } 707 checkIsInitialState(); 709 710 } 711 712 public void testBasicRemoveInRelTxNo() throws Exception { 713 _testBasicRemoveInRel(TX_NO); 714 } 715 716 public void testBasicRemoveInRelTxCall() throws Exception { 717 _testBasicRemoveInRel(TX_CALL); 718 } 719 720 public void testBasicRemoveInRelTxCont() throws Exception { 721 _testBasicRemoveInRel(TX_CONT); 722 } 723 724 public void testBasicRemoveInRelTxRb() throws Exception { 725 _testBasicRemoveInRel(TX_RB); 726 } 727 728 729 735 public void _testCohRemove(int tx) throws Exception { 736 if (tx == TX_CONT) { 737 fail("Transaction cannot be initiate by the container for this test"); 740 } 741 String bRemoved = "b3_1"; 742 if ((tx == TX_CALL) || (tx == TX_RB)) { 743 utx.begin(); 744 } 745 bhome.remove(bRemoved); 746 if (tx == TX_CALL) { 747 utx.commit(); 748 } else if (tx == TX_RB) { 749 utx.rollback(); 750 } 751 ARemote a = ahome.findByPrimaryKey("a3"); 753 Collection ca = a.retrieveB(); 754 if (tx != TX_RB) { 755 assertEquals("Wrong relations size for a3: ", 0, ca.size()); 756 757 bhome.create(bRemoved); 759 a.addInBInNewTx(bRemoved); 760 } else { 761 assertEquals("Wrong relations size for a3: ", 1, ca.size()); 762 } 763 checkIsInitialState(); 765 } 766 767 public void testCohRemoveTxNo() throws Exception { 768 _testCohRemove(TX_NO); 769 } 770 771 public void testCohRemoveTxCall() throws Exception { 772 _testCohRemove(TX_CALL); 773 } 774 775 public void testCohRemoveTxRb() throws Exception { 776 _testCohRemove(TX_RB); 777 } 778 779 780 788 public void _testCohBeanRemove(int tx) throws Exception { 789 if (tx == TX_CONT) { 790 fail("Transaction cannot be initiate by the container for this test"); 793 } 794 String bRemoved = "b3_1"; 795 if ((tx == TX_CALL) || (tx == TX_RB)) { 796 utx.begin(); 797 } 798 BRemote b = bhome.findByPrimaryKey(bRemoved); 799 b.remove(); 800 if (tx == TX_CALL) { 801 utx.commit(); 802 } else if (tx == TX_RB) { 803 utx.rollback(); 804 } 805 ARemote a = ahome.findByPrimaryKey("a3"); 807 Collection ca = a.retrieveB(); 808 if (tx != TX_RB) { 809 assertEquals("Wrong relations size for a3: ", 0, ca.size()); 810 811 bhome.create(bRemoved); 813 a.addInBInNewTx(bRemoved); 814 } else { 815 assertEquals("Wrong relations size for a3: ", 1, ca.size()); 816 } 817 checkIsInitialState(); 819 } 820 821 public void testCohBeanRemoveTxNo() throws Exception { 822 _testCohBeanRemove(TX_NO); 823 } 824 825 public void testCohBeanRemoveTxCall() throws Exception { 826 _testCohBeanRemove(TX_CALL); 827 } 828 829 public void testCohBeanRemoveTxRb() throws Exception { 830 _testCohBeanRemove(TX_RB); 831 } 832 833 834 843 public void _testCohSetOne(int tx) throws Exception { 844 ArrayList ce = new ArrayList (); 845 String bAdded = "b3_1"; 846 ce.add(bAdded); 847 if ((tx == TX_CALL) || (tx == TX_RB)) { 848 utx.begin(); 849 } 850 ARemote a = ahome.findByPrimaryKey("a0"); 851 if (tx == TX_CONT) { 852 a.assignBInNewTx(ce); 853 } else { 854 a.assignB(ce); 855 } 856 if (tx == TX_CALL) { 857 utx.commit(); 858 } else if (tx == TX_RB) { 859 utx.rollback(); 860 } 861 Collection ca = a.retrieveB(); 863 ARemote a3 = ahome.findByPrimaryKey("a3"); 864 Collection ca3 = a3.retrieveB(); 865 if (tx != TX_RB) { 866 assertTrue("Wrong relations a0 (required:" + ce + ", found:" + ca 867 + ")", isCollectionEqual(ce, ca)); 868 assertTrue("Wrong relations for " + bAdded + ": found:" + ca3 , 869 !ca3.contains(bAdded)); 870 871 a.assignB(new ArrayList ()); 873 a3.addInB(bAdded); 874 ca = a.retrieveB(); 876 assertEquals("After undo, Relations size of: ", 0, ca.size()); 877 } else { 878 assertTrue("Wrong relations for " + bAdded + ": ", a3.containInB(bAdded)); 879 } 880 checkIsInitialState(); 881 } 882 883 public void testCohSetOneTxNo() throws Exception { 884 _testCohSetOne(TX_NO); 885 } 886 887 public void testCohSetOneTxCall() throws Exception { 888 _testCohSetOne(TX_CALL); 889 } 890 891 public void testCohSetOneTxCont() throws Exception { 892 _testCohSetOne(TX_CONT); 893 } 894 895 public void testCohSetOneTxRb() throws Exception { 896 _testCohSetOne(TX_RB); 897 } 898 899 900 917 public void _testCohAddOneInMulti(int tx) throws Exception { 918 ArrayList ce = new ArrayList (); 919 ce.add("b1_1"); 920 ce.add("b1_2"); 921 ce.add("b1_3"); 922 String bAdded = "b3_1"; 923 if ((tx == TX_CALL) || (tx == TX_RB)) { 924 utx.begin(); 925 } 926 ARemote a = ahome.findByPrimaryKey("a1"); 927 Collection co = a.retrieveB(); 928 if (tx == TX_CONT) { 929 a.addInBInNewTx(bAdded); 930 } else { 931 a.addInB(bAdded); 932 } 933 ce.add(bAdded); 934 if (tx == TX_CALL) { 935 utx.commit(); 936 } else if (tx == TX_RB) { 937 utx.rollback(); 938 } 939 Collection ca = a.retrieveB(); 941 ARemote a3 = ahome.findByPrimaryKey("a3"); 942 if (tx == TX_RB) { 943 assertTrue("Wrong relations a1 (required:" + co + ", found:" + ca 944 + ") (Rollback problem)", isCollectionEqual(co, ca)); 945 assertTrue("Wrong relations for " + bAdded + ": (coherence/rollback problem)", a3.containInB(bAdded)); 946 } else { 947 try { 948 assertTrue("Wrong relations: ", isCollectionEqual(ce, ca)); 949 assertTrue("The added element (" + bAdded 950 + ") is yet in the relation a3", !a3.containInB(bAdded)); 951 } finally { 952 a.removeFromB(bAdded); 954 a3.addInB(bAdded); 955 } 956 } 957 checkIsInitialState(); 958 } 959 960 public void testCohAddOneInMultiTxNo() throws Exception { 961 _testCohAddOneInMulti(TX_NO); 962 } 963 964 public void testCohAddOneInMultiTxCall() throws Exception { 965 _testCohAddOneInMulti(TX_CALL); 966 } 967 968 public void testCohAddOneInMultiTxCont() throws Exception { 969 _testCohAddOneInMulti(TX_CONT); 970 } 971 972 public void testCohAddOneInMultiTxRb() throws Exception { 973 _testCohAddOneInMulti(TX_RB); 974 } 975 976 981 public void _testCohAddAllInMulti(int tx) throws Exception { 982 ArrayList c = new ArrayList (); 983 c.add("b0"); 984 c.add("b3_1"); 985 if ((tx == TX_CALL) || (tx == TX_RB)) { 986 utx.begin(); 987 } 988 ARemote a = ahome.findByPrimaryKey("a1"); 989 Collection co = a.retrieveB(); 990 if (tx == TX_CONT) { 991 a.addAllInBInNewTx(c); 992 } else { 993 a.addAllInB(c); 994 } 995 c.addAll(co); if (tx == TX_CALL) { 997 utx.commit(); 998 } else if (tx == TX_RB) { 999 utx.rollback(); 1000 } 1001 Collection ca = a.retrieveB(); 1003 ARemote a3 = ahome.findByPrimaryKey("a3"); 1004 if (tx != TX_RB) { 1005 assertTrue("Wrong relations: ", isCollectionEqual(c, ca)); 1006 assertTrue("Wrong relations for a3 ", !a3.containInB("b3_1")); 1007 } else { 1008 assertTrue("Wrong relations: ", isCollectionEqual(co, ca)); 1009 assertTrue("Wrong relations for a3 ", a3.containInB("b3_1")); 1010 } 1011 if (tx != TX_RB) { 1013 a.removeFromB("b0"); 1014 a3.addInB("b3_1"); 1015 } 1016 checkIsInitialState(); 1018 1019 } 1020 1021 public void testCohAddAllInMultiTxNo() throws Exception { 1022 _testCohAddAllInMulti(TX_NO); 1023 } 1024 1025 public void testCohAddAllInMultiTxCall() throws Exception { 1026 _testCohAddAllInMulti(TX_CALL); 1027 } 1028 1029 public void testCohAddAllInMultiTxCont() throws Exception { 1030 _testCohAddAllInMulti(TX_CONT); 1031 } 1032 1033 public void testCohAddAllInMultiTxRb() throws Exception { 1034 _testCohAddAllInMulti(TX_RB); 1035 } 1036 1037 1058 public void _testCohSetMulti(int tx) throws Exception { 1059 if ((tx == TX_CALL) || (tx == TX_RB)) { 1060 utx.begin(); 1061 } 1062 ARemote a1 = ahome.findByPrimaryKey("a1"); 1063 Collection co1 = a1.retrieveB(); 1064 ARemote a2 = ahome.findByPrimaryKey("a2"); 1065 Collection co2 = a2.retrieveB(); 1066 if (tx == TX_CONT) { 1067 a1.assignBInNewTx(co2); 1068 } else { 1069 a1.assignB(co2); 1070 } 1071 if (tx == TX_CALL) { 1072 utx.commit(); 1073 } else if (tx == TX_RB) { 1074 utx.rollback(); 1075 } 1076 if (tx != TX_RB) { 1078 Collection ca1 = a1.retrieveB(); 1079 assertTrue("Wrong relations for a1 (required:" + co2 + ", found:" + ca1 + ")", isCollectionEqual(co2, ca1)); 1080 Collection ca2 = a2.retrieveB(); 1081 assertEquals("Wrong relations size for a2: ", 0, ca2.size()); 1082 a1.assignB(co1); 1084 a2.assignB(co2); 1085 } 1086 checkIsInitialState(); 1087 } 1088 1089 public void testCohSetMultiTxNo() throws Exception { 1090 _testCohSetMulti(TX_NO); 1091 } 1092 1093 public void testCohSetMultiTxCall() throws Exception { 1094 _testCohSetMulti(TX_CALL); 1095 } 1096 1097 public void testCohSetMultiTxCont() throws Exception { 1098 _testCohSetMulti(TX_CONT); 1099 } 1100 1101 public void testCohSetMultiTxRb() throws Exception { 1102 _testCohSetMulti(TX_RB); 1103 } 1104 1105 1111 public void _testCohSetMultiVarious(int tx) throws Exception { 1112 ArrayList ce = new ArrayList (); 1113 ce.add("b0"); 1114 ce.add("b1_2"); 1115 String b3Added = "b3_1"; 1116 ce.add(b3Added); 1117 if ((tx == TX_CALL) || (tx == TX_RB)) { 1118 utx.begin(); 1119 } 1120 ARemote a = ahome.findByPrimaryKey("a1"); 1121 if (tx == TX_CONT) { 1122 a.assignBInNewTx(ce); 1123 } else { 1124 a.assignB(ce); 1125 } 1126 if (tx == TX_CALL) { 1127 utx.commit(); 1128 } else if (tx == TX_RB) { 1129 utx.rollback(); 1130 } 1131 Collection co = new ArrayList (3); 1133 co.add("b1_1"); 1134 co.add("b1_2"); 1135 co.add("b1_3"); 1136 Collection ca = a.retrieveB(); 1137 ARemote a3 = ahome.findByPrimaryKey("a3"); 1138 if (tx != TX_RB) { 1139 assertTrue("Wrong relations: ", isCollectionEqual(ce, ca)); 1140 assertTrue("Wrong relations for " + b3Added + ": ", !a3.containInB(b3Added)); 1141 1142 a.assignB(co); 1144 a3.addInB(b3Added); 1145 ca = a.retrieveB(); 1147 if (!isCollectionEqual(co, ca)) { 1148 fail("After undo, wrong relations: expected:" + co + ", found:" + ca + ")"); 1149 } 1150 } 1151 checkIsInitialState(); 1152 } 1153 1154 public void testCohSetMultiVariousTxNo() throws Exception { 1155 _testCohSetMultiVarious(TX_NO); 1156 } 1157 1158 public void testCohSetMultiVariousTxCall() throws Exception { 1159 _testCohSetMultiVarious(TX_CALL); 1160 } 1161 1162 public void testCohSetMultiVariousTxCont() throws Exception { 1163 _testCohSetMultiVarious(TX_CONT); 1164 } 1165 1166 public void testCohSetMultiVariousTxRb() throws Exception { 1167 _testCohSetMultiVarious(TX_RB); 1168 } 1169 1170 1171 1172 1176 public void _testCmrMultiIsInit(int tx) throws Exception { 1177 if (tx == TX_CONT) { 1178 fail("Transaction cannot be initiate by the container for this test"); 1181 } 1182 if (tx == TX_RB) { 1183 fail("Transaction attribute 'TX_RB' has no sense for this test"); 1184 } 1185 if (tx == TX_CALL) { 1186 utx.begin(); 1187 } 1188 ARemote a = ahome.create("aX"); 1189 if (tx == TX_CALL) { 1190 utx.commit(); 1191 } 1192 Collection cb = a.retrieveB(); 1194 assertEquals("The multi-valued cmr field 'b' not initialized with an empty collection", 1195 0, cb.size()); 1196 if (tx != TX_RB) { 1197 a.remove(); 1199 } 1200 checkIsInitialState(); 1202 } 1203 1204 public void testCmrMultiIsInitTxNo() throws Exception { 1205 _testCmrMultiIsInit(TX_NO); 1206 } 1207 1208 public void testCmrMultiIsInitTxCall() throws Exception { 1209 _testCmrMultiIsInit(TX_CALL); 1210 } 1211 1212 1213 public static Test suite() { 1214 return new TestSuite(F_Relation_omuEC2.class); 1215 } 1216 1217 public static void main(String args[]) { 1218 String testtorun = null; 1219 for (int argn = 0; argn < args.length; argn++) { 1221 String s_arg = args[argn]; 1222 Integer i_arg; 1223 if (s_arg.equals("-n")) { 1224 testtorun = args[++argn]; 1225 } 1226 } 1227 if (testtorun == null) { 1228 junit.textui.TestRunner.run(suite()); 1229 } else { 1230 junit.textui.TestRunner.run(new F_Relation_omuEC2(testtorun)); 1231 } 1232 } 1233 1234} 1235 | Popular Tags |