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 import org.objectweb.jonas.jtests.beans.relation.omb.Front; 45 import org.objectweb.jonas.jtests.beans.relation.omb.FrontHome; 46 47 51 public class F_Relation_ombEC2 extends A_Cmp2Util { 52 53 54 private static String BEAN_HOME_A = "relation_omb_AHome"; 55 protected static AHomeRemote ahome = null; 56 private static String BEAN_HOME_B = "relation_omb_BHome"; 57 protected static BHomeRemote bhome = null; 58 private static String BEAN_HOME_FRONT = "relation_omb_FrontHome"; 59 protected static FrontHome fhome = null; 60 61 static Hashtable a2b = new Hashtable (); 62 static String [][] b2a = { 63 {"bs0", null}, 64 {"bs1_1", "as1"}, 65 {"bs2_1", "as2"}, 66 {"bs2_2", "as2"}, 67 {"bs2_3", "as2"}, 68 {"bs3", null}, 69 {"b0", null}, 70 {"b1_1", "a1"}, 71 {"b1_2", "a1"}, 72 {"b1_3", "a1"}, 73 {"b2_1", "a2"}, 74 {"b2_2", "a2"}, 75 {"b2_3", "a2"}, 76 {"b3_1", "a3"}}; 77 78 static { 79 a2b.put("as0", new String []{}); 80 a2b.put("as1", new String []{"bs1_1"}); 81 a2b.put("as2", new String []{"bs2_1", "bs2_2", "bs2_3"}); 82 a2b.put("a0", new String []{}); 83 a2b.put("a1", new String []{"b1_1", "b1_2", "b1_3"}); 84 a2b.put("a2", new String []{"b2_1", "b2_2", "b2_3"}); 85 a2b.put("a3", new String []{"b3_1"}); 86 a2b.put("ax0", new String []{}); 87 88 for (Iterator it = a2b.keySet().iterator(); it.hasNext();) { 90 String aname = (String ) (it.next()); 91 String [] tb = (String []) a2b.get(aname); 92 ArrayList col = new ArrayList (tb.length); 93 for (int i = 0; i < tb.length; i++) { 94 col.add(tb[i]); 95 } 96 a2b.put(aname, col); 97 } 98 } 99 100 101 public F_Relation_ombEC2(String name) { 102 super(name); 103 } 104 105 protected static boolean isInit = false; 106 107 protected void setUp() { 108 super.setUp(); 109 boolean ok = false; 110 int nbtry = 0; 111 while (!ok && nbtry < 3) { 112 if (!isInit) { 113 useBeans("omb", false); 115 try { 116 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A), 117 AHomeRemote.class); 118 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B), 119 BHomeRemote.class); 120 fhome = (FrontHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_FRONT), 121 FrontHome.class); 122 assertNotNull(ahome); 123 assertNotNull(bhome); 124 } catch (NamingException e) { 125 fail("Cannot get bean home: " + e.getMessage()); 126 } 127 try { 129 ahome.findByPrimaryKey("a0"); 130 } catch (Exception e) { 131 try { 132 utx.begin(); 133 bhome.create("bs0"); 134 bhome.create("bs1_1"); 135 bhome.create("bs2_1"); 136 bhome.create("bs2_2"); 137 bhome.create("bs2_3"); 138 bhome.create("bs3"); 139 bhome.create("b0"); 140 bhome.create("b1_1"); 141 bhome.create("b1_2"); 142 bhome.create("b1_3"); 143 bhome.create("b2_1"); 144 bhome.create("b2_2"); 145 bhome.create("b2_3"); 146 bhome.create("b3_1"); 147 ahome.create("as0"); 148 ahome.create("as1").assignB((Collection ) a2b.get("as1")); 149 ahome.create("as2").assignB((Collection ) a2b.get("as2")); 150 ahome.create("a0"); 151 ahome.create("a1").assignB((Collection ) a2b.get("a1")); 152 ahome.create("a2").assignB((Collection ) a2b.get("a2")); 153 ahome.create("a3").assignB((Collection ) a2b.get("a3")); 154 ahome.create("ax0"); 155 } catch (Exception i) { 156 fail("InitialState creation problem: " + i); 157 } finally { 158 try { 159 utx.commit(); 160 } catch (Exception ii) { 161 } 162 } 163 } 164 isInit = true; 165 } 166 nbtry++; 169 try { 170 if (initStateOK()) { 171 ok = true; 172 } 173 } catch (Exception e) { 174 } 175 if (!ok) { 176 isInit = false; 177 unloadBeans("omb"); 178 } 179 } 180 } 181 182 186 boolean initStateOK() throws Exception { 187 boolean isOk = true; 188 msgerror = new StringBuffer (); 189 for (Enumeration ea = a2b.keys(); ea.hasMoreElements();) { 191 String aname = (String ) (ea.nextElement()); 192 ARemote a = ahome.findByPrimaryKey(aname); 193 Collection colActual = a.retrieveB(); 194 Collection colExpected = (Collection ) (a2b.get(aname)); 195 if (!isCollectionEqual(colExpected, colActual)) { 196 isOk = false; 197 msgerror = msgerror.append("\nWrong relation for " + aname 198 + " (expected:" + colExpected 199 + ", found:" + colActual + ")"); 200 } 201 } 202 for (int i = 0; i < b2a.length; i++) { 204 BRemote b = bhome.findByPrimaryKey(b2a[i][0]); 205 String pkb = b.getId(); 206 String pka = b.retrieveA(); 207 if (b2a[i][1] == null && pka != null 208 || b2a[i][1] != null && !b2a[i][1].equals(pka)) { 209 isOk = false; 210 msgerror = msgerror.append("\nWrong relation for " + pkb 211 + " (expected:" + b2a[i][1] 212 + ", found:" + pka + ")"); 213 } 214 215 } 216 return isOk; 217 } 218 219 220 223 public void tBasicGetEmptyA2B(int tx) throws Exception { 224 Collection c = null; 225 if ((tx == TX_CALL) || (tx == TX_RB)) { 226 utx.begin(); 227 } 228 ARemote a = ahome.findByPrimaryKey("as0"); 229 if (tx == TX_CONT) { 230 c = a.retrieveBInNewTx(); 231 } else { 232 c = a.retrieveB(); 233 } 234 if (tx == TX_CALL) { 235 utx.commit(); 236 } else if (tx == TX_RB) { 237 utx.rollback(); 238 } 239 checkIsInitialState(); 241 } 242 243 public void testBasicGetEmptyA2BTxNo() throws Exception { 244 tBasicGetEmptyA2B(TX_NO); 245 } 246 public void testBasicGetEmptyA2BTxCall() throws Exception { 247 tBasicGetEmptyA2B(TX_CALL); 248 } 249 public void testBasicGetEmptyA2BTxCont() throws Exception { 250 tBasicGetEmptyA2B(TX_CONT); 251 } 252 public void testBasicGetEmptyA2BTxRb() throws Exception { 253 tBasicGetEmptyA2B(TX_RB); 254 } 255 256 259 public void tBasicGetEmptyB2A(int tx) throws Exception { 260 if ((tx == TX_CALL) || (tx == TX_RB)) { 261 utx.begin(); 262 } 263 String pka = null; 264 BRemote b = bhome.findByPrimaryKey("bs0"); 265 if (tx == TX_CONT) { 266 pka = b.retrieveAInNewTx(); 267 } else { 268 pka = b.retrieveA(); 269 } 270 if (tx == TX_CALL) { 271 utx.commit(); 272 } else if (tx == TX_RB) { 273 utx.rollback(); 274 } 275 checkIsInitialState(); 277 } 278 public void testBasicGetEmptyB2ANoTx() throws Exception { 279 tBasicGetEmptyB2A(TX_NO); 280 } 281 public void testBasicGetEmptyB2ATxCall() throws Exception { 282 tBasicGetEmptyB2A(TX_CALL); 283 } 284 public void testBasicGetEmptyB2ATxCont() throws Exception { 285 tBasicGetEmptyB2A(TX_CONT); 286 } 287 public void testBasicGetEmptyB2ATxRb() throws Exception { 288 tBasicGetEmptyB2A(TX_RB); 289 } 290 291 292 295 public void tBasicGetOneA2B(int tx) throws Exception { 296 297 Collection c = null; 298 if ((tx == TX_CALL) || (tx == TX_RB)) { 299 utx.begin(); 300 } 301 ARemote a = ahome.findByPrimaryKey("as1"); 302 if (tx == TX_CONT) { 303 c = a.retrieveBInNewTx(); 304 } else { 305 c = a.retrieveB(); 306 } 307 if (tx == TX_CALL) { 308 utx.commit(); 309 } else if (tx == TX_RB) { 310 utx.rollback(); 311 } 312 assertEquals("Relations size of: ", 1, c.size()); 314 String s = "bs1_1"; 315 assertTrue("Relation missing " + s + ": ", c.contains(s)); 316 checkIsInitialState(); 317 } 318 319 public void testBasicGetOneA2BTxNo() throws Exception { 320 tBasicGetOneA2B(TX_NO); 321 } 322 323 public void testBasicGetOneA2BTxCall() throws Exception { 324 tBasicGetOneA2B(TX_CALL); 325 } 326 327 public void testBasicGetOneA2BTxCont() throws Exception { 328 tBasicGetOneA2B(TX_CONT); 329 } 330 331 public void testBasicGetOneA2BTxRb() throws Exception { 332 tBasicGetOneA2B(TX_RB); 333 } 334 335 336 339 public void tBasicGetManyA2B(int tx) throws Exception { 340 341 Collection c = null; 342 if ((tx == TX_CALL) || (tx == TX_RB)) { 343 utx.begin(); 344 } 345 ARemote a = ahome.findByPrimaryKey("as2"); 346 if (tx == TX_CONT) { 347 c = a.retrieveBInNewTx(); 348 } else { 349 c = a.retrieveB(); 350 } 351 if (tx == TX_CALL) { 352 utx.commit(); 353 } else if (tx == TX_RB) { 354 utx.rollback(); 355 } 356 assertEquals("Relations size of: ", 3, c.size()); 358 String s = "bs2_1"; 359 assertTrue("Relation missing " + s + ": ", c.contains(s)); 360 s = "bs2_2"; 361 assertTrue("Relation missing " + s + ": ", c.contains(s)); 362 s = "bs2_3"; 363 assertTrue("Relation missing " + s + ": ", c.contains(s)); 364 checkIsInitialState(); 365 } 366 367 public void testBasicGetManyA2BTxNo() throws Exception { 368 tBasicGetManyA2B(TX_NO); 369 } 370 371 public void testBasicGetManyA2BTxCall() throws Exception { 372 tBasicGetManyA2B(TX_CALL); 373 } 374 375 public void testBasicGetManyA2BTxCont() throws Exception { 376 tBasicGetManyA2B(TX_CONT); 377 } 378 379 public void testBasicGetManyA2BTxRb() throws Exception { 380 tBasicGetManyA2B(TX_RB); 381 } 382 383 384 390 public void tCohSetEmptyA2B(int tx) throws Exception { 391 ArrayList ce = new ArrayList (); 392 if ((tx == TX_CALL) || (tx == TX_RB)) { 393 utx.begin(); 394 } 395 ARemote a = ahome.findByPrimaryKey("as1"); 396 if (tx == TX_CONT) { 397 a.assignBInNewTx(ce); 398 } else { 399 a.assignB(ce); 400 } 401 if (tx == TX_CALL) { 402 utx.commit(); 403 } else if (tx == TX_RB) { 404 utx.rollback(); 405 } 406 if (tx != TX_RB) { 407 Collection ca = a.retrieveB(); 409 assertEquals("Relations size for as1 ", 0, ca.size()); 410 BRemote b = bhome.findByPrimaryKey("bs1_1"); 411 assertNull("Bad relation for bs1_1", b.retrieveA()); 412 a.addInB("bs1_1"); 414 } 415 checkIsInitialState(); 416 } 417 418 public void testCohSetEmptyA2BTxNo() throws Exception { 419 tCohSetEmptyA2B(TX_NO); 420 } 421 422 public void testCohSetEmptyA2BTxCall() throws Exception { 423 tCohSetEmptyA2B(TX_CALL); 424 } 425 426 public void testCohSetEmptyA2BTxCont() throws Exception { 427 tCohSetEmptyA2B(TX_CONT); 428 } 429 430 public void testCohSetEmptyA2BTxRb() throws Exception { 431 tCohSetEmptyA2B(TX_RB); 432 } 433 434 435 441 public void tCohClearA2B(int tx) throws Exception { 442 if ((tx == TX_CALL) || (tx == TX_RB)) { 443 utx.begin(); 444 } 445 ARemote a = ahome.findByPrimaryKey("as1"); 446 if (tx == TX_CONT) { 447 a.clearBInNewTx(); 448 } else { 449 a.clearB(); 450 } 451 if (tx == TX_CALL) { 452 utx.commit(); 453 } else if (tx == TX_RB) { 454 utx.rollback(); 455 } 456 if (tx != TX_RB) { 457 Collection c = a.retrieveB(); 459 BRemote b = bhome.findByPrimaryKey("bs1_1"); 460 String r = b.retrieveA(); 461 assertEquals("Expected empty collection for as1 relation: ", 0, c.size()); 462 assertNull("Expected no relation for bs1_1", r); 463 b.assignA("as1"); 465 } 466 checkIsInitialState(); 467 } 468 469 public void testCohClearA2BTxNo() throws Exception { 470 tCohClearA2B(TX_NO); 471 } 472 473 public void testCohClearA2BTxCall() throws Exception { 474 tCohClearA2B(TX_CALL); 475 } 476 477 public void testCohClearA2BTxCont() throws Exception { 478 tCohClearA2B(TX_CONT); 479 } 480 481 public void testCohClearA2BTxRb() throws Exception { 482 tCohClearA2B(TX_RB); 483 } 484 485 486 493 public void tCohSetOneA2B(int tx) throws Exception { 494 ArrayList ce = new ArrayList (); 495 ce.add("b0"); 496 if ((tx == TX_CALL) || (tx == TX_RB)) { 497 utx.begin(); 498 } 499 ARemote a = ahome.findByPrimaryKey("as0"); 500 if (tx == TX_CONT) { 501 a.assignBInNewTx(ce); 502 } else { 503 a.assignB(ce); 504 } 505 if (tx == TX_CALL) { 506 utx.commit(); 507 } else if (tx == TX_RB) { 508 utx.rollback(); 509 } 510 if (tx != TX_RB) { 511 Collection ca = a.retrieveB(); 513 BRemote b = bhome.findByPrimaryKey("b0"); 514 String r = b.retrieveA(); 515 assertTrue("Bad relations for as0 (required:" + ce + ", found:" + ca 516 + ")", isCollectionEqual(ce, ca)); 517 assertEquals("Bad relation for b0: ", "as0", r); 518 a.assignB(new ArrayList ()); 520 } 521 checkIsInitialState(); 522 } 523 524 public void testCohSetOneA2BTxNo() throws Exception { 525 tCohSetOneA2B(TX_NO); 526 } 527 528 public void testCohSetOneA2BTxCall() throws Exception { 529 tCohSetOneA2B(TX_CALL); 530 } 531 532 public void testCohSetOneA2BTxCont() throws Exception { 533 tCohSetOneA2B(TX_CONT); 534 } 535 536 public void testCohSetOneA2BTxRb() throws Exception { 537 tCohSetOneA2B(TX_RB); 538 } 539 540 541 548 public void tCohSet1B2A(int tx) throws Exception { 549 if ((tx == TX_CALL) || (tx == TX_RB)) { 550 utx.begin(); 551 } 552 BRemote b = bhome.findByPrimaryKey("b0"); 553 if (tx == TX_CONT) { 554 b.assignAInNewTx("as0"); 555 } else { 556 b.assignA("as0"); 557 } 558 if (tx == TX_CALL) { 559 utx.commit(); 560 } else if (tx == TX_RB) { 561 utx.rollback(); 562 } 563 String r = b.retrieveA(); 565 ARemote a = ahome.findByPrimaryKey("as0"); 566 Collection ca = a.retrieveB(); 567 ArrayList ce = new ArrayList (); 568 ce.add("b0"); 569 if (tx != TX_RB) { 570 assertEquals("Bad relation for b0: ", "as0", r); 571 assertTrue("Bad relations for as0 (required:" + ce + ", found:" + ca 572 + ")", isCollectionEqual(ce, ca)); 573 b.assignA(null); 575 } 576 checkIsInitialState(); 577 } 578 579 public void testCohSet1B2ATxNo() throws Exception { 580 tCohSet1B2A(TX_NO); 581 } 582 583 public void testCohSet1B2ATxCall() throws Exception { 584 tCohSet1B2A(TX_CALL); 585 } 586 587 public void testCohSet1B2ATxCont() throws Exception { 588 tCohSet1B2A(TX_CONT); 589 } 590 591 public void testCohSet1B2ATxRb() throws Exception { 592 tCohSet1B2A(TX_RB); 593 } 594 595 596 597 605 public void tCohAddOneA2B(int tx) throws Exception { 606 ArrayList ce = new ArrayList (); 607 ce.add("bs0"); 608 if ((tx == TX_CALL) || (tx == TX_RB)) { 609 utx.begin(); 610 } 611 ARemote a = ahome.findByPrimaryKey("as0"); 612 if (tx == TX_CONT) { 613 a.addInBInNewTx("bs0"); 614 } else { 615 a.addInB("bs0"); 616 } 617 if (tx == TX_CALL) { 618 utx.commit(); 619 } else if (tx == TX_RB) { 620 utx.rollback(); 621 } 622 if (tx != TX_RB) { 623 Collection ca = a.retrieveB(); 625 BRemote b = bhome.findByPrimaryKey("bs0"); 626 String r = b.retrieveA(); 627 assertTrue("Bad relations for as0 (required:" + ce + ", found:" + ca 628 + ")", isCollectionEqual(ce, ca)); 629 assertEquals("Bad relation for bs0", "as0", r); 630 a.assignB(new ArrayList ()); 632 } 633 checkIsInitialState(); 634 } 635 636 public void testCohAddOneA2BTxNo() throws Exception { 637 tCohAddOneA2B(TX_NO); 638 } 639 640 public void testCohAddOneA2BTxCall() throws Exception { 641 tCohAddOneA2B(TX_CALL); 642 } 643 644 public void testCohAddOneA2BTxCont() throws Exception { 645 tCohAddOneA2B(TX_CONT); 646 } 647 648 public void testCohAddOneA2BTxRb() throws Exception { 649 tCohAddOneA2B(TX_RB); 650 } 651 652 653 662 public void tCohSetMultiA2B(int tx) throws Exception { 663 ArrayList ce = new ArrayList (2); 664 ce.add("bs0"); 665 ce.add("bs3"); 666 if ((tx == TX_CALL) || (tx == TX_RB)) { 667 utx.begin(); 668 } 669 ARemote a = ahome.findByPrimaryKey("as1"); 670 Collection co = a.retrieveB(); 671 if (tx == TX_CONT) { 672 a.assignBInNewTx(ce); 673 } else { 674 a.assignB(ce); 675 } 676 if (tx == TX_CALL) { 677 utx.commit(); 678 } else if (tx == TX_RB) { 679 utx.rollback(); 680 } 681 if (tx != TX_RB) { 682 Collection ca = a.retrieveB(); 684 BRemote bs1_1 = bhome.findByPrimaryKey("bs1_1"); 685 BRemote bs0 = bhome.findByPrimaryKey("bs0"); 686 BRemote bs3 = bhome.findByPrimaryKey("bs3"); 687 assertTrue("Bad relations for as1 (required:" + ce + ", found:" + ca 688 + ")", isCollectionEqual(ce, ca)); 689 assertNull("Not null relation for bs1_1", bs1_1.retrieveA()); 690 assertEquals("Bad relation for bs0: ", "as1", bs0.retrieveA()); 691 assertEquals("Bad relation for bs3: ", "as1", bs3.retrieveA()); 692 a.assignB(co); 694 } 695 checkIsInitialState(); 696 } 697 698 public void testCohSetMultiA2BTxNo() throws Exception { 699 tCohSetMultiA2B(TX_NO); 700 } 701 702 public void testCohSetMultiA2BTxCall() throws Exception { 703 tCohSetMultiA2B(TX_CALL); 704 } 705 706 public void testCohSetMultiA2BTxCont() throws Exception { 707 tCohSetMultiA2B(TX_CONT); 708 } 709 710 public void testCohSetMultiA2BTxRb() throws Exception { 711 tCohSetMultiA2B(TX_RB); 712 } 713 714 715 726 public void tCohSet2B2A(int tx) throws Exception { 727 if ((tx == TX_CALL) || (tx == TX_RB)) { 728 utx.begin(); 729 } 730 BRemote b = bhome.findByPrimaryKey("bs1_1"); 731 if (tx == TX_CONT) { 732 b.assignAInNewTx("as0"); 733 } else { 734 b.assignA("as0"); 735 } 736 if (tx == TX_CALL) { 737 utx.commit(); 738 } else if (tx == TX_RB) { 739 utx.rollback(); 740 } 741 if (tx != TX_RB) { 742 String r = b.retrieveA(); 744 assertEquals("Bad relation for bs1_1: ", "as0", r); 745 ARemote as0 = ahome.findByPrimaryKey("as0"); 746 Collection cas0 = as0.retrieveB(); 747 ARemote as1 = ahome.findByPrimaryKey("as1"); 748 Collection cas1 = as1.retrieveB(); 749 ArrayList ce = new ArrayList (); 750 ce.add("bs1_1"); 751 assertTrue("Bad relations for as0 (required:" + ce + ", found:" + cas0 752 + ")", isCollectionEqual(ce, cas0)); 753 ce = new ArrayList (); 754 assertTrue("Bad relations for as1 (required:" + ce + ", found:" + cas1 755 + ")", isCollectionEqual(ce, cas1)); 756 b.assignA("as1"); 758 } 759 checkIsInitialState(); 760 } 761 762 public void testCohSet2B2ATxNo() throws Exception { 763 tCohSet2B2A(TX_NO); 764 } 765 766 public void testCohSet2B2ATxCall() throws Exception { 767 tCohSet2B2A(TX_CALL); 768 } 769 770 public void testCohSet2B2ATxCont() throws Exception { 771 tCohSet2B2A(TX_CONT); 772 } 773 774 public void testCohSet2B2ATxRb() throws Exception { 775 tCohSet2B2A(TX_RB); 776 } 777 778 779 792 public void tCohSet3B2A(int tx) throws Exception { 793 if ((tx == TX_CALL) || (tx == TX_RB)) { 794 utx.begin(); 795 } 796 BRemote bs1_1 = bhome.findByPrimaryKey("bs1_1"); 797 if (tx == TX_CONT) { 798 bs1_1.assignAInNewTx("a3"); 799 } else { 800 bs1_1.assignA("a3"); 801 } 802 if (tx == TX_CALL) { 803 utx.commit(); 804 } else if (tx == TX_RB) { 805 utx.rollback(); 806 } 807 if (tx != TX_RB) { 808 String rbs1_1 = bs1_1.retrieveA(); 810 ARemote as1 = ahome.findByPrimaryKey("as1"); 811 Collection cas1 = as1.retrieveB(); 812 ARemote a3 = ahome.findByPrimaryKey("a3"); 813 Collection ca3 = a3.retrieveB(); 814 assertEquals("Bad relation for bs1_1: ", "a3", rbs1_1); 815 ArrayList ce = new ArrayList (); 816 ce.add("bs1_1"); 817 ce.add("b3_1"); 818 assertTrue("Bad relations for a3 (required:" + ce + ", found:" + ca3 819 + ")", isCollectionEqual(ce, ca3)); 820 ce = new ArrayList (); 821 assertTrue("Bad relations for as1 (required:" + ce + ", found:" + cas1 822 + ")", isCollectionEqual(ce, cas1)); 823 bs1_1.assignA("as1"); 825 } 826 checkIsInitialState(); 827 } 828 829 public void testCohSet3B2ATxNo() throws Exception { 830 tCohSet3B2A(TX_NO); 831 } 832 833 public void testCohSet3B2ATxCall() throws Exception { 834 tCohSet3B2A(TX_CALL); 835 } 836 837 public void testCohSet3B2ATxCont() throws Exception { 838 tCohSet3B2A(TX_CONT); 839 } 840 841 public void testCohSet3B2ATxRb() throws Exception { 842 tCohSet3B2A(TX_RB); 843 } 844 845 846 853 public void tCohRemoveInRelA2B(int tx) throws Exception { 854 if ((tx == TX_CALL) || (tx == TX_RB)) { 855 utx.begin(); 856 } 857 ARemote a = ahome.findByPrimaryKey("a3"); 858 if (tx == TX_CONT) { 859 a.removeFromBInNewTx("b3_1"); 860 } else { 861 a.removeFromB("b3_1"); 862 } 863 if (tx == TX_CALL) { 864 utx.commit(); 865 } else if (tx == TX_RB) { 866 utx.rollback(); 867 } 868 if (tx != TX_RB) { 869 Collection ca = a.retrieveB(); 871 BRemote b = bhome.findByPrimaryKey("b3_1"); 872 String r = b.retrieveA(); 873 ArrayList ce = new ArrayList (); 874 assertTrue("Bad relations for a3: (required:" + ce + ", found:" + ca 875 + ")", isCollectionEqual(ce, ca)); 876 assertNull("Bad not null relation for b3_1", r); 877 a.addInB("b3_1"); 879 } 880 checkIsInitialState(); 882 883 } 884 885 public void testCohRemoveInRelA2BTxNo() throws Exception { 886 tCohRemoveInRelA2B(TX_NO); 887 } 888 889 public void testCohRemoveInRelA2BTxCall() throws Exception { 890 tCohRemoveInRelA2B(TX_CALL); 891 } 892 893 public void testCohRemoveInRelA2BTxCont() throws Exception { 894 tCohRemoveInRelA2B(TX_CONT); 895 } 896 897 public void testCohRemoveInRelA2BTxRb() throws Exception { 898 tCohRemoveInRelA2B(TX_RB); 899 } 900 901 902 909 public void tCohRemoveB(int tx) throws Exception { 910 if (tx == TX_CONT) { 911 fail("Transaction cannot be initiate by the container for this test"); 914 } 915 if ((tx == TX_CALL) || (tx == TX_RB)) { 916 utx.begin(); 917 } 918 bhome.remove("b3_1"); 919 if (tx == TX_CALL) { 920 utx.commit(); 921 } else if (tx == TX_RB) { 922 utx.rollback(); 923 } 924 if (tx != TX_RB) { 925 ARemote a = ahome.findByPrimaryKey("a3"); 927 Collection ca = a.retrieveB(); 928 assertEquals("Wrong relations size for a3: (expected: 0 found:" 929 + ca.size(), 0, ca.size()); 930 bhome.create("b3_1"); 932 a.addInBInNewTx("b3_1"); 933 } 934 checkIsInitialState(); 935 } 936 937 public void testCohRemoveBTxNo() throws Exception { 938 tCohRemoveB(TX_NO); 939 } 940 941 public void testCohRemoveBTxCall() throws Exception { 942 tCohRemoveB(TX_CALL); 943 } 944 945 public void testCohRemoveBTxRb() throws Exception { 946 tCohRemoveB(TX_RB); 947 } 948 949 950 959 public void tCohBeanRemoveB(int tx) throws Exception { 960 if (tx == TX_CONT) { 961 fail("Transaction cannot be initiate by the container for this test"); 964 } 965 if ((tx == TX_CALL) || (tx == TX_RB)) { 966 utx.begin(); 967 } 968 BRemote b = bhome.findByPrimaryKey("b3_1"); 969 b.remove(); 970 if (tx == TX_CALL) { 971 utx.commit(); 972 } else if (tx == TX_RB) { 973 utx.rollback(); 974 } 975 if (tx != TX_RB) { 976 ARemote a = ahome.findByPrimaryKey("a3"); 978 Collection ca = a.retrieveB(); 979 assertEquals("Wrong relations size for a3: (expected: 0 found:" 980 + ca.size(), 0, ca.size()); 981 bhome.create("b3_1"); 983 a.addInBInNewTx("b3_1"); 984 } 985 checkIsInitialState(); 986 } 987 988 public void testCohBeanRemoveBTxNo() throws Exception { 989 tCohBeanRemoveB(TX_NO); 990 } 991 992 public void testCohBeanRemoveBTxCall() throws Exception { 993 tCohBeanRemoveB(TX_CALL); 994 } 995 996 public void testCohBeanRemoveBTxRb() throws Exception { 997 tCohBeanRemoveB(TX_RB); 998 } 999 1000 1001 1002 1011 public void tCohSetOne2A2B(int tx) throws Exception { 1012 ArrayList ce = new ArrayList (); 1013 ce.add("b3_1"); 1014 if ((tx == TX_CALL) || (tx == TX_RB)) { 1015 utx.begin(); 1016 } 1017 ARemote a = ahome.findByPrimaryKey("a0"); 1018 if (tx == TX_CONT) { 1019 a.assignBInNewTx(ce); 1020 } else { 1021 a.assignB(ce); 1022 } 1023 if (tx == TX_CALL) { 1024 utx.commit(); 1025 } else if (tx == TX_RB) { 1026 utx.rollback(); 1027 } 1028 if (tx != TX_RB) { 1029 Collection ca = a.retrieveB(); 1031 ARemote a3 = ahome.findByPrimaryKey("a3"); 1032 Collection ca3 = a3.retrieveB(); 1033 BRemote b = bhome.findByPrimaryKey("b3_1"); 1034 String r = b.retrieveA(); 1035 assertTrue("Wrong relations a0 (required:" + ce + ", found:" + ca 1036 + ")", isCollectionEqual(ce, ca)); 1037 assertTrue("Wrong relations for b3_1" + ": found:" + ca3 , 1038 !ca3.contains("b3_1")); 1039 assertEquals("Bad relation for b3_1: ", "a0", r); 1040 a.assignB(new ArrayList ()); 1042 a3.addInB("b3_1"); 1043 } 1044 checkIsInitialState(); 1045 } 1046 1047 public void testCohSetOne2A2BTxNo() throws Exception { 1048 tCohSetOne2A2B(TX_NO); 1049 } 1050 1051 public void testCohSetOne2A2BTxCall() throws Exception { 1052 tCohSetOne2A2B(TX_CALL); 1053 } 1054 1055 public void testCohSetOne2A2BTxCont() throws Exception { 1056 tCohSetOne2A2B(TX_CONT); 1057 } 1058 1059 public void testCohSetOne2A2BTxRb() throws Exception { 1060 tCohSetOne2A2B(TX_RB); 1061 } 1062 1063 1064 1082 public void tCohAddOneInMultiA2B(int tx) throws Exception { 1083 1084 ArrayList ce = new ArrayList (); 1085 ce.add("b1_1"); 1086 ce.add("b1_2"); 1087 ce.add("b1_3"); 1088 String bAdded = "b3_1"; 1089 if ((tx == TX_CALL) || (tx == TX_RB)) { 1090 utx.begin(); 1091 } 1092 ARemote a = ahome.findByPrimaryKey("a1"); 1093 if (tx == TX_CONT) { 1094 a.addInBInNewTx(bAdded); 1095 } else { 1096 a.addInB(bAdded); 1097 } 1098 ce.add(bAdded); 1099 if (tx == TX_CALL) { 1100 utx.commit(); 1101 } else if (tx == TX_RB) { 1102 utx.rollback(); 1103 } 1104 if (tx != TX_RB) { 1105 Collection ca1 = a.retrieveB(); 1107 ARemote a3 = ahome.findByPrimaryKey("a3"); 1108 Collection ca3 = a3.retrieveB(); 1109 assertTrue("Bad relations for a1 (required:" + ce + ", found:" + ca1 + ")", 1110 isCollectionEqual(ce, ca1)); 1111 ce = new ArrayList (); 1112 assertTrue("Bad relations for a3 (required:" + ce + ", found:" + ca3 + ")", 1113 isCollectionEqual(ce, ca3)); 1114 BRemote b = bhome.findByPrimaryKey(bAdded); 1115 assertEquals("Bad relation for b3_1: ", "a1", b.retrieveA()); 1116 a3.addInB(bAdded); 1118 } 1119 1120 checkIsInitialState(); 1121 } 1122 1123 public void testCohAddOneInMultiA2BTxNo() throws Exception { 1124 tCohAddOneInMultiA2B(TX_NO); 1125 } 1126 1127 public void testCohAddOneInMultiA2BTxCall() throws Exception { 1128 tCohAddOneInMultiA2B(TX_CALL); 1129 } 1130 1131 public void testCohAddOneInMultiA2BTxCont() throws Exception { 1132 tCohAddOneInMultiA2B(TX_CONT); 1133 } 1134 1135 public void testCohAddOneInMultiA2BTxRb() throws Exception { 1136 tCohAddOneInMultiA2B(TX_RB); 1137 } 1138 1139 1140 1162 public void tCohSetMultiBisA2B(int tx) throws Exception { 1163 if ((tx == TX_CALL) || (tx == TX_RB)) { 1164 utx.begin(); 1165 } 1166 ARemote a1 = ahome.findByPrimaryKey("a1"); 1167 Collection co1 = a1.retrieveB(); 1168 ARemote a2 = ahome.findByPrimaryKey("a2"); 1169 Collection co2 = a2.retrieveB(); 1170 if (tx == TX_CONT) { 1171 a1.assignBInNewTx(co2); 1172 } else { 1173 a1.assignB(co2); 1174 } 1175 if (tx == TX_CALL) { 1176 utx.commit(); 1177 } else if (tx == TX_RB) { 1178 utx.rollback(); 1179 } 1180 if (tx != TX_RB) { 1181 Collection ca1 = a1.retrieveB(); 1183 assertTrue("Wrong relations for a1 (required:" + co2 + ", found:" + ca1 + ")", isCollectionEqual(co2, ca1)); 1184 Collection ca2 = a2.retrieveB(); 1185 assertEquals("Wrong relations size for a2: ", 0, ca2.size()); 1186 BRemote b; 1187 b = bhome.findByPrimaryKey("b1_1"); 1188 assertNull("Wrong not null relation for b1_1: ", b.retrieveA()); 1189 b = bhome.findByPrimaryKey("b1_2"); 1190 assertNull("Wrong not null relation for b1_2: ", b.retrieveA()); 1191 b = bhome.findByPrimaryKey("b1_3"); 1192 assertNull("Wrong not null relation for b1_3: ", b.retrieveA()); 1193 b = bhome.findByPrimaryKey("b2_1"); 1194 assertEquals("Wrong relation for b2_1: ", "a1", b.retrieveA()); 1195 b = bhome.findByPrimaryKey("b2_2"); 1196 assertEquals("Wrong relation for b2_2: ", "a1", b.retrieveA()); 1197 b = bhome.findByPrimaryKey("b2_3"); 1198 assertEquals("Wrong relation for b2_3: ", "a1", b.retrieveA()); 1199 a1.assignB(co1); 1201 a2.assignB(co2); 1202 } 1203 checkIsInitialState(); 1204 } 1205 1206 public void testCohSetMultiBisA2BTxNo() throws Exception { 1207 tCohSetMultiBisA2B(TX_NO); 1208 } 1209 1210 public void testCohSetMultiBisA2BTxCall() throws Exception { 1211 tCohSetMultiBisA2B(TX_CALL); 1212 } 1213 1214 public void testCohSetMultiBisA2BTxCont() throws Exception { 1215 tCohSetMultiBisA2B(TX_CONT); 1216 } 1217 1218 public void testCohSetMultiBisA2BTxRb() throws Exception { 1219 tCohSetMultiBisA2B(TX_RB); 1220 } 1221 1222 1227 public void testResetPkForbidden() throws Exception { 1228 ARemote a = ahome.findByPrimaryKey("ax0"); 1229 assertTrue("IllegalStateException not thrown when a pk value is reset", 1230 a.testResetPkForbidden("aY0")); 1231 } 1232 1233 1236 public void testCreateFindTx() throws Exception { 1237 utx.begin(); 1238 ARemote project = ahome.create("project"); 1239 BRemote role = bhome.create("role"); 1240 project.addInB("role"); 1241 bhome.findByName("role", "project"); 1242 utx.rollback(); 1243 checkIsInitialState(); 1244 } 1245 1246 1250 public void testCreateFindTx2() throws Exception { 1251 utx.begin(); 1252 ARemote project = ahome.create("project"); 1253 project.addNewB("role"); 1254 bhome.findByName("role", "project"); 1255 utx.rollback(); 1256 checkIsInitialState(); 1257 } 1258 1259 1262 public void testNewArrayListOnCmr() throws Exception { 1263 ArrayList ce = new ArrayList (); 1264 ce.add("bs2_1"); 1265 ce.add("bs2_2"); 1266 ce.add("bs2_3"); 1267 Collection ca = null; 1268 ARemote as2 = ahome.findByPrimaryKey("as2"); 1269 ca = as2.retrieveB(); 1271 assertTrue("Bad relations for as2.retrieveB() (required:" + ce + ", found:" + ca 1272 + ")", isCollectionEqual(ce, ca)); 1273 ca = as2.retrieveBisB(); 1275 assertTrue("Bad relations for as2.retrieveBisB() (required:" + ce + ", found:" + ca 1276 + ")", isCollectionEqual(ce, ca)); 1277 } 1278 1279 1283 public void testRemove1() throws Exception { 1284 Front fb = fhome.create(); 1285 fb.testRemove1(); 1286 1287 } 1288 1289 1294 1300 1306 public void testSetCmrWithDeleted() throws Exception { 1307 Front fb = fhome.create(); 1308 fb.testSetCmrWithDeleted(); 1309 } 1310 1311 1315 public void testSetCmrWithWrongType() throws Exception { 1316 Front fb = fhome.create(); 1317 fb.testSetCmrWithWrongType(); 1318 1319 } 1320 1321 public static Test suite() { 1322 return new TestSuite(F_Relation_ombEC2.class); 1323 } 1324 1325 public static void main(String args[]) { 1326 String testtorun = null; 1327 for (int argn = 0; argn < args.length; argn++) { 1329 String s_arg = args[argn]; 1330 Integer i_arg; 1331 if (s_arg.equals("-n")) { 1332 testtorun = args[++argn]; 1333 } 1334 } 1335 if (testtorun == null) { 1336 junit.textui.TestRunner.run(suite()); 1337 } else { 1338 junit.textui.TestRunner.run(new F_Relation_ombEC2(testtorun)); 1339 } 1340 } 1341 1342} 1343 | Popular Tags |