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 import java.util.Iterator ; 33 34 import javax.naming.NamingException ; 35 import javax.rmi.PortableRemoteObject ; 36 37 import junit.framework.Test; 38 import junit.framework.TestSuite; 39 40 import org.objectweb.jonas.jtests.beans.relation.omb.AHomeRemote; 41 import org.objectweb.jonas.jtests.beans.relation.omb.ARemote; 42 import org.objectweb.jonas.jtests.beans.relation.omb.BHomeRemote; 43 import org.objectweb.jonas.jtests.beans.relation.omb.BRemote; 44 45 49 public class G_Relation_ombEC2 extends A_Cmp2Util { 50 51 52 private static String BEAN_HOME_A = "relation_omb_AHome"; 53 protected static AHomeRemote ahome = null; 54 private static String BEAN_HOME_B = "relation_omb_BHome"; 55 protected static BHomeRemote bhome = null; 56 57 static Hashtable a2b = new Hashtable (); 58 static String [][] b2a = { 59 {"bs0", null}, 60 {"bs1_1", "as1"}, 61 {"bs2_1", "as2"}, 62 {"bs2_2", "as2"}, 63 {"bs2_3", "as2"}, 64 {"bs3", null}, 65 {"b0", null}, 66 {"b1_1", "a1"}, 67 {"b1_2", "a1"}, 68 {"b1_3", "a1"}, 69 {"b2_1", "a2"}, 70 {"b2_2", "a2"}, 71 {"b2_3", "a2"}, 72 {"b3_1", "a3"}}; 73 74 static { 75 a2b.put("as0", new String []{}); 76 a2b.put("as1", new String []{"bs1_1"}); 77 a2b.put("as2", new String []{"bs2_1", "bs2_2", "bs2_3"}); 78 a2b.put("a0", new String []{}); 79 a2b.put("a1", new String []{"b1_1", "b1_2", "b1_3"}); 80 a2b.put("a2", new String []{"b2_1", "b2_2", "b2_3"}); 81 a2b.put("a3", new String []{"b3_1"}); 82 a2b.put("ax0", new String []{}); 83 84 for (Iterator it = a2b.keySet().iterator(); it.hasNext();) { 86 String aname = (String ) (it.next()); 87 String [] tb = (String []) a2b.get(aname); 88 ArrayList col = new ArrayList (tb.length); 89 for (int i = 0; i < tb.length; i++) { 90 col.add(tb[i]); 91 } 92 a2b.put(aname, col); 93 } 94 } 95 96 97 public G_Relation_ombEC2(String name) { 98 super(name); 99 } 100 101 102 public void testEmpty() throws Exception { 103 } 104 protected static boolean isInit = false; 105 106 protected void setUp() { 107 super.setUp(); 108 boolean ok = false; 109 int nbtry = 0; 110 while (!ok && nbtry < 3) { 111 if (!isInit) { 112 useBeans("omb", false); 114 try { 115 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A), 116 AHomeRemote.class); 117 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B), 118 BHomeRemote.class); 119 assertNotNull(ahome); 120 assertNotNull(bhome); 121 } catch (NamingException e) { 122 fail("Cannot get bean home: " + e.getMessage()); 123 } 124 try { 126 ahome.findByPrimaryKey("a0"); 127 } catch (Exception e) { 128 try { 129 utx.begin(); 130 bhome.create("bs0"); 131 bhome.create("bs1_1"); 132 bhome.create("bs2_1"); 133 bhome.create("bs2_2"); 134 bhome.create("bs2_3"); 135 bhome.create("bs3"); 136 bhome.create("b0"); 137 bhome.create("b1_1"); 138 bhome.create("b1_2"); 139 bhome.create("b1_3"); 140 bhome.create("b2_1"); 141 bhome.create("b2_2"); 142 bhome.create("b2_3"); 143 bhome.create("b3_1"); 144 ahome.create("as0"); 145 ahome.create("as1").assignB((Collection ) a2b.get("as1")); 146 ahome.create("as2").assignB((Collection ) a2b.get("as2")); 147 ahome.create("a0"); 148 ahome.create("a1").assignB((Collection ) a2b.get("a1")); 149 ahome.create("a2").assignB((Collection ) a2b.get("a2")); 150 ahome.create("a3").assignB((Collection ) a2b.get("a3")); 151 ahome.create("ax0"); 152 } catch (Exception i) { 153 fail("InitialState creation problem: " + i); 154 } finally { 155 try { 156 utx.commit(); 157 } catch (Exception ii) { 158 } 159 } 160 } 161 isInit = true; 162 } 163 nbtry++; 166 try { 167 if (initStateOK()) { 168 ok = true; 169 } 170 } catch (Exception e) { 171 } 172 if (!ok) { 173 isInit = false; 174 unloadBeans("omb"); 175 } 176 } 177 } 178 179 183 boolean initStateOK() throws Exception { 184 boolean isOk = true; 185 msgerror = new StringBuffer (); 186 for (Enumeration ea = a2b.keys(); ea.hasMoreElements();) { 188 String aname = (String ) (ea.nextElement()); 189 ARemote a = ahome.findByPrimaryKey(aname); 190 Collection colActual = a.retrieveB(); 191 Collection colExpected = (Collection ) (a2b.get(aname)); 192 if (!isCollectionEqual(colExpected, colActual)) { 193 isOk = false; 194 msgerror = msgerror.append("\nWrong relation for " + aname 195 + " (expected:" + colExpected 196 + ", found:" + colActual + ")"); 197 } 198 } 199 for (int i = 0; i < b2a.length; i++) { 201 BRemote b = bhome.findByPrimaryKey(b2a[i][0]); 202 String pkb = b.getId(); 203 String pka = b.retrieveA(); 204 if (b2a[i][1] == null && pka != null 205 || b2a[i][1] != null && !b2a[i][1].equals(pka)) { 206 isOk = false; 207 msgerror = msgerror.append("\nWrong relation for " + pkb 208 + " (expected:" + b2a[i][1] 209 + ", found:" + pka + ")"); 210 } 211 212 } 213 return isOk; 214 } 215 216 217 220 public void tBasicGetEmptyA2B(int tx) throws Exception { 221 Collection c = null; 222 if ((tx == TX_CALL) || (tx == TX_RB)) { 223 utx.begin(); 224 } 225 ARemote a = ahome.findByPrimaryKey("as0"); 226 if (tx == TX_CONT) { 227 c = a.retrieveBInNewTx(); 228 } else { 229 c = a.retrieveB(); 230 } 231 if (tx == TX_CALL) { 232 utx.commit(); 233 } else if (tx == TX_RB) { 234 utx.rollback(); 235 } 236 checkIsInitialState(); 238 } 239 240 public void testBasicGetEmptyA2BTxNo() throws Exception { 241 tBasicGetEmptyA2B(TX_NO); 242 } 243 public void testBasicGetEmptyA2BTxCall() throws Exception { 244 tBasicGetEmptyA2B(TX_CALL); 245 } 246 public void testBasicGetEmptyA2BTxCont() throws Exception { 247 tBasicGetEmptyA2B(TX_CONT); 248 } 249 250 251 254 public void tBasicGetEmptyB2A(int tx) throws Exception { 255 if ((tx == TX_CALL) || (tx == TX_RB)) { 256 utx.begin(); 257 } 258 String pka = null; 259 BRemote b = bhome.findByPrimaryKey("bs0"); 260 if (tx == TX_CONT) { 261 pka = b.retrieveAInNewTx(); 262 } else { 263 pka = b.retrieveA(); 264 } 265 if (tx == TX_CALL) { 266 utx.commit(); 267 } else if (tx == TX_RB) { 268 utx.rollback(); 269 } 270 checkIsInitialState(); 272 } 273 public void testBasicGetEmptyB2ANoTx() throws Exception { 274 tBasicGetEmptyB2A(TX_NO); 275 } 276 public void testBasicGetEmptyB2ATxCall() throws Exception { 277 tBasicGetEmptyB2A(TX_CALL); 278 } 279 public void testBasicGetEmptyB2ATxCont() throws Exception { 280 tBasicGetEmptyB2A(TX_CONT); 281 } 282 283 284 285 288 public void tBasicGetOneA2B(int tx) throws Exception { 289 290 Collection c = null; 291 if ((tx == TX_CALL) || (tx == TX_RB)) { 292 utx.begin(); 293 } 294 ARemote a = ahome.findByPrimaryKey("as1"); 295 if (tx == TX_CONT) { 296 c = a.retrieveBInNewTx(); 297 } else { 298 c = a.retrieveB(); 299 } 300 if (tx == TX_CALL) { 301 utx.commit(); 302 } else if (tx == TX_RB) { 303 utx.rollback(); 304 } 305 assertEquals("Relations size of: ", 1, c.size()); 307 String s = "bs1_1"; 308 assertTrue("Relation missing " + s + ": ", c.contains(s)); 309 checkIsInitialState(); 310 } 311 312 313 316 public void tBasicGetManyA2B(int tx) throws Exception { 317 318 Collection c = null; 319 if ((tx == TX_CALL) || (tx == TX_RB)) { 320 utx.begin(); 321 } 322 ARemote a = ahome.findByPrimaryKey("as2"); 323 if (tx == TX_CONT) { 324 c = a.retrieveBInNewTx(); 325 } else { 326 c = a.retrieveB(); 327 } 328 if (tx == TX_CALL) { 329 utx.commit(); 330 } else if (tx == TX_RB) { 331 utx.rollback(); 332 } 333 assertEquals("Relations size of: ", 3, c.size()); 335 String s = "bs2_1"; 336 assertTrue("Relation missing " + s + ": ", c.contains(s)); 337 s = "bs2_2"; 338 assertTrue("Relation missing " + s + ": ", c.contains(s)); 339 s = "bs2_3"; 340 assertTrue("Relation missing " + s + ": ", c.contains(s)); 341 checkIsInitialState(); 342 } 343 344 345 346 352 public void tCohSetEmptyA2B(int tx) throws Exception { 353 ArrayList ce = new ArrayList (); 354 if ((tx == TX_CALL) || (tx == TX_RB)) { 355 utx.begin(); 356 } 357 ARemote a = ahome.findByPrimaryKey("as1"); 358 if (tx == TX_CONT) { 359 a.assignBInNewTx(ce); 360 } else { 361 a.assignB(ce); 362 } 363 if (tx == TX_CALL) { 364 utx.commit(); 365 } else if (tx == TX_RB) { 366 utx.rollback(); 367 } 368 if (tx != TX_RB) { 369 Collection ca = a.retrieveB(); 371 assertEquals("Relations size for as1 ", 0, ca.size()); 372 BRemote b = bhome.findByPrimaryKey("bs1_1"); 373 assertNull("Bad relation for bs1_1", b.retrieveA()); 374 a.addInB("bs1_1"); 376 } 377 checkIsInitialState(); 378 } 379 380 381 382 388 public void tCohClearA2B(int tx) throws Exception { 389 if ((tx == TX_CALL) || (tx == TX_RB)) { 390 utx.begin(); 391 } 392 ARemote a = ahome.findByPrimaryKey("as1"); 393 if (tx == TX_CONT) { 394 a.clearBInNewTx(); 395 } else { 396 a.clearB(); 397 } 398 if (tx == TX_CALL) { 399 utx.commit(); 400 } else if (tx == TX_RB) { 401 utx.rollback(); 402 } 403 if (tx != TX_RB) { 404 Collection c = a.retrieveB(); 406 BRemote b = bhome.findByPrimaryKey("bs1_1"); 407 String r = b.retrieveA(); 408 assertEquals("Expected empty collection for as1 relation: ", 0, c.size()); 409 assertNull("Expected no relation for bs1_1", r); 410 b.assignA("as1"); 412 } 413 checkIsInitialState(); 414 } 415 416 417 424 public void tCohSetOneA2B(int tx) throws Exception { 425 ArrayList ce = new ArrayList (); 426 ce.add("b0"); 427 if ((tx == TX_CALL) || (tx == TX_RB)) { 428 utx.begin(); 429 } 430 ARemote a = ahome.findByPrimaryKey("as0"); 431 if (tx == TX_CONT) { 432 a.assignBInNewTx(ce); 433 } else { 434 a.assignB(ce); 435 } 436 if (tx == TX_CALL) { 437 utx.commit(); 438 } else if (tx == TX_RB) { 439 utx.rollback(); 440 } 441 if (tx != TX_RB) { 442 Collection ca = a.retrieveB(); 444 BRemote b = bhome.findByPrimaryKey("b0"); 445 String r = b.retrieveA(); 446 assertTrue("Bad relations for as0 (required:" + ce + ", found:" + ca 447 + ")", isCollectionEqual(ce, ca)); 448 assertEquals("Bad relation for b0: ", "as0", r); 449 a.assignB(new ArrayList ()); 451 } 452 checkIsInitialState(); 453 } 454 455 456 457 458 465 public void tCohSet1B2A(int tx) throws Exception { 466 if ((tx == TX_CALL) || (tx == TX_RB)) { 467 utx.begin(); 468 } 469 BRemote b = bhome.findByPrimaryKey("b0"); 470 if (tx == TX_CONT) { 471 b.assignAInNewTx("as0"); 472 } else { 473 b.assignA("as0"); 474 } 475 if (tx == TX_CALL) { 476 utx.commit(); 477 } else if (tx == TX_RB) { 478 utx.rollback(); 479 } 480 String r = b.retrieveA(); 482 ARemote a = ahome.findByPrimaryKey("as0"); 483 Collection ca = a.retrieveB(); 484 ArrayList ce = new ArrayList (); 485 ce.add("b0"); 486 if (tx != TX_RB) { 487 assertEquals("Bad relation for b0: ", "as0", r); 488 assertTrue("Bad relations for as0 (required:" + ce + ", found:" + ca 489 + ")", isCollectionEqual(ce, ca)); 490 b.assignA(null); 492 } 493 checkIsInitialState(); 494 } 495 496 497 498 499 507 public void tCohAddOneA2B(int tx) throws Exception { 508 ArrayList ce = new ArrayList (); 509 ce.add("bs0"); 510 if ((tx == TX_CALL) || (tx == TX_RB)) { 511 utx.begin(); 512 } 513 ARemote a = ahome.findByPrimaryKey("as0"); 514 if (tx == TX_CONT) { 515 a.addInBInNewTx("bs0"); 516 } else { 517 a.addInB("bs0"); 518 } 519 if (tx == TX_CALL) { 520 utx.commit(); 521 } else if (tx == TX_RB) { 522 utx.rollback(); 523 } 524 if (tx != TX_RB) { 525 Collection ca = a.retrieveB(); 527 BRemote b = bhome.findByPrimaryKey("bs0"); 528 String r = b.retrieveA(); 529 assertTrue("Bad relations for as0 (required:" + ce + ", found:" + ca 530 + ")", isCollectionEqual(ce, ca)); 531 assertEquals("Bad relation for bs0", "as0", r); 532 a.assignB(new ArrayList ()); 534 } 535 checkIsInitialState(); 536 } 537 538 539 548 public void tCohSetMultiA2B(int tx) throws Exception { 549 ArrayList ce = new ArrayList (2); 550 ce.add("bs0"); 551 ce.add("bs3"); 552 if ((tx == TX_CALL) || (tx == TX_RB)) { 553 utx.begin(); 554 } 555 ARemote a = ahome.findByPrimaryKey("as1"); 556 Collection co = a.retrieveB(); 557 if (tx == TX_CONT) { 558 a.assignBInNewTx(ce); 559 } else { 560 a.assignB(ce); 561 } 562 if (tx == TX_CALL) { 563 utx.commit(); 564 } else if (tx == TX_RB) { 565 utx.rollback(); 566 } 567 if (tx != TX_RB) { 568 Collection ca = a.retrieveB(); 570 BRemote bs1_1 = bhome.findByPrimaryKey("bs1_1"); 571 BRemote bs0 = bhome.findByPrimaryKey("bs0"); 572 BRemote bs3 = bhome.findByPrimaryKey("bs3"); 573 assertTrue("Bad relations for as1 (required:" + ce + ", found:" + ca 574 + ")", isCollectionEqual(ce, ca)); 575 assertNull("Not null relation for bs1_1", bs1_1.retrieveA()); 576 assertEquals("Bad relation for bs0: ", "as1", bs0.retrieveA()); 577 assertEquals("Bad relation for bs3: ", "as1", bs3.retrieveA()); 578 a.assignB(co); 580 } 581 checkIsInitialState(); 582 } 583 584 585 586 587 598 public void tCohSet2B2A(int tx) throws Exception { 599 if ((tx == TX_CALL) || (tx == TX_RB)) { 600 utx.begin(); 601 } 602 BRemote b = bhome.findByPrimaryKey("bs1_1"); 603 if (tx == TX_CONT) { 604 b.assignAInNewTx("as0"); 605 } else { 606 b.assignA("as0"); 607 } 608 if (tx == TX_CALL) { 609 utx.commit(); 610 } else if (tx == TX_RB) { 611 utx.rollback(); 612 } 613 if (tx != TX_RB) { 614 String r = b.retrieveA(); 616 assertEquals("Bad relation for bs1_1: ", "as0", r); 617 ARemote as0 = ahome.findByPrimaryKey("as0"); 618 Collection cas0 = as0.retrieveB(); 619 ARemote as1 = ahome.findByPrimaryKey("as1"); 620 Collection cas1 = as1.retrieveB(); 621 ArrayList ce = new ArrayList (); 622 ce.add("bs1_1"); 623 assertTrue("Bad relations for as0 (required:" + ce + ", found:" + cas0 624 + ")", isCollectionEqual(ce, cas0)); 625 ce = new ArrayList (); 626 assertTrue("Bad relations for as1 (required:" + ce + ", found:" + cas1 627 + ")", isCollectionEqual(ce, cas1)); 628 b.assignA("as1"); 630 } 631 checkIsInitialState(); 632 } 633 634 635 636 637 650 public void tCohSet3B2A(int tx) throws Exception { 651 if ((tx == TX_CALL) || (tx == TX_RB)) { 652 utx.begin(); 653 } 654 BRemote bs1_1 = bhome.findByPrimaryKey("bs1_1"); 655 if (tx == TX_CONT) { 656 bs1_1.assignAInNewTx("a3"); 657 } else { 658 bs1_1.assignA("a3"); 659 } 660 if (tx == TX_CALL) { 661 utx.commit(); 662 } else if (tx == TX_RB) { 663 utx.rollback(); 664 } 665 if (tx != TX_RB) { 666 String rbs1_1 = bs1_1.retrieveA(); 668 ARemote as1 = ahome.findByPrimaryKey("as1"); 669 Collection cas1 = as1.retrieveB(); 670 ARemote a3 = ahome.findByPrimaryKey("a3"); 671 Collection ca3 = a3.retrieveB(); 672 assertEquals("Bad relation for bs1_1: ", "a3", rbs1_1); 673 ArrayList ce = new ArrayList (); 674 ce.add("bs1_1"); 675 ce.add("b3_1"); 676 assertTrue("Bad relations for a3 (required:" + ce + ", found:" + ca3 677 + ")", isCollectionEqual(ce, ca3)); 678 ce = new ArrayList (); 679 assertTrue("Bad relations for as1 (required:" + ce + ", found:" + cas1 680 + ")", isCollectionEqual(ce, cas1)); 681 bs1_1.assignA("as1"); 683 } 684 checkIsInitialState(); 685 } 686 687 688 689 696 public void tCohRemoveInRelA2B(int tx) throws Exception { 697 if ((tx == TX_CALL) || (tx == TX_RB)) { 698 utx.begin(); 699 } 700 ARemote a = ahome.findByPrimaryKey("a3"); 701 if (tx == TX_CONT) { 702 a.removeFromBInNewTx("b3_1"); 703 } else { 704 a.removeFromB("b3_1"); 705 } 706 if (tx == TX_CALL) { 707 utx.commit(); 708 } else if (tx == TX_RB) { 709 utx.rollback(); 710 } 711 if (tx != TX_RB) { 712 Collection ca = a.retrieveB(); 714 BRemote b = bhome.findByPrimaryKey("b3_1"); 715 String r = b.retrieveA(); 716 ArrayList ce = new ArrayList (); 717 assertTrue("Bad relations for a3: (required:" + ce + ", found:" + ca 718 + ")", isCollectionEqual(ce, ca)); 719 assertNull("Bad not null relation for b3_1", r); 720 a.addInB("b3_1"); 722 } 723 checkIsInitialState(); 725 726 } 727 728 729 730 737 public void tCohRemoveB(int tx) throws Exception { 738 if (tx == TX_CONT) { 739 fail("Transaction cannot be initiate by the container for this test"); 742 } 743 if ((tx == TX_CALL) || (tx == TX_RB)) { 744 utx.begin(); 745 } 746 bhome.remove("b3_1"); 747 if (tx == TX_CALL) { 748 utx.commit(); 749 } else if (tx == TX_RB) { 750 utx.rollback(); 751 } 752 if (tx != TX_RB) { 753 ARemote a = ahome.findByPrimaryKey("a3"); 755 Collection ca = a.retrieveB(); 756 assertEquals("Wrong relations size for a3: (expected: 0 found:" 757 + ca.size(), 0, ca.size()); 758 bhome.create("b3_1"); 760 a.addInBInNewTx("b3_1"); 761 } 762 checkIsInitialState(); 763 } 764 765 766 767 776 public void tCohBeanRemoveB(int tx) throws Exception { 777 if (tx == TX_CONT) { 778 fail("Transaction cannot be initiate by the container for this test"); 781 } 782 if ((tx == TX_CALL) || (tx == TX_RB)) { 783 utx.begin(); 784 } 785 BRemote b = bhome.findByPrimaryKey("b3_1"); 786 b.remove(); 787 if (tx == TX_CALL) { 788 utx.commit(); 789 } else if (tx == TX_RB) { 790 utx.rollback(); 791 } 792 if (tx != TX_RB) { 793 ARemote a = ahome.findByPrimaryKey("a3"); 795 Collection ca = a.retrieveB(); 796 assertEquals("Wrong relations size for a3: (expected: 0 found:" 797 + ca.size(), 0, ca.size()); 798 bhome.create("b3_1"); 800 a.addInBInNewTx("b3_1"); 801 } 802 checkIsInitialState(); 803 } 804 805 806 807 808 809 818 public void tCohSetOne2A2B(int tx) throws Exception { 819 ArrayList ce = new ArrayList (); 820 ce.add("b3_1"); 821 if ((tx == TX_CALL) || (tx == TX_RB)) { 822 utx.begin(); 823 } 824 ARemote a = ahome.findByPrimaryKey("a0"); 825 if (tx == TX_CONT) { 826 a.assignBInNewTx(ce); 827 } else { 828 a.assignB(ce); 829 } 830 if (tx == TX_CALL) { 831 utx.commit(); 832 } else if (tx == TX_RB) { 833 utx.rollback(); 834 } 835 if (tx != TX_RB) { 836 Collection ca = a.retrieveB(); 838 ARemote a3 = ahome.findByPrimaryKey("a3"); 839 Collection ca3 = a3.retrieveB(); 840 BRemote b = bhome.findByPrimaryKey("b3_1"); 841 String r = b.retrieveA(); 842 assertTrue("Wrong relations a0 (required:" + ce + ", found:" + ca 843 + ")", isCollectionEqual(ce, ca)); 844 assertTrue("Wrong relations for b3_1" + ": found:" + ca3 , 845 !ca3.contains("b3_1")); 846 assertEquals("Bad relation for b3_1: ", "a0", r); 847 a.assignB(new ArrayList ()); 849 a3.addInB("b3_1"); 850 } 851 checkIsInitialState(); 852 } 853 854 855 856 857 875 public void tCohAddOneInMultiA2B(int tx) throws Exception { 876 877 ArrayList ce = new ArrayList (); 878 ce.add("b1_1"); 879 ce.add("b1_2"); 880 ce.add("b1_3"); 881 String bAdded = "b3_1"; 882 if ((tx == TX_CALL) || (tx == TX_RB)) { 883 utx.begin(); 884 } 885 ARemote a = ahome.findByPrimaryKey("a1"); 886 if (tx == TX_CONT) { 887 a.addInBInNewTx(bAdded); 888 } else { 889 a.addInB(bAdded); 890 } 891 ce.add(bAdded); 892 if (tx == TX_CALL) { 893 utx.commit(); 894 } else if (tx == TX_RB) { 895 utx.rollback(); 896 } 897 if (tx != TX_RB) { 898 Collection ca1 = a.retrieveB(); 900 ARemote a3 = ahome.findByPrimaryKey("a3"); 901 Collection ca3 = a3.retrieveB(); 902 assertTrue("Bad relations for a1 (required:" + ce + ", found:" + ca1 + ")", 903 isCollectionEqual(ce, ca1)); 904 ce = new ArrayList (); 905 assertTrue("Bad relations for a3 (required:" + ce + ", found:" + ca3 + ")", 906 isCollectionEqual(ce, ca3)); 907 BRemote b = bhome.findByPrimaryKey(bAdded); 908 assertEquals("Bad relation for b3_1: ", "a1", b.retrieveA()); 909 a3.addInB(bAdded); 911 } 912 913 checkIsInitialState(); 914 } 915 916 917 939 public void tCohSetMultiBisA2B(int tx) throws Exception { 940 if ((tx == TX_CALL) || (tx == TX_RB)) { 941 utx.begin(); 942 } 943 ARemote a1 = ahome.findByPrimaryKey("a1"); 944 Collection co1 = a1.retrieveB(); 945 ARemote a2 = ahome.findByPrimaryKey("a2"); 946 Collection co2 = a2.retrieveB(); 947 if (tx == TX_CONT) { 948 a1.assignBInNewTx(co2); 949 } else { 950 a1.assignB(co2); 951 } 952 if (tx == TX_CALL) { 953 utx.commit(); 954 } else if (tx == TX_RB) { 955 utx.rollback(); 956 } 957 if (tx != TX_RB) { 958 Collection ca1 = a1.retrieveB(); 960 assertTrue("Wrong relations for a1 (required:" + co2 + ", found:" + ca1 + ")", isCollectionEqual(co2, ca1)); 961 Collection ca2 = a2.retrieveB(); 962 assertEquals("Wrong relations size for a2: ", 0, ca2.size()); 963 BRemote b; 964 b = bhome.findByPrimaryKey("b1_1"); 965 assertNull("Wrong not null relation for b1_1: ", b.retrieveA()); 966 b = bhome.findByPrimaryKey("b1_2"); 967 assertNull("Wrong not null relation for b1_2: ", b.retrieveA()); 968 b = bhome.findByPrimaryKey("b1_3"); 969 assertNull("Wrong not null relation for b1_3: ", b.retrieveA()); 970 b = bhome.findByPrimaryKey("b2_1"); 971 assertEquals("Wrong relation for b2_1: ", "a1", b.retrieveA()); 972 b = bhome.findByPrimaryKey("b2_2"); 973 assertEquals("Wrong relation for b2_2: ", "a1", b.retrieveA()); 974 b = bhome.findByPrimaryKey("b2_3"); 975 assertEquals("Wrong relation for b2_3: ", "a1", b.retrieveA()); 976 a1.assignB(co1); 978 a2.assignB(co2); 979 } 980 checkIsInitialState(); 981 } 982 983 984 985 986 987 public static Test suite() { 988 return new TestSuite(G_Relation_ombEC2.class); 989 } 990 991 public static void main(String args[]) { 992 String testtorun = null; 993 for (int argn = 0; argn < args.length; argn++) { 995 String s_arg = args[argn]; 996 Integer i_arg; 997 if (s_arg.equals("-n")) { 998 testtorun = args[++argn]; 999 } 1000 } 1001 if (testtorun == null) { 1002 junit.textui.TestRunner.run(suite()); 1003 } else { 1004 junit.textui.TestRunner.run(new G_Relation_ombEC2(testtorun)); 1005 } 1006 } 1007 1008} 1009 | Popular Tags |