Source Code Cross Referenced for A_mnu.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » clients » entity » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.jtests.clients.entity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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_mnu.java 10108 2007-03-28 09:21:26Z durieuxp $
023:         * --------------------------------------------------------------------------
024:         */
025:
026:        package org.objectweb.jonas.jtests.clients.entity;
027:
028:        import java.util.ArrayList;
029:        import java.util.Collection;
030:        import java.util.Enumeration;
031:        import java.util.Hashtable;
032:
033:        import javax.naming.NamingException;
034:        import javax.rmi.PortableRemoteObject;
035:
036:        import junit.framework.Test;
037:        import junit.framework.TestSuite;
038:
039:        import org.objectweb.jonas.jtests.beans.relation.mnu.AHomeRemote;
040:        import org.objectweb.jonas.jtests.beans.relation.mnu.ARemote;
041:        import org.objectweb.jonas.jtests.beans.relation.mnu.BHomeRemote;
042:        import org.objectweb.jonas.jtests.beans.relation.mnu.BRemote;
043:
044:        /**
045:         * For testing many-to-many unidirectional relationships
046:         * @author Ph Durieux
047:         **/
048:        public abstract class A_mnu extends A_Cmp2Util {
049:
050:            public abstract AHomeRemote getAHome();
051:
052:            public abstract BHomeRemote getBHome();
053:
054:            /**
055:             * predefined relations between a and b beans
056:             */
057:            static Hashtable tbRelationA2B = new Hashtable();
058:            static {
059:                tbRelationA2B.put("a0", new String[] {});
060:                tbRelationA2B.put("a1", new String[] { "b1", "b2" });
061:                tbRelationA2B.put("a2", new String[] { "b1", "b2", "b3" });
062:                tbRelationA2B.put("a3", new String[] { "b2", "b3", "b4" });
063:                // Translate the String[] to a Collection of String
064:                for (Enumeration ea = tbRelationA2B.keys(); ea
065:                        .hasMoreElements();) {
066:                    String aname = (String) (ea.nextElement());
067:                    String[] tb = (String[]) tbRelationA2B.get(aname);
068:                    ArrayList col = new ArrayList(tb.length);
069:                    for (int i = 0; i < tb.length; i++) {
070:                        col.add(tb[i]);
071:                    }
072:                    tbRelationA2B.put(aname, col);
073:                }
074:            }
075:
076:            public A_mnu(String name) {
077:                super (name);
078:            }
079:
080:            protected boolean isInit = false;
081:
082:            protected void setUp() {
083:                super .setUp();
084:                boolean ok = false;
085:                int nbtry = 0;
086:                while (!ok && nbtry < 3) {
087:                    if (!isInit) {
088:                        // load bean if not loaded yet
089:                        useBeans("mnu", false);
090:                        // check if tables have been initialized
091:                        try {
092:                            getAHome().findByPrimaryKey("a0");
093:                        } catch (Exception e) {
094:                            try {
095:                                utx.begin();
096:                                ARemote a0 = getAHome().create("a0");
097:                                ARemote a1 = getAHome().create("a1");
098:                                ARemote a2 = getAHome().create("a2");
099:                                ARemote a3 = getAHome().create("a3");
100:                                getBHome().create("b0");
101:                                getBHome().create("b1");
102:                                getBHome().create("b2");
103:                                getBHome().create("b3");
104:                                getBHome().create("b4");
105:                                a0
106:                                        .assignB((Collection) tbRelationA2B
107:                                                .get("a0"));
108:                                a1
109:                                        .assignB((Collection) tbRelationA2B
110:                                                .get("a1"));
111:                                a2
112:                                        .assignB((Collection) tbRelationA2B
113:                                                .get("a2"));
114:                                a3
115:                                        .assignB((Collection) tbRelationA2B
116:                                                .get("a3"));
117:                            } catch (Exception i) {
118:                                fail("InitialState creation problem: " + i);
119:                            } finally {
120:                                try {
121:                                    utx.commit();
122:                                } catch (Exception ii) {
123:                                }
124:                            }
125:                        }
126:                        isInit = true;
127:                    }
128:                    // Check that all is OK. Sometimes, a test has failed and has corrupted
129:                    // the bean state in the database. We must unload and reload the bean then.
130:                    nbtry++;
131:                    try {
132:                        if (initStateOK()) {
133:                            ok = true;
134:                        }
135:                    } catch (Exception e) {
136:                    }
137:                    if (!ok) {
138:                        isInit = false;
139:                        unloadBeans("mnu");
140:                    }
141:                }
142:            }
143:
144:            /*
145:             * Check that we are in the same state as after the tables creation for thoses beans A and B
146:             * (ie if it is the initial state)
147:             */
148:            boolean initStateOK() throws Exception {
149:                boolean isOk = true;
150:                msgerror = new StringBuffer();
151:                for (Enumeration ea = tbRelationA2B.keys(); ea
152:                        .hasMoreElements();) {
153:                    String aname = (String) (ea.nextElement());
154:                    ARemote a = getAHome().findByPrimaryKey(aname);
155:                    Collection colActual = a.retrieveB();
156:                    ArrayList colExpected = (ArrayList) (tbRelationA2B
157:                            .get(aname));
158:                    if (!isCollectionEqual(colExpected, colActual)) {
159:                        isOk = false;
160:                        msgerror = msgerror.append("Wrong relation for "
161:                                + aname + " (expected:" + colExpected
162:                                + ", found:" + colActual + ")");
163:                    }
164:                }
165:                return isOk;
166:            }
167:
168:            /**
169:             * Check that the bean 'a3' has no relation.
170:             */
171:            public void _testBasicGetEmpty(int tx) throws Exception {
172:                Collection c;
173:                if ((tx == TX_CALL) || (tx == TX_RB)) {
174:                    utx.begin();
175:                }
176:                ARemote a = getAHome().findByPrimaryKey("a0");
177:                if (tx == TX_CONT) {
178:                    c = a.retrieveBInNewTx();
179:                } else {
180:                    c = a.retrieveB();
181:                }
182:                if (tx == TX_CALL) {
183:                    utx.commit();
184:                } else if (tx == TX_RB) {
185:                    utx.rollback();
186:                }
187:
188:                checkIsInitialState();
189:            }
190:
191:            public void testBasicGetEmptyTxNo() throws Exception {
192:                _testBasicGetEmpty(TX_NO);
193:            }
194:
195:            public void testBasicGetEmptyTxCall() throws Exception {
196:                _testBasicGetEmpty(TX_CALL);
197:            }
198:
199:            public void testBasicGetEmptyTxCont() throws Exception {
200:                _testBasicGetEmpty(TX_CONT);
201:            }
202:
203:            /**
204:             * Ckeck the new relation a0-b0
205:             */
206:            public void _testBasicSetEmpty(int tx) throws Exception {
207:                ArrayList c = new ArrayList(1);
208:                c.add("b0");
209:                if ((tx == TX_CALL) || (tx == TX_RB)) {
210:                    utx.begin();
211:                }
212:                ARemote a = getAHome().findByPrimaryKey("a0");
213:                if (tx == TX_CONT) {
214:                    a.assignBInNewTx(c);
215:                } else {
216:                    a.assignB(c);
217:                }
218:                if (tx == TX_CALL) {
219:                    utx.commit();
220:                } else if (tx == TX_RB) {
221:                    utx.rollback();
222:                }
223:                // checking
224:                Collection c_value = a.retrieveB();
225:                if (tx != TX_RB) {
226:                    assertTrue("Wrong relations a0 (required:" + c + ", found:"
227:                            + c_value + ")", isCollectionEqual(c_value, c));
228:                    // undo
229:                    a.assignB(new ArrayList(0));
230:                }
231:                checkIsInitialState();
232:
233:            }
234:
235:            public void testBasicSetEmptyTxNo() throws Exception {
236:                _testBasicSetEmpty(TX_NO);
237:            }
238:
239:            public void testBasicSetEmptyTxCall() throws Exception {
240:                _testBasicSetEmpty(TX_CALL);
241:            }
242:
243:            public void testBasicSetEmptyTxCont() throws Exception {
244:                _testBasicSetEmpty(TX_CONT);
245:            }
246:
247:            public void testBasicSetEmptyTxRb() throws Exception {
248:                _testBasicSetEmpty(TX_RB);
249:            }
250:
251:            /**
252:             * See 10.3.7.7 of spec  : a1.assignB(a3.retrieveB()) =>
253:             *   a1.retreiveB().contains("b2") &&
254:             *   a1.retreiveB().contains("b3") &&
255:             *   a1.retreiveB().contains("b4") &&
256:             *   a3.retreiveB().contains("b2") &&
257:             *   a3.retreiveB().contains("b3") &&
258:             *   a3.retreiveB().contains("b4") &&
259:             */
260:            public void _testBasicSetFirst(int tx) throws Exception {
261:                String c = null;
262:                if ((tx == TX_CALL) || (tx == TX_RB)) {
263:                    utx.begin();
264:                }
265:                ARemote a1 = getAHome().findByPrimaryKey("a1");
266:                ARemote a3 = getAHome().findByPrimaryKey("a3");
267:                Collection c1 = a1.retrieveB();
268:                if (tx == TX_CONT) {
269:                    a1.assignBInNewTx(a3.retrieveB());
270:                } else {
271:                    a1.assignB(a3.retrieveB());
272:                }
273:                if (tx == TX_CALL) {
274:                    utx.commit();
275:                } else if (tx == TX_RB) {
276:                    utx.rollback();
277:                }
278:                // checking
279:                if (tx != TX_RB) {
280:                    ArrayList c1_att = new ArrayList(3);
281:                    c1_att.add("b2");
282:                    c1_att.add("b3");
283:                    c1_att.add("b4");
284:                    assertTrue("Wrong test of coherence First before commit: ",
285:                            isCollectionEqual(a1.retrieveB(), c1_att));
286:                } else {
287:                    assertTrue(
288:                            "Wrong test of coherence First before roolback: ",
289:                            isCollectionEqual(a1.retrieveB(), c1));
290:                }
291:                // undo
292:                if (tx != TX_RB) {
293:                    a1.assignB(null);
294:                    a1.assignB(c1);
295:                }
296:                checkIsInitialState();
297:            }
298:
299:            public void testBasicSetFirstTxNo() throws Exception {
300:                _testBasicSetFirst(TX_NO);
301:            }
302:
303:            public void testBasicSetFirstTxCall() throws Exception {
304:                _testBasicSetFirst(TX_CALL);
305:            }
306:
307:            public void testBasicSetFirstTxCont() throws Exception {
308:                _testBasicSetFirst(TX_CONT);
309:            }
310:
311:            public void testBasicSetFirstTxRb() throws Exception {
312:                _testBasicSetFirst(TX_RB);
313:            }
314:
315:            /**
316:             * See  10.3.7.7 of spec : a1.getB().add(b3) =>
317:             *   a1.retreiveB().contains("b1") &&
318:             *   a1.retreiveB().contains("b2") &&
319:             *   a1.retreiveB().contains("b3") &&
320:             */
321:            public void _testBasicSetSecond(int tx) throws Exception {
322:                String c = null;
323:
324:                if ((tx == TX_CALL) || (tx == TX_RB)) {
325:                    utx.begin();
326:                }
327:                ARemote a1 = getAHome().findByPrimaryKey("a1");
328:                Collection c1 = a1.retrieveB();
329:
330:                if (tx == TX_CONT) {
331:                    a1.addInB("b3");
332:                } else {
333:                    a1.addInB("b3");
334:                }
335:                if (tx == TX_CALL) {
336:                    utx.commit();
337:                } else if (tx == TX_RB) {
338:                    utx.rollback();
339:                }
340:                // checking
341:                if (tx != TX_RB) {
342:                    ArrayList c1_att = new ArrayList(3);
343:                    c1_att.add("b1");
344:                    c1_att.add("b2");
345:                    c1_att.add("b3");
346:                    assertTrue(
347:                            "Wrong test of coherence Second before commit: ",
348:                            isCollectionEqual(a1.retrieveB(), c1_att));
349:                } else {
350:                    assertTrue(
351:                            "Wrong test of coherence Second before roolback: ",
352:                            isCollectionEqual(a1.retrieveB(), c1));
353:                }
354:                // undo
355:                if (tx != TX_RB) {
356:                    a1.assignB(null);
357:                    a1.assignB(c1);
358:                }
359:                checkIsInitialState();
360:            }
361:
362:            public void testBasicSetSecondTxNo() throws Exception {
363:                _testBasicSetSecond(TX_NO);
364:            }
365:
366:            public void testBasicSetSecondTxCall() throws Exception {
367:                _testBasicSetSecond(TX_CALL);
368:            }
369:
370:            public void testBasicSetSecondTxCont() throws Exception {
371:                _testBasicSetSecond(TX_CONT);
372:            }
373:
374:            public void testBasicSetSecondTxRb() throws Exception {
375:                _testBasicSetSecond(TX_RB);
376:            }
377:
378:            /**
379:             * See  10.3.7.7 of spec : a2.getB().remove(b2) =>
380:             *   a2.retreiveB().contains("b1") &&
381:             *   a2.retreiveB().contains("b3") &&
382:             */
383:            public void _testBasicSetRemove(int tx) throws Exception {
384:                String c = null;
385:
386:                if ((tx == TX_CALL) || (tx == TX_RB)) {
387:                    utx.begin();
388:                }
389:                ARemote a2 = getAHome().findByPrimaryKey("a2");
390:                Collection c2 = a2.retrieveB();
391:                if (tx == TX_CONT) {
392:                    a2.removeFromB("b2");
393:                } else {
394:                    a2.removeFromB("b2");
395:                }
396:                if (tx == TX_CALL) {
397:                    utx.commit();
398:                } else if (tx == TX_RB) {
399:                    utx.rollback();
400:                }
401:                // checking
402:                if (tx != TX_RB) {
403:                    ArrayList c2_att = new ArrayList(3);
404:                    c2_att.add("b1");
405:                    c2_att.add("b3");
406:                    assertTrue(
407:                            "Wrong test of coherence Remove before commit: ",
408:                            isCollectionEqual(a2.retrieveB(), c2_att));
409:                } else {
410:                    assertTrue(
411:                            "Wrong test of coherence Remove before roolback: ",
412:                            isCollectionEqual(a2.retrieveB(), c2));
413:                }
414:                // undo
415:                if (tx != TX_RB) {
416:                    a2.assignB(c2);
417:                }
418:                checkIsInitialState();
419:            }
420:
421:            public void testBasicSetRemoveTxNo() throws Exception {
422:                _testBasicSetRemove(TX_NO);
423:            }
424:
425:            public void testBasicSetRemoveTxCall() throws Exception {
426:                _testBasicSetRemove(TX_CALL);
427:            }
428:
429:            public void testBasicSetRemoveTxCont() throws Exception {
430:                _testBasicSetRemove(TX_CONT);
431:            }
432:
433:            public void testBasicSetRemoveTxRb() throws Exception {
434:                _testBasicSetRemove(TX_RB);
435:            }
436:
437:            /**
438:             * Ckeck clear function
439:             */
440:            public void _testBasicClear(int tx) throws Exception {
441:                if ((tx == TX_CALL) || (tx == TX_RB)) {
442:                    utx.begin();
443:                }
444:                ARemote a2 = getAHome().findByPrimaryKey("a2");
445:                if (tx == TX_CONT) {
446:                    a2.clearBInNewTx();
447:                } else {
448:                    a2.clearB();
449:                }
450:                if (tx == TX_CALL) {
451:                    utx.commit();
452:                } else if (tx == TX_RB) {
453:                    utx.rollback();
454:                }
455:                // checking
456:                Collection a2_value = a2.retrieveB();
457:                if (tx != TX_RB) {
458:                    assertTrue("Wrong relations a2 (required: Empty, found:"
459:                            + a2_value + ")", a2_value.isEmpty());
460:
461:                    // undo
462:                    ArrayList a2undo = new ArrayList(3);
463:                    a2undo.add("b1");
464:                    a2undo.add("b2");
465:                    a2undo.add("b3");
466:                    a2.assignB(a2undo);
467:                }
468:                checkIsInitialState();
469:            }
470:
471:            public void testBasicClearTxNo() throws Exception {
472:                _testBasicClear(TX_NO);
473:            }
474:
475:            public void testBasicClearTxCall() throws Exception {
476:                _testBasicClear(TX_CALL);
477:            }
478:
479:            public void testBasicClearTxCont() throws Exception {
480:                _testBasicClear(TX_CONT);
481:            }
482:
483:            public void testBasicClearTxRb() throws Exception {
484:                _testBasicClear(TX_RB);
485:            }
486:
487:            /**
488:             * Remove an element in a relation.
489:             */
490:            public void _testCohRemoveInRel(int tx) throws Exception {
491:                String bRemoved = "b4";
492:                if ((tx == TX_CALL) || (tx == TX_RB)) {
493:                    utx.begin();
494:                }
495:                ARemote a = getAHome().findByPrimaryKey("a3");
496:                if (tx == TX_CONT) {
497:                    a.removeFromBInNewTx(bRemoved);
498:                } else {
499:                    a.removeFromB(bRemoved);
500:                }
501:                if (tx == TX_CALL) {
502:                    utx.commit();
503:                } else if (tx == TX_RB) {
504:                    utx.rollback();
505:                }
506:                // checking
507:                Collection ca = a.retrieveB();
508:                if (tx != TX_RB) {
509:                    assertEquals("Wrong relations size for a3: ", 2, ca.size());
510:                } else {
511:                    assertEquals("Wrong relations size for a3: ", 3, ca.size());
512:                }
513:                // undo
514:                if (tx != TX_RB) {
515:                    a.addInB(bRemoved);
516:                }
517:                // check to initial state
518:                checkIsInitialState();
519:
520:            }
521:
522:            public void testCohRemoveInRelTxNo() throws Exception {
523:                _testCohRemoveInRel(TX_NO);
524:            }
525:
526:            public void testCohRemoveInRelTxCall() throws Exception {
527:                _testCohRemoveInRel(TX_CALL);
528:            }
529:
530:            public void testCohRemoveInRelTxCont() throws Exception {
531:                _testCohRemoveInRel(TX_CONT);
532:            }
533:
534:            public void testCohRemoveInRelTxRb() throws Exception {
535:                _testCohRemoveInRel(TX_RB);
536:            }
537:
538:            /**
539:             * Test of coherence b2.remove() => a1.retrieveB()=null && a2.retrieveB()=null && a3.retrieveB()=null
540:             */
541:            public void _testCohRemove(int tx) throws Exception {
542:                if (tx == TX_CONT) {
543:                    // The transaction attribute of the remove method is TX_SUPPORT,
544:                    // so the transaction cannot be initiate by the container
545:                    fail("Transaction cannot be initiate by the container for this test");
546:                }
547:                if ((tx == TX_CALL) || (tx == TX_RB)) {
548:                    utx.begin();
549:                }
550:                getBHome().remove("b2");
551:                if (tx == TX_CALL) {
552:                    utx.commit();
553:                } else if (tx == TX_RB) {
554:                    utx.rollback();
555:                }
556:                // checking
557:                ARemote a1 = getAHome().findByPrimaryKey("a1");
558:                ARemote a2 = getAHome().findByPrimaryKey("a2");
559:                ARemote a3 = getAHome().findByPrimaryKey("a3");
560:                Collection idrela1 = a1.retrieveB();
561:                Collection idrela2 = a2.retrieveB();
562:                Collection idrela3 = a3.retrieveB();
563:                ArrayList col_a1 = new ArrayList(1);
564:                col_a1.add("b1");
565:                ArrayList col_a2 = new ArrayList(2);
566:                col_a2.add("b1");
567:                col_a2.add("b3");
568:                ArrayList col_a3 = new ArrayList(2);
569:                col_a3.add("b3");
570:                col_a3.add("b4");
571:                if (tx != TX_RB) {
572:                    assertTrue("Wrong relation a1 : Expected [b1] , found "
573:                            + idrela1, isCollectionEqual(idrela1, col_a1));
574:                    assertTrue("Wrong relation a2 : Expected [b1, b3] , found "
575:                            + idrela2, isCollectionEqual(idrela2, col_a2));
576:                    assertTrue("Wrong relation a3 : Expected [b3, b4] , found "
577:                            + idrela3, isCollectionEqual(idrela3, col_a3));
578:                    // undo
579:                    getBHome().create("b2");
580:                    col_a1 = new ArrayList(2);
581:                    col_a1.add("b1");
582:                    col_a1.add("b2");
583:                    col_a2 = new ArrayList(3);
584:                    col_a2.add("b1");
585:                    col_a2.add("b2");
586:                    col_a2.add("b3");
587:                    a1.assignB(col_a1);
588:                    col_a3 = new ArrayList(3);
589:                    col_a3.add("b2");
590:                    col_a3.add("b3");
591:                    col_a3.add("b4");
592:
593:                    a1.assignB(col_a1);
594:                    a2.assignB(col_a2);
595:                    a3.assignB(col_a3);
596:                }
597:                checkIsInitialState();
598:            }
599:
600:            public void testCohRemoveTxNo() throws Exception {
601:                _testCohRemove(TX_NO);
602:            }
603:
604:            public void testCohRemoveTxCall() throws Exception {
605:                _testCohRemove(TX_CALL);
606:            }
607:
608:            public void testCohRemoveTxRb() throws Exception {
609:                _testCohRemove(TX_RB);
610:            }
611:
612:            /**
613:             * Test of coherence b2.remove() => a1.retrieveB()=null && a2.retrieveB()=null && a3.retrieveB()=null
614:             * Same as _testCohRemove except that the called remove method is on the bean
615:             * instead of the home.
616:             */
617:            public void _testCohBeanRemove(int tx) throws Exception {
618:                if (tx == TX_CONT) {
619:                    // The transaction attribute of the remove method is TX_SUPPORT,
620:                    // so the transaction cannot be initiate by the container
621:                    fail("Transaction cannot be initiate by the container for this test");
622:                }
623:                if ((tx == TX_CALL) || (tx == TX_RB)) {
624:                    utx.begin();
625:                }
626:                BRemote b = getBHome().findByPrimaryKey("b2");
627:                b.remove();
628:                if (tx == TX_CALL) {
629:                    utx.commit();
630:                } else if (tx == TX_RB) {
631:                    utx.rollback();
632:                }
633:                // checking
634:                ARemote a1 = getAHome().findByPrimaryKey("a1");
635:                ARemote a2 = getAHome().findByPrimaryKey("a2");
636:                ARemote a3 = getAHome().findByPrimaryKey("a3");
637:                Collection idrela1 = a1.retrieveB();
638:                Collection idrela2 = a2.retrieveB();
639:                Collection idrela3 = a3.retrieveB();
640:                ArrayList col_a1 = new ArrayList(1);
641:                col_a1.add("b1");
642:                ArrayList col_a2 = new ArrayList(2);
643:                col_a2.add("b1");
644:                col_a2.add("b3");
645:                ArrayList col_a3 = new ArrayList(2);
646:                col_a3.add("b3");
647:                col_a3.add("b4");
648:                if (tx != TX_RB) {
649:                    assertTrue("Wrong relation a1 : Expected [b1] , found "
650:                            + idrela1, isCollectionEqual(idrela1, col_a1));
651:                    assertTrue("Wrong relation a2 : Expected [b1, b3] , found "
652:                            + idrela2, isCollectionEqual(idrela2, col_a2));
653:                    assertTrue("Wrong relation a3 : Expected [b3, b4] , found "
654:                            + idrela3, isCollectionEqual(idrela3, col_a3));
655:                    // undo
656:                    getBHome().create("b2");
657:                    col_a1 = new ArrayList(2);
658:                    col_a1.add("b1");
659:                    col_a1.add("b2");
660:                    col_a2 = new ArrayList(3);
661:                    col_a2.add("b1");
662:                    col_a2.add("b2");
663:                    col_a2.add("b3");
664:                    a1.assignB(col_a1);
665:                    col_a3 = new ArrayList(3);
666:                    col_a3.add("b2");
667:                    col_a3.add("b3");
668:                    col_a3.add("b4");
669:
670:                    a1.assignB(col_a1);
671:                    a2.assignB(col_a2);
672:                    a3.assignB(col_a3);
673:                }
674:                checkIsInitialState();
675:            }
676:
677:            public void testCohBeanRemoveTxNo() throws Exception {
678:                _testCohBeanRemove(TX_NO);
679:            }
680:
681:            public void testCohBeanRemoveTxCall() throws Exception {
682:                _testCohBeanRemove(TX_CALL);
683:            }
684:
685:            public void testCohBeanRemoveTxRb() throws Exception {
686:                _testCohBeanRemove(TX_RB);
687:            }
688:
689:            /**
690:             * These several tests linked fails on Oracle (testCohBeanRemoveTxCall)
691:             */
692:            public void testRemoveSeries() throws Exception {
693:
694:                testBasicSetRemoveTxCall();
695:                testBasicClearTxCall();
696:                testBasicClearTxRb();
697:                testCohRemoveTxNo();
698:                testCohRemoveTxCall();
699:            }
700:
701:            public void testRemoves1() throws Exception {
702:                ARemote a1 = getAHome().findByPrimaryKey("a1");
703:                ARemote a2 = getAHome().findByPrimaryKey("a2");
704:                ARemote a3 = getAHome().findByPrimaryKey("a3");
705:                Collection col;
706:                Collection b;
707:                Collection a1bsave = a1.retrieveB();
708:                Collection a2bsave = a2.retrieveB();
709:                Collection a3bsave = a3.retrieveB();
710:
711:                //_testBasicSetRemove(TX_CALL);
712:                utx.begin();
713:                a2.removeFromB("b2");
714:                utx.commit();
715:                // checking
716:                col = new ArrayList(2);
717:                col.add("b1");
718:                col.add("b3");
719:                assertTrue("Wrong test of coherence Remove before commit: ",
720:                        isCollectionEqual(a2.retrieveB(), col));
721:                // undo
722:                a2.assignB(a2bsave);
723:
724:                //_testBasicClear(TX_CALL);
725:                utx.begin();
726:                a2.clearB();
727:                utx.commit();
728:                // checking
729:                b = a2.retrieveB();
730:                assertTrue("Wrong relations a2 (required: Empty, found:" + b
731:                        + ")", b.isEmpty());
732:                // undo
733:                a2.assignB(a2bsave);
734:
735:                //_testBasicClear(TX_RB);
736:                utx.begin();
737:                a2.clearB();
738:                utx.rollback();
739:
740:                //_testCohRemove(TX_NO);
741:                getBHome().remove("b2");
742:                // check a1
743:                col = new ArrayList(1);
744:                col.add("b1");
745:                b = a1.retrieveB();
746:                assertTrue("Wrong relation a1 : Expected " + col + ", found "
747:                        + b, isCollectionEqual(b, col));
748:                // check a2
749:                col = new ArrayList(2);
750:                col.add("b1");
751:                col.add("b3");
752:                b = a2.retrieveB();
753:                assertTrue("Wrong relation a2 : Expected " + col + ", found "
754:                        + b, isCollectionEqual(b, col));
755:                // check a3
756:                col = new ArrayList(2);
757:                col.add("b3");
758:                col.add("b4");
759:                b = a3.retrieveB();
760:                assertTrue("Wrong relation a3 : Expected " + col + ", found "
761:                        + b, isCollectionEqual(b, col));
762:                // undo
763:                getBHome().create("b2");
764:                a1.assignB(a1bsave);
765:                a2.assignB(a2bsave);
766:                a3.assignB(a3bsave);
767:                checkIsInitialState();
768:            }
769:
770:            public void testRemoves2() throws Exception {
771:                ARemote a1 = getAHome().findByPrimaryKey("a1");
772:                ARemote a2 = getAHome().findByPrimaryKey("a2");
773:                ARemote a3 = getAHome().findByPrimaryKey("a3");
774:                Collection col;
775:                Collection b;
776:                Collection a1bsave = a1.retrieveB();
777:                Collection a2bsave = a2.retrieveB();
778:                Collection a3bsave = a3.retrieveB();
779:
780:                //_testBasicSetRemove(TX_CALL);
781:                utx.begin();
782:                a2.removeFromB("b2");
783:                utx.commit();
784:                // checking
785:                col = new ArrayList(2);
786:                col.add("b1");
787:                col.add("b3");
788:                assertTrue("Wrong test of coherence Remove before commit: ",
789:                        isCollectionEqual(a2.retrieveB(), col));
790:                // undo
791:                a2.assignB(a2bsave);
792:
793:                //_testBasicClear(TX_RB);
794:                utx.begin();
795:                a2.clearB();
796:                utx.rollback();
797:
798:                //_testCohRemove(TX_NO);
799:                getBHome().remove("b2");
800:                // check a1
801:                col = new ArrayList(1);
802:                col.add("b1");
803:                b = a1.retrieveB();
804:                assertTrue("Wrong relation a1 : Expected " + col + ", found "
805:                        + b, isCollectionEqual(b, col));
806:                // check a2
807:                col = new ArrayList(2);
808:                col.add("b1");
809:                col.add("b3");
810:                b = a2.retrieveB();
811:                assertTrue("Wrong relation a2 : Expected " + col + ", found "
812:                        + b, isCollectionEqual(b, col));
813:                // check a3
814:                col = new ArrayList(2);
815:                col.add("b3");
816:                col.add("b4");
817:                b = a3.retrieveB();
818:                assertTrue("Wrong relation a3 : Expected " + col + ", found "
819:                        + b, isCollectionEqual(b, col));
820:                // undo
821:                getBHome().create("b2");
822:                a1.assignB(a1bsave);
823:                a2.assignB(a2bsave);
824:                a3.assignB(a3bsave);
825:                checkIsInitialState();
826:            }
827:
828:            public void testRemoves3() throws Exception {
829:                ARemote a1 = getAHome().findByPrimaryKey("a1");
830:                ARemote a2 = getAHome().findByPrimaryKey("a2");
831:                ARemote a3 = getAHome().findByPrimaryKey("a3");
832:                Collection col;
833:                Collection b;
834:                Collection a1bsave = a1.retrieveB();
835:                Collection a2bsave = a2.retrieveB();
836:                Collection a3bsave = a3.retrieveB();
837:
838:                //_testBasicSetRemove(TX_CALL);
839:                utx.begin();
840:                a2.removeFromB("b2");
841:                utx.commit();
842:                // checking
843:                col = new ArrayList(2);
844:                col.add("b1");
845:                col.add("b3");
846:                assertTrue("Wrong test of coherence Remove before commit: ",
847:                        isCollectionEqual(a2.retrieveB(), col));
848:                // undo
849:                a2.assignB(a2bsave);
850:
851:                //_testBasicClear(TX_CALL);
852:                utx.begin();
853:                a2.clearB();
854:                utx.commit();
855:                // checking
856:                b = a2.retrieveB();
857:                assertTrue("Wrong relations a2 (required: Empty, found:" + b
858:                        + ")", b.isEmpty());
859:                // undo
860:                a2.assignB(a2bsave);
861:
862:                //_testCohRemove(TX_NO);
863:                getBHome().remove("b2");
864:                // check a1
865:                col = new ArrayList(1);
866:                col.add("b1");
867:                b = a1.retrieveB();
868:                assertTrue("Wrong relation a1 : Expected " + col + ", found "
869:                        + b, isCollectionEqual(b, col));
870:                // check a2
871:                col = new ArrayList(2);
872:                col.add("b1");
873:                col.add("b3");
874:                b = a2.retrieveB();
875:                assertTrue("Wrong relation a2 : Expected " + col + ", found "
876:                        + b, isCollectionEqual(b, col));
877:                // check a3
878:                col = new ArrayList(2);
879:                col.add("b3");
880:                col.add("b4");
881:                b = a3.retrieveB();
882:                assertTrue("Wrong relation a3 : Expected " + col + ", found "
883:                        + b, isCollectionEqual(b, col));
884:                // undo
885:                getBHome().create("b2");
886:                a1.assignB(a1bsave);
887:                a2.assignB(a2bsave);
888:                a3.assignB(a3bsave);
889:                checkIsInitialState();
890:            }
891:
892:            public void testRemoves4() throws Exception {
893:                ARemote a1 = getAHome().findByPrimaryKey("a1");
894:                ARemote a2 = getAHome().findByPrimaryKey("a2");
895:                ARemote a3 = getAHome().findByPrimaryKey("a3");
896:                Collection col;
897:                Collection b;
898:                Collection a1bsave = a1.retrieveB();
899:                Collection a2bsave = a2.retrieveB();
900:                Collection a3bsave = a3.retrieveB();
901:
902:                //_testBasicClear(TX_RB);
903:                utx.begin();
904:                a2.clearB();
905:                utx.rollback();
906:                // check a2
907:                col = new ArrayList(2);
908:                col.add("b1");
909:                col.add("b2");
910:                col.add("b3");
911:                b = a2.retrieveB();
912:                assertTrue("Wrong relation a2 : Expected " + col + ", found "
913:                        + b, isCollectionEqual(b, col));
914:
915:                getBHome().remove("b2");
916:                // check a1
917:                col = new ArrayList(1);
918:                col.add("b1");
919:                b = a1.retrieveB();
920:                assertTrue("Wrong relation a1 : Expected " + col + ", found "
921:                        + b, isCollectionEqual(b, col));
922:
923:                // check a2
924:                col = new ArrayList(2);
925:                col.add("b1");
926:                col.add("b3");
927:                b = a2.retrieveB();
928:                assertTrue("Wrong relation a2 : Expected " + col + ", found "
929:                        + b, isCollectionEqual(b, col));
930:                // check a3
931:                col = new ArrayList(2);
932:                col.add("b3");
933:                col.add("b4");
934:                b = a3.retrieveB();
935:                assertTrue("Wrong relation a3 : Expected " + col + ", found "
936:                        + b, isCollectionEqual(b, col));
937:                // undo
938:                getBHome().create("b2");
939:                a1.assignB(a1bsave);
940:                a2.assignB(a2bsave);
941:                a3.assignB(a3bsave);
942:                checkIsInitialState();
943:            }
944:
945:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.