1 21 22 package org.objectweb.jonas.jtests.clients.entity; 23 24 import javax.naming.NamingException ; 25 import javax.rmi.PortableRemoteObject ; 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 import org.objectweb.jonas.jtests.beans.ejbql.*; 29 import java.util.ArrayList ; 30 import java.util.Calendar ; 31 import java.util.Collection ; 32 import java.util.Date ; 33 import java.util.HashSet ; 34 import java.util.Iterator ; 35 import java.util.Set ; 36 37 40 public class F_EjbqlEC2 extends A_Cmp2Util { 41 42 private static String BEAN_HOME_SESSION_TEST = "EjbqlSessionTestHomeRemote"; 43 private static String BEAN_HOME_CUSTOMER = "CustomerHomeRemote"; 44 private static String BEAN_HOME_RESERVATION = "ReservationHomeRemote"; 45 private static String BEAN_HOME_CRUISE = "CruiseHomeRemote"; 46 private static String BEAN_HOME_SHIP = "ShipHomeRemote"; 47 private static String BEAN_HOME_CABIN = "CabinHomeRemote"; 48 private static String BEAN_HOME_ADDRESS = "AddressHomeRemote"; 49 50 protected static SessionTestHomeRemote sessiontesthome = null; 51 protected static CustomerHomeRemote customerhome = null; 52 protected static ReservationHomeRemote reservationhome = null; 53 protected static CruiseHomeRemote cruisehome = null; 54 protected static ShipHomeRemote shiphome = null; 55 protected static CabinHomeRemote cabinhome = null; 56 protected static AddressHomeRemote addresshome = null; 57 protected static CreditCardHomeRemote creditcardhome = null; 58 59 public F_EjbqlEC2(String name) { 60 super(name); 61 } 62 63 protected static boolean isInit = false; 64 65 protected void setUp() { 66 super.setUp(); 67 boolean ok = false; 68 int nbtry = 0; 69 while (!ok && nbtry < 3) { 70 if (!isInit) { 71 useBeans("ejbql", false); 73 75 try { 76 sessiontesthome = (SessionTestHomeRemote) 77 PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_SESSION_TEST), 78 SessionTestHomeRemote.class); 79 customerhome = (CustomerHomeRemote) 80 PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_CUSTOMER), 81 CustomerHomeRemote.class); 82 shiphome = (ShipHomeRemote) 83 PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_SHIP), 84 ShipHomeRemote.class); 85 cruisehome = (CruiseHomeRemote) 86 PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_CRUISE), 87 CruiseHomeRemote.class); 88 reservationhome = (ReservationHomeRemote) 89 PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_RESERVATION), 90 ReservationHomeRemote.class); 91 cabinhome = (CabinHomeRemote) 92 PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_CABIN), 93 CabinHomeRemote.class); 94 addresshome = (AddressHomeRemote) 95 PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_ADDRESS), 96 AddressHomeRemote.class); 97 } catch (NamingException e) { 98 fail("Cannot get bean home: " + e.getMessage()); 99 } 100 try { 102 customerhome.findByPrimaryKey(new Integer (80)); 103 } catch (Exception e) { 104 try { 106 utx.begin(); 107 String cities[] = new String [6]; 108 cities[0] = "Minneapolis"; cities[1] = "St. Paul"; cities[2] = "Rochester"; 109 cities[3] = "Winona"; cities[4] = "Wayzata"; cities[5] = "Eagan"; 110 ShipRemote shipA = null; 111 CruiseRemote cruiseA = null; 112 shipA = shiphome.create(new Integer (10772), "Ship A", 30000.0); 113 cruiseA = cruisehome.create("Cruise A", new Integer (10772)); 114 for (int jj = 1; jj <= 10; jj++) { 115 ShipRemote ship = shiphome.create(new Integer (jj), "Ship " + jj, 30000.0 + (10000.0 * jj)); 116 } 117 cruiseA = null; 118 CruiseRemote cruiseB = null; 119 ShipRemote ship1 = shiphome.findByPrimaryKey(new Integer (1)); 120 cruiseA = cruisehome.create("Alaska Cruise", new Integer (1)); 121 cruiseB = cruisehome.create("Bohemian Cruise", new Integer (1)); 122 for (int kk = 80; kk <= 99; kk++) { 123 CustomerRemote customer = null; 124 125 customer = customerhome.create(new Integer (kk)); 126 customer.setName(new Name("Smith"+kk,"John") ); 127 customer.addPhoneNumber("612-555-12"+kk,(byte) 1); 128 129 customer.setAddress("10"+kk+" Elm Street", 130 cities[(kk-80)%6], 131 (kk%2==0?"MN":"CA"), 132 "5540"+(kk%5+1)); 133 customer.setHasGoodCredit((kk%4 == 0)); 134 if (kk%4 == 0) 135 customer.setCreditCard(new Date (System.currentTimeMillis()+100000), "100001"+kk, "MasterCard", "CA" ,"CETELEM", "rue de jeunet", cities[0], "France", "3888" ); 136 } 137 Calendar date = Calendar.getInstance(); 139 date.set(2002,10,1); 140 141 for (int kk=201; kk<207; kk++) { 142 Collection customers = new ArrayList (); 143 CustomerRemote cust = customerhome.create(new Integer (kk)); 144 cust.setName(new Name("Customer "+kk,"Mike")); 145 cust.setHasGoodCredit( (kk%2==0) ); cust.setAddress("50"+kk+" Main Street","Minneapolis","MN","5510"+kk); 147 customers.add(new Integer (kk)); 149 Collection reservations = new ArrayList (); 150 151 for (int jj=0; jj<2; jj++) { 152 153 ReservationRemote reservation = reservationhome.create(cruiseA.getId(), customers); 154 reservation.setDate(date.getTime()); 155 reservation.setAmountPaid(1000*kk+100*jj+2000); 156 157 date.add(Calendar.DAY_OF_MONTH, 7); 158 159 Set cabins = new HashSet (); 160 CabinRemote cabin = cabinhome.create(new Integer (1000+kk*100+jj)); 161 cabin.setDeckLevel(kk-200); 162 cabin.setName("Cabin "+kk+"0"+jj+"1"); 163 164 cabins.add(cabin.getId()); 165 cabin = cabinhome.create(new Integer (1000+kk*100+10+jj)); 166 cabin.setDeckLevel(kk-200); 167 cabin.setName("Cabin "+kk+"0"+jj+"2"); 168 169 cabins.add(cabin.getId()); 170 171 reservation.setAllCabins(cabins); 173 } 174 } 175 String fnames[] = new String [5]; 176 fnames[0]="John"; fnames[1]="Paul"; fnames[2]="Ringo"; 177 fnames[3]="Joe"; fnames[4]="Roger"; 178 179 String lnames[] = new String [3]; 180 lnames[0]="Smith"; lnames[1]="Johnson"; lnames[2]="Star"; 181 for (int kk=50; kk<=69; kk++) { 183 CustomerRemote customer = customerhome.create(new Integer (kk)); 184 customer.setName( new Name(lnames[(kk-50)%3], fnames[(kk-50)%5]) ); 185 customer.addPhoneNumber("612-555-12"+kk,(byte)1); 186 customer.setAddress("10"+kk+" Elm Street", 187 cities[(kk-50)%6], 188 (kk%2==0?"MN":"CA"), 189 "5540"+(kk%5+1)); 190 customer.setHasGoodCredit((kk%4==0)); 191 192 if (kk%3!=0) { 194 Collection customers = new ArrayList (); 195 customers.add(customer.getId()); ReservationRemote reservation = reservationhome.create((kk%3==1?cruiseA.getId():cruiseB.getId()), customers); 197 reservation.setDate(date.getTime()); 198 reservation.setAmountPaid(10*kk+2000); 199 date.add(Calendar.DAY_OF_MONTH, 7); 200 } 201 } 202 203 205 for (int kk=100; kk<=109; kk++) { 206 CustomerRemote customer = customerhome.create(new Integer (kk)); 207 customer.setName( new Name("Lennon"+kk, "Paul") ); 208 customer.addPhoneNumber("666-543-12"+kk,(byte)1); 209 210 customer.setAddress("10"+kk+" Abbey Road", 211 cities[(kk-100)%6], 212 (kk%2==0?"FL":"WA"), 213 "5540"+(kk%5+1)); 214 customer.setHasGoodCredit((kk%4==0)); 215 } 216 217 } catch (Exception i) { 218 i.printStackTrace(System.out); 219 fail("InitialState creation problem: "+i); 220 } finally { 221 try { 222 utx.commit(); 223 } catch (Exception ii) { 224 } 225 } 226 } 227 isInit = true; 228 } 229 nbtry++; 232 try { 233 if (initStateOK()) { 234 ok = true; 235 } 236 } catch (Exception e) { 237 e.printStackTrace(System.out); 238 } 239 if (!ok) { 240 isInit = false; 241 unloadBeans("ejbql"); 242 } 243 } 244 } 245 246 247 251 boolean initStateOK() throws Exception { 252 boolean isOk = true; 254 255 msgerror = new StringBuffer (); 256 257 ShipRemote ship10772 = shiphome.findByPrimaryKey(new Integer (10772)); 258 for (int i=1; i<=10; i++) { 259 ShipRemote ship = shiphome.findByPrimaryKey(new Integer (i)); 260 } 261 262 CruiseRemote cruiseA = cruisehome.findByName("Cruise A"); 263 CruiseRemote cruiseB = cruisehome.findByName("Alaska Cruise"); 264 CruiseRemote cruiseC = cruisehome.findByName("Bohemian Cruise"); 265 for (int j=10; j<=12; j++) { 266 CruiseRemote cruise = cruisehome.findByPrimaryKey(new Integer (j)); 267 } 268 269 for (int k=80; k<=109; k++) { 270 CustomerRemote customer = customerhome.findByPrimaryKey(new Integer (k)); 271 } 272 273 for (int l=201; l<=206; l++) { 274 CustomerRemote customer1 = customerhome.findByPrimaryKey(new Integer (l)); 275 } 276 277 for (int p=50; p<=69; p++) { 278 CustomerRemote customer2 = customerhome.findByPrimaryKey(new Integer (p)); 279 } 280 for (int kk=201;kk<207;kk++) { 281 for (int jj=0;jj<2;jj++) { 282 CabinRemote cabin = cabinhome.findByPrimaryKey(new Integer (1000+kk*100+jj)); 283 CabinRemote cabin1 = cabinhome.findByPrimaryKey(new Integer (1000+kk*100+10+jj)); 284 } 285 } 286 287 for (int kkh=10;kkh<=34;kkh++) { 288 ReservationRemote reservation = reservationhome.findByPrimaryKey(new Integer (kkh)); 289 } 290 291 return isOk; 292 } 293 294 297 public void testSeries1() throws Exception { 298 testWildcards(); 299 testWildcards(); 300 } 301 302 306 public void testAnd1() throws Exception { 307 CustomerRemote customer85 = customerhome.findByExactName("Smith85","John"); 308 assertEquals("Wrong Customer : ",new Integer (85), customer85.getId()); 309 } 311 312 316 public void testEgalString() throws Exception { 317 CustomerRemote customer90 = customerhome.findSmith90(); 318 assertEquals("Wrong Customer : ",new Integer (90), customer90.getId()); 319 } 321 322 326 public void testEgalBoolean() throws Exception { 327 Collection mplscustomers = customerhome.findByGoodCredit(); 328 ArrayList customers_id = new ArrayList (); 329 Iterator customer = mplscustomers.iterator(); 330 while (customer.hasNext()) { 331 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 332 customers_id.add(customer_remote.getId()); 333 } 334 ArrayList result = new ArrayList (); 335 336 for (int ii=80;ii<=96;ii=ii+4) { 337 result.add(new Integer (ii)); 338 } 339 340 for (int ii=100;ii<=108;ii=ii+4) { 341 result.add(new Integer (ii)); 342 } 343 for (int jj=202;jj<=206;jj=jj+2) { 344 result.add(new Integer (jj)); 345 } 346 347 for (int kk=52;kk<=68;kk=kk+4) { 348 result.add(new Integer (kk)); 349 } 350 351 assertTrue("Wrong result EJBQL Customer.findByGoogCredit() (required:" + result + ", found:" +customers_id 352 + ")", isCollectionEqual(result, customers_id)); 353 354 } 356 357 361 public void testAnd2() throws Exception { 362 Collection mplscustomers = customerhome.findByCity("Minneapolis","MN"); 363 364 ArrayList customers_id = new ArrayList (); 365 Iterator customer = mplscustomers.iterator(); 366 while (customer.hasNext()) { 367 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 368 customers_id.add(customer_remote.getId()); 369 } 370 ArrayList result = new ArrayList (); 371 result.add(new Integer (206)); 372 result.add(new Integer (50)); 373 result.add(new Integer (56)); 374 result.add(new Integer (62)); 375 result.add(new Integer (68)); 376 result.add(new Integer (80)); 377 result.add(new Integer (86)); 378 result.add(new Integer (92)); 379 result.add(new Integer (98)); 380 result.add(new Integer (201)); 381 result.add(new Integer (202)); 382 result.add(new Integer (203)); 383 result.add(new Integer (204)); 384 result.add(new Integer (205)); 385 386 assertTrue("Wrong result EJBQL Customer.findByCity(Minneapolis,MN) (required:" + result + ", found:" +customers_id 387 + ")", isCollectionEqual(result, customers_id)); 388 389 } 391 401 public void testWildcards() throws Exception { 402 CustomerRemote customer = customerhome.findByExactName("Star","Joe"); 404 assertEquals("Wrong Customer for customerhome.findByExactName(Star,Joe);: ",new Integer (58), customer.getId()); 405 406 Collection customers = customerhome.findByName("S","Jo"); 408 ArrayList customers_id = new ArrayList (); 409 Iterator customerit1 = customers.iterator(); 410 while (customerit1.hasNext()) { 411 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customerit1.next(), CustomerRemote.class); 412 customers_id.add(customer_remote.getId()); 413 } 414 ArrayList result = new ArrayList (); 415 assertTrue("Wrong result EJBQL customerhome.findByName(S,Jo) (required:" + result + ", found:" +customers_id 416 + ")", isCollectionEqual(result, customers_id)); 417 418 customers = customerhome.findByName("S%","Jo%"); 420 customers_id = new ArrayList (); 421 Iterator customerit2 = customers.iterator(); 422 while (customerit2.hasNext()) { 423 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customerit2.next(), CustomerRemote.class); 424 customers_id.add(customer_remote.getId()); 425 } 426 result = new ArrayList (); 427 result.add(new Integer (50)); 428 result.add(new Integer (53)); 429 result.add(new Integer (55)); 430 result.add(new Integer (58)); 431 result.add(new Integer (65)); 432 result.add(new Integer (68)); 433 for (int i=80;i<=99;i++) { 434 result.add(new Integer (i)); 435 } 436 assertTrue("Wrong result EJBQL customerhome.findByName(S%,Jo%) (required:" + result + ", found:" +customers_id 437 + ")", isCollectionEqual(result, customers_id)); 438 439 customers = customerhome.findByNameAndState("S%","Jo%","MN"); 440 customers_id = new ArrayList (); 441 Iterator customerit3 = customers.iterator(); 442 while (customerit3.hasNext()) { 443 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customerit3.next(), CustomerRemote.class); 444 customers_id.add(customer_remote.getId()); 445 } 446 result = new ArrayList (); 447 result.add(new Integer (50)); 448 result.add(new Integer (68)); 449 result.add(new Integer (58)); 450 for (int i=80;i<=99;i=i+2) { 451 result.add(new Integer (i)); 452 } 453 assertTrue("Wrong result EJBQL customerhome.findByNameAndState(S%,Jo%,MN) (required:" + result + ", found:" +customers_id 454 + ")", isCollectionEqual(result, customers_id)); 455 456 457 } 459 460 465 public void testNotLike() throws Exception { 466 Collection customers = customerhome.findByNotName("S%","Jo%"); 467 ArrayList customers_id = new ArrayList (); 468 Iterator customerit1 = customers.iterator(); 469 while (customerit1.hasNext()) { 470 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customerit1.next(), CustomerRemote.class); 471 customers_id.add(customer_remote.getId()); 472 } 473 ArrayList result = new ArrayList (); 474 result.add(new Integer (51)); 475 result.add(new Integer (52)); 476 result.add(new Integer (54)); 477 result.add(new Integer (56)); 478 result.add(new Integer (57)); 479 result.add(new Integer (59)); 480 for (int i=60;i<=64;i++) { 481 result.add(new Integer (i)); 482 } 483 result.add(new Integer (66)); 484 result.add(new Integer (67)); 485 result.add(new Integer (69)); 486 for (int i=100;i<=109;i++) { 487 result.add(new Integer (i)); 488 } 489 for (int i=201;i<=206;i++) { 490 result.add(new Integer (i)); 491 } 492 assertTrue("Wrong result EJBQL customerhome.findByNotName(S%,Jo%) (required:" + result + ", found:" +customers_id 493 + ")", isCollectionEqual(result, customers_id)); 494 495 } 497 498 502 public void testEgalInteger() throws Exception { 503 Collection cabins = cabinhome.findAllOnDeckLevel(new Integer (3)); 504 505 ArrayList cabins_id = new ArrayList (); 506 Iterator cabin = cabins.iterator(); 507 while (cabin.hasNext()) { 508 CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject.narrow(cabin.next(), CabinRemote.class); 509 cabins_id.add(cabin_remote.getId()); 510 } 511 ArrayList result = new ArrayList (); 512 result.add(new Integer (21300)); 513 result.add(new Integer (21310)); 514 result.add(new Integer (21301)); 515 result.add(new Integer (21311)); 516 517 assertTrue("Wrong result EJBQL cabinhome.findAllOnDeckLevel(new Integer(3))(required:" + result + ", found:" +cabins_id+ 518 ")", isCollectionEqual(result,cabins_id)); 519 520 } 522 523 527 public void testInWhere() throws Exception { 528 Collection customers = customerhome.findInHotStates(); 529 530 ArrayList customers_id = new ArrayList (); 531 Iterator customer = customers.iterator(); 532 while (customer.hasNext()) { 533 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 534 customers_id.add(customer_remote.getId()); 535 } 536 ArrayList result = new ArrayList (); 537 for (int i=51;i<=69;i=i+2) { 538 result.add(new Integer (i)); 539 } 540 for (int j=100;j<=109;j=j+2) { 541 result.add(new Integer (j)); 542 } 543 for (int k=81;k<=99;k=k+2) { 544 result.add(new Integer (k)); 545 } 546 547 assertTrue("Wrong result EJBQL customerhome.findInHotStates() (required:" + result + ", found:" +customers_id+ 548 ")", isCollectionEqual(result,customers_id)); 549 550 } 552 553 557 public void test2InWhere() throws Exception { 558 Collection cabins = cabinhome.findAllOnDeckLevel1_3_5(); 559 560 ArrayList customers_id = new ArrayList (); 561 Iterator icabins = cabins.iterator(); 562 int nb = 0; 563 while (icabins.hasNext()) { 564 CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject.narrow(icabins.next(), CabinRemote.class); 565 nb++; 566 int level = cabin_remote.getDeckLevel(); 567 if ((level != 1) && (level != 3) && (level != 5)) { 568 fail("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_5(5) (level=" 569 + level + ")"); 570 } 571 } 572 assertEquals("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_5(5)", 12, nb); 573 574 } 576 577 581 public void test3InWhere() throws Exception { 582 Collection cabins = cabinhome.findAllOnDeckLevel1_3_X(5); 583 584 ArrayList customers_id = new ArrayList (); 585 Iterator icabins = cabins.iterator(); 586 int nb = 0; 587 while (icabins.hasNext()) { 588 CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject.narrow(icabins.next(), CabinRemote.class); 589 nb++; 590 int level = cabin_remote.getDeckLevel(); 591 if ((level != 1) && (level != 3) && (level != 5)) { 592 fail("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_X(5) (level=" 593 + level + ")"); 594 } 595 } 596 assertEquals("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_X(5)", 12, nb); 597 598 } 600 601 605 public void testIsEmpty() throws Exception { 606 Collection customers = customerhome.findWithoutReservations(); 607 608 ArrayList customers_id = new ArrayList (); 609 Iterator customer = customers.iterator(); 610 while (customer.hasNext()) { 611 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 612 customers_id.add(customer_remote.getId()); 613 } 614 ArrayList result = new ArrayList (); 615 for (int i=51;i<=69;i=i+3) { 616 result.add(new Integer (i)); 617 } 618 for (int i=80;i<=109;i++) { 619 result.add(new Integer (i)); 620 } 621 622 assertTrue("Wrong result EJBQL customerhome.findWithoutReservations() (required:" 623 + result + ", found:" + customers_id + ")", 624 isCollectionEqual(result,customers_id)); 625 626 } 628 629 633 public void testIsNotEmpty() throws Exception { 634 Collection customers = customerhome.findWithReservations(); 635 636 ArrayList customers_id = new ArrayList (); 637 Iterator customer = customers.iterator(); 638 while (customer.hasNext()) { 639 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 640 customers_id.add(customer_remote.getId()); 641 } 642 ArrayList result = new ArrayList (); 643 for (int i=201;i<=206;i++) { 644 result.add(new Integer (i)); 645 } 646 result.add(new Integer (50)); 647 result.add(new Integer (52)); 648 result.add(new Integer (53)); 649 result.add(new Integer (55)); 650 result.add(new Integer (56)); 651 result.add(new Integer (58)); 652 result.add(new Integer (59)); 653 result.add(new Integer (61)); 654 result.add(new Integer (62)); 655 result.add(new Integer (64)); 656 result.add(new Integer (65)); 657 result.add(new Integer (67)); 658 result.add(new Integer (68)); 659 660 assertTrue("Wrong result EJBQL customerhome.findWithReservations() (required:" 661 + result + ", found:" + customers_id + ")", 662 isCollectionEqual(result,customers_id)); 663 664 } 666 667 673 public void testIsEmptyIsNotEmpty() throws Exception { 674 Collection customers = customerhome.findWithOrWithoutReservations(); 675 676 ArrayList customers_id = new ArrayList (); 677 Iterator customer = customers.iterator(); 678 while (customer.hasNext()) { 679 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 680 customers_id.add(customer_remote.getId()); 681 } 682 ArrayList result = new ArrayList (); 683 for (int i=50;i<=69;i++) { 684 result.add(new Integer (i)); 685 } 686 for (int i=80;i<=109;i++) { 687 result.add(new Integer (i)); 688 } 689 for (int i=201;i<=206;i++) { 690 result.add(new Integer (i)); 691 } 692 693 assertTrue("Wrong result EJBQL customerhome.findWithOrWithoutReservations() (required:" 694 + result + ", found:" + customers_id + ")", 695 isCollectionEqual(result,customers_id)); 696 697 } 699 700 705 public void testIsEmptyInExp1() throws Exception { 706 Collection customers = customerhome.findWithoutReservationsAndWithGoodCredit(true); 707 708 ArrayList customers_id = new ArrayList (); 709 Iterator customer = customers.iterator(); 710 while (customer.hasNext()) { 711 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 712 customers_id.add(customer_remote.getId()); 713 } 714 ArrayList result = new ArrayList (); 715 result.add(new Integer (80)); 716 result.add(new Integer (84)); 717 result.add(new Integer (88)); 718 result.add(new Integer (92)); 719 result.add(new Integer (96)); 720 result.add(new Integer (60)); 721 result.add(new Integer (100)); 722 result.add(new Integer (104)); 723 result.add(new Integer (108)); 724 725 assertTrue("Wrong result EJBQL customerhome.findWithoutReservationsAndWithGoodCredit() (required:" 726 + result + ", found:" + customers_id + ")", 727 isCollectionEqual(result,customers_id)); 728 729 } 731 732 738 public void testIsEmptyInExp1Bis() throws Exception { 739 Collection customers = customerhome.findBisWithoutReservationsAndWithGoodCredit(true); 740 741 ArrayList customers_id = new ArrayList (); 742 Iterator customer = customers.iterator(); 743 while (customer.hasNext()) { 744 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 745 customers_id.add(customer_remote.getId()); 746 } 747 ArrayList result = new ArrayList (); 748 result.add(new Integer (80)); 749 result.add(new Integer (84)); 750 result.add(new Integer (88)); 751 result.add(new Integer (92)); 752 result.add(new Integer (96)); 753 result.add(new Integer (60)); 754 result.add(new Integer (100)); 755 result.add(new Integer (104)); 756 result.add(new Integer (108)); 757 758 assertTrue("Wrong result EJBQL customerhome.findBisWithoutReservationsAndWithGoodCredit() (required:" 759 + result + ", found:" + customers_id + ")", 760 isCollectionEqual(result,customers_id)); 761 762 } 764 765 771 public void testIsEmptyInExp1Ter() throws Exception { 772 Collection customers = customerhome.findTerWithoutReservationsAndWithGoodCredit(true); 773 774 ArrayList customers_id = new ArrayList (); 775 Iterator customer = customers.iterator(); 776 while (customer.hasNext()) { 777 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 778 customers_id.add(customer_remote.getId()); 779 } 780 ArrayList result = new ArrayList (); 781 result.add(new Integer (80)); 782 result.add(new Integer (84)); 783 result.add(new Integer (88)); 784 result.add(new Integer (92)); 785 result.add(new Integer (96)); 786 result.add(new Integer (60)); 787 result.add(new Integer (100)); 788 result.add(new Integer (104)); 789 result.add(new Integer (108)); 790 791 assertTrue("Wrong result EJBQL customerhome.findTerWithoutReservationsAndWithGoodCredit() (required:" 792 + result + ", found:" + customers_id + ")", 793 isCollectionEqual(result,customers_id)); 794 795 } 797 798 804 public void testIsEmptyInExp1Quad() throws Exception { 805 Collection customers = customerhome.findQuadWithoutReservationsAndWithGoodCredit(true); 806 807 ArrayList customers_id = new ArrayList (); 808 Iterator customer = customers.iterator(); 809 while (customer.hasNext()) { 810 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 811 customers_id.add(customer_remote.getId()); 812 } 813 ArrayList result = new ArrayList (); 814 result.add(new Integer (80)); 815 result.add(new Integer (84)); 816 result.add(new Integer (88)); 817 result.add(new Integer (92)); 818 result.add(new Integer (96)); 819 result.add(new Integer (60)); 820 result.add(new Integer (100)); 821 result.add(new Integer (104)); 822 result.add(new Integer (108)); 823 824 assertTrue("Wrong result EJBQL customerhome.findQuadWithoutReservationsAndWithGoodCredit() (required:" 825 + result + ", found:" + customers_id + ")", 826 isCollectionEqual(result,customers_id)); 827 828 } 830 831 837 public void testIsEmptyInExp2() throws Exception { 838 Collection customers = customerhome.findWithoutReservationsOrWithGoodCredit(true); 839 840 ArrayList customers_id = new ArrayList (); 841 Iterator customer = customers.iterator(); 842 while (customer.hasNext()) { 843 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 844 customers_id.add(customer_remote.getId()); 845 } 846 ArrayList result = new ArrayList (); 847 for (int i=51;i<=69;i=i+3) { 848 result.add(new Integer (i)); 849 } 850 for (int i=80;i<=109;i++) { 851 result.add(new Integer (i)); 852 } 853 result.add(new Integer (202)); 854 result.add(new Integer (204)); 855 result.add(new Integer (206)); 856 result.add(new Integer (52)); 857 result.add(new Integer (56)); 858 result.add(new Integer (64)); 859 result.add(new Integer (68)); 860 861 assertTrue("Wrong result EJBQL customerhome.findWithoutReservationsOrWithGoodCredit() (required:" 862 + result + ", found:" + customers_id + ")", 863 isCollectionEqual(result,customers_id)); 864 865 } 867 868 873 public void testSimpleMemberOf() throws Exception { 874 SessionTestRemote sTest = sessiontesthome.create(); 875 int custId = sTest.getCustomerWithPhone("612-555-1280").intValue();; 876 assertEquals("Wrong result EJBQL session.getCustomerWithPhone(612-555-1280): ", 877 80, custId); 878 879 } 881 882 887 public void testMemberOfNavigate() throws Exception { 888 CruiseRemote crA = cruisehome.findByName("Alaska Cruise"); 889 Collection customers_id = customerhome.callFindOnCruise(crA.getId()); 890 891 ArrayList result = new ArrayList (); 892 result.add(new Integer (201)); 893 result.add(new Integer (201)); 894 result.add(new Integer (202)); 895 result.add(new Integer (202)); 896 result.add(new Integer (203)); 897 result.add(new Integer (203)); 898 result.add(new Integer (204)); 899 result.add(new Integer (204)); 900 result.add(new Integer (205)); 901 result.add(new Integer (205)); 902 result.add(new Integer (206)); 903 result.add(new Integer (206)); 904 result.add(new Integer (52)); 905 result.add(new Integer (55)); 906 result.add(new Integer (58)); 907 result.add(new Integer (61)); 908 result.add(new Integer (64)); 909 result.add(new Integer (67)); 910 911 assertTrue("Wrong result EJBQL customerhome.findOnCruise(crA) (required:" + result + ", found:" +customers_id+ 912 ")", isCollectionEqual(result,customers_id)); 913 914 } 916 917 922 public void testEgalDouble() throws Exception { 923 Collection ships = shiphome.findByTonnage(new Double (100000)); 924 925 ArrayList ships_id = new ArrayList (); 926 Iterator ship = ships.iterator(); 927 while (ship.hasNext()) { 928 ShipRemote ship_remote = (ShipRemote) PortableRemoteObject.narrow(ship.next(), ShipRemote.class); 929 ships_id.add(ship_remote.getId()); 930 } 931 ArrayList result = new ArrayList (); 932 result.add(new Integer (7)); 933 934 935 assertTrue("Wrong result EJBQL shiphome.findByTonnage(new Double(100000)) (required:" + result + ", found:" +ships_id+ ")", isCollectionEqual(result,ships_id)); 936 937 } 939 940 941 946 public void testBetweenDouble() throws Exception { 947 Collection ships = shiphome.findByTonnage(new Double (100000),new Double (130000)); 948 949 ArrayList ships_id = new ArrayList (); 950 Iterator ship = ships.iterator(); 951 while (ship.hasNext()) { 952 ShipRemote ship_remote = (ShipRemote) PortableRemoteObject.narrow(ship.next(), ShipRemote.class); 953 ships_id.add(ship_remote.getId()); 954 } 955 ArrayList result = new ArrayList (); 956 result.add(new Integer (7)); 957 result.add(new Integer (8)); 958 result.add(new Integer (9)); 959 result.add(new Integer (10)); 960 961 assertTrue("Wrong result EJBQL shiphome.findByTonnage(new Double(100000),new Double(130000)) (required:" + result + ", found:" +ships_id+ ")", isCollectionEqual(result,ships_id)); 962 963 } 965 966 970 public void testNavigate() throws Exception { 971 972 973 Collection customers = customerhome.findAllCreditCardAddress("Minneapolis"); 974 975 ArrayList customers_id = new ArrayList (); 976 Iterator customer = customers.iterator(); 977 while (customer.hasNext()) { 978 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 979 customers_id.add(customer_remote.getId()); 980 } 981 ArrayList result = new ArrayList (); 982 result.add(new Integer (80)); 983 result.add(new Integer (84)); 984 result.add(new Integer (88)); 985 result.add(new Integer (92)); 986 result.add(new Integer (96)); 987 988 assertTrue("Wrong result EJBQL customerhome.findAllCreditCardAddress() (required:" + result + ", found:" +customers_id+ 989 ")", isCollectionEqual(result,customers_id)); 990 991 checkIsInitialState(); 992 993 } 994 995 999 public void testNavigateOr() throws Exception { 1000 1001 1002 Collection customers = customerhome.findCustWithCCNumOrAddrZip("10000184", "55404"); 1003 1004 ArrayList customers_id = new ArrayList (); 1005 Iterator customer = customers.iterator(); 1006 while (customer.hasNext()) { 1007 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1008 customers_id.add(customer_remote.getId()); 1009 } 1010 ArrayList result = new ArrayList (); 1011 result.add(new Integer (84)); 1012 result.add(new Integer (88)); 1013 1014 assertTrue("Wrong result EJBQL customerhome.findCustWithCCNumOrAddrZip() (required:" + result + ", found:" +customers_id+ 1015 ")", isCollectionEqual(result,customers_id)); 1016 1017 checkIsInitialState(); 1018 1019 } 1020 1021 1026 public void testInFrom() throws Exception { 1027 1028 Collection customers = customerhome.findAllCustomersWithReservation(); 1029 1030 ArrayList customers_id = new ArrayList (); 1031 Iterator customer = customers.iterator(); 1032 while (customer.hasNext()) { 1033 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1034 customers_id.add(customer_remote.getId()); 1035 } 1036 ArrayList result = new ArrayList (); 1037 1038 result.add(new Integer (201)); 1039 result.add(new Integer (201)); 1040 result.add(new Integer (202)); 1041 result.add(new Integer (202)); 1042 result.add(new Integer (203)); 1043 result.add(new Integer (203)); 1044 result.add(new Integer (204)); 1045 result.add(new Integer (204)); 1046 result.add(new Integer (205)); 1047 result.add(new Integer (205)); 1048 result.add(new Integer (206)); 1049 result.add(new Integer (206)); 1050 result.add(new Integer (50)); 1051 result.add(new Integer (52)); 1052 result.add(new Integer (53)); 1053 result.add(new Integer (55)); 1054 result.add(new Integer (56)); 1055 result.add(new Integer (58)); 1056 result.add(new Integer (59)); 1057 result.add(new Integer (61)); 1058 result.add(new Integer (62)); 1059 result.add(new Integer (64)); 1060 result.add(new Integer (65)); 1061 result.add(new Integer (67)); 1062 result.add(new Integer (68)); 1063 1064 assertTrue("Wrong result EJBQL customerhome.findAllCustomersWithReservation (required:" + result + ", found:" +customers_id+ 1065 ")", isCollectionEqual(result,customers_id)); 1066 1067 } 1069 1070 1075 public void testDistinctInFrom() throws Exception { 1076 1077 Collection customers = customerhome.findAllCustomersWithReservationDistinct(); 1078 1079 ArrayList customers_id = new ArrayList (); 1080 Iterator customer = customers.iterator(); 1081 while (customer.hasNext()) { 1082 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1083 customers_id.add(customer_remote.getId()); 1084 } 1085 ArrayList result = new ArrayList (); 1086 1087 result.add(new Integer (201)); 1088 result.add(new Integer (202)); 1089 result.add(new Integer (203)); 1090 result.add(new Integer (204)); 1091 result.add(new Integer (205)); 1092 result.add(new Integer (206)); 1093 result.add(new Integer (50)); 1094 result.add(new Integer (52)); 1095 result.add(new Integer (53)); 1096 result.add(new Integer (55)); 1097 result.add(new Integer (56)); 1098 result.add(new Integer (58)); 1099 result.add(new Integer (59)); 1100 result.add(new Integer (61)); 1101 result.add(new Integer (62)); 1102 result.add(new Integer (64)); 1103 result.add(new Integer (65)); 1104 result.add(new Integer (67)); 1105 result.add(new Integer (68)); 1106 1107 assertTrue("Wrong result EJBQL customerhome.findAllCustomersWithReservationDistinct (required:" + result + ", found:" +customers_id+ 1108 ")", isCollectionEqual(result,customers_id)); 1109 1110 } 1112 1113 1119 public void _testBeanAsParameter() throws Exception { 1120 1121 AddressRemote add = addresshome.findByPrimaryKey(new Integer (10)); 1122 1123 Collection customers = customerhome.findByAddress(add); 1124 1125 ArrayList customers_id = new ArrayList (); 1126 Iterator customer = customers.iterator(); 1127 while (customer.hasNext()) { 1128 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1129 customers_id.add(customer_remote.getId()); 1130 } 1131 ArrayList result = new ArrayList (); 1132 1133 result.add(new Integer (80)); 1134 1135 assertTrue("Wrong result EJBQL customerhome.findByAddress(add)(required:" + result + ", found:" +customers_id+ 1136 ")", isCollectionEqual(result,customers_id)); 1137 1138 } 1140 1141 1147 public void _testBeanNullAsParameter() throws Exception { 1148 1149 Collection customers = customerhome.findByAddress(null); 1150 1151 ArrayList customers_id = new ArrayList (); 1152 Iterator customer = customers.iterator(); 1153 while (customer.hasNext()) { 1154 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1155 customers_id.add(customer_remote.getId()); 1156 } 1157 ArrayList result = new ArrayList (); 1158 1159 assertTrue("Wrong result EJBQL customerhome.findByAddress(add)(required:" + result + ", found:" +customers_id+ 1160 ")", isCollectionEqual(result,customers_id)); 1161 1162 } 1164 1165 1170 public void testFindCustomerAll() throws Exception { 1171 1172 Collection customers = customerhome.findCustomersAll(); 1173 1174 ArrayList customers_id = new ArrayList (); 1175 Iterator customer = customers.iterator(); 1176 while (customer.hasNext()) { 1177 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1178 customers_id.add(customer_remote.getId()); 1179 } 1180 ArrayList result = new ArrayList (); 1181 1182 for (int i=80;i<=99;i++) { 1183 result.add(new Integer (i)); 1184 } 1185 for (int j=201;j<=206;j++) { 1186 result.add(new Integer (j)); 1187 } 1188 for (int k=50;k<=69;k++) { 1189 result.add(new Integer (k)); 1190 } 1191 for (int l=100;l<=109;l++) { 1192 result.add(new Integer (l)); 1193 } 1194 1195 assertTrue("Wrong result EJBQL customerhome.findCustomersAll()(required:" + result + ", found:" +customers_id+ 1196 ")", isCollectionEqual(result,customers_id)); 1197 1198 } 1200 1201 1205 public void testFindCustByAddrId() throws Exception { 1206 Collection customers = customerhome.findByAddressId(new Integer (10)); 1207 1208 ArrayList customers_id = new ArrayList (); 1209 Iterator customer = customers.iterator(); 1210 while (customer.hasNext()) { 1211 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1212 customers_id.add(customer_remote.getId()); 1213 } 1214 ArrayList result = new ArrayList (); 1215 result.add(new Integer (80)); 1216 1217 assertTrue("Wrong result EJBQL customerhome.findByAddressId(10) (required:" + result + ", found:" +customers_id+ 1218 ")", isCollectionEqual(result,customers_id)); 1219 1220 } 1222 1223 1231 public void testAddrQuery300626() throws Exception { 1232 AddressRemote a = addresshome.findQuery300626(); 1233 assertEquals("Wrong result EJBQL : addresshome.findQuery300626()", 10, a.getId().intValue()); 1234 } 1235 1236 1240 public void testBeanLocalAsParameter() throws Exception { 1241 Collection customers = customerhome.callFindByAddressLocal(new Integer (10)); 1242 1243 ArrayList customers_id = new ArrayList (); 1244 Iterator customer = customers.iterator(); 1245 while (customer.hasNext()) { 1246 customers_id.add((Integer )customer.next()); 1247 } 1248 ArrayList result = new ArrayList (); 1249 result.add(new Integer (80)); 1250 1251 assertTrue("Wrong result EJBQL customerhome.callFindByAddressLocal(10) (required:" + result + ", found:" +customers_id+ 1252 ")", isCollectionEqual(result,customers_id)); 1253 1254 } 1256 1257 1261 public void testBeanLocalNullAsParameter() throws Exception { 1262 Collection customers = customerhome.callFindByAddressLocal(null); 1263 1264 ArrayList customers_id = new ArrayList (); 1265 Iterator customer = customers.iterator(); 1266 while (customer.hasNext()) { 1267 customers_id.add((Integer )customer.next()); 1268 } 1269 ArrayList result = new ArrayList (); 1270 1271 assertTrue("Wrong result EJBQL customerhome.callFindByAddressLocal(null) (required:" + result + ", found:" +customers_id+ 1272 ")", isCollectionEqual(result,customers_id)); 1273 1274 } 1276 1277 1283 public void testFindAllMike() throws Exception { 1284 Collection customers = customerhome.findAllMike(); 1285 ArrayList customers_id = new ArrayList (); 1286 Iterator customer = customers.iterator(); 1287 while (customer.hasNext()) { 1288 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1289 assertEquals("findAllMike() wrong result: ", 1290 "Mike", customer_remote.getName().getFirstName()); 1291 } 1292 } 1293 1294 1298 public void testIsNull1() throws Exception { 1299 Collection customers = customerhome.findCustomersWithCreditCard(); 1300 ArrayList customers_id = new ArrayList (); 1301 Iterator customer = customers.iterator(); 1302 while (customer.hasNext()) { 1303 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1304 customers_id.add(customer_remote.getId()); 1305 } 1306 ArrayList resExpected = new ArrayList (); 1307 resExpected.add(new Integer (80)); 1308 resExpected.add(new Integer (84)); 1309 resExpected.add(new Integer (88)); 1310 resExpected.add(new Integer (92)); 1311 resExpected.add(new Integer (96)); 1312 assertTrue("Wrong result EJBQL customerhome.findCustomersWithCreditCard (required:" 1313 + resExpected + ", found:" + customers_id + ")", 1314 isCollectionEqual(resExpected,customers_id)); 1315 } 1316 1317 1321 public void testIsNull1bis() throws Exception { 1322 Collection customers = customerhome.findCustomersWithOutCreditCard(); 1323 ArrayList customers_id = new ArrayList (); 1324 Iterator customer = customers.iterator(); 1325 while (customer.hasNext()) { 1326 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1327 customers_id.add(customer_remote.getId()); 1328 } 1329 ArrayList resExpected = new ArrayList (); 1330 for (int i = 50; i <= 69; i++) { 1331 resExpected.add(new Integer (i)); 1332 } 1333 for (int i = 81; i <= 83; i++) { 1334 resExpected.add(new Integer (i)); 1335 } 1336 for (int i = 85; i <= 87; i++) { 1337 resExpected.add(new Integer (i)); 1338 } 1339 for (int i = 89; i <= 91; i++) { 1340 resExpected.add(new Integer (i)); 1341 } 1342 for (int i = 93; i <= 95; i++) { 1343 resExpected.add(new Integer (i)); 1344 } 1345 for (int i = 97; i <= 109; i++) { 1346 resExpected.add(new Integer (i)); 1347 } 1348 for (int i = 201; i <= 206; i++) { 1349 resExpected.add(new Integer (i)); 1350 } 1351 assertTrue("Wrong result EJBQL customerhome.findCustomersWithOutCreditCard (required:" 1352 + resExpected + ", found:" + customers_id + ")", 1353 isCollectionEqual(resExpected,customers_id)); 1354 } 1355 1356 1360 public void testIsNull1ter() throws Exception { 1361 Collection customers = customerhome.findCustomersXWithOutCreditCard("John"); 1362 assertEquals("Wrong result EJBQL customerhome.findCustomersXWithOutCreditCard: ", 19, customers.size()); 1363 1364 } 1365 1366 1370 public void testIsNull2() throws Exception { 1371 Collection customers = customerhome.findCustomersWithCreditCompany(); 1372 ArrayList customers_id = new ArrayList (); 1373 Iterator customer = customers.iterator(); 1374 while (customer.hasNext()) { 1375 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1376 customers_id.add(customer_remote.getId()); 1377 } 1378 ArrayList resExpected = new ArrayList (); 1379 resExpected.add(new Integer (80)); 1380 resExpected.add(new Integer (84)); 1381 resExpected.add(new Integer (88)); 1382 resExpected.add(new Integer (92)); 1383 resExpected.add(new Integer (96)); 1384 assertTrue("Wrong result EJBQL customerhome.findCustomersWithCreditCompany (required:" 1385 + resExpected + ", found:" + customers_id + ")", 1386 isCollectionEqual(resExpected,customers_id)); 1387 } 1388 1389 1393 public void testIsNull3() throws Exception { 1394 Collection customers = customerhome.callFindByParameterIsNull(null); 1395 assertEquals("Wrong result EJBQL customerhome.callFindByParameterIsNull(null): ", 1396 56, customers.size()); 1397 } 1398 1399 1403 public void testIsNull3bis() throws Exception { 1404 Collection customers = customerhome.callFindByParameterIsNull(new Integer (10)); 1405 assertEquals("Wrong result EJBQL customerhome.callFindByParameterIsNull(): ", 1406 0, customers.size()); 1407 } 1408 1409 1413 public void testCustEjbSelectLastName() throws Exception { 1414 assertEquals("Wrong ejbSelectLastName for c.id=80: ", 1415 "Smith80", customerhome.selectLastName(new Integer (80))); 1416 } 1417 1418 1422 public void testCustEjbSelectAddrCity() throws Exception { 1423 assertEquals("Wrong ejbSelectAddrCity for c.id=80: ", 1424 "Minneapolis", customerhome.selectAddrCity(new Integer (80))); 1425 } 1426 1427 1431 public void testCabinEjbSelectDeckLevel() throws Exception { 1432 assertEquals("Wrong ejbSelectDeckLevel for c.id=21100: ", 1433 1, cabinhome.selectDeckLevel(new Integer (21100))); 1434 } 1435 1436 1440 public void testCustEjbSelectFirstName() throws Exception { 1441 Set lfn = customerhome.selectFirstName(); 1442 Iterator ilfn = lfn.iterator(); 1443 StringBuffer slfn = new StringBuffer (); 1444 while (ilfn.hasNext()) { 1445 slfn = slfn.append((String ) ilfn.next() + ","); 1446 } 1447 assertEquals("Wrong ejbSelectFirstName() number results (" + slfn.toString() + "): ", 1448 6, lfn.size()); 1449 if (!lfn.contains("John") 1450 || !lfn.contains("Mike") 1451 || !lfn.contains("Paul") 1452 || !lfn.contains("Ringo") 1453 || !lfn.contains("Roger") 1454 || !lfn.contains("Joe")) { 1455 fail("Wrong ejbSelectFirstName() result (" + slfn.toString() 1456 + "): does not contain 'John', 'Mike' or 'Paul' or 'Ringo' or 'Roger' or 'Joe'"); 1457 } 1458 } 1459 1460 1464 public void testCustEjbSelectDistinctFirstName() throws Exception { 1465 Collection lfn = customerhome.selectDistinctFirstName(); 1466 assertEquals("Wrong ejbSelectDistinctFirstName() number results (" + lfn.toString() + "): ", 1467 6, lfn.size()); 1468 if (!lfn.contains("John") 1469 || !lfn.contains("Mike") 1470 || !lfn.contains("Paul") 1471 || !lfn.contains("Ringo") 1472 || !lfn.contains("Roger") 1473 || !lfn.contains("Joe")) { 1474 fail("Wrong ejbSelectDistinctDistinctFirstName() result (" + lfn.toString() 1475 + "): does not contain 'John', 'Mike' or 'Paul' or 'Ringo' or 'Roger' or 'Joe'"); 1476 } 1477 } 1478 1479 1484 public void testCustEjbSelectAddr() throws Exception { 1485 assertEquals("Wrong ejbSelectAddr for c.id=80: ", 1486 new Integer (10), customerhome.selectAddr(new Integer (80))); 1487 } 1488 1489 1494 public void testCustEjbSelectAllCreditCartAddr() throws Exception { 1495 Collection addr = customerhome.selectAllCreditCardAddr(); 1496 StringBuffer sAddr = new StringBuffer (); 1497 Iterator iAddr = addr.iterator(); 1498 while (iAddr.hasNext()) { 1499 sAddr = sAddr.append(((Integer ) iAddr.next()).toString() + ","); 1500 } 1501 ArrayList eAddr = new ArrayList (); 1502 eAddr.add(new Integer (11)); 1503 eAddr.add(new Integer (16)); 1504 eAddr.add(new Integer (21)); 1505 eAddr.add(new Integer (26)); 1506 eAddr.add(new Integer (31)); 1507 assertTrue("Wrong ejbSelectCreditCardAddr: (" + sAddr + "): ", 1508 isCollectionEqual(eAddr, addr)); 1509 } 1510 1511 1516 public void testCustEjbSelectRogerAddr() throws Exception { 1517 Collection addr = customerhome.selectRogerAddr(); 1518 StringBuffer sAddr = new StringBuffer (); 1519 Iterator iAddr = addr.iterator(); 1520 while (iAddr.hasNext()) { 1521 sAddr = sAddr.append(((Integer ) iAddr.next()).toString() + ","); 1522 } 1523 ArrayList eAddr = new ArrayList (); 1524 eAddr.add(new Integer (45)); 1525 eAddr.add(new Integer (50)); 1526 eAddr.add(new Integer (55)); 1527 eAddr.add(new Integer (60)); 1528 assertTrue("Wrong ejbCustSelectRogerAddr: (" + sAddr + "): ", 1529 isCollectionEqual(eAddr, addr)); 1530 } 1531 1532 1536 public void testSimpleOrderBy() throws Exception { 1537 Collection customers = customerhome.findAllOrderByLastname(); 1538 assertEquals("Wrong customers number for customerhome.findAllOrderByLastname(): ", 1539 56, customers.size()); 1540 Iterator ci = customers.iterator(); 1541 String previous = ((CustomerRemote) PortableRemoteObject.narrow(ci.next(), CustomerRemote.class)).getName().getLastName(); 1542 while (ci.hasNext()) { 1543 String lname = ((CustomerRemote) PortableRemoteObject.narrow(ci.next(), CustomerRemote.class)).getName().getLastName(); 1544 assertTrue("Wrong ordered (previous=" + previous + ",current=" + lname + ")", 1545 previous.compareTo(lname)<=0); 1546 previous = lname; 1547 } 1548 } 1549 1550 1554 public void testOrderByDescAsc() throws Exception { 1555 Collection customers = customerhome.findAllOrderByDescLastnameAscFirstname(); 1556 assertEquals("Wrong customers number for customerhome.findAllOrderByLastname(): ", 1557 56, customers.size()); 1558 Iterator ci = customers.iterator(); 1559 Name previous = ((CustomerRemote) PortableRemoteObject.narrow(ci.next(), CustomerRemote.class)).getName(); 1560 while (ci.hasNext()) { 1561 Name current = ((CustomerRemote) PortableRemoteObject.narrow(ci.next(), CustomerRemote.class)).getName(); 1562 assertTrue("Wrong ordered (previous=" + previous + ",current=" + current + ")", 1563 previous.getLastName().compareTo(current.getLastName())>=0); 1564 if (previous.getLastName().equals(current.getLastName())) { 1565 assertTrue("Wrong ordered (previous=" + previous + ",current=" + current + ")", 1566 previous.getFirstName().compareTo(current.getFirstName())<=0); 1567 } 1568 previous = current; 1569 } 1570 1571 } 1572 1573 1579 public void testOrderBy2() throws Exception { 1580 Collection reservations = reservationhome.findOrderedRsrv(); 1581 assertEquals("Wrong reservations number for reservationhome.findOrderedRsrv(): ", 1582 25, reservations.size()); 1583 } 1584 1585 1589 public void testAverageofTonnage() throws Exception { 1590 assertEquals("AverageofTonnage: ", 80000.0D, shiphome.getAverageOfTonnage(), 0.1); 1591 } 1592 1593 1597 public void testCountOfReservations() throws Exception { 1598 assertEquals("CountOfReservations: ", 25L, reservationhome.getCountOfReservations()); 1599 } 1600 1601 1606 public void testCountOfCustomersWithId1() throws Exception { 1607 assertEquals("CountOfCustomersWithId1: ", 1L, customerhome.getCountCustomersWithId1(new Integer (82))); 1608 } 1609 1610 1615 public void testCountOfCustomersWithId2() throws Exception { 1616 assertEquals("CountOfCustomersWithId2: ", 1L, customerhome.getCountCustomersWithId2(82)); 1617 } 1618 1619 1623 public void testCountOfCustomersRingo() throws Exception { 1624 assertEquals("CountOfCustomersRingo: ", 4L, customerhome.getCountCustomersRingo()); 1625 } 1626 1627 1631 public void testCustFindById() throws Exception { 1632 assertEquals("CustFindById: ", new Integer (82), customerhome.findById(new Integer (82)).getId()); 1633 } 1634 1635 1639 public void testMinAmountOfReservations() throws Exception { 1640 assertEquals("testMinAmountOfReservations: ", 1641 2500.0, reservationhome.getMinAmountOfReservations(), 0.1); 1642 } 1643 1644 1649 public void testMinAmountForCruise() throws Exception { 1650 assertEquals("testMinAmountForCruise(Alaska Cruise): ", 1651 2520.0, reservationhome.getMinAmountForCruise("Alaska Cruise"), 0.1); 1652 } 1653 1654 1658 public void testAmountsForCruise() throws Exception { 1659 assertEquals("testAmountsForCruise(Alaska Cruise): ", 1660 18, reservationhome.getAmountsForCruise("Alaska Cruise").size()); 1661 } 1662 1663 1667 public void testMaxAmountOfReservations() throws Exception { 1668 assertEquals("testMaxAmountOfReservations: ", 1669 208100.0, reservationhome.getMaxAmountOfReservations(), 0.1); 1670 } 1671 1672 1677 public void testCountOfReservationsForCustomer() throws Exception { 1678 assertEquals("CountOfReservationsForCustomer: ", 1679 2L, reservationhome.getCountOfReservationsForCustomer(new Integer (202))); 1680 } 1681 1682 1687 public void testAmountOfReservationsForCustomer() throws Exception { 1688 assertEquals("AmountOfReservationsForCustomer: ", 1689 408100.0, reservationhome.getAmountOfReservationsForCustomer(new Integer (202)), 0.1); 1690 } 1691 1692 1698 public void testCustomersCountCreditCard() throws Exception { 1699 assertEquals("CustomersCountCreditCard: ", 5, customerhome.getCountCreditCard()); 1700 } 1701 1702 1706 public void testCustomersCreditCardNumbers() throws Exception { 1707 assertEquals("CustomersCreditCardNumbers: ", 5, customerhome.getCreditCardNumbers().size()); 1708 } 1709 1710 1711 1715 public void testFindAllAddresses() throws Exception { 1716 Collection addresses = addresshome.findAllAddress(); 1717 Iterator iAddr = addresses.iterator(); 1718 int nbAddr = 0; 1719 while (iAddr.hasNext()) { 1720 nbAddr++; 1721 iAddr.next(); 1722 } 1723 assertEquals("testFindAllAddresses: ", 61, nbAddr); 1724 } 1725 1726 1730 public void testAddrGetAllCities() throws Exception { 1731 assertEquals("testAddrGetAllCities: ", 61, addresshome.getAllCities().size()); 1732 } 1733 1734 1738 public void testAddrGetAllCreditCompanies() throws Exception { 1739 assertEquals("testAddrGetAllCreditCompanies: ", 5, addresshome.getAllCreditCompanies().size()); 1740 } 1741 1742 1751 public void testAddrGetAllCreditCompanyNames() throws Exception { 1752 assertEquals("testAddrGetAllCreditCompanyNames: ", 61, addresshome.getAllCreditCompanyNames().size()); 1753 } 1754 1755 1764 public void testAddrGetAllCreditCompanyIds() throws Exception { 1765 assertEquals("testAddrGetAllCreditCompanyIds: ", 61, addresshome.getAllCreditCompanyIds().size()); 1766 } 1767 1768 1777 public void testAddrGetAllCreditCompanyNums() throws Exception { 1778 assertEquals("testAddrGetAllCreditCompanyNums: ", 5, addresshome.getAllCreditCompanyNums().size()); 1779 } 1780 1781 1782 1786 public void testAddrCountOfCities() throws Exception { 1787 assertEquals("testAddrCountOfCities: ", 61L, addresshome.getCountOfCities()); 1788 } 1789 1790 1794 public void testAddrCountOfDistinctCities() throws Exception { 1795 assertEquals("testAddrCountOfDistinctCities: ", 6L, addresshome.getCountOfDistinctCities()); 1796 } 1797 1798 1803 public void testFindResWithLesserAmount() throws Exception { 1804 Collection reservations = reservationhome.findReservationsWithLesserAmount(); 1805 assertEquals("Wrong reservations number for reservationhome.findReservationsWithLesserAmount(): ", 1806 4, reservations.size()); 1807 } 1808 1809 1814 public void testFindCustAllLimit_1() throws Exception { 1815 1816 Collection customers = customerhome.findAllWithLimit_1(40); 1817 1818 ArrayList customers_id = new ArrayList (); 1819 Iterator customer = customers.iterator(); 1820 while (customer.hasNext()) { 1821 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1822 customers_id.add(customer_remote.getId()); 1823 } 1824 ArrayList result = new ArrayList (); 1825 for (int l=100;l<=109;l++) { 1826 result.add(new Integer (l)); 1827 } 1828 for (int j=201;j<=206;j++) { 1829 result.add(new Integer (j)); 1830 } 1831 1832 assertTrue("Wrong result EJBQL customerhome.findAllWithLimit_1()(required:" + result + ", found:" +customers_id+ 1833 ")", isCollectionEqual(result,customers_id)); 1834 1835 } 1837 1838 1843 public void testFindCustAllLimit_2() throws Exception { 1844 1845 Collection customers = customerhome.findAllWithLimit_2(40); 1846 1847 ArrayList customers_id = new ArrayList (); 1848 Iterator customer = customers.iterator(); 1849 while (customer.hasNext()) { 1850 CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class); 1851 customers_id.add(customer_remote.getId()); 1852 } 1853 ArrayList result = new ArrayList (); 1854 for (int l=100;l<=104;l++) { 1855 result.add(new Integer (l)); 1856 } 1857 1858 assertTrue("Wrong result EJBQL customerhome.findAllWithLimit_2()(required:" + result + ", found:" +customers_id+ 1859 ")", isCollectionEqual(result,customers_id)); 1860 1861 } 1863 1864 1865 1866 public static Test suite() { 1867 return new TestSuite(F_EjbqlEC2.class); 1868 } 1869 1870 public static void main (String args[]) { 1871 String testtorun = null; 1872 for (int argn = 0; argn < args.length; argn++) { 1874 String s_arg = args[argn]; 1875 Integer i_arg; 1876 if (s_arg.equals("-n")) { 1877 testtorun = args[++argn]; 1878 } 1879 } 1880 if (testtorun == null) { 1881 junit.textui.TestRunner.run(suite()); 1882 } else { 1883 junit.textui.TestRunner.run(new F_EjbqlEC2(testtorun)); 1884 } 1885 } 1886} 1887 1888 | Popular Tags |