KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > entity > F_Relation_oobEC2


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_Relation_oobEC2.java,v 1.19 2003/06/10 08:30:11 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import javax.ejb.ObjectNotFoundException JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33 import org.objectweb.jonas.jtests.beans.relation.oob.ARemote;
34 import org.objectweb.jonas.jtests.beans.relation.oob.AHomeRemote;
35 import org.objectweb.jonas.jtests.beans.relation.oob.BRemote;
36 import org.objectweb.jonas.jtests.beans.relation.oob.BHomeRemote;
37
38 /**
39  * This is an advanced test suite for home interface on entity bean CMP2.
40  * Beans used: oob
41  */

42 public class F_Relation_oobEC2 extends A_Cmp2Util {
43
44     private static String JavaDoc BEAN_HOME_A = "relation_oob_AHome";
45     private static String JavaDoc BEAN_HOME_B = "relation_oob_BHome";
46     protected static AHomeRemote ahome = null;
47     protected static BHomeRemote bhome = null;
48
49    
50     public F_Relation_oobEC2(String JavaDoc name) {
51         super(name);
52     }
53
54     protected static boolean isInit = false;
55
56     protected void setUp() {
57         super.setUp();
58         boolean ok = false;
59         int nbtry = 0;
60         while (!ok && nbtry < 3) {
61             if (!isInit) {
62                 // load bean if not loaded yet
63
useBeans("oob", false);
64                 // lookup home used in the tests
65
try {
66                     ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A),
67                                                                       AHomeRemote.class);
68                     bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B),
69                                                                       BHomeRemote.class);
70                 } catch (NamingException JavaDoc e) {
71                     fail("Cannot get bean home: " + e.getMessage());
72                 }
73                 // check if tables have been initialized
74
try {
75                     ahome.findByPrimaryKey("a2");
76                 } catch (Exception JavaDoc e) {
77                     // Make the initialization needed for the tests
78
try {
79                         utx.begin();
80                         ARemote a1 = ahome.create("a1");
81                         ARemote a2 = ahome.create("a2");
82                         ahome.create("a3");
83                         bhome.create("b1");
84                         bhome.create("b2");
85                         bhome.create("b3");
86                         a1.assignB("b1");
87                         a2.assignB("b2");
88                     } catch (Exception JavaDoc i) {
89                         fail("InitialState creation problem: " + i);
90                     } finally {
91                         try {
92                             utx.commit();
93                         } catch (Exception JavaDoc ii) {
94                         }
95                     }
96                 }
97                 isInit = true;
98             }
99             // Check that all is OK. Sometimes, a test has failed and has corrupted
100
// the bean state in the database. We must unload and reload the bean then.
101
nbtry++;
102             try {
103                 if (initStateOK()) {
104                     ok = true;
105                 }
106             } catch (Exception JavaDoc e) {
107             }
108             if (!ok) {
109                 isInit = false;
110                 unloadBeans("oob");
111             }
112         }
113     }
114
115     /*
116      * Check that we are in the same state as after the tables creation for thoses beans A and B
117      * (ie if it is the initial state)
118      */

119     boolean initStateOK() throws Exception JavaDoc {
120         boolean isOk = true;
121
122         msgerror = new StringBuffer JavaDoc();
123
124         ARemote a1 = ahome.findByPrimaryKey("a1");
125         BRemote b1 = bhome.findByPrimaryKey("b1");
126         ARemote a2 = ahome.findByPrimaryKey("a2");
127         BRemote b2 = bhome.findByPrimaryKey("b2");
128         ARemote a3 = ahome.findByPrimaryKey("a3");
129         BRemote b3 = bhome.findByPrimaryKey("b3");
130         String JavaDoc idB1 = a1.retrieveB();
131         String JavaDoc idB2 = a2.retrieveB();
132         String JavaDoc idB3 = a3.retrieveB();
133         String JavaDoc idA1 = b1.retrieveA();
134         String JavaDoc idA2 = b2.retrieveA();
135         String JavaDoc idA3 = b3.retrieveA();
136
137         if (idB1 != null && !idB1.equals("b1")) {
138             isOk = false;
139             msgerror.append("\nWrong relation for a1->b1"
140                             + "(expected: A1.retrieveB()='b1'"
141                             + ", found:" + idB1 + ")");
142         }
143         if (idB2 != null && !idB2.equals("b2")) {
144             isOk = false;
145             msgerror.append("\nWrong relation for a2->b2"
146                             + "(expected: A2.retrieveB()='b2'"
147                             + ", found:" + idB2 + ")");
148         }
149         if (idA1 != null && !idA1.equals("a1")) {
150             isOk = false;
151             msgerror.append("\nWrong relation for b1->a1"
152                             + "(expected: B1.retrieveA()='a1'"
153                             + ", found:" + idA1 + ")");
154         }
155         if (idA2 != null && !idA2.equals("a2")) {
156             isOk = false;
157             msgerror.append("\nWrong relation for b2->a2"
158                             + "(expected: B2.retrieveA()='a2'"
159                             + ", found:" + idA2 + ")");
160         }
161         if (idA3 != null) {
162             isOk = false;
163             msgerror.append("\nWrong relation for a3->b3"
164                             + "(expected: A3.retrieveB()=null"
165                             + ", found:" + idA3 + ")");
166         }
167         if (idB3 != null) {
168             isOk = false;
169             msgerror.append("\nWrong relation for b3->a3"
170                             + "(expected: B3.retrieveA()=null"
171                             + ", found:" + idB3 + ")");
172         }
173         return isOk;
174     }
175
176
177     /**
178      * Check that the bean 'a3' has no relation.
179      */

180     public void _testBasicGetEmpty(int tx) throws Exception JavaDoc {
181         String JavaDoc idB = null;
182         if ((tx == TX_CALL) || (tx == TX_RB)) {
183             utx.begin();
184         }
185         ARemote a = ahome.findByPrimaryKey("a3");
186         if (tx == TX_CONT) {
187             idB = a.retrieveBInNewTx();
188         } else {
189             idB = a.retrieveB();
190         }
191         if (tx == TX_CALL) {
192             utx.commit();
193         } else if (tx == TX_RB) {
194             utx.rollback();
195         }
196         checkIsInitialState();
197     }
198
199     public void testBasicGetEmptyTxNo() throws Exception JavaDoc {
200         _testBasicGetEmpty(TX_NO);
201     }
202     public void testBasicGetEmptyTxCall() throws Exception JavaDoc {
203         _testBasicGetEmpty(TX_CALL);
204     }
205     public void testBasicGetEmptyTxCont() throws Exception JavaDoc {
206         _testBasicGetEmpty(TX_CONT);
207     }
208
209     /**
210      * Set a relation to empty : a3.assignB("b3")
211      */

212     public void _testBasicSetEmpty(int tx) throws Exception JavaDoc {
213         if ((tx == TX_CALL) || (tx == TX_RB)) {
214             utx.begin();
215         }
216         ARemote a = ahome.findByPrimaryKey("a3");
217         if (tx == TX_CONT) {
218             a.assignBInNewTx("b3");
219         } else {
220             a.assignB("b3");
221         }
222         if (tx == TX_CALL) {
223             utx.commit();
224         } else if (tx == TX_RB) {
225             utx.rollback();
226         }
227         // checking
228
String JavaDoc idB = a.retrieveB();
229         if (tx != TX_RB) {
230             assertEquals("Wrong assign null for relation a3->b3 : ","b3", idB);
231         } else {
232             assertNull("Wrong assign null for relation a3->b3 : ", idB);
233         }
234         // undo
235
if (tx != TX_RB) {
236             a.assignB(null);
237         }
238         checkIsInitialState();
239     }
240
241     public void testBasicSetEmptyTxNo() throws Exception JavaDoc {
242         _testBasicSetEmpty(TX_NO);
243     }
244     public void testBasicSetEmptyTxCall() throws Exception JavaDoc {
245         _testBasicSetEmpty(TX_CALL);
246     }
247     public void testBasicSetEmptyTxCont() throws Exception JavaDoc {
248         _testBasicSetEmpty(TX_CONT);
249     }
250     public void testBasicSetEmptyTxRb() throws Exception JavaDoc {
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 JavaDoc {
258         if ((tx == TX_CALL) || (tx == TX_RB)) {
259             utx.begin();
260         }
261         ARemote a = ahome.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 JavaDoc idB = a.retrieveB();
274         if (tx == TX_RB) {
275             assertEquals("Wrong assign null for relation a1->b1: ", "b1", idB);
276         } else {
277             assertNull("Wrong assign null for relation a1->b1: " + idB, idB);
278         }
279         // undo
280
if (tx != TX_RB) {
281             a.assignB("b1");
282         }
283         checkIsInitialState();
284     }
285
286     public void testBasicSetEmptyNullTxNo() throws Exception JavaDoc {
287         _testBasicSetEmptyNull(TX_NO);
288     }
289     public void testBasicSetEmptyNullTxCall() throws Exception JavaDoc {
290         _testBasicSetEmptyNull(TX_CALL);
291     }
292     public void testBasicSetEmptyNullTxCont() throws Exception JavaDoc {
293         _testBasicSetEmptyNull(TX_CONT);
294     }
295     public void testBasicSetEmptyNullTxRb() throws Exception JavaDoc {
296         _testBasicSetEmptyNull(TX_RB);
297     }
298
299
300
301     /**
302      * test coherence relation one to one bidirectionnel,
303      * A1.assignB(B2) => A1.retreiveB()=B2 && B2.retreiveA()=A1 && B1.retreiveA()=null && A2.retreiveB()=null
304      */

305     public void _testCohSetOne(int tx) throws Exception JavaDoc {
306         if ((tx == TX_CALL) || (tx == TX_RB)) {
307             utx.begin();
308         }
309         ARemote a1 = ahome.findByPrimaryKey("a1");
310         BRemote b1 = bhome.findByPrimaryKey("b1");
311         ARemote a2 = ahome.findByPrimaryKey("a2");
312         BRemote b2 = bhome.findByPrimaryKey("b2");
313         ARemote a3 = ahome.findByPrimaryKey("a3");
314         BRemote b3 = bhome.findByPrimaryKey("b3");
315         // change the relation
316
if (tx == TX_CONT) {
317             a1.assignBInNewTx("b2");
318         } else {
319             a1.assignB("b2");
320         }
321         if (tx == TX_CALL) {
322             utx.commit();
323         } else if (tx == TX_RB) {
324             utx.rollback();
325         }
326         if (tx != TX_RB) {
327             // Verify expected result
328
assertNull("Bad coherence of relation null : expected for a2.retreiveB() found :" + a2.retrieveB(), a2.retrieveB());
329             assertNull("Bad coherence of relation null : expected for b1.retreiveA() found :" + b1.retrieveA(), b1.retrieveA());
330             assertEquals("Bad coherence of relation a1 : expected for b2.retreiveA() found :" + b2.retrieveA(), "a1", b2.retrieveA());
331             assertEquals("Bad coherence of relation b2 : expected for a1.retreiveB() found :" + a1.retrieveB(), "b2", a1.retrieveB());
332
333             // undo
334
a1.assignB("b1");
335             a2.assignB("b2");
336         }
337         checkIsInitialState();
338     }
339
340     public void testCohSetOneTxNo() throws Exception JavaDoc {
341         _testCohSetOne(TX_NO);
342     }
343     public void testCohSetOneTxCall() throws Exception JavaDoc {
344         _testCohSetOne(TX_CALL);
345     }
346
347     /**
348      * test coherence relation one to one bidirectionnel,
349      * A3.assignB(B3)=>A3.retreiveB()==B3 && B3.retreiveB()==A3
350      */

351     public void _testCohWithoutRelation(int tx) throws Exception JavaDoc {
352         if ((tx == TX_CALL) || (tx == TX_RB)) {
353             utx.begin();
354         }
355         ARemote a3 = ahome.findByPrimaryKey("a3");
356         BRemote b3 = bhome.findByPrimaryKey("b3");
357         // change the relation
358
if (tx == TX_CONT) {
359             a3.assignBInNewTx("b3");
360         } else {
361             a3.assignB("b3");
362         }
363         if (tx == TX_CALL) {
364             utx.commit();
365         } else if (tx == TX_RB) {
366             utx.rollback();
367         }
368         if (tx != TX_RB) {
369             // Verify expected result
370
assertEquals("Bad coherence of relation : b3 expected for a3.retreiveB() found :" + a3.retrieveB(), "b3", a3.retrieveB());
371             assertEquals("Bad coherence of relation : a3 expected for b3.retreiveA() found :" + b3.retrieveA(), "a3", b3.retrieveA());
372
373             // undo
374
a3.assignB(null);
375         }
376         checkIsInitialState();
377     }
378
379     public void testBasicCohWithoutRelation() throws Exception JavaDoc {
380         _testCohWithoutRelation(TX_NO);
381     }
382     public void testBasicCohWithoutRelationTxCall() throws Exception JavaDoc {
383         _testCohWithoutRelation(TX_CALL);
384     }
385
386     /**
387      * test coherence relation one to one bidirectionnel,
388      * A1.assignB(B3)=>A1.retreiveB()==B3 && B1.retreiveB()==null && B2.retreiveB()=null
389      */

390     public void _testCohAlreadyAssign(int tx) throws Exception JavaDoc {
391         if ((tx == TX_CALL) || (tx == TX_RB)) {
392             utx.begin();
393         }
394         ARemote a1 = ahome.findByPrimaryKey("a1");
395         BRemote b1 = bhome.findByPrimaryKey("b1");
396         BRemote b3 = bhome.findByPrimaryKey("b3");
397         // change the relation
398
if (tx == TX_CONT) {
399             a1.assignBInNewTx("b3");
400         } else {
401             a1.assignB("b3");
402         }
403         if (tx == TX_CALL) {
404             utx.commit();
405         } else if (tx == TX_RB) {
406             utx.rollback();
407         }
408         if (tx != TX_RB) {
409             // Verify expected result
410
assertEquals("Bad coherence of relation : b3 expected for a1.retreiveB() found :" + a1.retrieveB(), "b3", a1.retrieveB());
411             assertNull("Bad coherence of relation : null expected for b1.retreiveA() found :" + b1.retrieveA(), b1.retrieveA());
412             assertEquals("Bad coherence of relation : a1 expected for b2.retreiveA() found :" + b3.retrieveA(), "a1", b3.retrieveA());
413
414             // undo
415
a1.assignB("b1");
416         }
417         checkIsInitialState();
418     }
419
420     public void testCohAlreadyAssign() throws Exception JavaDoc {
421         _testCohAlreadyAssign(TX_NO);
422     }
423     public void testCohAlreadyAssignTxCall() throws Exception JavaDoc {
424         _testCohAlreadyAssign(TX_CALL);
425     }
426
427     /**
428      * test coherence relation one to one bidirectionnel,
429      * A1.assignB(null)=>A1.retreiveB()==null && B1.retreiveB()==null
430      */

431     public void _testCohSetNull(int tx) throws Exception JavaDoc {
432         if ((tx == TX_CALL) || (tx == TX_RB)) {
433             utx.begin();
434         }
435         ARemote a1 = ahome.findByPrimaryKey("a1");
436         BRemote b1 = bhome.findByPrimaryKey("b1");
437         ARemote a2 = ahome.findByPrimaryKey("a2");
438         BRemote b2 = bhome.findByPrimaryKey("b2");
439         ARemote a3 = ahome.findByPrimaryKey("a3");
440         BRemote b3 = bhome.findByPrimaryKey("b3");
441         // change the relation
442
if (tx == TX_CONT) {
443             a1.assignBInNewTx(null);
444         } else {
445             a1.assignB(null);
446         }
447         if (tx == TX_CALL) {
448             utx.commit();
449         } else if (tx == TX_RB) {
450             utx.rollback();
451         }
452         if (tx != TX_RB) {
453             // Verify expected result
454
assertNull("Bad coherence of relation : null expected for a1.retreiveB() found :" + a1.retrieveB(), a1.retrieveB());
455             assertNull("Bad coherence of relation : null expected for b1.retreiveA() found :" + b1.retrieveA(), b1.retrieveA());
456
457             // undo
458
a1.assignB("b1");
459         }
460         checkIsInitialState();
461     }
462
463     public void testCohSetNull() throws Exception JavaDoc {
464         _testCohSetNull(TX_NO);
465     }
466     public void testCohSetNullTxCall() throws Exception JavaDoc {
467         _testCohSetNull(TX_CALL);
468     }
469
470     /**
471      * test coherence relation one to one bidirectionnel,
472      * A1.remove=>A1removed && B1.retreiveA()==null
473      */

474     public void _testCohRemoveA(int tx) throws Exception JavaDoc {
475         if (tx == TX_CONT) {
476             // The transaction attribute of the remove method is TX_SUPPORT,
477
// so the transaction cannot be initiate by the container
478
fail("Transaction cannot be initiate by the container for this test");
479         }
480         if ((tx == TX_CALL) || (tx == TX_RB)) {
481             utx.begin();
482         }
483         BRemote b1 = bhome.findByPrimaryKey("b1");
484         // remove the bean
485
ahome.remove("a1");
486         if (tx == TX_CALL) {
487             utx.commit();
488         } else if (tx == TX_RB) {
489             utx.rollback();
490         }
491         if (tx != TX_RB) {
492             // Verify expected result
493
assertNull("Bad coherence of relation : null expected for b1.retreiveB() found :" + b1.retrieveA(), b1.retrieveA());
494             boolean not_found = false;
495             try {
496                 ARemote a1 = ahome.findByPrimaryKey("a1");
497             } catch (ObjectNotFoundException JavaDoc e) {
498                 not_found = true;
499             }
500             assertTrue("a1 is not removed", not_found);
501             // undo
502
ahome.create("a1");
503             ARemote a1 = ahome.findByPrimaryKey("a1");
504             a1.assignB("b1");
505         }
506         checkIsInitialState();
507     }
508
509     public void testCohRemoveATxNo() throws Exception JavaDoc {
510         _testCohRemoveA(TX_NO);
511     }
512     public void testCohRemoveATxCall() throws Exception JavaDoc {
513         _testCohRemoveA(TX_CALL);
514     }
515     public void testCohRemoveATxRb() throws Exception JavaDoc {
516         _testCohRemoveA(TX_RB);
517     }
518
519     /**
520      * test coherence relation one to one bidirectionnel,
521      * Ahome.remove(a1)=>A1removed && B1.retreiveA()==null
522      * Same as _testCohRemoveA except that the called remove method is on the bean
523      * instead of the home.
524      */

525     public void _testCohBeanRemoveA(int tx) throws Exception JavaDoc {
526         if (tx == TX_CONT) {
527             // The transaction attribute of the remove method is TX_SUPPORT,
528
// so the transaction cannot be initiate by the container
529
fail("Transaction cannot be initiate by the container for this test");
530         }
531            
532         if ((tx == TX_CALL) || (tx == TX_RB)) {
533             utx.begin();
534         }
535         ARemote a1 = ahome.findByPrimaryKey("a1");
536         BRemote b1 = bhome.findByPrimaryKey("b1");
537         a1.remove();
538         if (tx == TX_CALL) {
539             utx.commit();
540         } else if (tx == TX_RB) {
541             utx.rollback();
542         }
543         if (tx != TX_RB) {
544             // Verify expected result
545
assertNull("Bad coherence of relation : null expected for b1.retreiveB() found :" + b1.retrieveA(), b1.retrieveA());
546             boolean not_found=false;
547             try {
548                 a1 = ahome.findByPrimaryKey("a1");
549             } catch (ObjectNotFoundException JavaDoc e) {
550                 not_found=true;
551             }
552             assertTrue("a1 is not removed",not_found);
553             // undo
554
ahome.create("a1");
555             a1 = ahome.findByPrimaryKey("a1");
556             a1.assignB("b1");
557         }
558         checkIsInitialState();
559     }
560
561     public void testCohBeanRemoveATxNo() throws Exception JavaDoc {
562         _testCohBeanRemoveA(TX_NO);
563     }
564     public void testCohBeanRemoveATxCall() throws Exception JavaDoc {
565         _testCohBeanRemoveA(TX_CALL);
566     }
567     public void testCohBeanRemoveATxRb() throws Exception JavaDoc {
568         _testCohBeanRemoveA(TX_RB);
569     }
570
571     /**
572      * test coherence relation one to one bidirectionnel,
573      * Bhome.remove(b1)=>B1 removed && A1.retreiveB()==null
574      */

575     public void _testCohRemoveB(int tx) throws Exception JavaDoc {
576         if (tx == TX_CONT) {
577             // The transaction attribute of the remove method is TX_SUPPORT,
578
// so the transaction cannot be initiate by the container
579
fail("Transaction cannot be initiate by the container for this test");
580         }
581            
582         if ((tx == TX_CALL) || (tx == TX_RB)) {
583             utx.begin();
584         }
585         ARemote a1 = ahome.findByPrimaryKey("a1");
586         BRemote b1 = bhome.findByPrimaryKey("b1");
587         ARemote a2 = ahome.findByPrimaryKey("a2");
588         BRemote b2 = bhome.findByPrimaryKey("b2");
589         ARemote a3 = ahome.findByPrimaryKey("a3");
590         BRemote b3 = bhome.findByPrimaryKey("b3");
591         // remove the bean
592
bhome.remove("b1");
593         if (tx == TX_CALL) {
594             utx.commit();
595         } else if (tx == TX_RB) {
596             utx.rollback();
597         }
598         if (tx != TX_RB) {
599             // Verify expected result
600
assertNull("Bad coherence of relation : null expected for a1.retreiveB() found :"+a1.retrieveB(), a1.retrieveB());
601             boolean not_found=false;
602             try {
603                 b1 = bhome.findByPrimaryKey("b1");
604             } catch (ObjectNotFoundException JavaDoc e) {
605                 not_found=true;
606             }
607             assertTrue("B is not removed",not_found);
608             // undo
609
bhome.create("b1");
610             a1.assignB("b1");
611         }
612         checkIsInitialState();
613     }
614
615     public void testCohRemoveBTxNo() throws Exception JavaDoc {
616         _testCohRemoveB(TX_NO);
617     }
618     public void testCohRemoveBTxCall() throws Exception JavaDoc {
619         _testCohRemoveB(TX_CALL);
620     }
621     public void testCohRemoveBTxRb() throws Exception JavaDoc {
622         _testCohRemoveB(TX_RB);
623     }
624
625     /**
626      * test coherence relation one to one bidirectionnel,
627      * B1.remove=>B1 removed && A1.retreiveB()==null
628      * Same as _testCohRemoveB except that the called remove method is on the bean
629      * instead of the home.
630      */

631     public void _testCohBeanRemoveB(int tx) throws Exception JavaDoc {
632         if (tx == TX_CONT) {
633             // The transaction attribute of the remove method is TX_SUPPORT,
634
// so the transaction cannot be initiate by the container
635
fail("Transaction cannot be initiate by the container for this test");
636         }
637            
638         if ((tx == TX_CALL) || (tx == TX_RB)) {
639             utx.begin();
640         }
641         ARemote a1 = ahome.findByPrimaryKey("a1");
642         BRemote b1 = bhome.findByPrimaryKey("b1");
643         ARemote a2 = ahome.findByPrimaryKey("a2");
644         BRemote b2 = bhome.findByPrimaryKey("b2");
645         ARemote a3 = ahome.findByPrimaryKey("a3");
646         BRemote b3 = bhome.findByPrimaryKey("b3");
647         // change the relation
648
b1.remove();
649         if (tx == TX_CALL) {
650             utx.commit();
651         } else if (tx == TX_RB) {
652             utx.rollback();
653         }
654         if (tx != TX_RB) {
655             // Verify expected result
656
assertNull("Bad coherence of relation : null expected for a1.retreiveB() found :"+a1.retrieveB(), a1.retrieveB());
657             boolean not_found=false;
658             try {
659                 b1 = bhome.findByPrimaryKey("b1");
660             } catch (ObjectNotFoundException JavaDoc e) {
661                 not_found=true;
662             }
663             assertTrue("B is not removed",not_found);
664             // undo
665
bhome.create("b1");
666             a1.assignB("b1");
667         }
668         checkIsInitialState();
669     }
670
671     public void testCohBeanRemoveBTxNo() throws Exception JavaDoc {
672         _testCohBeanRemoveB(TX_NO);
673     }
674     public void testCohBeanRemoveBTxCall() throws Exception JavaDoc {
675         _testCohBeanRemoveB(TX_CALL);
676     }
677     public void testCohBeanRemoveBTxRb() throws Exception JavaDoc {
678         _testCohBeanRemoveB(TX_RB);
679     }
680
681     /**
682      * Combination of 2 tests that fails :
683      * _testCohAlreadyAssign(TX_CALL) + _testCohRemoveA(TX_RB)
684      */

685     public void testMultiA1() throws Exception JavaDoc {
686         ARemote a1 = ahome.findByPrimaryKey("a1");
687         BRemote b1 = bhome.findByPrimaryKey("b1");
688         BRemote b3 = bhome.findByPrimaryKey("b3");
689         utx.begin();
690         a1.assignB("b3");
691         utx.commit();
692         a1.assignB("b1");
693         utx.begin();
694         ahome.remove("a1");
695         utx.rollback();
696         String JavaDoc idB1 = a1.retrieveB();
697         assertEquals("a1.b", "b1", idB1);
698         checkIsInitialState();
699     }
700
701     public void testMultiA2() throws Exception JavaDoc {
702         ARemote a1 = ahome.findByPrimaryKey("a1");
703         BRemote b1 = bhome.findByPrimaryKey("b1");
704         BRemote b3 = bhome.findByPrimaryKey("b3");
705         utx.begin();
706         a1.assignB("b3");
707         utx.commit();
708         a1.assignB("b1");
709         utx.begin();
710         String JavaDoc idB1 = a1.retrieveB();
711         utx.commit();
712         assertEquals("a1.b", "b1", idB1);
713         checkIsInitialState();
714     }
715
716     public void testMultiA3() throws Exception JavaDoc {
717         ARemote a1 = ahome.findByPrimaryKey("a1");
718         BRemote b1 = bhome.findByPrimaryKey("b1");
719         BRemote b3 = bhome.findByPrimaryKey("b3");
720         utx.begin();
721         a1.assignB("b3");
722         utx.commit();
723         a1.assignB("b1");
724         utx.begin();
725         String JavaDoc idA1 = b1.retrieveA();
726         utx.commit();
727         assertEquals("b1.a", "a1", idA1);
728         checkIsInitialState();
729     }
730
731     public void testMultiA4() throws Exception JavaDoc {
732         ARemote a1 = ahome.findByPrimaryKey("a1");
733         BRemote b1 = bhome.findByPrimaryKey("b1");
734         BRemote b3 = bhome.findByPrimaryKey("b3");
735         utx.begin();
736         a1.assignB("b3");
737         utx.commit();
738         a1.assignB("b1");
739         utx.begin();
740         bhome.remove("b1");
741         utx.rollback();
742         String JavaDoc idB1 = a1.retrieveB();
743         assertEquals("a1.b", "b1", idB1);
744         checkIsInitialState();
745     }
746
747     public void testMultiA5() throws Exception JavaDoc {
748         ARemote a1 = ahome.findByPrimaryKey("a1");
749         BRemote b1 = bhome.findByPrimaryKey("b1");
750         BRemote b3 = bhome.findByPrimaryKey("b3");
751         utx.begin();
752         a1.assignB("b3");
753         utx.commit();
754         a1.assignB("b1");
755         utx.begin();
756         bhome.remove("b3");
757         utx.rollback();
758         String JavaDoc idB1 = a1.retrieveB();
759         assertEquals("a1.b", "b1", idB1);
760         checkIsInitialState();
761     }
762
763     public static Test suite() {
764         return new TestSuite(F_Relation_oobEC2.class);
765     }
766
767     public static void main (String JavaDoc args[]) {
768         String JavaDoc testtorun = null;
769         // Get args
770
for (int argn = 0; argn < args.length; argn++) {
771             String JavaDoc s_arg = args[argn];
772             Integer JavaDoc i_arg;
773             if (s_arg.equals("-n")) {
774                 testtorun = args[++argn];
775             }
776         }
777         if (testtorun == null) {
778             junit.textui.TestRunner.run(suite());
779         } else {
780             junit.textui.TestRunner.run(new F_Relation_oobEC2(testtorun));
781         }
782     }
783 }
784
785
Popular Tags