001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: A_oob.java 7671 2005-11-16 09:31:11Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.entity;
027:
028: import javax.ejb.ObjectNotFoundException;
029:
030: import org.objectweb.jonas.jtests.beans.relation.oob.AHomeRemote;
031: import org.objectweb.jonas.jtests.beans.relation.oob.ARemote;
032: import org.objectweb.jonas.jtests.beans.relation.oob.BHomeRemote;
033: import org.objectweb.jonas.jtests.beans.relation.oob.BRemote;
034:
035: /**
036: * This is an advanced test suite for home interface on entity bean CMP2.
037: * Beans used: oob
038: * @author Ph. Durieux
039: */
040: public abstract class A_oob extends A_Cmp2Util {
041:
042: public abstract AHomeRemote getAHome();
043:
044: public abstract BHomeRemote getBHome();
045:
046: public A_oob(String name) {
047: super (name);
048: }
049:
050: protected boolean isInit = false;
051:
052: protected void setUp() {
053: super .setUp();
054: boolean ok = false;
055: int nbtry = 0;
056: while (!ok && nbtry < 3) {
057: if (!isInit) {
058: // load bean if not loaded yet
059: useBeans("oob", false);
060: // check if tables have been initialized
061: try {
062: debug("find a2");
063: getAHome().findByPrimaryKey("a2");
064: } catch (Exception e) {
065: // Make the initialization needed for the tests
066: try {
067: utx.begin();
068: debug("Make initialization");
069: ARemote a1 = getAHome().create("a1");
070: ARemote a2 = getAHome().create("a2");
071: getAHome().create("a3");
072: getBHome().create("b1");
073: getBHome().create("b2");
074: getBHome().create("b3");
075: a1.assignB("b1");
076: a2.assignB("b2");
077: } catch (Exception i) {
078: fail("InitialState creation problem: " + i);
079: } finally {
080: try {
081: utx.commit();
082: } catch (Exception ii) {
083: }
084: }
085: }
086: isInit = true;
087: }
088: // Check that all is OK. Sometimes, a test has failed and has corrupted
089: // the bean state in the database. We must unload and reload the bean then.
090: nbtry++;
091: try {
092: if (initStateOK()) {
093: ok = true;
094: }
095: } catch (Exception e) {
096: }
097: if (!ok) {
098: debug("Unload oob");
099: isInit = false;
100: unloadBeans("oob");
101: }
102: }
103: }
104:
105: /*
106: * Check that we are in the same state as after the tables creation for thoses beans A and B
107: * (ie if it is the initial state)
108: */
109: boolean initStateOK() throws Exception {
110: boolean isOk = true;
111:
112: msgerror = new StringBuffer();
113:
114: debug("Checking init state");
115: ARemote a1 = getAHome().findByPrimaryKey("a1");
116: BRemote b1 = getBHome().findByPrimaryKey("b1");
117: ARemote a2 = getAHome().findByPrimaryKey("a2");
118: BRemote b2 = getBHome().findByPrimaryKey("b2");
119: ARemote a3 = getAHome().findByPrimaryKey("a3");
120: BRemote b3 = getBHome().findByPrimaryKey("b3");
121: String idB1 = a1.retrieveB();
122: String idB2 = a2.retrieveB();
123: String idB3 = a3.retrieveB();
124: String idA1 = b1.retrieveA();
125: String idA2 = b2.retrieveA();
126: String idA3 = b3.retrieveA();
127:
128: if (idB1 != null && !idB1.equals("b1")) {
129: isOk = false;
130: msgerror.append("\nWrong relation for a1->b1"
131: + "(expected: A1.retrieveB()='b1'" + ", found:"
132: + idB1 + ")");
133: }
134: if (idB2 != null && !idB2.equals("b2")) {
135: isOk = false;
136: msgerror.append("\nWrong relation for a2->b2"
137: + "(expected: A2.retrieveB()='b2'" + ", found:"
138: + idB2 + ")");
139: }
140: if (idA1 != null && !idA1.equals("a1")) {
141: isOk = false;
142: msgerror.append("\nWrong relation for b1->a1"
143: + "(expected: B1.retrieveA()='a1'" + ", found:"
144: + idA1 + ")");
145: }
146: if (idA2 != null && !idA2.equals("a2")) {
147: isOk = false;
148: msgerror.append("\nWrong relation for b2->a2"
149: + "(expected: B2.retrieveA()='a2'" + ", found:"
150: + idA2 + ")");
151: }
152: if (idA3 != null) {
153: isOk = false;
154: msgerror.append("\nWrong relation for a3->b3"
155: + "(expected: A3.retrieveB()=null" + ", found:"
156: + idA3 + ")");
157: }
158: if (idB3 != null) {
159: isOk = false;
160: msgerror.append("\nWrong relation for b3->a3"
161: + "(expected: B3.retrieveA()=null" + ", found:"
162: + idB3 + ")");
163: }
164: if (!isOk) {
165: debug(msgerror.toString());
166: }
167: return isOk;
168: }
169:
170: /**
171: * Check that the bean 'a3' has no relation.
172: */
173: public void _testBasicGetEmpty(int tx) throws Exception {
174: String idB = null;
175: if ((tx == TX_CALL) || (tx == TX_RB)) {
176: utx.begin();
177: }
178: ARemote a = getAHome().findByPrimaryKey("a3");
179: if (tx == TX_CONT) {
180: idB = a.retrieveBInNewTx();
181: } else {
182: idB = a.retrieveB();
183: }
184: if (tx == TX_CALL) {
185: utx.commit();
186: } else if (tx == TX_RB) {
187: utx.rollback();
188: }
189: // checking
190: if (idB != null) {
191: fail("a3->b not empty");
192: }
193: }
194:
195: public void testBasicGetEmptyTxNo() throws Exception {
196: _testBasicGetEmpty(TX_NO);
197: }
198:
199: public void testBasicGetEmptyTxCall() throws Exception {
200: _testBasicGetEmpty(TX_CALL);
201: }
202:
203: public void testBasicGetEmptyTxCont() throws Exception {
204: _testBasicGetEmpty(TX_CONT);
205: }
206:
207: /**
208: * Set a relation : a3.assignB("b3")
209: */
210: public void _testBasicSetEmpty(int tx) throws Exception {
211: if ((tx == TX_CALL) || (tx == TX_RB)) {
212: utx.begin();
213: }
214: ARemote a = getAHome().findByPrimaryKey("a3");
215: if (tx == TX_CONT) {
216: a.assignBInNewTx("b3");
217: } else {
218: a.assignB("b3");
219: }
220: if (tx == TX_CALL) {
221: utx.commit();
222: } else if (tx == TX_RB) {
223: utx.rollback();
224: }
225: // checking
226: String idB = a.retrieveBInNewTx();
227: if (tx != TX_RB) {
228: assertEquals("Wrong assign for relation a3->b3 : ", "b3",
229: idB);
230: // undo
231: a.assignBInNewTx(null);
232: } else {
233: assertNull("Rollback did not occur", idB);
234: }
235: checkIsInitialState();
236: }
237:
238: public void testBasicSetEmptyTxNo() throws Exception {
239: _testBasicSetEmpty(TX_NO);
240: }
241:
242: public void testBasicSetEmptyTxCall() throws Exception {
243: _testBasicSetEmpty(TX_CALL);
244: }
245:
246: public void testBasicSetEmptyTxCont() throws Exception {
247: _testBasicSetEmpty(TX_CONT);
248: }
249:
250: public void testBasicSetEmptyTxRb() throws Exception {
251: _testBasicSetEmpty(TX_RB);
252: }
253:
254: /**
255: * Set a relation to empty : a3.assignB(null)
256: */
257: public void _testBasicSetEmptyNull(int tx) throws Exception {
258: if ((tx == TX_CALL) || (tx == TX_RB)) {
259: utx.begin();
260: }
261: ARemote a = getAHome().findByPrimaryKey("a1");
262: if (tx == TX_CONT) {
263: a.assignBInNewTx(null);
264: } else {
265: a.assignB(null);
266: }
267: if (tx == TX_CALL) {
268: utx.commit();
269: } else if (tx == TX_RB) {
270: utx.rollback();
271: }
272: // checking
273: String idB = a.retrieveBInNewTx();
274: if (tx == TX_RB) {
275: assertEquals("Wrong assign null for relation a1->b1: ",
276: "b1", idB);
277: } else {
278: assertNull("Wrong assign null for relation a1->b1: " + idB,
279: idB);
280: // undo
281: a.assignBInNewTx("b1");
282: }
283: checkIsInitialState();
284: }
285:
286: public void testBasicSetEmptyNullTxNo() throws Exception {
287: _testBasicSetEmptyNull(TX_NO);
288: }
289:
290: public void testBasicSetEmptyNullTxCall() throws Exception {
291: _testBasicSetEmptyNull(TX_CALL);
292: }
293:
294: public void testBasicSetEmptyNullTxCont() throws Exception {
295: _testBasicSetEmptyNull(TX_CONT);
296: }
297:
298: public void testBasicSetEmptyNullTxRb() throws Exception {
299: _testBasicSetEmptyNull(TX_RB);
300: }
301:
302: /**
303: * test coherence relation one to one bidirectionnel,
304: * A1.assignB(B2) => A1.retreiveB()=B2 && B2.retreiveA()=A1 && B1.retreiveA()=null && A2.retreiveB()=null
305: */
306: public void _testCohSetOne(int tx) throws Exception {
307: if ((tx == TX_CALL) || (tx == TX_RB)) {
308: utx.begin();
309: }
310: ARemote a1 = getAHome().findByPrimaryKey("a1");
311: BRemote b1 = getBHome().findByPrimaryKey("b1");
312: ARemote a2 = getAHome().findByPrimaryKey("a2");
313: BRemote b2 = getBHome().findByPrimaryKey("b2");
314: ARemote a3 = getAHome().findByPrimaryKey("a3");
315: BRemote b3 = getBHome().findByPrimaryKey("b3");
316: // change the relation
317: if (tx == TX_CONT) {
318: a1.assignBInNewTx("b2");
319: } else {
320: a1.assignB("b2");
321: }
322: if (tx == TX_CALL) {
323: utx.commit();
324: } else if (tx == TX_RB) {
325: utx.rollback();
326: }
327: if (tx != TX_RB) {
328: // Verify expected result
329: utx.begin();
330: try {
331: assertNull(
332: "Bad coherence of relation null : expected for a2.retreiveB() found :"
333: + a2.retrieveB(), a2.retrieveB());
334: assertNull(
335: "Bad coherence of relation null : expected for b1.retreiveA() found :"
336: + b1.retrieveA(), b1.retrieveA());
337: assertEquals(
338: "Bad coherence of relation a1 : expected for b2.retreiveA() found :"
339: + b2.retrieveA(), "a1", b2.retrieveA());
340: assertEquals(
341: "Bad coherence of relation b2 : expected for a1.retreiveB() found :"
342: + a1.retrieveB(), "b2", a1.retrieveB());
343:
344: // undo
345: a1.assignB("b1");
346: a2.assignB("b2");
347: } finally {
348: utx.commit();
349: }
350: }
351: checkIsInitialState();
352: }
353:
354: public void testCohSetOneTxNo() throws Exception {
355: _testCohSetOne(TX_NO);
356: }
357:
358: public void testCohSetOneTxCall() throws Exception {
359: _testCohSetOne(TX_CALL);
360: }
361:
362: /**
363: * test coherence relation one to one bidirectionnel,
364: * A3.assignB(B3)=>A3.retreiveB()==B3 && B3.retreiveB()==A3
365: */
366: public void _testCohWithoutRelation(int tx) throws Exception {
367: if ((tx == TX_CALL) || (tx == TX_RB)) {
368: utx.begin();
369: }
370: ARemote a3 = getAHome().findByPrimaryKey("a3");
371: BRemote b3 = getBHome().findByPrimaryKey("b3");
372: // change the relation
373: if (tx == TX_CONT) {
374: a3.assignBInNewTx("b3");
375: } else {
376: a3.assignB("b3");
377: }
378: if (tx == TX_CALL) {
379: utx.commit();
380: } else if (tx == TX_RB) {
381: utx.rollback();
382: }
383: if (tx != TX_RB) {
384: // Verify expected result
385: utx.begin();
386: try {
387: assertEquals("Bad coherence of relation : b3 expected:"
388: + a3.retrieveB(), "b3", a3.retrieveB());
389: assertEquals("Bad coherence of relation : a3 expected:"
390: + b3.retrieveA(), "a3", b3.retrieveA());
391:
392: // undo
393: a3.assignB(null);
394: } finally {
395: utx.commit();
396: }
397: }
398: checkIsInitialState();
399: }
400:
401: public void testBasicCohWithoutRelation() throws Exception {
402: _testCohWithoutRelation(TX_NO);
403: }
404:
405: public void testBasicCohWithoutRelationTxCall() throws Exception {
406: _testCohWithoutRelation(TX_CALL);
407: }
408:
409: /**
410: * test coherence relation one to one bidirectionnel,
411: * A1.assignB(B3)=>A1.retreiveB()==B3 && B1.retreiveB()==null && B2.retreiveB()=null
412: */
413: public void _testCohAlreadyAssign(int tx) throws Exception {
414: if ((tx == TX_CALL) || (tx == TX_RB)) {
415: utx.begin();
416: }
417: ARemote a1 = getAHome().findByPrimaryKey("a1");
418: BRemote b1 = getBHome().findByPrimaryKey("b1");
419: BRemote b3 = getBHome().findByPrimaryKey("b3");
420: // change the relation
421: if (tx == TX_CONT) {
422: a1.assignBInNewTx("b3");
423: } else {
424: a1.assignB("b3");
425: }
426: if (tx == TX_CALL) {
427: utx.commit();
428: } else if (tx == TX_RB) {
429: utx.rollback();
430: }
431: if (tx != TX_RB) {
432: // Verify expected result
433: utx.begin();
434: try {
435: assertEquals("Bad coherence of relation : b3 expected:"
436: + a1.retrieveB(), "b3", a1.retrieveB());
437: assertNull("Bad coherence of relation : null expected:"
438: + b1.retrieveA(), b1.retrieveA());
439: assertEquals("Bad coherence of relation : a1 expected:"
440: + b3.retrieveA(), "a1", b3.retrieveA());
441:
442: // undo
443: a1.assignB("b1");
444: } finally {
445: utx.commit();
446: }
447: }
448: checkIsInitialState();
449: }
450:
451: public void testCohAlreadyAssign() throws Exception {
452: _testCohAlreadyAssign(TX_NO);
453: }
454:
455: public void testCohAlreadyAssignTxCall() throws Exception {
456: _testCohAlreadyAssign(TX_CALL);
457: }
458:
459: /**
460: * test coherence relation one to one bidirectionnel,
461: * A1.assignB(null)=>A1.retreiveB()==null && B1.retreiveB()==null
462: */
463: public void _testCohSetNull(int tx) throws Exception {
464: if ((tx == TX_CALL) || (tx == TX_RB)) {
465: utx.begin();
466: }
467: ARemote a1 = getAHome().findByPrimaryKey("a1");
468: BRemote b1 = getBHome().findByPrimaryKey("b1");
469: ARemote a2 = getAHome().findByPrimaryKey("a2");
470: BRemote b2 = getBHome().findByPrimaryKey("b2");
471: ARemote a3 = getAHome().findByPrimaryKey("a3");
472: BRemote b3 = getBHome().findByPrimaryKey("b3");
473: // change the relation
474: if (tx == TX_CONT) {
475: a1.assignBInNewTx(null);
476: } else {
477: a1.assignB(null);
478: }
479: if (tx == TX_CALL) {
480: utx.commit();
481: } else if (tx == TX_RB) {
482: utx.rollback();
483: }
484: if (tx != TX_RB) {
485: try {
486: utx.begin();
487: // Verify expected result
488: assertNull(
489: "Bad coherence of relation : null expected for a1.retreiveB() found :"
490: + a1.retrieveB(), a1.retrieveB());
491: assertNull(
492: "Bad coherence of relation : null expected for b1.retreiveA() found :"
493: + b1.retrieveA(), b1.retrieveA());
494:
495: // undo
496: a1.assignB("b1");
497: } finally {
498: utx.commit();
499: }
500: }
501: checkIsInitialState();
502: }
503:
504: public void testCohSetNull() throws Exception {
505: _testCohSetNull(TX_NO);
506: }
507:
508: public void testCohSetNullTxCall() throws Exception {
509: _testCohSetNull(TX_CALL);
510: }
511:
512: /**
513: * test coherence relation one to one bidirectionnel,
514: * A1.remove=>A1removed && B1.retreiveA()==null
515: */
516: public void _testCohRemoveA(int tx) throws Exception {
517: if (tx == TX_CONT) {
518: // The transaction attribute of the remove method is TX_SUPPORT,
519: // so the transaction cannot be initiate by the container
520: fail("Transaction cannot be initiate by the container for this test");
521: }
522: if ((tx == TX_CALL) || (tx == TX_RB)) {
523: utx.begin();
524: }
525: BRemote b1 = getBHome().findByPrimaryKey("b1");
526: // remove the bean
527: getAHome().remove("a1");
528: if (tx == TX_CALL) {
529: utx.commit();
530: } else if (tx == TX_RB) {
531: utx.rollback();
532: }
533: if (tx != TX_RB) {
534: // Verify expected result
535: assertNull(
536: "Bad coherence of relation : null expected for b1.retreiveB() found :"
537: + b1.retrieveAInNewTx(), b1
538: .retrieveAInNewTx());
539: boolean not_found = false;
540: try {
541: ARemote a1 = getAHome().findByPrimaryKey("a1");
542: } catch (ObjectNotFoundException e) {
543: not_found = true;
544: }
545: assertTrue("a1 is not removed", not_found);
546: // undo
547: getAHome().create("a1");
548: ARemote a1 = getAHome().findByPrimaryKey("a1");
549: a1.assignBInNewTx("b1");
550: }
551: checkIsInitialState();
552: }
553:
554: public void testCohRemoveATxNo() throws Exception {
555: _testCohRemoveA(TX_NO);
556: }
557:
558: public void testCohRemoveATxCall() throws Exception {
559: _testCohRemoveA(TX_CALL);
560: }
561:
562: public void testCohRemoveATxRb() throws Exception {
563: _testCohRemoveA(TX_RB);
564: }
565:
566: /**
567: * test coherence relation one to one bidirectionnel,
568: * getAHome().remove(a1)=>A1removed && B1.retreiveA()==null
569: * Same as _testCohRemoveA except that the called remove method is on the bean
570: * instead of the home.
571: */
572: public void _testCohBeanRemoveA(int tx) throws Exception {
573: if (tx == TX_CONT) {
574: // The transaction attribute of the remove method is TX_SUPPORT,
575: // so the transaction cannot be initiate by the container
576: fail("Transaction cannot be initiate by the container for this test");
577: }
578:
579: if ((tx == TX_CALL) || (tx == TX_RB)) {
580: utx.begin();
581: }
582: ARemote a1 = getAHome().findByPrimaryKey("a1");
583: BRemote b1 = getBHome().findByPrimaryKey("b1");
584: a1.remove();
585: if (tx == TX_CALL) {
586: utx.commit();
587: } else if (tx == TX_RB) {
588: utx.rollback();
589: }
590: if (tx != TX_RB) {
591: // Verify expected result
592: assertNull(
593: "Bad coherence of relation : null expected for b1.retreiveB() found :"
594: + b1.retrieveAInNewTx(), b1
595: .retrieveAInNewTx());
596: boolean not_found = false;
597: try {
598: a1 = getAHome().findByPrimaryKey("a1");
599: } catch (ObjectNotFoundException e) {
600: not_found = true;
601: }
602: assertTrue("a1 is not removed", not_found);
603: // undo
604: getAHome().create("a1");
605: a1 = getAHome().findByPrimaryKey("a1");
606: a1.assignBInNewTx("b1");
607: }
608: checkIsInitialState();
609: }
610:
611: public void testCohBeanRemoveATxNo() throws Exception {
612: _testCohBeanRemoveA(TX_NO);
613: }
614:
615: public void testCohBeanRemoveATxCall() throws Exception {
616: _testCohBeanRemoveA(TX_CALL);
617: }
618:
619: public void testCohBeanRemoveATxRb() throws Exception {
620: _testCohBeanRemoveA(TX_RB);
621: }
622:
623: /**
624: * test coherence relation one to one bidirectionnel,
625: * getBHome().remove(b1)=>B1 removed && A1.retreiveB()==null
626: */
627: public void _testCohRemoveB(int tx) throws Exception {
628: if (tx == TX_CONT) {
629: // The transaction attribute of the remove method is TX_SUPPORT,
630: // so the transaction cannot be initiate by the container
631: fail("Transaction cannot be initiate by the container for this test");
632: }
633:
634: if ((tx == TX_CALL) || (tx == TX_RB)) {
635: utx.begin();
636: }
637: ARemote a1 = getAHome().findByPrimaryKey("a1");
638: BRemote b1 = getBHome().findByPrimaryKey("b1");
639: ARemote a2 = getAHome().findByPrimaryKey("a2");
640: BRemote b2 = getBHome().findByPrimaryKey("b2");
641: ARemote a3 = getAHome().findByPrimaryKey("a3");
642: BRemote b3 = getBHome().findByPrimaryKey("b3");
643: // remove the bean
644: getBHome().remove("b1");
645: if (tx == TX_CALL) {
646: utx.commit();
647: } else if (tx == TX_RB) {
648: utx.rollback();
649: }
650: if (tx != TX_RB) {
651: // Verify expected result
652: assertNull(
653: "Bad coherence of relation : null expected for a1.retreiveB() found :"
654: + a1.retrieveBInNewTx(), a1
655: .retrieveBInNewTx());
656: boolean not_found = false;
657: try {
658: b1 = getBHome().findByPrimaryKey("b1");
659: } catch (ObjectNotFoundException e) {
660: not_found = true;
661: }
662: assertTrue("B is not removed", not_found);
663: // undo
664: getBHome().create("b1");
665: a1.assignBInNewTx("b1");
666: }
667: checkIsInitialState();
668: }
669:
670: public void testCohRemoveBTxNo() throws Exception {
671: _testCohRemoveB(TX_NO);
672: }
673:
674: public void testCohRemoveBTxCall() throws Exception {
675: _testCohRemoveB(TX_CALL);
676: }
677:
678: public void testCohRemoveBTxRb() throws Exception {
679: _testCohRemoveB(TX_RB);
680: }
681:
682: /**
683: * test coherence relation one to one bidirectionnel,
684: * B1.remove=>B1 removed && A1.retreiveB()==null
685: * Same as _testCohRemoveB except that the called remove method is on the bean
686: * instead of the home.
687: */
688: public void _testCohBeanRemoveB(int tx) throws Exception {
689: if (tx == TX_CONT) {
690: // The transaction attribute of the remove method is TX_SUPPORT,
691: // so the transaction cannot be initiate by the container
692: fail("Transaction cannot be initiate by the container for this test");
693: }
694:
695: if ((tx == TX_CALL) || (tx == TX_RB)) {
696: utx.begin();
697: }
698: ARemote a1 = getAHome().findByPrimaryKey("a1");
699: BRemote b1 = getBHome().findByPrimaryKey("b1");
700: ARemote a2 = getAHome().findByPrimaryKey("a2");
701: BRemote b2 = getBHome().findByPrimaryKey("b2");
702: ARemote a3 = getAHome().findByPrimaryKey("a3");
703: BRemote b3 = getBHome().findByPrimaryKey("b3");
704: // change the relation
705: b1.remove();
706: if (tx == TX_CALL) {
707: utx.commit();
708: } else if (tx == TX_RB) {
709: utx.rollback();
710: }
711: if (tx != TX_RB) {
712: // Verify expected result
713: assertNull(
714: "Bad coherence of relation : null expected for a1.retreiveB() found :"
715: + a1.retrieveBInNewTx(), a1
716: .retrieveBInNewTx());
717: boolean not_found = false;
718: try {
719: b1 = getBHome().findByPrimaryKey("b1");
720: } catch (ObjectNotFoundException e) {
721: not_found = true;
722: }
723: assertTrue("B is not removed", not_found);
724: // undo
725: getBHome().create("b1");
726: a1.assignBInNewTx("b1");
727: }
728: checkIsInitialState();
729: }
730:
731: public void testCohBeanRemoveBTxNo() throws Exception {
732: _testCohBeanRemoveB(TX_NO);
733: }
734:
735: public void testCohBeanRemoveBTxCall() throws Exception {
736: _testCohBeanRemoveB(TX_CALL);
737: }
738:
739: public void testCohBeanRemoveBTxRb() throws Exception {
740: _testCohBeanRemoveB(TX_RB);
741: }
742:
743: /**
744: * Combination of 2 tests that fails :
745: * _testCohAlreadyAssign(TX_CALL) + _testCohRemoveA(TX_RB)
746: */
747: public void testMultiA1() throws Exception {
748: ARemote a1 = getAHome().findByPrimaryKey("a1");
749: BRemote b1 = getBHome().findByPrimaryKey("b1");
750: BRemote b3 = getBHome().findByPrimaryKey("b3");
751: utx.begin();
752: a1.assignB("b3");
753: utx.commit();
754: a1.assignB("b1");
755: utx.begin();
756: getAHome().remove("a1");
757: utx.rollback();
758: String idB1 = a1.retrieveB();
759: assertEquals("a1.b", "b1", idB1);
760: checkIsInitialState();
761: }
762:
763: public void testMultiA2() throws Exception {
764: ARemote a1 = getAHome().findByPrimaryKey("a1");
765: BRemote b1 = getBHome().findByPrimaryKey("b1");
766: BRemote b3 = getBHome().findByPrimaryKey("b3");
767: utx.begin();
768: a1.assignB("b3");
769: utx.commit();
770: a1.assignB("b1");
771: utx.begin();
772: String idB1 = a1.retrieveB();
773: utx.commit();
774: assertEquals("a1.b", "b1", idB1);
775: checkIsInitialState();
776: }
777:
778: public void testMultiA3() throws Exception {
779: ARemote a1 = getAHome().findByPrimaryKey("a1");
780: BRemote b1 = getBHome().findByPrimaryKey("b1");
781: BRemote b3 = getBHome().findByPrimaryKey("b3");
782: utx.begin();
783: a1.assignB("b3");
784: utx.commit();
785: a1.assignB("b1");
786: utx.begin();
787: String idA1 = b1.retrieveA();
788: utx.commit();
789: assertEquals("b1.a", "a1", idA1);
790: checkIsInitialState();
791: }
792:
793: public void testMultiA4() throws Exception {
794: ARemote a1 = getAHome().findByPrimaryKey("a1");
795: BRemote b1 = getBHome().findByPrimaryKey("b1");
796: BRemote b3 = getBHome().findByPrimaryKey("b3");
797: utx.begin();
798: a1.assignB("b3");
799: utx.commit();
800: a1.assignB("b1");
801: utx.begin();
802: getBHome().remove("b1");
803: utx.rollback();
804: String idB1 = a1.retrieveB();
805: assertEquals("a1.b", "b1", idB1);
806: checkIsInitialState();
807: }
808:
809: public void testMultiA5() throws Exception {
810: ARemote a1 = getAHome().findByPrimaryKey("a1");
811: BRemote b1 = getBHome().findByPrimaryKey("b1");
812: BRemote b3 = getBHome().findByPrimaryKey("b3");
813: utx.begin();
814: a1.assignB("b3");
815: utx.commit();
816: a1.assignB("b1");
817: utx.begin();
818: getBHome().remove("b3");
819: utx.rollback();
820: String idB1 = a1.retrieveB();
821: assertEquals("a1.b", "b1", idB1);
822: checkIsInitialState();
823: }
824:
825: public void testRollback() throws Exception {
826: ARemote a = getAHome().findByPrimaryKey("a1");
827: BRemote b = getBHome().findByPrimaryKey("b1");
828: String orig = a.retrieveB();
829:
830: // disassociate and commit
831: utx.begin();
832: a.assignB(null);
833: utx.commit();
834: assertEquals(null, a.retrieveB());
835:
836: // revert to original state outside of a user transaction
837: a.assignB(orig);
838:
839: // retrieveB inside a transaction
840: utx.begin();
841: assertEquals(orig, a.retrieveB());
842: utx.rollback();
843:
844: // verify that retrieveB returns correct value after rollback
845: try {
846: assertEquals("a1", b.retrieveA());
847: assertEquals(orig, a.retrieveB());
848: } finally {
849: // force sync to cleanup
850: sync(true);
851: }
852: checkIsInitialState();
853: }
854: }
|