1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.Enumeration ; 31 import java.util.Hashtable ; 32 33 import javax.naming.NamingException ; 34 import javax.rmi.PortableRemoteObject ; 35 36 import junit.framework.Test; 37 import junit.framework.TestSuite; 38 39 import org.objectweb.jonas.jtests.beans.relation.mnb.AHomeRemote; 40 import org.objectweb.jonas.jtests.beans.relation.mnb.ARemote; 41 import org.objectweb.jonas.jtests.beans.relation.mnb.BHomeRemote; 42 import org.objectweb.jonas.jtests.beans.relation.mnb.BRemote; 43 44 50 public class F_Relation_mnbEC2 extends A_Cmp2Util { 51 52 static Hashtable tbRelationA2B = new Hashtable (); 53 54 55 static { 56 tbRelationA2B.put("a0", new String []{}); 57 tbRelationA2B.put("a1", new String []{"b1", "b2"}); 58 tbRelationA2B.put("a2", new String []{"b1", "b2", "b3"}); 59 tbRelationA2B.put("a3", new String []{"b2", "b3", "b4"}); 60 for (Enumeration ea = tbRelationA2B.keys(); ea.hasMoreElements();) { 62 String aname = (String ) (ea.nextElement()); 63 String [] tb = (String []) tbRelationA2B.get(aname); 64 ArrayList col = new ArrayList (tb.length); 65 for (int i = 0; i < tb.length; i++) { 66 col.add(tb[i]); 67 } 68 tbRelationA2B.put(aname, col); 69 } 70 } 71 72 static Hashtable tbRelationB2A = new Hashtable (); 73 74 static { 75 tbRelationB2A.put("b0", new String []{}); 76 tbRelationB2A.put("b1", new String []{"a1", "a2"}); 77 tbRelationB2A.put("b2", new String []{"a1", "a2", "a3"}); 78 tbRelationB2A.put("b3", new String []{"a2", "a3"}); 79 tbRelationB2A.put("b4", new String []{"a3"}); 80 for (Enumeration ea1 = tbRelationB2A.keys(); ea1.hasMoreElements();) { 82 String aname1 = (String ) (ea1.nextElement()); 83 String [] tb1 = (String []) tbRelationB2A.get(aname1); 84 ArrayList col1 = new ArrayList (tb1.length); 85 for (int j = 0; j < tb1.length; j++) { 86 col1.add(tb1[j]); 87 } 88 tbRelationB2A.put(aname1, col1); 89 } 90 } 91 92 private static String BEAN_HOME_A = "relation_mnb_AHome"; 93 protected static AHomeRemote ahome = null; 94 private static String BEAN_HOME_B = "relation_mnb_BHome"; 95 protected static BHomeRemote bhome = null; 96 97 98 public F_Relation_mnbEC2(String name) { 99 super(name); 100 } 101 102 protected static boolean isInit = false; 103 104 protected void setUp() { 105 super.setUp(); 106 boolean ok = false; 107 int nbtry = 0; 108 while (!ok && nbtry < 3) { 109 if (!isInit) { 110 useBeans("mnb", false); 112 try { 114 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A), 115 AHomeRemote.class); 116 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B), 117 BHomeRemote.class); 118 } catch (NamingException e) { 119 fail("Cannot get bean home: " + e.getMessage()); 120 } 121 try { 123 ahome.findByPrimaryKey("a0"); 124 } catch (Exception e) { 125 try { 126 utx.begin(); 128 ahome.create("a0"); 129 ahome.create("a1"); 130 ahome.create("a2"); 131 ahome.create("a3"); 132 bhome.create("b0"); 133 bhome.create("b1"); 134 bhome.create("b2"); 135 bhome.create("b3"); 136 bhome.create("b4"); 137 ARemote a0 = ahome.findByPrimaryKey("a0"); 138 ARemote a1 = ahome.findByPrimaryKey("a1"); 139 ARemote a2 = ahome.findByPrimaryKey("a2"); 140 ARemote a3 = ahome.findByPrimaryKey("a3"); 141 Collection rel_a0 = (Collection ) (tbRelationA2B.get("a0")); 142 a0.assignB(rel_a0); 143 Collection rel_a1 = (Collection ) (tbRelationA2B.get("a1")); 144 a1.assignB(rel_a1); 145 Collection rel_a2 = (Collection ) (tbRelationA2B.get("a2")); 146 a2.assignB(rel_a2); 147 Collection rel_a3 = (Collection ) (tbRelationA2B.get("a3")); 148 a3.assignB(rel_a3); 149 } catch (Exception i) { 150 fail("InitialState creation problem: "+i); 151 } finally { 152 try { 153 utx.commit(); 154 } catch (Exception ii) { 155 } 156 } 157 } 158 isInit = true; 159 } 160 nbtry++; 163 try { 164 if (initStateOK()) { 165 ok = true; 166 } 167 } catch (Exception e) { 168 } 169 if (!ok) { 170 debug("F_Relation_mnbEC2 setUp: unload bean and retry"); 171 isInit = false; 172 unloadBeans("mnb"); 173 } 174 } 175 } 176 177 181 boolean initStateOK() throws Exception { 182 boolean isOk = true; 183 msgerror = new StringBuffer (); 184 for (Enumeration ea = tbRelationA2B.keys(); ea.hasMoreElements();) { 186 String aname = (String ) (ea.nextElement()); 187 ARemote a = ahome.findByPrimaryKey(aname); 188 Collection colActual = a.retrieveB(); 189 ArrayList colExpected = (ArrayList ) (tbRelationA2B.get(aname)); 190 if (!isCollectionEqual(colExpected, colActual)) { 191 isOk = false; 192 msgerror = msgerror.append("Wrong relation for " + aname 193 + " (expected:" + colExpected 194 + ", found:" + colActual + ")"); 195 } 196 } 197 for (Enumeration ea1 = tbRelationB2A.keys(); ea1.hasMoreElements();) { 199 String aname1 = (String ) (ea1.nextElement()); 200 BRemote b = bhome.findByPrimaryKey(aname1); 201 Collection colActual1 = b.retrieveA(); 202 ArrayList colExpected1 = (ArrayList ) (tbRelationB2A.get(aname1)); 203 if (!isCollectionEqual(colExpected1, colActual1)) { 204 isOk = false; 205 msgerror = msgerror.append("Wrong relation for " + aname1 206 + " (expected:" + colExpected1 207 + ", found:" + colActual1 + ")"); 208 } 209 } 210 return isOk; 211 } 212 213 216 public void _testBasicGetEmpty(int tx) throws Exception { 217 Collection c; 218 if ((tx == TX_CALL) || (tx == TX_RB)) { 219 utx.begin(); 220 } 221 ARemote a = ahome.findByPrimaryKey("a0"); 222 if (tx == TX_CONT) { 223 c = a.retrieveBInNewTx(); 224 } else { 225 c = a.retrieveB(); 226 } 227 if (tx == TX_CALL) { 228 utx.commit(); 229 } else if (tx == TX_RB) { 230 utx.rollback(); 231 } 232 checkIsInitialState(); 233 } 234 235 public void testBasicGetEmptyTxNo() throws Exception { 236 _testBasicGetEmpty(TX_NO); 237 } 238 239 public void testBasicGetEmptyTxCall() throws Exception { 240 _testBasicGetEmpty(TX_CALL); 241 } 242 243 public void testBasicGetEmptyTxCont() throws Exception { 244 _testBasicGetEmpty(TX_CONT); 245 } 246 247 public void testBasicGetEmptyTxRb() throws Exception { 248 _testBasicGetEmpty(TX_RB); 249 } 250 251 254 public void _testBasicSetEmpty(int tx) throws Exception { 255 ArrayList c = new ArrayList (1); 256 c.add("b0"); 257 if ((tx == TX_CALL) || (tx == TX_RB)) { 258 utx.begin(); 259 } 260 ARemote a = ahome.findByPrimaryKey("a0"); 261 if (tx == TX_CONT) { 262 a.assignBInNewTx(c); 263 } else { 264 a.assignB(c); 265 } 266 if (tx == TX_CALL) { 267 utx.commit(); 268 } else if (tx == TX_RB) { 269 utx.rollback(); 270 } 271 Collection c_value = a.retrieveB(); 273 if (tx != TX_RB) { 274 assertTrue("Wrong relations a0 (required:" + c + ", found:" + c_value 275 + ")", isCollectionEqual(c_value, c)); 276 } else { 277 assertTrue("Wrong relation a0->b0 : ", c_value.isEmpty()); 278 } 279 if (tx != TX_RB) { 281 a.assignB(new ArrayList ()); 282 } 283 checkIsInitialState(); 284 } 285 286 public void testBasicSetEmptyTxNo() throws Exception { 287 _testBasicSetEmpty(TX_NO); 288 } 289 290 public void testBasicSetEmptyTxCall() throws Exception { 291 _testBasicSetEmpty(TX_CALL); 292 } 293 294 public void testBasicSetEmptyTxCont() throws Exception { 295 _testBasicSetEmpty(TX_CONT); 296 } 297 298 public void testBasicSetEmptyTxRb() throws Exception { 299 _testBasicSetEmpty(TX_RB); 300 } 301 302 public void testPhil() throws Exception { 303 utx.begin(); 304 ARemote a2 = ahome.findByPrimaryKey("a2"); 305 a2.clearB(); 306 utx.rollback(); 307 } 309 310 313 public void _testBasicClear(int tx) throws Exception { 314 if ((tx == TX_CALL) || (tx == TX_RB)) { 315 utx.begin(); 316 } 317 ARemote a2 = ahome.findByPrimaryKey("a2"); 318 if (tx == TX_CONT) { 319 a2.clearBInNewTx(); 320 } else { 321 a2.clearB(); 322 } 323 if (tx == TX_CALL) { 324 utx.commit(); 325 } else if (tx == TX_RB) { 326 utx.rollback(); 327 } 328 Collection a2_value = a2.retrieveB(); 330 BRemote b1 = bhome.findByPrimaryKey("b1"); 331 BRemote b2 = bhome.findByPrimaryKey("b2"); 332 BRemote b3 = bhome.findByPrimaryKey("b3"); 333 ArrayList collb1 = new ArrayList (1); 334 collb1.add("a1"); 335 ArrayList collb2 = new ArrayList (2); 336 collb2.add("a1"); 337 collb2.add("a3"); 338 ArrayList collb3 = new ArrayList (1); 339 collb3.add("a3"); 340 Collection col=null; 341 if (tx != TX_RB) { 342 assertTrue("Wrong relations a2 (required: Empty "+", found:" + a2_value 343 + ")", a2_value.isEmpty()); 344 col = bhome.findByPrimaryKey("b1").retrieveA(); 345 assertTrue("Wrong collection returned by b1.getA(): expected:" + collb1 346 + " found: " + col, isCollectionEqual(collb1, col)); 347 col = bhome.findByPrimaryKey("b2").retrieveA(); 348 assertTrue("Wrong collection returned by b2.getA(): expected:" + collb2 349 + " found: " + col, isCollectionEqual(collb2, col)); 350 col = bhome.findByPrimaryKey("b3").retrieveA(); 351 assertTrue("Wrong collection returned by b3.getA(): expected:" + collb3 352 + " found: " + col, isCollectionEqual(collb3, col)); 353 ArrayList a2undo = new ArrayList (3); 355 a2undo.add("b1"); 356 a2undo.add("b2"); 357 a2undo.add("b3"); 358 a2.assignB(a2undo); 359 } 360 checkIsInitialState(); 361 } 362 363 public void testBasicClearTxNo() throws Exception { 364 _testBasicClear(TX_NO); 365 } 366 367 public void testBasicClearTxCall() throws Exception { 368 _testBasicClear(TX_CALL); 369 } 370 371 public void testBasicClearTxCont() throws Exception { 372 _testBasicClear(TX_CONT); 373 } 374 375 public void testBasicClearTxRb() throws Exception { 376 _testBasicClear(TX_RB); 377 } 378 379 382 public void _testCohRemoveInRel(int tx) throws Exception { 383 String bRemoved = "b4"; 384 if ((tx == TX_CALL) || (tx == TX_RB)) { 385 utx.begin(); 386 } 387 ARemote a = ahome.findByPrimaryKey("a3"); 388 if (tx == TX_CONT) { 389 a.removeFromBInNewTx(bRemoved); 390 } else { 391 a.removeFromB(bRemoved); 392 } 393 if (tx == TX_CALL) { 394 utx.commit(); 395 } else if (tx == TX_RB) { 396 utx.rollback(); 397 } 398 Collection ca = a.retrieveB(); 400 BRemote b4 = bhome.findByPrimaryKey("b4"); 401 Collection cb4 = b4.retrieveA(); 402 if (tx != TX_RB) { 403 assertEquals("Wrong relations size for a3: ", 2, ca.size()); 404 assertEquals("Wrong relations size for b4: ", 0, cb4.size()); 405 } else { 406 assertEquals("Wrong relations size for a3: ", 3, ca.size()); 407 assertEquals("Wrong relations size for b4: ", 1, cb4.size()); 408 } 409 if (tx != TX_RB) { 411 a.addInB(bRemoved); 412 } 413 checkIsInitialState(); 415 416 } 417 418 public void testCohRemoveInRelTxNo() throws Exception { 419 _testCohRemoveInRel(TX_NO); 420 } 421 422 public void testCohRemoveInRelTxCall() throws Exception { 423 _testCohRemoveInRel(TX_CALL); 424 } 425 426 public void testCohRemoveInRelTxCont() throws Exception { 427 _testCohRemoveInRel(TX_CONT); 428 } 429 430 public void testCohRemoveInRelTxRb() throws Exception { 431 _testCohRemoveInRel(TX_RB); 432 } 433 434 455 public void _testCoSetFirst(int tx) throws Exception { 456 String c = null; 457 if ((tx == TX_CALL) || (tx == TX_RB)) { 458 utx.begin(); 459 } 460 ARemote a1 = ahome.findByPrimaryKey("a1"); 461 ARemote a3 = ahome.findByPrimaryKey("a3"); 462 Collection c1 = a1.retrieveB(); 463 if (tx == TX_CONT) { 464 a1.assignBInNewTx(a3.retrieveB()); 465 } else { 466 a1.assignB(a3.retrieveB()); 467 } 468 if (tx == TX_CALL) { 469 utx.commit(); 470 } else if (tx == TX_RB) { 471 utx.rollback(); 472 } 473 474 if (tx == TX_RB) { 476 checkIsInitialState(); 477 return; 478 } 479 480 ArrayList al = new ArrayList (3); 481 Collection col = null; 482 al.add("b2"); 483 al.add("b3"); 484 al.add("b4"); 485 col = a1.retrieveB(); 486 assertTrue("Wrong collection returned by a1.getB(): expected:" + al 487 + " found: " + col, isCollectionEqual(al, col)); 488 col = a3.retrieveB(); 489 assertTrue("Wrong collection returned by a3.getB(): expected:" + al 490 + " found: " + col, isCollectionEqual(al, col)); 491 492 al = new ArrayList (1); 493 al.add("a2"); 494 col = bhome.findByPrimaryKey("b1").retrieveA(); 495 assertTrue("Wrong collection returned by b1.getA(): expected:" + al 496 + " found: " + col, isCollectionEqual(al, col)); 497 498 al = new ArrayList (3); 499 al.add("a1"); 500 al.add("a2"); 501 al.add("a3"); 502 col = bhome.findByPrimaryKey("b2").retrieveA(); 503 assertTrue("Wrong collection returned by b2.getA(): expected:" + al 504 + " found: " + col, isCollectionEqual(al, col)); 505 506 al = new ArrayList (2); 507 al.add("a1"); 508 al.add("a2"); 509 al.add("a3"); 510 col = bhome.findByPrimaryKey("b3").retrieveA(); 511 assertTrue("Wrong collection returned by b3.getA(): expected:" + al 512 + " found: " + col, isCollectionEqual(al, col)); 513 514 al = new ArrayList (2); 515 al.add("a1"); 516 al.add("a3"); 517 col = bhome.findByPrimaryKey("b4").retrieveA(); 518 assertTrue("Wrong collection returned by b4.getA(): expected:" + al 519 + " found: " + col, isCollectionEqual(al, col)); 520 521 a1.assignB(null); 522 al = new ArrayList (2); 523 al.add("b1"); 524 al.add("b2"); 525 a1.assignBInNewTx(al); 526 checkIsInitialState(); 527 528 } 529 530 public void testCoSetFirstTxNo() throws Exception { 531 _testCoSetFirst(TX_NO); 532 } 533 534 public void testCoSetFirstTxCall() throws Exception { 535 _testCoSetFirst(TX_CALL); 536 } 537 538 public void testCoSetFirstTxCont() throws Exception { 539 _testCoSetFirst(TX_CONT); 540 } 541 542 public void testCoSetFirstTxRb() throws Exception { 543 _testCoSetFirst(TX_RB); 544 } 545 546 556 public void _testCoSetSecond(int tx) throws Exception { 557 String c = null; 558 559 if ((tx == TX_CALL) || (tx == TX_RB)) { 560 utx.begin(); 561 } 562 ARemote a1 = ahome.findByPrimaryKey("a1"); 563 564 if (tx == TX_CONT) { 565 a1.addInBInNewTx("b3"); 566 } else { 567 a1.addInB("b3"); 568 } 569 if (tx == TX_CALL) { 570 utx.commit(); 571 } else if (tx == TX_RB) { 572 utx.rollback(); 573 } 574 if (tx != TX_RB) { 576 ArrayList al = new ArrayList (3); 577 Collection col = null; 578 al.add("b1"); 579 al.add("b2"); 580 al.add("b3"); 581 col = a1.retrieveB(); 582 assertTrue("Wrong collection returned by a1.getB(): expected:" + al 583 + " found: " + col, isCollectionEqual(al, col)); 584 585 al = new ArrayList (3); 586 al.add("a1"); 587 al.add("a2"); 588 al.add("a3"); 589 590 col = bhome.findByPrimaryKey("b3").retrieveA(); 591 assertTrue("Wrong collection returned by b3.getA(): expected:" + al 592 + " found: " + col, isCollectionEqual(al, col)); 593 594 a1.removeFromB("b3"); 596 } 597 checkIsInitialState(); 598 } 599 600 public void testCoSetSecondTxNo() throws Exception { 601 _testCoSetSecond(TX_NO); 602 } 603 604 public void testCoSetSecondTxCall() throws Exception { 605 _testCoSetSecond(TX_CALL); 606 } 607 608 public void testCoSetSecondTxCont() throws Exception { 609 _testCoSetSecond(TX_CONT); 610 } 611 612 public void testCoSetSecondTxRb() throws Exception { 613 _testCoSetSecond(TX_RB); 614 } 615 616 624 public void _testCoSetRemove(int tx) throws Exception { 625 626 if (tx == TX_CONT) { 627 fail("Transaction cannot be initiate by the container for this test"); 630 } 631 632 String c = null; 633 634 if ((tx == TX_CALL) || (tx == TX_RB)) { 635 utx.begin(); 636 } 637 ARemote a2 = ahome.findByPrimaryKey("a2"); 638 BRemote b2 = bhome.findByPrimaryKey("b2"); 639 Collection c2 = a2.retrieveB(); 640 if (tx == TX_CONT) { 641 a2.removeFromBInNewTx("b2"); 642 } else { 643 a2.removeFromB("b2"); 644 } 645 if (tx == TX_CALL) { 646 utx.commit(); 647 } else if (tx == TX_RB) { 648 utx.rollback(); 649 } 650 if (tx != TX_RB) { 652 ArrayList al = new ArrayList (2); 653 Collection col = null; 654 al.add("b1"); 655 al.add("b3"); 656 col = a2.retrieveB(); 657 assertTrue("Wrong collection returned by a2.getB(): expected:" + al 658 + " found: " + col, isCollectionEqual(al, col)); 659 660 al = new ArrayList (2); 661 al.add("a1"); 662 al.add("a3"); 663 col = b2.retrieveA(); 664 assertTrue("Wrong collection returned by b2.getA(): expected:" + al 665 + " found: " + col, isCollectionEqual(al, col)); 666 667 a2.addInB("b2"); 669 } 670 checkIsInitialState(); 671 } 672 673 public void testCoSetRemoveTxNo() throws Exception { 674 _testCoSetRemove(TX_NO); 675 } 676 677 public void testCoSetRemoveTxCall() throws Exception { 678 _testCoSetRemove(TX_CALL); 679 } 680 681 public void testCoSetRemoveTxRb() throws Exception { 682 _testCoSetRemove(TX_RB); 683 } 684 685 688 public void _testCohRemoveB(int tx) throws Exception { 689 690 if (tx == TX_CONT) { 691 fail("Transaction cannot be initiate by the container for this test"); 694 } 695 696 if ((tx == TX_CALL) || (tx == TX_RB)) { 697 utx.begin(); 698 } 699 bhome.remove("b2"); 700 if (tx == TX_CALL) { 701 utx.commit(); 702 } else if (tx == TX_RB) { 703 utx.rollback(); 704 } 705 707 if (tx != TX_RB) { 708 ARemote a1 = ahome.findByPrimaryKey("a1"); 709 ARemote a2 = ahome.findByPrimaryKey("a2"); 710 ARemote a3 = ahome.findByPrimaryKey("a3"); 711 Collection idrela1 = a1.retrieveB(); 712 Collection idrela2 = a2.retrieveB(); 713 Collection idrela3 = a3.retrieveB(); 714 ArrayList col_a1 = new ArrayList (1); 715 col_a1.add("b1"); 716 ArrayList col_a2 = new ArrayList (2); 717 col_a2.add("b1"); 718 col_a2.add("b3"); 719 ArrayList col_a3 = new ArrayList (2); 720 col_a3.add("b3"); 721 col_a3.add("b4"); 722 assertTrue("Wrong relation a1 : Expected [b1] , found "+idrela1, isCollectionEqual(idrela1,col_a1)); 723 assertTrue("Wrong relation a2 : Expected [b1, b3] , found "+idrela2 , isCollectionEqual(idrela2,col_a2)); 724 assertTrue("Wrong relation a3 : Expected [b3, b4] , found "+idrela3, isCollectionEqual(idrela3,col_a3)); 725 BRemote b2 = bhome.create("b2"); 727 col_a2 = new ArrayList (3); 728 col_a2.add("a1"); 729 col_a2.add("a2"); 730 col_a2.add("a3"); 731 732 b2.assignAInNewTx(col_a2); 733 } 734 checkIsInitialState(); 735 } 736 737 public void testCohRemoveBTxNo() throws Exception { 738 _testCohRemoveB(TX_NO); 739 } 740 741 public void testCohRemoveBTxCall() throws Exception { 742 _testCohRemoveB(TX_CALL); 743 } 744 745 public void testCohRemoveBTxRb() throws Exception { 746 _testCohRemoveB(TX_RB); 747 } 748 749 754 public void _testCohBeanRemoveB(int tx) throws Exception { 755 756 if (tx == TX_CONT) { 757 fail("Transaction cannot be initiate by the container for this test"); 760 } 761 762 if ((tx == TX_CALL) || (tx == TX_RB)) { 763 utx.begin(); 764 } 765 BRemote b = bhome.findByPrimaryKey("b2"); 766 b.remove(); 767 if (tx == TX_CALL) { 768 utx.commit(); 769 } else if (tx == TX_RB) { 770 utx.rollback(); 771 } 772 774 if (tx != TX_RB) { 775 ARemote a1 = ahome.findByPrimaryKey("a1"); 776 ARemote a2 = ahome.findByPrimaryKey("a2"); 777 ARemote a3 = ahome.findByPrimaryKey("a3"); 778 Collection idrela1 = a1.retrieveB(); 779 Collection idrela2 = a2.retrieveB(); 780 Collection idrela3 = a3.retrieveB(); 781 ArrayList col_a1 = new ArrayList (1); 782 col_a1.add("b1"); 783 ArrayList col_a2 = new ArrayList (2); 784 col_a2.add("b1"); 785 col_a2.add("b3"); 786 ArrayList col_a3 = new ArrayList (2); 787 col_a3.add("b3"); 788 col_a3.add("b4"); 789 assertTrue("Wrong relation a1 : Expected [b1] , found "+idrela1, isCollectionEqual(idrela1,col_a1)); 790 assertTrue("Wrong relation a2 : Expected [b1, b3] , found "+idrela2 , isCollectionEqual(idrela2,col_a2)); 791 assertTrue("Wrong relation a3 : Expected [b3, b4] , found "+idrela3, isCollectionEqual(idrela3,col_a3)); 792 BRemote b2 = bhome.create("b2"); 794 col_a2 = new ArrayList (3); 795 col_a2.add("a1"); 796 col_a2.add("a2"); 797 col_a2.add("a3"); 798 799 b2.assignAInNewTx(col_a2); 800 } 801 checkIsInitialState(); 802 } 803 804 public void testCohBeanRemoveBTxNo() throws Exception { 805 _testCohBeanRemoveB(TX_NO); 806 } 807 808 public void testCohBeanRemoveBTxCall() throws Exception { 809 _testCohBeanRemoveB(TX_CALL); 810 } 811 812 public void testCohBeanRemoveBTxRb() throws Exception { 813 _testCohBeanRemoveB(TX_RB); 814 } 815 816 819 public void _testCohRemoveA(int tx) throws Exception { 820 821 if (tx == TX_CONT) { 822 fail("Transaction cannot be initiate by the container for this test"); 825 } 826 827 if ((tx == TX_CALL) || (tx == TX_RB)) { 828 utx.begin(); 829 } 830 ahome.remove("a2"); 831 if (tx == TX_CALL) { 832 utx.commit(); 833 } else if (tx == TX_RB) { 834 utx.rollback(); 835 } 836 838 if (tx != TX_RB) { 839 BRemote b1 = bhome.findByPrimaryKey("b1"); 840 BRemote b2 = bhome.findByPrimaryKey("b2"); 841 BRemote b3 = bhome.findByPrimaryKey("b3"); 842 Collection idrelb1 = b1.retrieveA(); 843 Collection idrelb2 = b2.retrieveA(); 844 Collection idrelb3 = b3.retrieveA(); 845 ArrayList col_b1 = new ArrayList (1); 846 col_b1.add("a1"); 847 ArrayList col_b2 = new ArrayList (2); 848 col_b2.add("a1"); 849 col_b2.add("a3"); 850 ArrayList col_b3 = new ArrayList (1); 851 col_b3.add("a3"); 852 assertTrue("Wrong relation b1 : Expected [a1] , found "+idrelb1, isCollectionEqual(idrelb1,col_b1)); 853 assertTrue("Wrong relation b2 : Expected [a1, a3] , found "+idrelb2 , isCollectionEqual(idrelb2,col_b2)); 854 assertTrue("Wrong relation b3 : Expected [a3] , found "+idrelb3, isCollectionEqual(idrelb3,col_b3)); 855 ahome.create("a2"); 857 ARemote a2 = ahome.findByPrimaryKey("a2"); 858 ArrayList col_a2 = new ArrayList (3); 859 col_a2.add("b1"); 860 col_a2.add("b2"); 861 col_a2.add("b3"); 862 863 a2.assignB(col_a2); 864 } 865 checkIsInitialState(); 866 } 867 868 public void testCohRemoveATxNo() throws Exception { 869 _testCohRemoveA(TX_NO); 870 } 871 872 public void testCohRemoveATxCall() throws Exception { 873 _testCohRemoveA(TX_CALL); 874 } 875 876 public void testCohRemoveATxRb() throws Exception { 877 _testCohRemoveA(TX_RB); 878 } 879 880 885 public void _testCohBeanRemoveA(int tx) throws Exception { 886 887 if (tx == TX_CONT) { 888 fail("Transaction cannot be initiate by the container for this test"); 891 } 892 893 if ((tx == TX_CALL) || (tx == TX_RB)) { 894 utx.begin(); 895 } 896 ARemote a = ahome.findByPrimaryKey("a2"); 897 a.remove(); 898 if (tx == TX_CALL) { 899 utx.commit(); 900 } else if (tx == TX_RB) { 901 utx.rollback(); 902 } 903 905 if (tx != TX_RB) { 906 BRemote b1 = bhome.findByPrimaryKey("b1"); 907 BRemote b2 = bhome.findByPrimaryKey("b2"); 908 BRemote b3 = bhome.findByPrimaryKey("b3"); 909 Collection idrelb1 = b1.retrieveA(); 910 Collection idrelb2 = b2.retrieveA(); 911 Collection idrelb3 = b3.retrieveA(); 912 ArrayList col_b1 = new ArrayList (1); 913 col_b1.add("a1"); 914 ArrayList col_b2 = new ArrayList (2); 915 col_b2.add("a1"); 916 col_b2.add("a3"); 917 ArrayList col_b3 = new ArrayList (1); 918 col_b3.add("a3"); 919 assertTrue("Wrong relation b1 : Expected [a1] , found "+idrelb1, isCollectionEqual(idrelb1,col_b1)); 920 assertTrue("Wrong relation b2 : Expected [a1, a3] , found "+idrelb2 , isCollectionEqual(idrelb2,col_b2)); 921 assertTrue("Wrong relation b3 : Expected [a3] , found "+idrelb3, isCollectionEqual(idrelb3,col_b3)); 922 ahome.create("a2"); 924 ARemote a2 = ahome.findByPrimaryKey("a2"); 925 ArrayList col_a2 = new ArrayList (3); 926 col_a2.add("b1"); 927 col_a2.add("b2"); 928 col_a2.add("b3"); 929 930 a2.assignB(col_a2); 931 } 932 checkIsInitialState(); 933 } 934 935 public void testCohBeanRemoveATxNo() throws Exception { 936 _testCohBeanRemoveA(TX_NO); 937 } 938 939 public void testCohBeanRemoveATxCall() throws Exception { 940 _testCohBeanRemoveA(TX_CALL); 941 } 942 943 public void testCohBeanRemoveATxRb() throws Exception { 944 _testCohBeanRemoveA(TX_RB); 945 } 946 947 public static Test suite() { 948 return new TestSuite(F_Relation_mnbEC2.class); 949 } 950 951 public static void main(String args[]) { 952 String testtorun = null; 953 for (int argn = 0; argn < args.length; argn++) { 955 String s_arg = args[argn]; 956 Integer i_arg; 957 if (s_arg.equals("-n")) { 958 testtorun = args[++argn]; 959 } 960 } 961 if (testtorun == null) { 962 junit.textui.TestRunner.run(suite()); 963 } else { 964 junit.textui.TestRunner.run(new F_Relation_mnbEC2(testtorun)); 965 } 966 } 967 968 } 969 | Popular Tags |