KickJava   Java API By Example, From Geeks To Geeks.

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


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_mnuEC2.java,v 1.21 2004/05/20 23:28:50 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.Hashtable JavaDoc;
32
33 import javax.naming.NamingException JavaDoc;
34 import javax.rmi.PortableRemoteObject JavaDoc;
35
36 import junit.framework.Test;
37 import junit.framework.TestSuite;
38
39 import org.objectweb.jonas.jtests.beans.relation.mnu.AHomeRemote;
40 import org.objectweb.jonas.jtests.beans.relation.mnu.ARemote;
41 import org.objectweb.jonas.jtests.beans.relation.mnu.BHomeRemote;
42 import org.objectweb.jonas.jtests.beans.relation.mnu.BRemote;
43
44 /**
45  * For testing many-to-many unidirectional relationships
46  * @author S.Chassande-Barrioz, J. Camilleri
47  *
48  **/

49 public class F_Relation_mnuEC2 extends A_Cmp2Util {
50
51     /**
52      * predefined relations between a and b beans
53      */

54     static Hashtable JavaDoc tbRelationA2B = new Hashtable JavaDoc();
55     static {
56         tbRelationA2B.put("a0", new String JavaDoc[]{});
57         tbRelationA2B.put("a1", new String JavaDoc[]{"b1","b2"});
58         tbRelationA2B.put("a2", new String JavaDoc[]{"b1", "b2", "b3"});
59         tbRelationA2B.put("a3", new String JavaDoc[]{"b2","b3","b4"});
60         // Translate the String[] to a Collection of String
61
for (Enumeration JavaDoc ea = tbRelationA2B.keys() ; ea.hasMoreElements() ;) {
62             String JavaDoc aname = (String JavaDoc) (ea.nextElement());
63             String JavaDoc [] tb = (String JavaDoc[])tbRelationA2B.get(aname);
64             ArrayList JavaDoc col = new ArrayList JavaDoc(tb.length);
65             for (int i=0; i<tb.length; i++ ) {
66                 col.add(tb[i]);
67             }
68             tbRelationA2B.put(aname, col);
69         }
70     }
71
72     private static String JavaDoc BEAN_HOME_A = "relation_mnu_AHome";
73     protected static AHomeRemote ahome = null;
74     private static String JavaDoc BEAN_HOME_B = "relation_mnu_BHome";
75     protected static BHomeRemote bhome = null;
76     
77
78     public F_Relation_mnuEC2(String JavaDoc name) {
79         super(name);
80     }
81
82     protected static boolean isInit = false;
83
84     protected void setUp() {
85         super.setUp();
86         boolean ok = false;
87         int nbtry = 0;
88         while (!ok && nbtry < 3) {
89             if (!isInit) {
90                 // load bean if not loaded yet
91
useBeans("mnu", false);
92                 try {
93                     ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A),
94                                                                       AHomeRemote.class);
95                     bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B),
96                                                                       BHomeRemote.class);
97                 } catch (NamingException JavaDoc e) {
98                     fail("Cannot get bean home: "+e.getMessage());
99                 }
100                 // check if tables have been initialized
101
try {
102                     ahome.findByPrimaryKey("a0");
103                 } catch (Exception JavaDoc e) {
104                     try {
105                         utx.begin();
106                         ARemote a0 = ahome.create("a0");
107                         ARemote a1 = ahome.create("a1");
108                         ARemote a2 = ahome.create("a2");
109                         ARemote a3 = ahome.create("a3");
110                         bhome.create("b0");
111                         bhome.create("b1");
112                         bhome.create("b2");
113                         bhome.create("b3");
114                         bhome.create("b4");
115                         a0.assignB((Collection JavaDoc) tbRelationA2B.get("a0"));
116                         a1.assignB((Collection JavaDoc) tbRelationA2B.get("a1"));
117                         a2.assignB((Collection JavaDoc) tbRelationA2B.get("a2"));
118                         a3.assignB((Collection JavaDoc) tbRelationA2B.get("a3"));
119                     } catch (Exception JavaDoc i) {
120                         fail("InitialState creation problem: "+i);
121                     } finally {
122                         try {
123                             utx.commit();
124                         } catch (Exception JavaDoc ii) {
125                         }
126                     }
127                 }
128                 isInit = true;
129             }
130             // Check that all is OK. Sometimes, a test has failed and has corrupted
131
// the bean state in the database. We must unload and reload the bean then.
132
nbtry++;
133             try {
134                 if (initStateOK()) {
135                     ok = true;
136                 }
137             } catch (Exception JavaDoc e) {
138             }
139             if (!ok) {
140                 isInit = false;
141                 unloadBeans("mnu");
142             }
143         }
144     }
145
146     /*
147      * Check that we are in the same state as after the tables creation for thoses beans A and B
148      * (ie if it is the initial state)
149      */

150     boolean initStateOK() throws Exception JavaDoc {
151         boolean isOk = true;
152         msgerror = new StringBuffer JavaDoc();
153         for (Enumeration JavaDoc ea = tbRelationA2B.keys(); ea.hasMoreElements();) {
154             String JavaDoc aname = (String JavaDoc) (ea.nextElement());
155             ARemote a = ahome.findByPrimaryKey(aname);
156             Collection JavaDoc colActual = a.retrieveB();
157             ArrayList JavaDoc colExpected = (ArrayList JavaDoc) (tbRelationA2B.get(aname));
158             if (!isCollectionEqual(colExpected, colActual)) {
159                 isOk = false;
160                 msgerror = msgerror.append("Wrong relation for " + aname
161                                            +" (expected:" + colExpected
162                                            + ", found:" + colActual + ")");
163             }
164         }
165         return isOk;
166     }
167
168
169     /**
170      * Check that the bean 'a3' has no relation.
171      */

172     public void _testBasicGetEmpty(int tx) throws Exception JavaDoc {
173         Collection JavaDoc c;
174         if ((tx == TX_CALL) || (tx == TX_RB)) {
175             utx.begin();
176         }
177         ARemote a = ahome.findByPrimaryKey("a0");
178         if (tx == TX_CONT) {
179             c = a.retrieveBInNewTx();
180         } else {
181             c = a.retrieveB();
182         }
183         if (tx == TX_CALL) {
184             utx.commit();
185         } else if (tx == TX_RB) {
186             utx.rollback();
187         }
188
189         checkIsInitialState();
190     }
191
192     public void testBasicGetEmptyTxNo() throws Exception JavaDoc {
193         _testBasicGetEmpty(TX_NO);
194     }
195     public void testBasicGetEmptyTxCall() throws Exception JavaDoc {
196         _testBasicGetEmpty(TX_CALL);
197     }
198     public void testBasicGetEmptyTxCont() throws Exception JavaDoc {
199         _testBasicGetEmpty(TX_CONT);
200     }
201
202     /**
203      * Ckeck the new relation a0-b0
204      */

205     public void _testBasicSetEmpty(int tx) throws Exception JavaDoc {
206         ArrayList JavaDoc c = new ArrayList JavaDoc(1);
207         c.add("b0");
208         if ((tx == TX_CALL) || (tx == TX_RB)) {
209             utx.begin();
210         }
211         ARemote a = ahome.findByPrimaryKey("a0");
212         if (tx == TX_CONT) {
213             a.assignBInNewTx(c);
214         } else {
215             a.assignB(c);
216         }
217         if (tx == TX_CALL) {
218             utx.commit();
219         } else if (tx == TX_RB) {
220             utx.rollback();
221         }
222         // checking
223
Collection JavaDoc c_value = a.retrieveB();
224         if (tx != TX_RB) {
225             assertTrue("Wrong relations a0 (required:" + c + ", found:" + c_value
226                        + ")", isCollectionEqual(c_value, c));
227             // undo
228
a.assignB(new ArrayList JavaDoc(0));
229         }
230         checkIsInitialState();
231
232     }
233     public void testBasicSetEmptyTxNo() throws Exception JavaDoc {
234         _testBasicSetEmpty(TX_NO);
235     }
236     public void testBasicSetEmptyTxCall() throws Exception JavaDoc {
237         _testBasicSetEmpty(TX_CALL);
238     }
239     public void testBasicSetEmptyTxCont() throws Exception JavaDoc {
240         _testBasicSetEmpty(TX_CONT);
241     }
242
243     public void testBasicSetEmptyTxRb() throws Exception JavaDoc {
244         _testBasicSetEmpty(TX_RB);
245     }
246
247     /**
248      * See 10.3.7.7 of spec : a1.assignB(a3.retrieveB()) =>
249      * a1.retreiveB().contains("b2") &&
250      * a1.retreiveB().contains("b3") &&
251      * a1.retreiveB().contains("b4") &&
252      * a3.retreiveB().contains("b2") &&
253      * a3.retreiveB().contains("b3") &&
254      * a3.retreiveB().contains("b4") &&
255      */

256     public void _testBasicSetFirst(int tx) throws Exception JavaDoc {
257         String JavaDoc c = null;
258         if ((tx == TX_CALL) || (tx == TX_RB)) {
259             utx.begin();
260         }
261         ARemote a1 = ahome.findByPrimaryKey("a1");
262         ARemote a3 = ahome.findByPrimaryKey("a3");
263         Collection JavaDoc c1 = a1.retrieveB();
264         if (tx == TX_CONT) {
265             a1.assignBInNewTx(a3.retrieveB());
266         } else {
267             a1.assignB(a3.retrieveB());
268         }
269         if (tx == TX_CALL) {
270             utx.commit();
271         } else if (tx == TX_RB) {
272             utx.rollback();
273         }
274         // checking
275
if (tx != TX_RB) {
276             ArrayList JavaDoc c1_att = new ArrayList JavaDoc(3);
277             c1_att.add("b2");
278             c1_att.add("b3");
279             c1_att.add("b4");
280             assertTrue("Wrong test of coherence First before commit: ", isCollectionEqual(a1.retrieveB(),c1_att));
281         } else {
282             assertTrue("Wrong test of coherence First before roolback: ", isCollectionEqual(a1.retrieveB(),c1));
283         }
284         // undo
285
if (tx != TX_RB) {
286             a1.assignB(null);
287             a1.assignB(c1);
288         }
289         checkIsInitialState();
290     }
291     public void testBasicSetFirstTxNo() throws Exception JavaDoc {
292         _testBasicSetFirst(TX_NO);
293     }
294     public void testBasicSetFirstTxCall() throws Exception JavaDoc {
295         _testBasicSetFirst(TX_CALL);
296     }
297     public void testBasicSetFirstTxCont() throws Exception JavaDoc {
298         _testBasicSetFirst(TX_CONT);
299     }
300     public void testBasicSetFirstTxRb() throws Exception JavaDoc {
301         _testBasicSetFirst(TX_RB);
302     }
303
304     /**
305      * See 10.3.7.7 of spec : a1.getB().add(b3) =>
306      * a1.retreiveB().contains("b1") &&
307      * a1.retreiveB().contains("b2") &&
308      * a1.retreiveB().contains("b3") &&
309      */

310     public void _testBasicSetSecond(int tx) throws Exception JavaDoc {
311         String JavaDoc c = null;
312
313         if ((tx == TX_CALL) || (tx == TX_RB)) {
314             utx.begin();
315         }
316         ARemote a1 = ahome.findByPrimaryKey("a1");
317         Collection JavaDoc c1 = a1.retrieveB();
318   
319         if (tx == TX_CONT) {
320             a1.addInB("b3");
321         } else {
322             a1.addInB("b3");
323         }
324         if (tx == TX_CALL) {
325             utx.commit();
326         } else if (tx == TX_RB) {
327             utx.rollback();
328         }
329         // checking
330
if (tx != TX_RB) {
331             ArrayList JavaDoc c1_att = new ArrayList JavaDoc(3);
332             c1_att.add("b1");
333             c1_att.add("b2");
334             c1_att.add("b3");
335             assertTrue("Wrong test of coherence Second before commit: ", isCollectionEqual(a1.retrieveB(),c1_att));
336         } else {
337             assertTrue("Wrong test of coherence Second before roolback: ", isCollectionEqual(a1.retrieveB(),c1));
338         }
339         // undo
340
if (tx != TX_RB) {
341             a1.assignB(null);
342             a1.assignB(c1);
343         }
344         checkIsInitialState();
345     }
346
347     public void testBasicSetSecondTxNo() throws Exception JavaDoc {
348         _testBasicSetSecond(TX_NO);
349     }
350     public void testBasicSetSecondTxCall() throws Exception JavaDoc {
351         _testBasicSetSecond(TX_CALL);
352     }
353     public void testBasicSetSecondTxCont() throws Exception JavaDoc {
354         _testBasicSetSecond(TX_CONT);
355     }
356     public void testBasicSetSecondTxRb() throws Exception JavaDoc {
357         _testBasicSetSecond(TX_RB);
358     }
359
360
361     /**
362      * See 10.3.7.7 of spec : a2.getB().remove(b2) =>
363      * a2.retreiveB().contains("b1") &&
364      * a2.retreiveB().contains("b3") &&
365      */

366     public void _testBasicSetRemove(int tx) throws Exception JavaDoc {
367         String JavaDoc c = null;
368
369         if ((tx == TX_CALL) || (tx == TX_RB)) {
370             utx.begin();
371         }
372         ARemote a2 = ahome.findByPrimaryKey("a2");
373         Collection JavaDoc c2 = a2.retrieveB();
374         if (tx == TX_CONT) {
375             a2.removeFromB("b2");
376         } else {
377             a2.removeFromB("b2");
378         }
379         if (tx == TX_CALL) {
380             utx.commit();
381         } else if (tx == TX_RB) {
382             utx.rollback();
383         }
384         // checking
385
if (tx != TX_RB) {
386             ArrayList JavaDoc c2_att = new ArrayList JavaDoc(3);
387             c2_att.add("b1");
388             c2_att.add("b3");
389             assertTrue("Wrong test of coherence Remove before commit: ", isCollectionEqual(a2.retrieveB(),c2_att));
390         } else {
391             assertTrue("Wrong test of coherence Remove before roolback: ", isCollectionEqual(a2.retrieveB(),c2));
392         }
393         // undo
394
if (tx != TX_RB) {
395             a2.assignB(c2);
396         }
397         checkIsInitialState();
398     }
399
400     public void testBasicSetRemoveTxNo() throws Exception JavaDoc {
401         _testBasicSetRemove(TX_NO);
402     }
403     public void testBasicSetRemoveTxCall() throws Exception JavaDoc {
404         _testBasicSetRemove(TX_CALL);
405     }
406     public void testBasicSetRemoveTxCont() throws Exception JavaDoc {
407         _testBasicSetRemove(TX_CONT);
408     }
409     public void testBasicSetRemoveTxRb() throws Exception JavaDoc {
410         _testBasicSetRemove(TX_RB);
411     }
412
413     /**
414      * Ckeck clear function
415      */

416     public void _testBasicClear(int tx) throws Exception JavaDoc {
417         if ((tx == TX_CALL) || (tx == TX_RB)) {
418             utx.begin();
419         }
420         ARemote a2 = ahome.findByPrimaryKey("a2");
421         if (tx == TX_CONT) {
422             a2.clearBInNewTx();
423         } else {
424             a2.clearB();
425         }
426         if (tx == TX_CALL) {
427             utx.commit();
428         } else if (tx == TX_RB) {
429             utx.rollback();
430         }
431         // checking
432
Collection JavaDoc a2_value = a2.retrieveB();
433         if (tx != TX_RB) {
434             assertTrue("Wrong relations a2 (required: Empty, found:" + a2_value + ")", a2_value.isEmpty());
435        
436             // undo
437
ArrayList JavaDoc a2undo = new ArrayList JavaDoc(3);
438             a2undo.add("b1");
439             a2undo.add("b2");
440             a2undo.add("b3");
441             a2.assignB(a2undo);
442         }
443         checkIsInitialState();
444     }
445
446     public void testBasicClearTxNo() throws Exception JavaDoc {
447         _testBasicClear(TX_NO);
448     }
449
450     public void testBasicClearTxCall() throws Exception JavaDoc {
451         _testBasicClear(TX_CALL);
452     }
453
454     public void testBasicClearTxCont() throws Exception JavaDoc {
455         _testBasicClear(TX_CONT);
456     }
457
458     public void testBasicClearTxRb() throws Exception JavaDoc {
459         _testBasicClear(TX_RB);
460     }
461
462     /**
463      * Remove an element in a relation.
464      */

465     public void _testCohRemoveInRel(int tx) throws Exception JavaDoc {
466         String JavaDoc bRemoved = "b4";
467         if ((tx == TX_CALL) || (tx == TX_RB)) {
468             utx.begin();
469         }
470         ARemote a = ahome.findByPrimaryKey("a3");
471         if (tx == TX_CONT) {
472             a.removeFromBInNewTx(bRemoved);
473         } else {
474             a.removeFromB(bRemoved);
475         }
476         if (tx == TX_CALL) {
477             utx.commit();
478         } else if (tx == TX_RB) {
479             utx.rollback();
480         }
481         // checking
482
Collection JavaDoc ca = a.retrieveB();
483         if (tx != TX_RB) {
484             assertEquals("Wrong relations size for a3: ", 2, ca.size());
485         } else {
486             assertEquals("Wrong relations size for a3: ", 3, ca.size());
487         }
488         // undo
489
if (tx != TX_RB) {
490             a.addInB(bRemoved);
491         }
492         // check to initial state
493
checkIsInitialState();
494
495     }
496
497     public void testCohRemoveInRelTxNo() throws Exception JavaDoc {
498         _testCohRemoveInRel(TX_NO);
499     }
500
501     public void testCohRemoveInRelTxCall() throws Exception JavaDoc {
502         _testCohRemoveInRel(TX_CALL);
503     }
504
505     public void testCohRemoveInRelTxCont() throws Exception JavaDoc {
506         _testCohRemoveInRel(TX_CONT);
507     }
508
509     public void testCohRemoveInRelTxRb() throws Exception JavaDoc {
510         _testCohRemoveInRel(TX_RB);
511     }
512
513     /**
514      * Test of coherence b2.remove() => a1.retrieveB()=null && a2.retrieveB()=null && a3.retrieveB()=null
515      */

516     public void _testCohRemove(int tx) throws Exception JavaDoc {
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         bhome.remove("b2");
526         if (tx == TX_CALL) {
527             utx.commit();
528         } else if (tx == TX_RB) {
529             utx.rollback();
530         }
531         // checking
532
ARemote a1 = ahome.findByPrimaryKey("a1");
533         ARemote a2 = ahome.findByPrimaryKey("a2");
534         ARemote a3 = ahome.findByPrimaryKey("a3");
535         Collection JavaDoc idrela1 = a1.retrieveB();
536         Collection JavaDoc idrela2 = a2.retrieveB();
537         Collection JavaDoc idrela3 = a3.retrieveB();
538         ArrayList JavaDoc col_a1 = new ArrayList JavaDoc(1);
539         col_a1.add("b1");
540         ArrayList JavaDoc col_a2 = new ArrayList JavaDoc(2);
541         col_a2.add("b1");
542         col_a2.add("b3");
543         ArrayList JavaDoc col_a3 = new ArrayList JavaDoc(2);
544         col_a3.add("b3");
545         col_a3.add("b4");
546         if (tx != TX_RB) {
547             assertTrue("Wrong relation a1 : Expected [b1] , found "+idrela1, isCollectionEqual(idrela1,col_a1));
548             assertTrue("Wrong relation a2 : Expected [b1, b3] , found "+idrela2 , isCollectionEqual(idrela2,col_a2));
549             assertTrue("Wrong relation a3 : Expected [b3, b4] , found " + idrela3, isCollectionEqual(idrela3, col_a3));
550             // undo
551
bhome.create("b2");
552             col_a1 = new ArrayList JavaDoc(2);
553             col_a1.add("b1");
554             col_a1.add("b2");
555             col_a2 = new ArrayList JavaDoc(3);
556             col_a2.add("b1");
557             col_a2.add("b2");
558             col_a2.add("b3");
559             a1.assignB(col_a1);
560             col_a3 = new ArrayList JavaDoc(3);
561             col_a3.add("b2");
562             col_a3.add("b3");
563             col_a3.add("b4");
564
565             a1.assignB(col_a1);
566             a2.assignB(col_a2);
567             a3.assignB(col_a3);
568         }
569         checkIsInitialState();
570     }
571
572     public void testCohRemoveTxNo() throws Exception JavaDoc {
573         _testCohRemove(TX_NO);
574     }
575
576     public void testCohRemoveTxCall() throws Exception JavaDoc {
577         _testCohRemove(TX_CALL);
578     }
579
580     public void testCohRemoveTxRb() throws Exception JavaDoc {
581         _testCohRemove(TX_RB);
582     }
583
584     /**
585      * Test of coherence b2.remove() => a1.retrieveB()=null && a2.retrieveB()=null && a3.retrieveB()=null
586      * Same as _testCohRemove except that the called remove method is on the bean
587      * instead of the home.
588      */

589     public void _testCohBeanRemove(int tx) throws Exception JavaDoc {
590         if (tx == TX_CONT) {
591             // The transaction attribute of the remove method is TX_SUPPORT,
592
// so the transaction cannot be initiate by the container
593
fail("Transaction cannot be initiate by the container for this test");
594         }
595         if ((tx == TX_CALL) || (tx == TX_RB)) {
596             utx.begin();
597         }
598         BRemote b = bhome.findByPrimaryKey("b2");
599         b.remove();
600         if (tx == TX_CALL) {
601             utx.commit();
602         } else if (tx == TX_RB) {
603             utx.rollback();
604         }
605         // checking
606
ARemote a1 = ahome.findByPrimaryKey("a1");
607         ARemote a2 = ahome.findByPrimaryKey("a2");
608         ARemote a3 = ahome.findByPrimaryKey("a3");
609         Collection JavaDoc idrela1 = a1.retrieveB();
610         Collection JavaDoc idrela2 = a2.retrieveB();
611         Collection JavaDoc idrela3 = a3.retrieveB();
612         ArrayList JavaDoc col_a1 = new ArrayList JavaDoc(1);
613         col_a1.add("b1");
614         ArrayList JavaDoc col_a2 = new ArrayList JavaDoc(2);
615         col_a2.add("b1");
616         col_a2.add("b3");
617         ArrayList JavaDoc col_a3 = new ArrayList JavaDoc(2);
618         col_a3.add("b3");
619         col_a3.add("b4");
620         if (tx != TX_RB) {
621             assertTrue("Wrong relation a1 : Expected [b1] , found "+idrela1, isCollectionEqual(idrela1,col_a1));
622             assertTrue("Wrong relation a2 : Expected [b1, b3] , found "+idrela2 , isCollectionEqual(idrela2,col_a2));
623             assertTrue("Wrong relation a3 : Expected [b3, b4] , found " + idrela3, isCollectionEqual(idrela3, col_a3));
624             // undo
625
bhome.create("b2");
626             col_a1 = new ArrayList JavaDoc(2);
627             col_a1.add("b1");
628             col_a1.add("b2");
629             col_a2 = new ArrayList JavaDoc(3);
630             col_a2.add("b1");
631             col_a2.add("b2");
632             col_a2.add("b3");
633             a1.assignB(col_a1);
634             col_a3 = new ArrayList JavaDoc(3);
635             col_a3.add("b2");
636             col_a3.add("b3");
637             col_a3.add("b4");
638
639             a1.assignB(col_a1);
640             a2.assignB(col_a2);
641             a3.assignB(col_a3);
642         }
643         checkIsInitialState();
644     }
645
646     public void testCohBeanRemoveTxNo() throws Exception JavaDoc {
647         _testCohBeanRemove(TX_NO);
648     }
649
650     public void testCohBeanRemoveTxCall() throws Exception JavaDoc {
651         _testCohBeanRemove(TX_CALL);
652     }
653
654     public void testCohBeanRemoveTxRb() throws Exception JavaDoc {
655         _testCohBeanRemove(TX_RB);
656     }
657
658     /**
659      * These several tests linked fails on Oracle (testCohBeanRemoveTxCall)
660      */

661     public void testRemoveSeries() throws Exception JavaDoc {
662
663         testBasicSetRemoveTxCall();
664         testBasicClearTxCall();
665         testBasicClearTxRb();
666         testCohRemoveTxNo();
667         testCohRemoveTxCall();
668     }
669
670     public void testRemoves1() throws Exception JavaDoc {
671         ARemote a1 = ahome.findByPrimaryKey("a1");
672         ARemote a2 = ahome.findByPrimaryKey("a2");
673         ARemote a3 = ahome.findByPrimaryKey("a3");
674         Collection JavaDoc col;
675         Collection JavaDoc b;
676         Collection JavaDoc a1bsave = a1.retrieveB();
677         Collection JavaDoc a2bsave = a2.retrieveB();
678         Collection JavaDoc a3bsave = a3.retrieveB();
679
680         //_testBasicSetRemove(TX_CALL);
681
utx.begin();
682         a2.removeFromB("b2");
683         utx.commit();
684         // checking
685
col = new ArrayList JavaDoc(2);
686         col.add("b1");
687         col.add("b3");
688         assertTrue("Wrong test of coherence Remove before commit: ", isCollectionEqual(a2.retrieveB(), col));
689         // undo
690
a2.assignB(a2bsave);
691
692         //_testBasicClear(TX_CALL);
693
utx.begin();
694         a2.clearB();
695         utx.commit();
696         // checking
697
b = a2.retrieveB();
698         assertTrue("Wrong relations a2 (required: Empty, found:" + b + ")", b.isEmpty());
699         // undo
700
a2.assignB(a2bsave);
701
702         //_testBasicClear(TX_RB);
703
utx.begin();
704         a2.clearB();
705         utx.rollback();
706
707         //_testCohRemove(TX_NO);
708
bhome.remove("b2");
709         // check a1
710
col = new ArrayList JavaDoc(1);
711         col.add("b1");
712         b = a1.retrieveB();
713         assertTrue("Wrong relation a1 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
714         // check a2
715
col = new ArrayList JavaDoc(2);
716         col.add("b1");
717         col.add("b3");
718         b = a2.retrieveB();
719         assertTrue("Wrong relation a2 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
720         // check a3
721
col = new ArrayList JavaDoc(2);
722         col.add("b3");
723         col.add("b4");
724         b = a3.retrieveB();
725         assertTrue("Wrong relation a3 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
726         // undo
727
bhome.create("b2");
728         a1.assignB(a1bsave);
729         a2.assignB(a2bsave);
730         a3.assignB(a3bsave);
731         checkIsInitialState();
732     }
733
734     public void testRemoves2() throws Exception JavaDoc {
735         ARemote a1 = ahome.findByPrimaryKey("a1");
736         ARemote a2 = ahome.findByPrimaryKey("a2");
737         ARemote a3 = ahome.findByPrimaryKey("a3");
738         Collection JavaDoc col;
739         Collection JavaDoc b;
740         Collection JavaDoc a1bsave = a1.retrieveB();
741         Collection JavaDoc a2bsave = a2.retrieveB();
742         Collection JavaDoc a3bsave = a3.retrieveB();
743
744         //_testBasicSetRemove(TX_CALL);
745
utx.begin();
746         a2.removeFromB("b2");
747         utx.commit();
748         // checking
749
col = new ArrayList JavaDoc(2);
750         col.add("b1");
751         col.add("b3");
752         assertTrue("Wrong test of coherence Remove before commit: ", isCollectionEqual(a2.retrieveB(), col));
753         // undo
754
a2.assignB(a2bsave);
755
756         //_testBasicClear(TX_RB);
757
utx.begin();
758         a2.clearB();
759         utx.rollback();
760
761         //_testCohRemove(TX_NO);
762
bhome.remove("b2");
763         // check a1
764
col = new ArrayList JavaDoc(1);
765         col.add("b1");
766         b = a1.retrieveB();
767         assertTrue("Wrong relation a1 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
768         // check a2
769
col = new ArrayList JavaDoc(2);
770         col.add("b1");
771         col.add("b3");
772         b = a2.retrieveB();
773         assertTrue("Wrong relation a2 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
774         // check a3
775
col = new ArrayList JavaDoc(2);
776         col.add("b3");
777         col.add("b4");
778         b = a3.retrieveB();
779         assertTrue("Wrong relation a3 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
780         // undo
781
bhome.create("b2");
782         a1.assignB(a1bsave);
783         a2.assignB(a2bsave);
784         a3.assignB(a3bsave);
785         checkIsInitialState();
786     }
787
788     public void testRemoves3() throws Exception JavaDoc {
789         ARemote a1 = ahome.findByPrimaryKey("a1");
790         ARemote a2 = ahome.findByPrimaryKey("a2");
791         ARemote a3 = ahome.findByPrimaryKey("a3");
792         Collection JavaDoc col;
793         Collection JavaDoc b;
794         Collection JavaDoc a1bsave = a1.retrieveB();
795         Collection JavaDoc a2bsave = a2.retrieveB();
796         Collection JavaDoc a3bsave = a3.retrieveB();
797
798         //_testBasicSetRemove(TX_CALL);
799
utx.begin();
800         a2.removeFromB("b2");
801         utx.commit();
802         // checking
803
col = new ArrayList JavaDoc(2);
804         col.add("b1");
805         col.add("b3");
806         assertTrue("Wrong test of coherence Remove before commit: ", isCollectionEqual(a2.retrieveB(), col));
807         // undo
808
a2.assignB(a2bsave);
809
810         //_testBasicClear(TX_CALL);
811
utx.begin();
812         a2.clearB();
813         utx.commit();
814         // checking
815
b = a2.retrieveB();
816         assertTrue("Wrong relations a2 (required: Empty, found:" + b + ")", b.isEmpty());
817         // undo
818
a2.assignB(a2bsave);
819
820         //_testCohRemove(TX_NO);
821
bhome.remove("b2");
822         // check a1
823
col = new ArrayList JavaDoc(1);
824         col.add("b1");
825         b = a1.retrieveB();
826         assertTrue("Wrong relation a1 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
827         // check a2
828
col = new ArrayList JavaDoc(2);
829         col.add("b1");
830         col.add("b3");
831         b = a2.retrieveB();
832         assertTrue("Wrong relation a2 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
833         // check a3
834
col = new ArrayList JavaDoc(2);
835         col.add("b3");
836         col.add("b4");
837         b = a3.retrieveB();
838         assertTrue("Wrong relation a3 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
839         // undo
840
bhome.create("b2");
841         a1.assignB(a1bsave);
842         a2.assignB(a2bsave);
843         a3.assignB(a3bsave);
844         checkIsInitialState();
845     }
846
847     public void testRemoves4() throws Exception JavaDoc {
848         ARemote a1 = ahome.findByPrimaryKey("a1");
849         ARemote a2 = ahome.findByPrimaryKey("a2");
850         // ARemote a3 = ahome.findByPrimaryKey("a3");
851
Collection JavaDoc col;
852         Collection JavaDoc b;
853         // Collection a1bsave = a1.retrieveB();
854
Collection JavaDoc a2bsave = a2.retrieveB();
855         // Collection a3bsave = a3.retrieveB();
856

857         //_testBasicClear(TX_RB);
858
utx.begin();
859         a2.clearB();
860         utx.rollback();
861         // check a2
862
// col = new ArrayList(2);
863
// col.add("b1");
864
// col.add("b2");
865
// col.add("b3");
866
// b = a2.retrieveB();
867
// assertTrue("Wrong relation a2 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
868

869         //_testCohRemove(TX_NO);
870
bhome.remove("b2");
871         // check a1
872
col = new ArrayList JavaDoc(1);
873         col.add("b1");
874         b = a1.retrieveB();
875         assertTrue("Wrong relation a1 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
876         /*
877         // check a2
878         col = new ArrayList(2);
879         col.add("b1");
880         col.add("b3");
881         b = a2.retrieveB();
882         assertTrue("Wrong relation a2 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
883         // check a3
884         col = new ArrayList(2);
885         col.add("b3");
886         col.add("b4");
887         b = a3.retrieveB();
888         assertTrue("Wrong relation a3 : Expected " + col + ", found " + b, isCollectionEqual(b, col));
889         // undo
890         bhome.create("b2");
891         a1.assignB(a1bsave);
892         a2.assignB(a2bsave);
893         a3.assignB(a3bsave);
894         checkIsInitialState();
895         */

896     }
897
898     public static Test suite() {
899         return new TestSuite(F_Relation_mnuEC2.class);
900     }
901
902     public static void main(String JavaDoc args[]) {
903         String JavaDoc testtorun = null;
904         // Get args
905
for (int argn = 0; argn < args.length; argn++) {
906             String JavaDoc s_arg = args[argn];
907             Integer JavaDoc i_arg;
908             if (s_arg.equals("-n")) {
909                 testtorun = args[++argn];
910             }
911         }
912         if (testtorun == null) {
913             junit.textui.TestRunner.run(suite());
914         } else {
915             junit.textui.TestRunner.run(new F_Relation_mnuEC2(testtorun));
916         }
917     }
918
919 }
920
Popular Tags