1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import java.util.Collection ; 29 import java.util.Enumeration ; 30 import java.util.Iterator ; 31 32 import javax.ejb.FinderException ; 33 34 35 import org.objectweb.jonas.jtests.beans.ebasic.Simple; 36 import org.objectweb.jonas.jtests.beans.ebasic.SimpleHome; 37 import org.objectweb.jonas.jtests.util.JTestCase; 38 39 42 public abstract class A_BasicHomeInterface extends JTestCase { 43 44 protected static SimpleHome home = null; 45 46 public A_BasicHomeInterface(String name) { 47 super(name); 48 } 49 50 55 protected void setUp() { 56 super.setUp(); 57 useBeans("ebasic", true); 58 } 59 60 63 abstract public SimpleHome getHome(); 64 65 71 public void testFindByPK() throws Exception { 72 getHome().findByPrimaryKey("pk1"); 73 } 74 75 82 public void testFindUnexistingPK() throws Exception { 83 try { 84 getHome().findByPrimaryKey("pk999"); 85 fail("findByPrimaryKey must throw ObjectNotFound Exception"); 86 } catch(FinderException e) { 87 } 88 } 89 90 96 public void testOtherFinder() throws Exception { 97 getHome().findByTestName("pk2"); 98 } 99 100 106 public void testFinderEnumObjNotFound() throws Exception { 107 Simple entity = null; 108 Enumeration listOfEntity = null; 109 110 listOfEntity = getHome().findInfoForNum(999); 111 if (listOfEntity.hasMoreElements()) 112 fail("findInfoForNum must return an empty enumeration"); 113 114 } 115 116 123 public void testCreateNewEntity() throws Exception { 124 getHome().create("pk100", 20, 6); 125 Simple entity2 = getHome().findByTestName("pk100"); 126 assertEquals(20, entity2.getInfo()); 127 entity2.remove(); 129 } 130 131 137 public void essaiC1() throws Exception { 138 getHome().create("pke1", 20, 6); 139 } 140 public void essaiA1() throws Exception { 141 getHome().findByPrimaryKey("pke1").getInfo(); 142 } 143 public void essaiA1C() throws Exception { 144 utx.begin(); 145 getHome().findByPrimaryKey("pke1").getInfo(); 146 utx.commit(); 147 } 148 public void essaiF1() throws Exception { 149 getHome().findByPrimaryKey("pke1"); 150 } 151 public void essaiR1() throws Exception { 152 getHome().remove("pke1"); 153 } 154 public void essaiR1C() throws Exception { 155 utx.begin(); 156 getHome().remove("pke1"); 157 utx.commit(); 158 } 159 public void essaiC2() throws Exception { 160 getHome().create("pke2", 20, 6); 161 } 162 public void essaiA2() throws Exception { 163 getHome().findByPrimaryKey("pke2").getInfo(); 164 } 165 public void essaiA2C() throws Exception { 166 utx.begin(); 167 getHome().findByPrimaryKey("pke2").getInfo(); 168 utx.commit(); 169 } 170 public void essaiF2() throws Exception { 171 getHome().findByTestName("pke2"); 172 } 173 public void essaiR2() throws Exception { 174 getHome().findByTestName("pke2").remove(); 175 } 176 public void essaiR2C() throws Exception { 177 utx.begin(); 178 getHome().findByTestName("pke2").remove(); 179 utx.commit(); 180 } 181 182 187 public void testCreateRolledBack() throws Exception { 188 utx.begin(); 189 try { 190 Simple entity1 = getHome().create("pk110", 30, 7); 191 } 192 catch (Exception e) { 193 fail(e.getMessage()); 194 } 195 finally { 196 utx.rollback(); 197 } 198 199 try { 200 getHome().findByTestName("pk110"); 201 fail("element should not be found"); 202 } catch(FinderException e) { 203 } 204 } 205 206 211 public void testCreateRolledBackPK() throws Exception { 212 utx.begin(); 213 try { 214 Simple entity1 = getHome().create("pk110", 30, 7); 215 } 216 catch (Exception e) { 217 fail(e.getMessage()); 218 } 219 finally { 220 utx.rollback(); 221 } 222 223 try { 224 getHome().findByPrimaryKey("pk110"); 225 fail("element should not be found"); 226 } catch(FinderException e) { 227 } 228 } 229 230 235 public void testRemoveViaEJBHome() throws Exception { 236 getHome().remove("pk4"); 237 try { 238 getHome().findByTestName("pk4"); 239 fail("not removed"); 240 } catch (FinderException e) { 241 } 242 getHome().create("pk4", 40, 8); 244 } 245 246 250 public void testRemoveByPKTwice() throws Exception { 251 getHome().create("pkn4", 40, 8); 252 getHome().remove("pkn4"); 253 getHome().create("pkn4", 40, 8); 254 getHome().remove("pkn4"); 255 } 256 257 261 public void testRemoveTwice() throws Exception { 262 Simple entity = getHome().create("pkn5", 50, 8); 263 entity.remove(); 264 entity = getHome().create("pkn5", 50, 8); 265 entity.remove(); 266 } 267 268 272 public void testRemoveViaEJBObject() throws Exception { 273 Simple entity = getHome().findByPrimaryKey("pk5"); 274 entity.remove(); 275 try { 276 getHome().findByPrimaryKey("pk5"); 277 fail("not removed"); 278 } catch (FinderException e) { 279 } 280 getHome().create("pk5", 50, 8); 282 } 283 284 289 public void testRemoveInsideTransaction() throws Exception { 290 Simple entity1 = getHome().findByPrimaryKey("pk4"); 291 utx.begin(); 292 try { 293 entity1.remove(); 294 } 295 catch (Exception e) { 296 fail(e.getMessage()); 297 } 298 finally { 299 utx.commit(); 300 } 301 utx.begin(); 302 try { 303 getHome().findByPrimaryKey("pk4"); 304 fail("should not exist anymore"); 305 } catch(FinderException e) { 306 } finally { 307 utx.rollback(); 308 } 309 getHome().create("pk4", 40, 8); 311 } 312 313 316 public void testRemoveInTransaction() throws Exception { 317 Simple entity1 = getHome().findByPrimaryKey("pk4"); 318 utx.begin(); 319 try { 320 entity1.remove(); 321 } 322 catch (Exception e) { 323 fail(e.getMessage()); 324 } 325 finally { 326 utx.commit(); 327 } 328 try { 329 getHome().findByPrimaryKey("pk4"); 330 fail("should not exist anymore"); 331 } catch(FinderException e) { 332 } 333 getHome().create("pk4", 40, 8); 335 } 336 337 340 public void testHomeRemoveCommitted() throws Exception { 341 utx.begin(); 342 try { 343 getHome().remove("pk4"); 344 } 345 catch (Exception e) { 346 fail(e.getMessage()); 347 } 348 finally { 349 utx.commit(); 350 } 351 try { 352 getHome().findByPrimaryKey("pk4"); 353 fail("should not exist anymore"); 354 } catch(FinderException e) { 355 } 356 getHome().create("pk4", 40, 8); 358 } 359 360 364 public void testRemoveRolledBack() throws Exception { 365 Simple entity1 = getHome().findByPrimaryKey("pk6"); 366 utx.begin(); 367 try { 368 entity1.remove(); 369 } 370 catch (Exception e) { 371 utx.rollback(); 372 fail(e.getMessage()); 373 } 374 try { 375 getHome().findByPrimaryKey("pk6"); 378 fail("should not exist anymore at this point"); 379 } catch(FinderException e) { 380 } finally { 381 utx.rollback(); 382 } 383 Simple entity3 = getHome().findByTestName("pk6"); 384 assertEquals(60, entity3.getInfo()); 385 } 386 387 392 public void testHomeRemoveRolledBack() throws Exception { 393 Simple entity1 = getHome().findByPrimaryKey("pk7"); 394 utx.begin(); 395 try { 396 getHome().remove("pk7"); 397 } 398 catch (Exception e) { 399 utx.rollback(); 400 fail(e.getMessage()); 401 } 402 try { 403 getHome().findByPrimaryKey("pk7"); 406 fail("should not exist anymore at this point"); 407 } catch(FinderException e) { 408 } finally { 409 utx.rollback(); 410 } 411 Simple entity3 = getHome().findByTestName("pk7"); 412 assertEquals(70, entity3.getInfo()); 413 } 414 415 420 public void testFinderEnum() throws Exception { 421 Simple entity = null; 422 Enumeration listOfEntity = getHome().findInfoForNum(4); 423 int nb = 0; 424 while (listOfEntity.hasMoreElements()) { 425 entity = (Simple)javax.rmi.PortableRemoteObject.narrow(listOfEntity.nextElement(), Simple.class); 426 assertEquals(10, entity.getInfo()); 427 nb++; 428 } 429 assertEquals(3, nb); 430 } 431 432 436 public void testCreateFindUserTx() throws Exception { 437 utx.begin(); 438 try { 439 Simple e1 = getHome().create("pk120", 32, 7); 440 Simple e2 = getHome().findByTestName("pk120"); 441 assertTrue(e2.isIdentical(e1)); 442 } 443 catch (Exception e) { 444 fail(e.getMessage()); 445 } finally { 446 utx.rollback(); 447 } 448 } 449 450 451 457 public void testFinderCollection() throws Exception { 458 Simple entity = null; 459 Collection cListEntity = getHome().findInCollection(); 460 int nb = 0; 461 Iterator icListEntity = cListEntity.iterator(); 462 while(icListEntity.hasNext()) { 463 entity = (Simple) javax.rmi.PortableRemoteObject.narrow(icListEntity.next(), Simple.class); 464 nb++; 465 } 466 assertEquals(4, nb); 467 } 468 469 472 public void testFindAfterRBR() throws Exception { 473 getHome().findByPrimaryKey("pk8"); 474 utx.begin(); 475 getHome().remove("pk8"); 476 utx.rollback(); 477 getHome().findByTestName("pk8"); 478 } 479 480 483 public void testLoopFindByPK() throws Exception { 484 for (int i = 0; i < 20; i++) { 485 getHome().findByPrimaryKey("pk9"); 486 } 487 } 488 489 492 public void testLoopFinder() throws Exception { 493 for (int i = 0; i < 20; i++) { 494 getHome().findByTestName("pk10"); 495 } 496 } 497 498 501 public void testLoopBackTx() throws Exception { 502 Simple s = getHome().findByPrimaryKey("pk9"); 503 assertTrue(s.loopBackTx()); 504 } 505 506 510 public void testAccessTwiceTx() throws Exception { 511 Simple s = getHome().findByPrimaryKey("pk9"); 512 utx.begin(); 513 try { 514 s.getNumTest(); 515 s.getNumTest(); 516 } finally { 517 utx.commit(); 518 } 519 } 520 521 525 public void testFindAccessTx() throws Exception { 526 utx.begin(); 527 try { 528 Simple s = getHome().findByPrimaryKey("pk9"); 529 s.getNumTest(); 530 } finally { 531 utx.commit(); 532 } 533 } 534 535 538 public void testLoopBack() throws Exception { 539 Simple s = getHome().findByPrimaryKey("pk10"); 540 assertTrue(s.loopBack()); 541 } 542 } 543 | Popular Tags |