1 24 25 package org.objectweb.jonas.jtests.clients.entity; 26 27 import java.util.ArrayList ; 28 import java.util.Calendar ; 29 import java.util.Collection ; 30 import java.util.Date ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.Set ; 34 import javax.naming.NamingException ; 35 import javax.rmi.PortableRemoteObject ; 36 import junit.framework.Test; 37 import junit.framework.TestSuite; 38 import org.objectweb.jonas.jtests.beans.ejbql.*; 39 import org.objectweb.jonas.jtests.util.JTestCase; 40 41 public class F_ConEnlist extends JTestCase { 42 43 private static SessionTestHomeRemote sessiontesthome = null; 44 private static CustomerHomeRemote customerhome = null; 45 private static ReservationHomeRemote reservationhome = null; 46 private static CruiseHomeRemote cruisehome = null; 47 private static ShipHomeRemote shiphome = null; 48 private static CabinHomeRemote cabinhome = null; 49 private static AddressHomeRemote addresshome = null; 50 private static CreditCardHomeRemote creditcardhome = null; 51 52 public F_ConEnlist(String name) { 53 super(name); 54 } 55 56 protected void setUp() { 57 super.setUp(); 58 useBeans("ejbql", false); 59 } 60 61 protected void tearDown() throws Exception { 62 Collection c = getShipHome().findAllShips(); 63 for (Iterator i = c.iterator(); i.hasNext();) { 64 ShipRemote s = (ShipRemote) i.next(); 65 s.remove(); 66 } 67 c = getReservationHome().findAllReservations(); 68 for (Iterator i = c.iterator(); i.hasNext();) { 69 ReservationRemote s = (ReservationRemote) i.next(); 70 s.remove(); 71 } 72 c = getCruiseHome().findAllCruises(); 73 for (Iterator i = c.iterator(); i.hasNext();) { 74 CruiseRemote s = (CruiseRemote) i.next(); 75 s.remove(); 76 } 77 c = getCustomerHome().findCustomersAll(); 78 for (Iterator i = c.iterator(); i.hasNext();) { 79 CustomerRemote s = (CustomerRemote) i.next(); 80 s.remove(); 81 } 82 for (int dl = 1; dl <= 7; dl++) { 83 c = getCabinHome().findAllOnDeckLevel(new Integer (dl)); 84 for (Iterator i = c.iterator(); i.hasNext();) { 85 CabinRemote s = (CabinRemote) i.next(); 86 s.remove(); 87 } 88 } 89 } 90 91 private SessionTestHomeRemote getSessionTestHome() throws Exception { 92 if (sessiontesthome == null) { 93 sessiontesthome = (SessionTestHomeRemote) 94 PortableRemoteObject.narrow(ictx.lookup("EjbqlSessionTestHomeRemote"), 95 SessionTestHomeRemote.class); 96 } 97 assertTrue(sessiontesthome != null); 98 return sessiontesthome; 99 } 100 101 private CustomerHomeRemote getCustomerHome() throws Exception { 102 if (customerhome == null) { 103 customerhome = (CustomerHomeRemote) 104 PortableRemoteObject.narrow(ictx.lookup("CustomerHomeRemote"), 105 CustomerHomeRemote.class); 106 } 107 assertTrue(customerhome != null); 108 return customerhome; 109 } 110 111 private ShipHomeRemote getShipHome() throws Exception { 112 if (shiphome == null) { 113 shiphome = (ShipHomeRemote) 114 PortableRemoteObject.narrow(ictx.lookup("ShipHomeRemote"), 115 ShipHomeRemote.class); 116 } 117 assertTrue(shiphome != null); 118 return shiphome; 119 } 120 121 private CruiseHomeRemote getCruiseHome() throws Exception { 122 if (cruisehome == null) { 123 cruisehome = (CruiseHomeRemote) 124 PortableRemoteObject.narrow(ictx.lookup("CruiseHomeRemote"), 125 CruiseHomeRemote.class); 126 } 127 assertTrue(cruisehome != null); 128 return cruisehome; 129 } 130 131 private ReservationHomeRemote getReservationHome() throws Exception { 132 if (reservationhome == null) { 133 reservationhome = (ReservationHomeRemote) 134 PortableRemoteObject.narrow(ictx.lookup("ReservationHomeRemote"), 135 ReservationHomeRemote.class); 136 } 137 assertTrue(reservationhome != null); 138 return reservationhome; 139 } 140 141 private CabinHomeRemote getCabinHome() throws Exception { 142 if (cabinhome == null) { 143 cabinhome = (CabinHomeRemote) 144 PortableRemoteObject.narrow(ictx.lookup("CabinHomeRemote"), 145 CabinHomeRemote.class); 146 } 147 assertTrue(cabinhome != null); 148 return cabinhome; 149 } 150 151 private AddressHomeRemote getAddressHome() throws Exception { 152 if (addresshome == null) { 153 addresshome = (AddressHomeRemote) 154 PortableRemoteObject.narrow(ictx.lookup("AddressHomeRemote"), 155 AddressHomeRemote.class); 156 } 157 assertTrue(addresshome != null); 158 return addresshome; 159 } 160 161 public void test1() throws Exception { 162 utx.begin(); 163 ShipRemote shipA = getShipHome().create(new Integer (10772), "Ship A", 30000.0); 164 CruiseRemote cruiseA = getCruiseHome().create("Cruise A", new Integer (10772)); 165 utx.commit(); 166 } 167 168 public void test2() throws Exception { 169 utx.begin(); 170 ShipRemote shipA = getShipHome().create(new Integer (10772), "Ship A", 30000.0); 171 CruiseRemote cruiseA = getCruiseHome().create("Cruise A", new Integer (10772)); 172 for (int j = 1; j <= 10; j++) { 173 getShipHome().create(new Integer (j), "Ship " + j, 30000.0 + (10000.0 * j)); 174 } 175 utx.commit(); 176 } 177 178 public void test3() throws Exception { 179 utx.begin(); 180 ShipRemote shipA = getShipHome().create(new Integer (10772), "Ship A", 30000.0); 181 CruiseRemote cruiseA = getCruiseHome().create("Cruise A", new Integer (10772)); 182 for (int j = 1; j <= 10; j++) { 183 getShipHome().create(new Integer (j), "Ship " + j, 30000.0 + (10000.0 * j)); 184 } 185 ShipRemote ship1 = getShipHome().findByPrimaryKey(new Integer (1)); 186 cruiseA = getCruiseHome().create("Alaska Cruise", new Integer (1)); 187 CruiseRemote cruiseB = getCruiseHome().create("Bohemian Cruise", new Integer (1)); 188 for (int i = 80; i <= 99; i++) { 189 CustomerRemote customer = getCustomerHome().create(new Integer (i)); 190 customer.setName(new Name("Smith" + i, "John")); 191 customer.addPhoneNumber("612-555-12" + i, (byte) 1); 192 customer.setAddress("10" + i + " Elm Street", "LONDON", "MN", "5540"); 193 customer.setHasGoodCredit(i % 4 == 0); 194 if (i % 4 == 0) { 195 customer.setCreditCard(new Date (), "100001" + i, "MasterCard", "CA" , 196 "CETELEM", "rue de jeunet", "PARIS", "France", "3888" ); 197 } 198 } 199 utx.commit(); 200 } 201 202 public void test4() throws Exception { 203 utx.begin(); 204 ShipRemote shipA = getShipHome().create(new Integer (10772), "Ship A", 30000.0); 205 CruiseRemote cruiseA = getCruiseHome().create("Cruise A", new Integer (10772)); 206 for (int j = 1; j <= 10; j++) { 207 getShipHome().create(new Integer (j), "Ship " + j, 30000.0 + (10000.0 * j)); 208 } 209 ShipRemote ship1 = getShipHome().findByPrimaryKey(new Integer (1)); 210 cruiseA = getCruiseHome().create("Alaska Cruise", new Integer (1)); 211 CruiseRemote cruiseB = getCruiseHome().create("Bohemian Cruise", new Integer (1)); 212 for (int i = 80; i <= 99; i++) { 213 CustomerRemote customer = getCustomerHome().create(new Integer (i)); 214 customer.setName(new Name("Smith" + i, "John")); 215 customer.addPhoneNumber("612-555-12" + i, (byte) 1); 216 customer.setAddress("10" + i + " Elm Street", "LONDON", "MN", "5540"); 217 customer.setHasGoodCredit(i % 4 == 0); 218 if (i % 4 == 0) { 219 customer.setCreditCard(new Date (), "100001" + i, "MasterCard", "CA" , 220 "CETELEM", "rue de jeunet", "PARIS", "France", "3888" ); 221 } 222 } 223 Calendar date = Calendar.getInstance(); 224 date.set(2004, 04, 01); 225 for (int i = 201; i <= 207; i++) { 226 Collection customers = new ArrayList (); 227 CustomerRemote cust = getCustomerHome().create(new Integer (i)); 228 cust.setName(new Name("Customer "+i,"Mike")); 229 cust.setHasGoodCredit(i % 2 == 0); 230 cust.setAddress("50"+i+" Main Street","Minneapolis","MN","5510"+i); 231 customers.add(new Integer (i)); 233 Collection reservations = new ArrayList (); 234 for (int j = 0; j < 2; j++) { 235 ReservationRemote reservation = getReservationHome().create(cruiseA.getId(), customers); 236 reservation.setDate(date.getTime()); 237 reservation.setAmountPaid(1000*i + 100*j + 2000); 238 date.add(Calendar.DAY_OF_MONTH, 7); 239 240 Set cabins = new HashSet (); 241 CabinRemote cabin = getCabinHome().create(new Integer (1000+i*100+j)); 242 cabin.setDeckLevel(i - 200); 243 cabin.setName("Cabin "+ i + "0" + j + "1"); 244 cabins.add(cabin.getId()); 245 cabin = getCabinHome().create(new Integer (1000+i*100+10+j)); 246 cabin.setDeckLevel(i - 200); 247 cabin.setName("Cabin "+i+"0"+j+"2"); 248 cabins.add(cabin.getId()); 249 reservation.setAllCabins(cabins); } 251 } 252 utx.commit(); 253 } 254 255 public void test35() throws Exception { 256 utx.begin(); 257 ShipRemote shipA = getShipHome().create(new Integer (10772), "Ship A", 30000.0); 258 CruiseRemote cruiseA = getCruiseHome().create("Cruise A", new Integer (10772)); 259 for (int j = 1; j <= 10; j++) { 260 getShipHome().create(new Integer (j), "Ship " + j, 30000.0 + (10000.0 * j)); 261 } 262 ShipRemote ship1 = getShipHome().findByPrimaryKey(new Integer (1)); 263 cruiseA = getCruiseHome().create("Alaska Cruise", new Integer (1)); 264 CruiseRemote cruiseB = getCruiseHome().create("Bohemian Cruise", new Integer (1)); 265 for (int i = 80; i <= 99; i++) { 266 CustomerRemote customer = getCustomerHome().create(new Integer (i)); 267 customer.setName(new Name("Smith" + i, "John")); 268 customer.addPhoneNumber("612-555-12" + i, (byte) 1); 269 customer.setAddress("10" + i + " Elm Street", "LONDON", "MN", "5540"); 270 customer.setHasGoodCredit(i % 4 == 0); 271 if (i % 4 == 0) { 272 customer.setCreditCard(new Date (), "100001" + i, "MasterCard", "CA" , 273 "CETELEM", "rue de jeunet", "PARIS", "France", "3888" ); 274 } 275 } 276 Calendar date = Calendar.getInstance(); 277 date.set(2004, 04, 01); 278 int i = 201; 279 Collection customers = new ArrayList (); 280 CustomerRemote cust = getCustomerHome().create(new Integer (i)); 281 cust.setName(new Name("Customer "+i,"Mike")); 282 cust.setHasGoodCredit(i % 2 == 0); 283 cust.setAddress("50"+i+" Main Street","Minneapolis","MN","5510"+i); 284 customers.add(new Integer (i)); 286 Collection reservations = new ArrayList (); 287 int j = 0; 288 ReservationRemote reservation = getReservationHome().create(cruiseA.getId(), customers); 289 reservation.setDate(date.getTime()); 290 reservation.setAmountPaid(1000*i + 100*j + 2000); 291 date.add(Calendar.DAY_OF_MONTH, 7); 292 293 Set cabins = new HashSet (); 294 CabinRemote cabin = getCabinHome().create(new Integer (1000+i*100+j)); 295 cabin.setDeckLevel(i - 200); 296 cabin.setName("Cabin "+ i + "0" + j + "1"); 297 cabins.add(cabin.getId()); 298 cabin = getCabinHome().create(new Integer (1000+i*100+10+j)); 299 cabin.setDeckLevel(i - 200); 300 cabin.setName("Cabin "+i+"0"+j+"2"); 301 cabins.add(cabin.getId()); 302 reservation.setAllCabins(cabins); utx.commit(); 304 } 305 306 public void test33() throws Exception { 307 utx.begin(); 308 ShipRemote shipA = getShipHome().create(new Integer (10772), "Ship A", 30000.0); 309 CruiseRemote cruiseA = getCruiseHome().create("Cruise A", new Integer (10772)); 310 for (int j = 1; j <= 10; j++) { 311 getShipHome().create(new Integer (j), "Ship " + j, 30000.0 + (10000.0 * j)); 312 } 313 ShipRemote ship1 = getShipHome().findByPrimaryKey(new Integer (1)); 314 cruiseA = getCruiseHome().create("Alaska Cruise", new Integer (1)); 315 CruiseRemote cruiseB = getCruiseHome().create("Bohemian Cruise", new Integer (1)); 316 for (int i = 80; i <= 82; i++) { 317 CustomerRemote customer = getCustomerHome().create(new Integer (i)); 318 customer.setName(new Name("Smith" + i, "John")); 319 customer.addPhoneNumber("612-555-12" + i, (byte) 1); 320 customer.setAddress("10" + i + " Elm Street", "LONDON", "MN", "5540"); 321 customer.setHasGoodCredit(i % 4 == 0); 322 if (i % 4 == 0) { 323 customer.setCreditCard(new Date (), "100001" + i, "MasterCard", "CA" , 324 "CETELEM", "rue de jeunet", "PARIS", "France", "3888" ); 325 } 326 } 327 utx.commit(); 328 329 utx.begin(); 330 Calendar date = Calendar.getInstance(); 331 date.set(2004, 04, 01); 332 int i = 201; 333 Collection customers = new ArrayList (); 334 CustomerRemote cust = getCustomerHome().create(new Integer (i)); 335 cust.setName(new Name("Customer "+i,"Mike")); 336 cust.setHasGoodCredit(i % 2 == 0); 337 cust.setAddress("50"+i+" Main Street","Minneapolis","MN","5510"+i); 338 customers.add(new Integer (i)); utx.commit(); 340 341 utx.begin(); 342 Collection reservations = new ArrayList (); 343 int j = 0; 344 ReservationRemote reservation = getReservationHome().create(cruiseA.getId(), customers); 345 reservation.setDate(date.getTime()); 346 reservation.setAmountPaid(1000*i + 100*j + 2000); 347 date.add(Calendar.DAY_OF_MONTH, 7); 348 349 CabinRemote cabin = getCabinHome().create(new Integer (1000+i*100+j)); 350 cabin.setDeckLevel(i - 200); 351 cabin.setName("Cabin "+ i + "0" + j + "1"); 352 cabin = getCabinHome().create(new Integer (1000+i*100+10+j)); 353 cabin.setDeckLevel(i - 200); 354 cabin.setName("Cabin "+i+"0"+j+"2"); 355 utx.commit(); 356 } 357 358 public void test11() throws Exception { 359 test3(); 360 for (int i = 0; i < 10; i++) { 361 Collection c = getShipHome().findAllShips(); 362 } 363 } 364 365 public void test100() throws Exception { 366 367 try { 369 getCustomerHome().findByPrimaryKey(new Integer (80)); 370 } catch (Exception e) { 371 try { 373 utx.begin(); 374 String cities[] = new String [6]; 375 cities[0] = "Minneapolis"; cities[1] = "St. Paul"; cities[2] = "Rochester"; 376 cities[3] = "Winona"; cities[4] = "Wayzata"; cities[5] = "Eagan"; 377 ShipRemote shipA = getShipHome().create(new Integer (10772), "Ship A", 30000.0); 378 CruiseRemote cruiseA = getCruiseHome().create("Cruise A", new Integer (10772)); 379 for (int jj = 1; jj <= 10; jj++) { 380 ShipRemote ship = getShipHome().create(new Integer (jj), "Ship " + jj, 30000.0 + (10000.0 * jj)); 381 } 382 cruiseA = null; 383 CruiseRemote cruiseB = null; 384 ShipRemote ship1 = getShipHome().findByPrimaryKey(new Integer (1)); 385 cruiseA = getCruiseHome().create("Alaska Cruise", new Integer (1)); 386 cruiseB = getCruiseHome().create("Bohemian Cruise", new Integer (1)); 387 for (int kk = 80; kk <= 99; kk++) { 388 CustomerRemote customer = null; 389 390 customer = getCustomerHome().create(new Integer (kk)); 391 customer.setName(new Name("Smith"+kk,"John") ); 392 customer.addPhoneNumber("612-555-12"+kk,(byte) 1); 393 394 customer.setAddress("10"+kk+" Elm Street", 395 cities[(kk-80)%6], 396 (kk%2==0?"MN":"CA"), 397 "5540"+(kk%5+1)); 398 customer.setHasGoodCredit((kk%4 == 0)); 399 if (kk%4 == 0) 400 customer.setCreditCard(new Date (System.currentTimeMillis()+100000), "100001"+kk, "MasterCard", "CA" ,"CETELEM", "rue de jeunet", cities[0], "France", "3888" ); 401 } 402 Calendar date = Calendar.getInstance(); 404 date.set(2002,10,1); 405 406 for (int kk=201; kk<207; kk++) { 407 Collection customers = new ArrayList (); 408 CustomerRemote cust = getCustomerHome().create(new Integer (kk)); 409 cust.setName(new Name("Customer "+kk,"Mike")); 410 cust.setHasGoodCredit( (kk%2==0) ); cust.setAddress("50"+kk+" Main Street","Minneapolis","MN","5510"+kk); 412 customers.add(new Integer (kk)); 414 Collection reservations = new ArrayList (); 415 416 for (int jj=0; jj<2; jj++) { 417 418 ReservationRemote reservation = getReservationHome().create(cruiseA.getId(), customers); 419 reservation.setDate(date.getTime()); 420 reservation.setAmountPaid(1000*kk+100*jj+2000); 421 422 date.add(Calendar.DAY_OF_MONTH, 7); 423 424 Set cabins = new HashSet (); 425 CabinRemote cabin = getCabinHome().create(new Integer (1000+kk*100+jj)); 426 cabin.setDeckLevel(kk-200); 427 cabin.setName("Cabin "+kk+"0"+jj+"1"); 428 429 cabins.add(cabin.getId()); 430 cabin = getCabinHome().create(new Integer (1000+kk*100+10+jj)); 431 cabin.setDeckLevel(kk-200); 432 cabin.setName("Cabin "+kk+"0"+jj+"2"); 433 434 cabins.add(cabin.getId()); 435 436 reservation.setAllCabins(cabins); 438 } 439 } 440 String fnames[] = new String [5]; 441 fnames[0]="John"; fnames[1]="Paul"; fnames[2]="Ringo"; 442 fnames[3]="Joe"; fnames[4]="Roger"; 443 444 String lnames[] = new String [3]; 445 lnames[0]="Smith"; lnames[1]="Johnson"; lnames[2]="Star"; 446 for (int kk=50; kk<=69; kk++) { 448 CustomerRemote customer = getCustomerHome().create(new Integer (kk)); 449 customer.setName( new Name(lnames[(kk-50)%3], fnames[(kk-50)%5]) ); 450 customer.addPhoneNumber("612-555-12"+kk,(byte)1); 451 customer.setAddress("10"+kk+" Elm Street", 452 cities[(kk-50)%6], 453 (kk%2==0?"MN":"CA"), 454 "5540"+(kk%5+1)); 455 customer.setHasGoodCredit((kk%4==0)); 456 457 if (kk%3!=0) { 459 Collection customers = new ArrayList (); 460 customers.add(customer.getId()); ReservationRemote reservation = getReservationHome().create((kk%3==1?cruiseA.getId():cruiseB.getId()), customers); 462 reservation.setDate(date.getTime()); 463 reservation.setAmountPaid(10*kk+2000); 464 date.add(Calendar.DAY_OF_MONTH, 7); 465 } 466 } 467 468 470 for (int kk=100; kk<=109; kk++) { 471 CustomerRemote customer = getCustomerHome().create(new Integer (kk)); 472 customer.setName( new Name("Lennon"+kk, "Paul") ); 473 customer.addPhoneNumber("666-543-12"+kk,(byte)1); 474 475 customer.setAddress("10"+kk+" Abbey Road", 476 cities[(kk-100)%6], 477 (kk%2==0?"FL":"WA"), 478 "5540"+(kk%5+1)); 479 customer.setHasGoodCredit((kk%4==0)); 480 } 481 482 } catch (Exception i) { 483 i.printStackTrace(System.out); 484 fail("InitialState creation problem: "+i); 485 } finally { 486 try { 487 utx.commit(); 488 } catch (Exception ii) { 489 } 490 } 491 } 492 } 493 494 495 496 497 public static Test suite() { 498 return new TestSuite(F_ConEnlist.class); 499 } 500 501 public static void main (String args[]) { 502 String testtorun = null; 503 for (int argn = 0; argn < args.length; argn++) { 505 String s_arg = args[argn]; 506 Integer i_arg; 507 if (s_arg.equals("-n")) { 508 testtorun = args[++argn]; 509 } 510 } 511 if (testtorun == null) { 512 junit.textui.TestRunner.run(suite()); 513 } else { 514 junit.textui.TestRunner.run(new F_ConEnlist(testtorun)); 515 } 516 } 517 } 518 519 | Popular Tags |