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.mnu.AHomeRemote; 40 import org.objectweb.jonas.jtests.beans.relation.mnu.ARemote; 41 import org.objectweb.jonas.jtests.beans.relation.mnu.BHomeRemote; 42 import org.objectweb.jonas.jtests.beans.relation.mnu.BRemote; 43 44 49 public class F_Relation_mnuEC2 extends A_Cmp2Util { 50 51 54 static Hashtable tbRelationA2B = new Hashtable (); 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 private static String BEAN_HOME_A = "relation_mnu_AHome"; 73 protected static AHomeRemote ahome = null; 74 private static String BEAN_HOME_B = "relation_mnu_BHome"; 75 protected static BHomeRemote bhome = null; 76 77 78 public F_Relation_mnuEC2(String name) { 79 super(name); 80 } 81 82 protected static boolean isInit = false; 83 84 protected void setUp() { 85 super.setUp(); 86 boolean ok = false; 87 int nbtry = 0; 88 while (!ok && nbtry < 3) { 89 if (!isInit) { 90 useBeans("mnu", false); 92 try { 93 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A), 94 AHomeRemote.class); 95 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B), 96 BHomeRemote.class); 97 } catch (NamingException e) { 98 fail("Cannot get bean home: "+e.getMessage()); 99 } 100 try { 102 ahome.findByPrimaryKey("a0"); 103 } catch (Exception e) { 104 try { 105 utx.begin(); 106 ARemote a0 = ahome.create("a0"); 107 ARemote a1 = ahome.create("a1"); 108 ARemote a2 = ahome.create("a2"); 109 ARemote a3 = ahome.create("a3"); 110 bhome.create("b0"); 111 bhome.create("b1"); 112 bhome.create("b2"); 113 bhome.create("b3"); 114 bhome.create("b4"); 115 a0.assignB((Collection ) tbRelationA2B.get("a0")); 116 a1.assignB((Collection ) tbRelationA2B.get("a1")); 117 a2.assignB((Collection ) tbRelationA2B.get("a2")); 118 a3.assignB((Collection ) tbRelationA2B.get("a3")); 119 } catch (Exception i) { 120 fail("InitialState creation problem: "+i); 121 } finally { 122 try { 123 utx.commit(); 124 } catch (Exception ii) { 125 } 126 } 127 } 128 isInit = true; 129 } 130 nbtry++; 133 try { 134 if (initStateOK()) { 135 ok = true; 136 } 137 } catch (Exception e) { 138 } 139 if (!ok) { 140 isInit = false; 141 unloadBeans("mnu"); 142 } 143 } 144 } 145 146 150 boolean initStateOK() throws Exception { 151 boolean isOk = true; 152 msgerror = new StringBuffer (); 153 for (Enumeration ea = tbRelationA2B.keys(); ea.hasMoreElements();) { 154 String aname = (String ) (ea.nextElement()); 155 ARemote a = ahome.findByPrimaryKey(aname); 156 Collection colActual = a.retrieveB(); 157 ArrayList colExpected = (ArrayList ) (tbRelationA2B.get(aname)); 158 if (!isCollectionEqual(colExpected, colActual)) { 159 isOk = false; 160 msgerror = msgerror.append("Wrong relation for " + aname 161 +" (expected:" + colExpected 162 + ", found:" + colActual + ")"); 163 } 164 } 165 return isOk; 166 } 167 168 169 172 public void _testBasicGetEmpty(int tx) throws Exception { 173 Collection c; 174 if ((tx == TX_CALL) || (tx == TX_RB)) { 175 utx.begin(); 176 } 177 ARemote a = ahome.findByPrimaryKey("a0"); 178 if (tx == TX_CONT) { 179 c = a.retrieveBInNewTx(); 180 } else { 181 c = a.retrieveB(); 182 } 183 if (tx == TX_CALL) { 184 utx.commit(); 185 } else if (tx == TX_RB) { 186 utx.rollback(); 187 } 188 189 checkIsInitialState(); 190 } 191 192 public void testBasicGetEmptyTxNo() throws Exception { 193 _testBasicGetEmpty(TX_NO); 194 } 195 public void testBasicGetEmptyTxCall() throws Exception { 196 _testBasicGetEmpty(TX_CALL); 197 } 198 public void testBasicGetEmptyTxCont() throws Exception { 199 _testBasicGetEmpty(TX_CONT); 200 } 201 202 205 public void _testBasicSetEmpty(int tx) throws Exception { 206 ArrayList c = new ArrayList (1); 207 c.add("b0"); 208 if ((tx == TX_CALL) || (tx == TX_RB)) { 209 utx.begin(); 210 } 211 ARemote a = ahome.findByPrimaryKey("a0"); 212 if (tx == TX_CONT) { 213 a.assignBInNewTx(c); 214 } else { 215 a.assignB(c); 216 } 217 if (tx == TX_CALL) { 218 utx.commit(); 219 } else if (tx == TX_RB) { 220 utx.rollback(); 221 } 222 Collection c_value = a.retrieveB(); 224 if (tx != TX_RB) { 225 assertTrue("Wrong relations a0 (required:" + c + ", found:" + c_value 226 + ")", isCollectionEqual(c_value, c)); 227 a.assignB(new ArrayList (0)); 229 } 230 checkIsInitialState(); 231 232 } 233 public void testBasicSetEmptyTxNo() throws Exception { 234 _testBasicSetEmpty(TX_NO); 235 } 236 public void testBasicSetEmptyTxCall() throws Exception { 237 _testBasicSetEmpty(TX_CALL); 238 } 239 public void testBasicSetEmptyTxCont() throws Exception { 240 _testBasicSetEmpty(TX_CONT); 241 } 242 243 public void testBasicSetEmptyTxRb() throws Exception { 244 _testBasicSetEmpty(TX_RB); 245 } 246 247 256 public void _testBasicSetFirst(int tx) throws Exception { 257 String c = null; 258 if ((tx == TX_CALL) || (tx == TX_RB)) { 259 utx.begin(); 260 } 261 ARemote a1 = ahome.findByPrimaryKey("a1"); 262 ARemote a3 = ahome.findByPrimaryKey("a3"); 263 Collection c1 = a1.retrieveB(); 264 if (tx == TX_CONT) { 265 a1.assignBInNewTx(a3.retrieveB()); 266 } else { 267 a1.assignB(a3.retrieveB()); 268 } 269 if (tx == TX_CALL) { 270 utx.commit(); 271 } else if (tx == TX_RB) { 272 utx.rollback(); 273 } 274 if (tx != TX_RB) { 276 ArrayList c1_att = new ArrayList (3); 277 c1_att.add("b2"); 278 c1_att.add("b3"); 279 c1_att.add("b4"); 280 assertTrue("Wrong test of coherence First before commit: ", isCollectionEqual(a1.retrieveB(),c1_att)); 281 } else { 282 assertTrue("Wrong test of coherence First before roolback: ", isCollectionEqual(a1.retrieveB(),c1)); 283 } 284 if (tx != TX_RB) { 286 a1.assignB(null); 287 a1.assignB(c1); 288 } 289 checkIsInitialState(); 290 } 291 public void testBasicSetFirstTxNo() throws Exception { 292 _testBasicSetFirst(TX_NO); 293 } 294 public void testBasicSetFirstTxCall() throws Exception { 295 _testBasicSetFirst(TX_CALL); 296 } 297 public void testBasicSetFirstTxCont() throws Exception { 298 _testBasicSetFirst(TX_CONT); 299 } 300 public void testBasicSetFirstTxRb() throws Exception { 301 _testBasicSetFirst(TX_RB); 302 } 303 304 310 public void _testBasicSetSecond(int tx) throws Exception { 311 String c = null; 312 313 if ((tx == TX_CALL) || (tx == TX_RB)) { 314 utx.begin(); 315 } 316 ARemote a1 = ahome.findByPrimaryKey("a1"); 317 Collection c1 = a1.retrieveB(); 318 319 if (tx == TX_CONT) { 320 a1.addInB("b3"); 321 } else { 322 a1.addInB("b3"); 323 } 324 if (tx == TX_CALL) { 325 utx.commit(); 326 } else if (tx == TX_RB) { 327 utx.rollback(); 328 } 329 if (tx != TX_RB) { 331 ArrayList c1_att = new ArrayList (3); 332 c1_att.add("b1"); 333 c1_att.add("b2"); 334 c1_att.add("b3"); 335 assertTrue("Wrong test of coherence Second before commit: ", isCollectionEqual(a1.retrieveB(),c1_att)); 336 } else { 337 assertTrue("Wrong test of coherence Second before roolback: ", isCollectionEqual(a1.retrieveB(),c1)); 338 } 339 if (tx != TX_RB) { 341 a1.assignB(null); 342 a1.assignB(c1); 343 } 344 checkIsInitialState(); 345 } 346 347 public void testBasicSetSecondTxNo() throws Exception { 348 _testBasicSetSecond(TX_NO); 349 } 350 public void testBasicSetSecondTxCall() throws Exception { 351 _testBasicSetSecond(TX_CALL); 352 } 353 public void testBasicSetSecondTxCont() throws Exception { 354 _testBasicSetSecond(TX_CONT); 355 } 356 public void testBasicSetSecondTxRb() throws Exception { 357 _testBasicSetSecond(TX_RB); 358 } 359 360 361 366 public void _testBasicSetRemove(int tx) throws Exception { 367 String c = null; 368 369 if ((tx == TX_CALL) || (tx == TX_RB)) { 370 utx.begin(); 371 } 372 ARemote a2 = ahome.findByPrimaryKey("a2"); 373 Collection c2 = a2.retrieveB(); 374 if (tx == TX_CONT) { 375 a2.removeFromB("b2"); 376 } else { 377 a2.removeFromB("b2"); 378 } 379 if (tx == TX_CALL) { 380 utx.commit(); 381 } else if (tx == TX_RB) { 382 utx.rollback(); 383 } 384 if (tx != TX_RB) { 386 ArrayList c2_att = new ArrayList (3); 387 c2_att.add("b1"); 388 c2_att.add("b3"); 389 assertTrue("Wrong test of coherence Remove before commit: ", isCollectionEqual(a2.retrieveB(),c2_att)); 390 } else { 391 assertTrue("Wrong test of coherence Remove before roolback: ", isCollectionEqual(a2.retrieveB(),c2)); 392 } 393 if (tx != TX_RB) { 395 a2.assignB(c2); 396 } 397 checkIsInitialState(); 398 } 399 400 public void testBasicSetRemoveTxNo() throws Exception { 401 _testBasicSetRemove(TX_NO); 402 } 403 public void testBasicSetRemoveTxCall() throws Exception { 404 _testBasicSetRemove(TX_CALL); 405 } 406 public void testBasicSetRemoveTxCont() throws Exception { 407 _testBasicSetRemove(TX_CONT); 408 } 409 public void testBasicSetRemoveTxRb() throws Exception { 410 _testBasicSetRemove(TX_RB); 411 } 412 413 416 public void _testBasicClear(int tx) throws Exception { 417 if ((tx == TX_CALL) || (tx == TX_RB)) { 418 utx.begin(); 419 } 420 ARemote a2 = ahome.findByPrimaryKey("a2"); 421 if (tx == TX_CONT) { 422 a2.clearBInNewTx(); 423 } else { 424 a2.clearB(); 425 } 426 if (tx == TX_CALL) { 427 utx.commit(); 428 } else if (tx == TX_RB) { 429 utx.rollback(); 430 } 431 Collection a2_value = a2.retrieveB(); 433 if (tx != TX_RB) { 434 assertTrue("Wrong relations a2 (required: Empty, found:" + a2_value + ")", a2_value.isEmpty()); 435 436 ArrayList a2undo = new ArrayList (3); 438 a2undo.add("b1"); 439 a2undo.add("b2"); 440 a2undo.add("b3"); 441 a2.assignB(a2undo); 442 } 443 checkIsInitialState(); 444 } 445 446 public void testBasicClearTxNo() throws Exception { 447 _testBasicClear(TX_NO); 448 } 449 450 public void testBasicClearTxCall() throws Exception { 451 _testBasicClear(TX_CALL); 452 } 453 454 public void testBasicClearTxCont() throws Exception { 455 _testBasicClear(TX_CONT); 456 } 457 458 public void testBasicClearTxRb() throws Exception { 459 _testBasicClear(TX_RB); 460 } 461 462 465 public void _testCohRemoveInRel(int tx) throws Exception { 466 String bRemoved = "b4"; 467 if ((tx == TX_CALL) || (tx == TX_RB)) { 468 utx.begin(); 469 } 470 ARemote a = ahome.findByPrimaryKey("a3"); 471 if (tx == TX_CONT) { 472 a.removeFromBInNewTx(bRemoved); 473 } else { 474 a.removeFromB(bRemoved); 475 } 476 if (tx == TX_CALL) { 477 utx.commit(); 478 } else if (tx == TX_RB) { 479 utx.rollback(); 480 } 481 Collection ca = a.retrieveB(); 483 if (tx != TX_RB) { 484 assertEquals("Wrong relations size for a3: ", 2, ca.size()); 485 } else { 486 assertEquals("Wrong relations size for a3: ", 3, ca.size()); 487 } 488 if (tx != TX_RB) { 490 a.addInB(bRemoved); 491 } 492 checkIsInitialState(); 494 495 } 496 497 public void testCohRemoveInRelTxNo() throws Exception { 498 _testCohRemoveInRel(TX_NO); 499 } 500 501 public void testCohRemoveInRelTxCall() throws Exception { 502 _testCohRemoveInRel(TX_CALL); 503 } 504 505 public void testCohRemoveInRelTxCont() throws Exception { 506 _testCohRemoveInRel(TX_CONT); 507 } 508 509 public void testCohRemoveInRelTxRb() throws Exception { 510 _testCohRemoveInRel(TX_RB); 511 } 512 513 516 public void _testCohRemove(int tx) throws Exception { 517 if (tx == TX_CONT) { 518 fail("Transaction cannot be initiate by the container for this test"); 521 } 522 if ((tx == TX_CALL) || (tx == TX_RB)) { 523 utx.begin(); 524 } 525 bhome.remove("b2"); 526 if (tx == TX_CALL) { 527 utx.commit(); 528 } else if (tx == TX_RB) { 529 utx.rollback(); 530 } 531 ARemote a1 = ahome.findByPrimaryKey("a1"); 533 ARemote a2 = ahome.findByPrimaryKey("a2"); 534 ARemote a3 = ahome.findByPrimaryKey("a3"); 535 Collection idrela1 = a1.retrieveB(); 536 Collection idrela2 = a2.retrieveB(); 537 Collection idrela3 = a3.retrieveB(); 538 ArrayList col_a1 = new ArrayList (1); 539 col_a1.add("b1"); 540 ArrayList col_a2 = new ArrayList (2); 541 col_a2.add("b1"); 542 col_a2.add("b3"); 543 ArrayList col_a3 = new ArrayList (2); 544 col_a3.add("b3"); 545 col_a3.add("b4"); 546 if (tx != TX_RB) { 547 assertTrue("Wrong relation a1 : Expected [b1] , found "+idrela1, isCollectionEqual(idrela1,col_a1)); 548 assertTrue("Wrong relation a2 : Expected [b1, b3] , found "+idrela2 , isCollectionEqual(idrela2,col_a2)); 549 assertTrue("Wrong relation a3 : Expected [b3, b4] , found " + idrela3, isCollectionEqual(idrela3, col_a3)); 550 bhome.create("b2"); 552 col_a1 = new ArrayList (2); 553 col_a1.add("b1"); 554 col_a1.add("b2"); 555 col_a2 = new ArrayList (3); 556 col_a2.add("b1"); 557 col_a2.add("b2"); 558 col_a2.add("b3"); 559 a1.assignB(col_a1); 560 col_a3 = new ArrayList (3); 561 col_a3.add("b2"); 562 col_a3.add("b3"); 563 col_a3.add("b4"); 564 565 a1.assignB(col_a1); 566 a2.assignB(col_a2); 567 a3.assignB(col_a3); 568 } 569 checkIsInitialState(); 570 } 571 572 public void testCohRemoveTxNo() throws Exception { 573 _testCohRemove(TX_NO); 574 } 575 576 public void testCohRemoveTxCall() throws Exception { 577 _testCohRemove(TX_CALL); 578 } 579 580 public void testCohRemoveTxRb() throws Exception { 581 _testCohRemove(TX_RB); 582 } 583 584 589 public void _testCohBeanRemove(int tx) throws Exception { 590 if (tx == TX_CONT) { 591 fail("Transaction cannot be initiate by the container for this test"); 594 } 595 if ((tx == TX_CALL) || (tx == TX_RB)) { 596 utx.begin(); 597 } 598 BRemote b = bhome.findByPrimaryKey("b2"); 599 b.remove(); 600 if (tx == TX_CALL) { 601 utx.commit(); 602 } else if (tx == TX_RB) { 603 utx.rollback(); 604 } 605 ARemote a1 = ahome.findByPrimaryKey("a1"); 607 ARemote a2 = ahome.findByPrimaryKey("a2"); 608 ARemote a3 = ahome.findByPrimaryKey("a3"); 609 Collection idrela1 = a1.retrieveB(); 610 Collection idrela2 = a2.retrieveB(); 611 Collection idrela3 = a3.retrieveB(); 612 ArrayList col_a1 = new ArrayList (1); 613 col_a1.add("b1"); 614 ArrayList col_a2 = new ArrayList (2); 615 col_a2.add("b1"); 616 col_a2.add("b3"); 617 ArrayList col_a3 = new ArrayList (2); 618 col_a3.add("b3"); 619 col_a3.add("b4"); 620 if (tx != TX_RB) { 621 assertTrue("Wrong relation a1 : Expected [b1] , found "+idrela1, isCollectionEqual(idrela1,col_a1)); 622 assertTrue("Wrong relation a2 : Expected [b1, b3] , found "+idrela2 , isCollectionEqual(idrela2,col_a2)); 623 assertTrue("Wrong relation a3 : Expected [b3, b4] , found " + idrela3, isCollectionEqual(idrela3, col_a3)); 624 bhome.create("b2"); 626 col_a1 = new ArrayList (2); 627 col_a1.add("b1"); 628 col_a1.add("b2"); 629 col_a2 = new ArrayList (3); 630 col_a2.add("b1"); 631 col_a2.add("b2"); 632 col_a2.add("b3"); 633 a1.assignB(col_a1); 634 col_a3 = new ArrayList (3); 635 col_a3.add("b2"); 636 col_a3.add("b3"); 637 col_a3.add("b4"); 638 639 a1.assignB(col_a1); 640 a2.assignB(col_a2); 641 a3.assignB(col_a3); 642 } 643 checkIsInitialState(); 644 } 645 646 public void testCohBeanRemoveTxNo() throws Exception { 647 _testCohBeanRemove(TX_NO); 648 } 649 650 public void testCohBeanRemoveTxCall() throws Exception { 651 _testCohBeanRemove(TX_CALL); 652 } 653 654 public void testCohBeanRemoveTxRb() throws Exception { 655 _testCohBeanRemove(TX_RB); 656 } 657 658 661 public void testRemoveSeries() throws Exception { 662 663 testBasicSetRemoveTxCall(); 664 testBasicClearTxCall(); 665 testBasicClearTxRb(); 666 testCohRemoveTxNo(); 667 testCohRemoveTxCall(); 668 } 669 670 public void testRemoves1() throws Exception { 671 ARemote a1 = ahome.findByPrimaryKey("a1"); 672 ARemote a2 = ahome.findByPrimaryKey("a2"); 673 ARemote a3 = ahome.findByPrimaryKey("a3"); 674 Collection col; 675 Collection b; 676 Collection a1bsave = a1.retrieveB(); 677 Collection a2bsave = a2.retrieveB(); 678 Collection a3bsave = a3.retrieveB(); 679 680 utx.begin(); 682 a2.removeFromB("b2"); 683 utx.commit(); 684 col = new ArrayList (2); 686 col.add("b1"); 687 col.add("b3"); 688 assertTrue("Wrong test of coherence Remove before commit: ", isCollectionEqual(a2.retrieveB(), col)); 689 a2.assignB(a2bsave); 691 692 utx.begin(); 694 a2.clearB(); 695 utx.commit(); 696 b = a2.retrieveB(); 698 assertTrue("Wrong relations a2 (required: Empty, found:" + b + ")", b.isEmpty()); 699 a2.assignB(a2bsave); 701 702 utx.begin(); 704 a2.clearB(); 705 utx.rollback(); 706 707 bhome.remove("b2"); 709 col = new ArrayList (1); 711 col.add("b1"); 712 b = a1.retrieveB(); 713 assertTrue("Wrong relation a1 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 714 col = new ArrayList (2); 716 col.add("b1"); 717 col.add("b3"); 718 b = a2.retrieveB(); 719 assertTrue("Wrong relation a2 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 720 col = new ArrayList (2); 722 col.add("b3"); 723 col.add("b4"); 724 b = a3.retrieveB(); 725 assertTrue("Wrong relation a3 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 726 bhome.create("b2"); 728 a1.assignB(a1bsave); 729 a2.assignB(a2bsave); 730 a3.assignB(a3bsave); 731 checkIsInitialState(); 732 } 733 734 public void testRemoves2() throws Exception { 735 ARemote a1 = ahome.findByPrimaryKey("a1"); 736 ARemote a2 = ahome.findByPrimaryKey("a2"); 737 ARemote a3 = ahome.findByPrimaryKey("a3"); 738 Collection col; 739 Collection b; 740 Collection a1bsave = a1.retrieveB(); 741 Collection a2bsave = a2.retrieveB(); 742 Collection a3bsave = a3.retrieveB(); 743 744 utx.begin(); 746 a2.removeFromB("b2"); 747 utx.commit(); 748 col = new ArrayList (2); 750 col.add("b1"); 751 col.add("b3"); 752 assertTrue("Wrong test of coherence Remove before commit: ", isCollectionEqual(a2.retrieveB(), col)); 753 a2.assignB(a2bsave); 755 756 utx.begin(); 758 a2.clearB(); 759 utx.rollback(); 760 761 bhome.remove("b2"); 763 col = new ArrayList (1); 765 col.add("b1"); 766 b = a1.retrieveB(); 767 assertTrue("Wrong relation a1 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 768 col = new ArrayList (2); 770 col.add("b1"); 771 col.add("b3"); 772 b = a2.retrieveB(); 773 assertTrue("Wrong relation a2 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 774 col = new ArrayList (2); 776 col.add("b3"); 777 col.add("b4"); 778 b = a3.retrieveB(); 779 assertTrue("Wrong relation a3 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 780 bhome.create("b2"); 782 a1.assignB(a1bsave); 783 a2.assignB(a2bsave); 784 a3.assignB(a3bsave); 785 checkIsInitialState(); 786 } 787 788 public void testRemoves3() throws Exception { 789 ARemote a1 = ahome.findByPrimaryKey("a1"); 790 ARemote a2 = ahome.findByPrimaryKey("a2"); 791 ARemote a3 = ahome.findByPrimaryKey("a3"); 792 Collection col; 793 Collection b; 794 Collection a1bsave = a1.retrieveB(); 795 Collection a2bsave = a2.retrieveB(); 796 Collection a3bsave = a3.retrieveB(); 797 798 utx.begin(); 800 a2.removeFromB("b2"); 801 utx.commit(); 802 col = new ArrayList (2); 804 col.add("b1"); 805 col.add("b3"); 806 assertTrue("Wrong test of coherence Remove before commit: ", isCollectionEqual(a2.retrieveB(), col)); 807 a2.assignB(a2bsave); 809 810 utx.begin(); 812 a2.clearB(); 813 utx.commit(); 814 b = a2.retrieveB(); 816 assertTrue("Wrong relations a2 (required: Empty, found:" + b + ")", b.isEmpty()); 817 a2.assignB(a2bsave); 819 820 bhome.remove("b2"); 822 col = new ArrayList (1); 824 col.add("b1"); 825 b = a1.retrieveB(); 826 assertTrue("Wrong relation a1 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 827 col = new ArrayList (2); 829 col.add("b1"); 830 col.add("b3"); 831 b = a2.retrieveB(); 832 assertTrue("Wrong relation a2 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 833 col = new ArrayList (2); 835 col.add("b3"); 836 col.add("b4"); 837 b = a3.retrieveB(); 838 assertTrue("Wrong relation a3 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 839 bhome.create("b2"); 841 a1.assignB(a1bsave); 842 a2.assignB(a2bsave); 843 a3.assignB(a3bsave); 844 checkIsInitialState(); 845 } 846 847 public void testRemoves4() throws Exception { 848 ARemote a1 = ahome.findByPrimaryKey("a1"); 849 ARemote a2 = ahome.findByPrimaryKey("a2"); 850 Collection col; 852 Collection b; 853 Collection a2bsave = a2.retrieveB(); 855 857 utx.begin(); 859 a2.clearB(); 860 utx.rollback(); 861 869 bhome.remove("b2"); 871 col = new ArrayList (1); 873 col.add("b1"); 874 b = a1.retrieveB(); 875 assertTrue("Wrong relation a1 : Expected " + col + ", found " + b, isCollectionEqual(b, col)); 876 896 } 897 898 public static Test suite() { 899 return new TestSuite(F_Relation_mnuEC2.class); 900 } 901 902 public static void main(String args[]) { 903 String testtorun = null; 904 for (int argn = 0; argn < args.length; argn++) { 906 String s_arg = args[argn]; 907 Integer i_arg; 908 if (s_arg.equals("-n")) { 909 testtorun = args[++argn]; 910 } 911 } 912 if (testtorun == null) { 913 junit.textui.TestRunner.run(suite()); 914 } else { 915 junit.textui.TestRunner.run(new F_Relation_mnuEC2(testtorun)); 916 } 917 } 918 919 } 920 | Popular Tags |