Source Code Cross Referenced for A_omb.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) 


0001:        /*
0002:         * JOnAS: Java(TM) Open Application Server
0003:         * Copyright (C) 1999 Bull S.A.
0004:         * Contact: jonas-team@objectweb.org
0005:         *
0006:         * This library is free software; you can redistribute it and/or
0007:         * modify it under the terms of the GNU Lesser General Public
0008:         * License as published by the Free Software Foundation; either
0009:         * version 2.1 of the License, or any later version.
0010:         *
0011:         * This library is distributed in the hope that it will be useful,
0012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014:         * Lesser General Public License for more details.
0015:         *
0016:         * You should have received a copy of the GNU Lesser General Public
0017:         * License along with this library; if not, write to the Free Software
0018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
0019:         * USA
0020:         *
0021:         * --------------------------------------------------------------------------
0022:         * $Id: A_omb.java 10108 2007-03-28 09:21:26Z durieuxp $
0023:         * --------------------------------------------------------------------------
0024:         */
0025:
0026:        package org.objectweb.jonas.jtests.clients.entity;
0027:
0028:        import java.util.ArrayList;
0029:        import java.util.Collection;
0030:        import java.util.Enumeration;
0031:        import java.util.Hashtable;
0032:        import java.util.Iterator;
0033:
0034:        import javax.naming.NamingException;
0035:        import javax.rmi.PortableRemoteObject;
0036:
0037:        import junit.framework.Test;
0038:        import junit.framework.TestSuite;
0039:
0040:        import org.objectweb.jonas.jtests.beans.relation.omb.AHomeRemote;
0041:        import org.objectweb.jonas.jtests.beans.relation.omb.ARemote;
0042:        import org.objectweb.jonas.jtests.beans.relation.omb.BHomeRemote;
0043:        import org.objectweb.jonas.jtests.beans.relation.omb.BRemote;
0044:        import org.objectweb.jonas.jtests.beans.relation.omb.Front;
0045:        import org.objectweb.jonas.jtests.beans.relation.omb.FrontHome;
0046:
0047:        /**
0048:         * For testing one-to-many bidirectional relationships
0049:         * @author Ph. Durieux
0050:         */
0051:        public abstract class A_omb extends A_Cmp2Util {
0052:
0053:            public abstract AHomeRemote getAHome();
0054:
0055:            public abstract BHomeRemote getBHome();
0056:
0057:            protected static String BEAN_HOME_FRONT = "relation_omb_FrontHome";
0058:            protected static FrontHome fhome = null;
0059:
0060:            static Hashtable a2b = new Hashtable();
0061:            static String[][] b2a = { { "bs0", null }, { "bs1_1", "as1" },
0062:                    { "bs2_1", "as2" }, { "bs2_2", "as2" }, { "bs2_3", "as2" },
0063:                    { "bs3", null }, { "b0", null }, { "b1_1", "a1" },
0064:                    { "b1_2", "a1" }, { "b1_3", "a1" }, { "b2_1", "a2" },
0065:                    { "b2_2", "a2" }, { "b2_3", "a2" }, { "b3_1", "a3" } };
0066:
0067:            static {
0068:                a2b.put("as0", new String[] {});
0069:                a2b.put("as1", new String[] { "bs1_1" });
0070:                a2b.put("as2", new String[] { "bs2_1", "bs2_2", "bs2_3" });
0071:                a2b.put("a0", new String[] {});
0072:                a2b.put("a1", new String[] { "b1_1", "b1_2", "b1_3" });
0073:                a2b.put("a2", new String[] { "b2_1", "b2_2", "b2_3" });
0074:                a2b.put("a3", new String[] { "b3_1" });
0075:                a2b.put("ax0", new String[] {});
0076:
0077:                // Translate the String[] to a Collection of String
0078:                for (Iterator it = a2b.keySet().iterator(); it.hasNext();) {
0079:                    String aname = (String) (it.next());
0080:                    String[] tb = (String[]) a2b.get(aname);
0081:                    ArrayList col = new ArrayList(tb.length);
0082:                    for (int i = 0; i < tb.length; i++) {
0083:                        col.add(tb[i]);
0084:                    }
0085:                    a2b.put(aname, col);
0086:                }
0087:            }
0088:
0089:            public A_omb(String name) {
0090:                super (name);
0091:            }
0092:
0093:            protected boolean isInit = false;
0094:
0095:            protected void setUp() {
0096:                super .setUp();
0097:                boolean ok = false;
0098:                int nbtry = 0;
0099:                while (!ok && nbtry < 3) {
0100:                    if (!isInit) {
0101:                        // load bean if not loaded yet
0102:                        useBeans("omb", false);
0103:                        try {
0104:                            fhome = (FrontHome) PortableRemoteObject.narrow(
0105:                                    ictx.lookup(BEAN_HOME_FRONT),
0106:                                    FrontHome.class);
0107:                        } catch (NamingException e) {
0108:                            fail("Cannot get bean home: " + e.getMessage());
0109:                        }
0110:                        // check if tables have been initialized
0111:                        try {
0112:                            getAHome().findByPrimaryKey("a0");
0113:                        } catch (Exception e) {
0114:                            try {
0115:                                utx.begin();
0116:                                getBHome().create("bs0");
0117:                                getBHome().create("bs1_1");
0118:                                getBHome().create("bs2_1");
0119:                                getBHome().create("bs2_2");
0120:                                getBHome().create("bs2_3");
0121:                                getBHome().create("bs3");
0122:                                getBHome().create("b0");
0123:                                getBHome().create("b1_1");
0124:                                getBHome().create("b1_2");
0125:                                getBHome().create("b1_3");
0126:                                getBHome().create("b2_1");
0127:                                getBHome().create("b2_2");
0128:                                getBHome().create("b2_3");
0129:                                getBHome().create("b3_1");
0130:                                getAHome().create("as0");
0131:                                getAHome().create("as1").assignB(
0132:                                        (Collection) a2b.get("as1"));
0133:                                getAHome().create("as2").assignB(
0134:                                        (Collection) a2b.get("as2"));
0135:                                getAHome().create("a0");
0136:                                getAHome().create("a1").assignB(
0137:                                        (Collection) a2b.get("a1"));
0138:                                getAHome().create("a2").assignB(
0139:                                        (Collection) a2b.get("a2"));
0140:                                getAHome().create("a3").assignB(
0141:                                        (Collection) a2b.get("a3"));
0142:                                getAHome().create("ax0");
0143:                            } catch (Exception i) {
0144:                                fail("InitialState creation problem: " + i);
0145:                            } finally {
0146:                                try {
0147:                                    utx.commit();
0148:                                } catch (Exception ii) {
0149:                                }
0150:                            }
0151:                        }
0152:                        isInit = true;
0153:                    }
0154:                    // Check that all is OK. Sometimes, a test has failed and has corrupted
0155:                    // the bean state in the database. We must unload and reload the bean then.
0156:                    nbtry++;
0157:                    try {
0158:                        if (initStateOK()) {
0159:                            ok = true;
0160:                        }
0161:                    } catch (Exception e) {
0162:                    }
0163:                    if (!ok) {
0164:                        isInit = false;
0165:                        unloadBeans("omb");
0166:                    }
0167:                }
0168:            }
0169:
0170:            /**
0171:             * Check that we are in the same state as after the tables creation for thoses beans A and B
0172:             * (ie if it is the initial state)
0173:             */
0174:            boolean initStateOK() throws Exception {
0175:                boolean isOk = true;
0176:                msgerror = new StringBuffer();
0177:                // Check the relations A => B
0178:                for (Enumeration ea = a2b.keys(); ea.hasMoreElements();) {
0179:                    String aname = (String) (ea.nextElement());
0180:                    ARemote a = getAHome().findByPrimaryKey(aname);
0181:                    Collection colActual = a.retrieveB();
0182:                    Collection colExpected = (Collection) (a2b.get(aname));
0183:                    if (!isCollectionEqual(colExpected, colActual)) {
0184:                        isOk = false;
0185:                        msgerror = msgerror.append("\nWrong relation for "
0186:                                + aname + " (expected:" + colExpected
0187:                                + ", found:" + colActual + ")");
0188:                    }
0189:                }
0190:                // Check the relation B => A
0191:                for (int i = 0; i < b2a.length; i++) {
0192:                    BRemote b = getBHome().findByPrimaryKey(b2a[i][0]);
0193:                    String pkb = b.getId();
0194:                    String pka = b.retrieveA();
0195:                    if (b2a[i][1] == null && pka != null || b2a[i][1] != null
0196:                            && !b2a[i][1].equals(pka)) {
0197:                        isOk = false;
0198:                        msgerror = msgerror.append("\nWrong relation for "
0199:                                + pkb + " (expected:" + b2a[i][1] + ", found:"
0200:                                + pka + ")");
0201:                    }
0202:
0203:                }
0204:                return isOk;
0205:            }
0206:
0207:            /**
0208:             * Check that the bean 'as0' has no relation.
0209:             */
0210:            public void tBasicGetEmptyA2B(int tx) throws Exception {
0211:                Collection c = null;
0212:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0213:                    utx.begin();
0214:                }
0215:                ARemote a = getAHome().findByPrimaryKey("as0");
0216:                if (tx == TX_CONT) {
0217:                    c = a.retrieveBInNewTx();
0218:                } else {
0219:                    c = a.retrieveB();
0220:                }
0221:                if (tx == TX_CALL) {
0222:                    utx.commit();
0223:                } else if (tx == TX_RB) {
0224:                    utx.rollback();
0225:                }
0226:                // checking
0227:                checkIsInitialState();
0228:            }
0229:
0230:            public void testBasicGetEmptyA2BTxNo() throws Exception {
0231:                tBasicGetEmptyA2B(TX_NO);
0232:            }
0233:
0234:            public void testBasicGetEmptyA2BTxCall() throws Exception {
0235:                tBasicGetEmptyA2B(TX_CALL);
0236:            }
0237:
0238:            public void testBasicGetEmptyA2BTxCont() throws Exception {
0239:                tBasicGetEmptyA2B(TX_CONT);
0240:            }
0241:
0242:            public void testBasicGetEmptyA2BTxRb() throws Exception {
0243:                tBasicGetEmptyA2B(TX_RB);
0244:            }
0245:
0246:            /**
0247:             * Check that the bean 'bs0' has no relation.
0248:             */
0249:            public void tBasicGetEmptyB2A(int tx) throws Exception {
0250:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0251:                    utx.begin();
0252:                }
0253:                String pka = null;
0254:                BRemote b = getBHome().findByPrimaryKey("bs0");
0255:                if (tx == TX_CONT) {
0256:                    pka = b.retrieveAInNewTx();
0257:                } else {
0258:                    pka = b.retrieveA();
0259:                }
0260:                if (tx == TX_CALL) {
0261:                    utx.commit();
0262:                } else if (tx == TX_RB) {
0263:                    utx.rollback();
0264:                }
0265:                // checking
0266:                checkIsInitialState();
0267:            }
0268:
0269:            public void testBasicGetEmptyB2ANoTx() throws Exception {
0270:                tBasicGetEmptyB2A(TX_NO);
0271:            }
0272:
0273:            public void testBasicGetEmptyB2ATxCall() throws Exception {
0274:                tBasicGetEmptyB2A(TX_CALL);
0275:            }
0276:
0277:            public void testBasicGetEmptyB2ATxCont() throws Exception {
0278:                tBasicGetEmptyB2A(TX_CONT);
0279:            }
0280:
0281:            public void testBasicGetEmptyB2ATxRb() throws Exception {
0282:                tBasicGetEmptyB2A(TX_RB);
0283:            }
0284:
0285:            /**
0286:             * Check that the bean 'as1' has only one relation with 'bs1_1'.
0287:             */
0288:            public void tBasicGetOneA2B(int tx) throws Exception {
0289:
0290:                Collection c = null;
0291:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0292:                    utx.begin();
0293:                }
0294:                ARemote a = getAHome().findByPrimaryKey("as1");
0295:                if (tx == TX_CONT) {
0296:                    c = a.retrieveBInNewTx();
0297:                } else {
0298:                    c = a.retrieveB();
0299:                }
0300:                if (tx == TX_CALL) {
0301:                    utx.commit();
0302:                } else if (tx == TX_RB) {
0303:                    utx.rollback();
0304:                }
0305:                // checking
0306:                assertEquals("Relations size of: ", 1, c.size());
0307:                String s = "bs1_1";
0308:                assertTrue("Relation missing " + s + ": ", c.contains(s));
0309:                checkIsInitialState();
0310:            }
0311:
0312:            public void testBasicGetOneA2BTxNo() throws Exception {
0313:                tBasicGetOneA2B(TX_NO);
0314:            }
0315:
0316:            public void testBasicGetOneA2BTxCall() throws Exception {
0317:                tBasicGetOneA2B(TX_CALL);
0318:            }
0319:
0320:            public void testBasicGetOneA2BTxCont() throws Exception {
0321:                tBasicGetOneA2B(TX_CONT);
0322:            }
0323:
0324:            public void testBasicGetOneA2BTxRb() throws Exception {
0325:                tBasicGetOneA2B(TX_RB);
0326:            }
0327:
0328:            /**
0329:             * Check that the bean 'as2' has many relations with 'bs2_1', 'bs2_2', 'bs2_3'.
0330:             */
0331:            public void tBasicGetManyA2B(int tx) throws Exception {
0332:
0333:                Collection c = null;
0334:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0335:                    utx.begin();
0336:                }
0337:                ARemote a = getAHome().findByPrimaryKey("as2");
0338:                if (tx == TX_CONT) {
0339:                    c = a.retrieveBInNewTx();
0340:                } else {
0341:                    c = a.retrieveB();
0342:                }
0343:                if (tx == TX_CALL) {
0344:                    utx.commit();
0345:                } else if (tx == TX_RB) {
0346:                    utx.rollback();
0347:                }
0348:                // checking
0349:                assertEquals("Relations size of: ", 3, c.size());
0350:                String s = "bs2_1";
0351:                assertTrue("Relation missing " + s + ": ", c.contains(s));
0352:                s = "bs2_2";
0353:                assertTrue("Relation missing " + s + ": ", c.contains(s));
0354:                s = "bs2_3";
0355:                assertTrue("Relation missing " + s + ": ", c.contains(s));
0356:                checkIsInitialState();
0357:            }
0358:
0359:            public void testBasicGetManyA2BTxNo() throws Exception {
0360:                tBasicGetManyA2B(TX_NO);
0361:            }
0362:
0363:            public void testBasicGetManyA2BTxCall() throws Exception {
0364:                tBasicGetManyA2B(TX_CALL);
0365:            }
0366:
0367:            public void testBasicGetManyA2BTxCont() throws Exception {
0368:                tBasicGetManyA2B(TX_CONT);
0369:            }
0370:
0371:            public void testBasicGetManyA2BTxRb() throws Exception {
0372:                tBasicGetManyA2B(TX_RB);
0373:            }
0374:
0375:            /**
0376:             * Set a A2B relation to empty.
0377:             * Before: as1 <-> bs1_1
0378:             * After:  as1     bs1_1
0379:             * Check also the assignement rules for relationships.
0380:             */
0381:            public void tCohSetEmptyA2B(int tx) throws Exception {
0382:                ArrayList ce = new ArrayList();
0383:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0384:                    utx.begin();
0385:                }
0386:                ARemote a = getAHome().findByPrimaryKey("as1");
0387:                if (tx == TX_CONT) {
0388:                    a.assignBInNewTx(ce);
0389:                } else {
0390:                    a.assignB(ce);
0391:                }
0392:                if (tx == TX_CALL) {
0393:                    utx.commit();
0394:                } else if (tx == TX_RB) {
0395:                    utx.rollback();
0396:                }
0397:                if (tx != TX_RB) {
0398:                    // checking
0399:                    Collection ca = a.retrieveB();
0400:                    assertEquals("Relations size for as1 ", 0, ca.size());
0401:                    BRemote b = getBHome().findByPrimaryKey("bs1_1");
0402:                    assertNull("Bad relation for bs1_1", b.retrieveA());
0403:                    // undo
0404:                    a.addInB("bs1_1");
0405:                }
0406:                checkIsInitialState();
0407:            }
0408:
0409:            public void testCohSetEmptyA2BTxNo() throws Exception {
0410:                tCohSetEmptyA2B(TX_NO);
0411:            }
0412:
0413:            public void testCohSetEmptyA2BTxCall() throws Exception {
0414:                tCohSetEmptyA2B(TX_CALL);
0415:            }
0416:
0417:            public void testCohSetEmptyA2BTxCont() throws Exception {
0418:                tCohSetEmptyA2B(TX_CONT);
0419:            }
0420:
0421:            public void testCohSetEmptyA2BTxRb() throws Exception {
0422:                tCohSetEmptyA2B(TX_RB);
0423:            }
0424:
0425:            /**
0426:             * Set a A2B relation to empty by clearing the collection.
0427:             * Before: as1 <-> bs1_1
0428:             * After:  as1     bs1_1
0429:             * Check also the assignement rules for relationships.
0430:             */
0431:            public void tCohClearA2B(int tx) throws Exception {
0432:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0433:                    utx.begin();
0434:                }
0435:                ARemote a = getAHome().findByPrimaryKey("as1");
0436:                if (tx == TX_CONT) {
0437:                    a.clearBInNewTx();
0438:                } else {
0439:                    a.clearB();
0440:                }
0441:                if (tx == TX_CALL) {
0442:                    utx.commit();
0443:                } else if (tx == TX_RB) {
0444:                    utx.rollback();
0445:                }
0446:                if (tx != TX_RB) {
0447:                    // checking
0448:                    Collection c = a.retrieveB();
0449:                    BRemote b = getBHome().findByPrimaryKey("bs1_1");
0450:                    String r = b.retrieveA();
0451:                    assertEquals(
0452:                            "Expected empty collection for as1 relation: ", 0,
0453:                            c.size());
0454:                    assertNull("Expected no relation for bs1_1", r);
0455:                    // undo
0456:                    b.assignA("as1");
0457:                }
0458:                checkIsInitialState();
0459:            }
0460:
0461:            public void testCohClearA2BTxNo() throws Exception {
0462:                tCohClearA2B(TX_NO);
0463:            }
0464:
0465:            public void testCohClearA2BTxCall() throws Exception {
0466:                tCohClearA2B(TX_CALL);
0467:            }
0468:
0469:            public void testCohClearA2BTxCont() throws Exception {
0470:                tCohClearA2B(TX_CONT);
0471:            }
0472:
0473:            public void testCohClearA2BTxRb() throws Exception {
0474:                tCohClearA2B(TX_RB);
0475:            }
0476:
0477:            /**
0478:             * Set an empty A2B relation with 1 element.
0479:             * This added element was'nt already in an other relation.
0480:             * Before: as0     b0
0481:             * After:  as0 <-> b0
0482:             * Check also the assignement rules for relationships.
0483:             */
0484:            public void tCohSetOneA2B(int tx) throws Exception {
0485:                ArrayList ce = new ArrayList();
0486:                ce.add("b0");
0487:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0488:                    utx.begin();
0489:                }
0490:                ARemote a = getAHome().findByPrimaryKey("as0");
0491:                if (tx == TX_CONT) {
0492:                    a.assignBInNewTx(ce);
0493:                } else {
0494:                    a.assignB(ce);
0495:                }
0496:                if (tx == TX_CALL) {
0497:                    utx.commit();
0498:                } else if (tx == TX_RB) {
0499:                    utx.rollback();
0500:                }
0501:                if (tx != TX_RB) {
0502:                    // checking
0503:                    Collection ca = a.retrieveB();
0504:                    BRemote b = getBHome().findByPrimaryKey("b0");
0505:                    String r = b.retrieveA();
0506:                    assertTrue("Bad relations for as0 (required:" + ce
0507:                            + ", found:" + ca + ")", isCollectionEqual(ce, ca));
0508:                    assertEquals("Bad relation for b0: ", "as0", r);
0509:                    // undo
0510:                    a.assignB(new ArrayList());
0511:                }
0512:                checkIsInitialState();
0513:            }
0514:
0515:            public void testCohSetOneA2BTxNo() throws Exception {
0516:                tCohSetOneA2B(TX_NO);
0517:            }
0518:
0519:            public void testCohSetOneA2BTxCall() throws Exception {
0520:                tCohSetOneA2B(TX_CALL);
0521:            }
0522:
0523:            public void testCohSetOneA2BTxCont() throws Exception {
0524:                tCohSetOneA2B(TX_CONT);
0525:            }
0526:
0527:            public void testCohSetOneA2BTxRb() throws Exception {
0528:                tCohSetOneA2B(TX_RB);
0529:            }
0530:
0531:            /**
0532:             * Set a null B2A relation with 1 element.
0533:             * This element was'nt already in an other relation.
0534:             * Before: b0     as0
0535:             * After:  b0 <-> as0
0536:             * Check also the assignement rules for relationships.
0537:             */
0538:            public void tCohSet1B2A(int tx) throws Exception {
0539:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0540:                    utx.begin();
0541:                }
0542:                BRemote b = getBHome().findByPrimaryKey("b0");
0543:                if (tx == TX_CONT) {
0544:                    b.assignAInNewTx("as0");
0545:                } else {
0546:                    b.assignA("as0");
0547:                }
0548:                if (tx == TX_CALL) {
0549:                    utx.commit();
0550:                } else if (tx == TX_RB) {
0551:                    utx.rollback();
0552:                }
0553:                // checking
0554:                String r = b.retrieveA();
0555:                ARemote a = getAHome().findByPrimaryKey("as0");
0556:                Collection ca = a.retrieveB();
0557:                ArrayList ce = new ArrayList();
0558:                ce.add("b0");
0559:                if (tx != TX_RB) {
0560:                    assertEquals("Bad relation for b0: ", "as0", r);
0561:                    assertTrue("Bad relations for as0 (required:" + ce
0562:                            + ", found:" + ca + ")", isCollectionEqual(ce, ca));
0563:                    // undo
0564:                    b.assignA(null);
0565:                }
0566:                checkIsInitialState();
0567:            }
0568:
0569:            public void testCohSet1B2ATxNo() throws Exception {
0570:                tCohSet1B2A(TX_NO);
0571:            }
0572:
0573:            public void testCohSet1B2ATxCall() throws Exception {
0574:                tCohSet1B2A(TX_CALL);
0575:            }
0576:
0577:            public void testCohSet1B2ATxCont() throws Exception {
0578:                tCohSet1B2A(TX_CONT);
0579:            }
0580:
0581:            public void testCohSet1B2ATxRb() throws Exception {
0582:                tCohSet1B2A(TX_RB);
0583:            }
0584:
0585:            /**
0586:             * Add an element to a empty relation.
0587:             * Same as tCohSetOneA2B except that we add the element in the collection
0588:             * instead of we set directly the collection.
0589:             * Before: as0     bs0
0590:             * After:  as0 <-> bs0
0591:             * Check also the assignement rules for relationships.
0592:             */
0593:            public void tCohAddOneA2B(int tx) throws Exception {
0594:                ArrayList ce = new ArrayList();
0595:                ce.add("bs0");
0596:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0597:                    utx.begin();
0598:                }
0599:                ARemote a = getAHome().findByPrimaryKey("as0");
0600:                if (tx == TX_CONT) {
0601:                    a.addInBInNewTx("bs0");
0602:                } else {
0603:                    a.addInB("bs0");
0604:                }
0605:                if (tx == TX_CALL) {
0606:                    utx.commit();
0607:                } else if (tx == TX_RB) {
0608:                    utx.rollback();
0609:                }
0610:                if (tx != TX_RB) {
0611:                    // checking
0612:                    Collection ca = a.retrieveB();
0613:                    BRemote b = getBHome().findByPrimaryKey("bs0");
0614:                    String r = b.retrieveA();
0615:                    assertTrue("Bad relations for as0 (required:" + ce
0616:                            + ", found:" + ca + ")", isCollectionEqual(ce, ca));
0617:                    assertEquals("Bad relation for bs0", "as0", r);
0618:                    // undo
0619:                    a.assignB(new ArrayList());
0620:                }
0621:                checkIsInitialState();
0622:            }
0623:
0624:            public void testCohAddOneA2BTxNo() throws Exception {
0625:                tCohAddOneA2B(TX_NO);
0626:            }
0627:
0628:            public void testCohAddOneA2BTxCall() throws Exception {
0629:                tCohAddOneA2B(TX_CALL);
0630:            }
0631:
0632:            public void testCohAddOneA2BTxCont() throws Exception {
0633:                tCohAddOneA2B(TX_CONT);
0634:            }
0635:
0636:            public void testCohAddOneA2BTxRb() throws Exception {
0637:                tCohAddOneA2B(TX_RB);
0638:            }
0639:
0640:            /**
0641:             * Re-Set a relation with N element.
0642:             * Before: as1 <-> bs1_1
0643:             *                 bs0
0644:             *                 bs3
0645:             * After:          bs1_1
0646:             *         as1 <-> bs0
0647:             *         as1 <-> bs3
0648:             */
0649:            public void tCohSetMultiA2B(int tx) throws Exception {
0650:                ArrayList ce = new ArrayList(2);
0651:                ce.add("bs0");
0652:                ce.add("bs3");
0653:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0654:                    utx.begin();
0655:                }
0656:                ARemote a = getAHome().findByPrimaryKey("as1");
0657:                Collection co = a.retrieveB();
0658:                if (tx == TX_CONT) {
0659:                    a.assignBInNewTx(ce);
0660:                } else {
0661:                    a.assignB(ce);
0662:                }
0663:                if (tx == TX_CALL) {
0664:                    utx.commit();
0665:                } else if (tx == TX_RB) {
0666:                    utx.rollback();
0667:                }
0668:                if (tx != TX_RB) {
0669:                    // checking
0670:                    Collection ca = a.retrieveB();
0671:                    BRemote bs1_1 = getBHome().findByPrimaryKey("bs1_1");
0672:                    BRemote bs0 = getBHome().findByPrimaryKey("bs0");
0673:                    BRemote bs3 = getBHome().findByPrimaryKey("bs3");
0674:                    assertTrue("Bad relations for as1 (required:" + ce
0675:                            + ", found:" + ca + ")", isCollectionEqual(ce, ca));
0676:                    assertNull("Not null relation for bs1_1", bs1_1.retrieveA());
0677:                    assertEquals("Bad relation for bs0: ", "as1", bs0
0678:                            .retrieveA());
0679:                    assertEquals("Bad relation for bs3: ", "as1", bs3
0680:                            .retrieveA());
0681:                    // undo
0682:                    a.assignB(co);
0683:                }
0684:                checkIsInitialState();
0685:            }
0686:
0687:            public void testCohSetMultiA2BTxNo() throws Exception {
0688:                tCohSetMultiA2B(TX_NO);
0689:            }
0690:
0691:            public void testCohSetMultiA2BTxCall() throws Exception {
0692:                tCohSetMultiA2B(TX_CALL);
0693:            }
0694:
0695:            public void testCohSetMultiA2BTxCont() throws Exception {
0696:                tCohSetMultiA2B(TX_CONT);
0697:            }
0698:
0699:            public void testCohSetMultiA2BTxRb() throws Exception {
0700:                tCohSetMultiA2B(TX_RB);
0701:            }
0702:
0703:            /**
0704:             * Set a B2A relation with 1 element.
0705:             * This element wasn't already in an other relation.
0706:             * Before: bs1_1 <-> as1
0707:             *                   as0
0708:             * Change: bs1_1.assignA(as0);
0709:             * After:  bs1_1 <-> as0
0710:             *                   as1
0711:             * Check also the assignement rules for relationships.
0712:             *
0713:             */
0714:            public void tCohSet2B2A(int tx) throws Exception {
0715:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0716:                    utx.begin();
0717:                }
0718:                BRemote b = getBHome().findByPrimaryKey("bs1_1");
0719:                if (tx == TX_CONT) {
0720:                    b.assignAInNewTx("as0");
0721:                } else {
0722:                    b.assignA("as0");
0723:                }
0724:                if (tx == TX_CALL) {
0725:                    utx.commit();
0726:                } else if (tx == TX_RB) {
0727:                    utx.rollback();
0728:                }
0729:                if (tx != TX_RB) {
0730:                    // checking
0731:                    String r = b.retrieveA();
0732:                    assertEquals("Bad relation for bs1_1: ", "as0", r);
0733:                    ARemote as0 = getAHome().findByPrimaryKey("as0");
0734:                    Collection cas0 = as0.retrieveB();
0735:                    ARemote as1 = getAHome().findByPrimaryKey("as1");
0736:                    Collection cas1 = as1.retrieveB();
0737:                    ArrayList ce = new ArrayList();
0738:                    ce.add("bs1_1");
0739:                    assertTrue("Bad relations for as0 (required:" + ce
0740:                            + ", found:" + cas0 + ")", isCollectionEqual(ce,
0741:                            cas0));
0742:                    ce = new ArrayList();
0743:                    assertTrue("Bad relations for as1 (required:" + ce
0744:                            + ", found:" + cas1 + ")", isCollectionEqual(ce,
0745:                            cas1));
0746:                    // undo
0747:                    b.assignA("as1");
0748:                }
0749:                checkIsInitialState();
0750:            }
0751:
0752:            public void testCohSet2B2ATxNo() throws Exception {
0753:                tCohSet2B2A(TX_NO);
0754:            }
0755:
0756:            public void testCohSet2B2ATxCall() throws Exception {
0757:                tCohSet2B2A(TX_CALL);
0758:            }
0759:
0760:            public void testCohSet2B2ATxCont() throws Exception {
0761:                tCohSet2B2A(TX_CONT);
0762:            }
0763:
0764:            public void testCohSet2B2ATxRb() throws Exception {
0765:                tCohSet2B2A(TX_RB);
0766:            }
0767:
0768:            /**
0769:             * Set a B2A relation with 1 element.
0770:             * This element was already in an other relation.
0771:             * Before: bs1_1 <-> as1
0772:             *         b3_1  <-> a3
0773:             * Change: bs1_1.assignA(b3_1.retrieveA())
0774:             * After:  bs1_1 <-> a3
0775:             *         b3_1  <->
0776:             *                   as1
0777:             * Check also the assignement rules for relationships.
0778:             *
0779:             * See Spec chapter 10.3.7.3, change example: b2m.setA(b1n.getA())
0780:             */
0781:            public void tCohSet3B2A(int tx) throws Exception {
0782:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0783:                    utx.begin();
0784:                }
0785:                BRemote bs1_1 = getBHome().findByPrimaryKey("bs1_1");
0786:                if (tx == TX_CONT) {
0787:                    bs1_1.assignAInNewTx("a3");
0788:                } else {
0789:                    bs1_1.assignA("a3");
0790:                }
0791:                if (tx == TX_CALL) {
0792:                    utx.commit();
0793:                } else if (tx == TX_RB) {
0794:                    utx.rollback();
0795:                }
0796:                if (tx != TX_RB) {
0797:                    // checking
0798:                    String rbs1_1 = bs1_1.retrieveA();
0799:                    ARemote as1 = getAHome().findByPrimaryKey("as1");
0800:                    Collection cas1 = as1.retrieveB();
0801:                    ARemote a3 = getAHome().findByPrimaryKey("a3");
0802:                    Collection ca3 = a3.retrieveB();
0803:                    assertEquals("Bad relation for bs1_1: ", "a3", rbs1_1);
0804:                    ArrayList ce = new ArrayList();
0805:                    ce.add("bs1_1");
0806:                    ce.add("b3_1");
0807:                    assertTrue("Bad relations for a3 (required:" + ce
0808:                            + ", found:" + ca3 + ")",
0809:                            isCollectionEqual(ce, ca3));
0810:                    ce = new ArrayList();
0811:                    assertTrue("Bad relations for as1 (required:" + ce
0812:                            + ", found:" + cas1 + ")", isCollectionEqual(ce,
0813:                            cas1));
0814:                    // undo
0815:                    bs1_1.assignA("as1");
0816:                }
0817:                checkIsInitialState();
0818:            }
0819:
0820:            public void testCohSet3B2ATxNo() throws Exception {
0821:                tCohSet3B2A(TX_NO);
0822:            }
0823:
0824:            public void testCohSet3B2ATxCall() throws Exception {
0825:                tCohSet3B2A(TX_CALL);
0826:            }
0827:
0828:            public void testCohSet3B2ATxCont() throws Exception {
0829:                tCohSet3B2A(TX_CONT);
0830:            }
0831:
0832:            public void testCohSet3B2ATxRb() throws Exception {
0833:                tCohSet3B2A(TX_RB);
0834:            }
0835:
0836:            /**
0837:             * Remove an element in a relation.
0838:             * Before: a3 <-> b3_1
0839:             * Change: a3.retrieveB().remove(b3_1)
0840:             * After:  a3     b3_1
0841:             * See Spec chapter 10.3.7.3, change example: a1.getB().remove(b1n)
0842:             */
0843:            public void tCohRemoveInRelA2B(int tx) throws Exception {
0844:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0845:                    utx.begin();
0846:                }
0847:                ARemote a = getAHome().findByPrimaryKey("a3");
0848:                if (tx == TX_CONT) {
0849:                    a.removeFromBInNewTx("b3_1");
0850:                } else {
0851:                    a.removeFromB("b3_1");
0852:                }
0853:                if (tx == TX_CALL) {
0854:                    utx.commit();
0855:                } else if (tx == TX_RB) {
0856:                    utx.rollback();
0857:                }
0858:                if (tx != TX_RB) {
0859:                    // checking
0860:                    Collection ca = a.retrieveB();
0861:                    BRemote b = getBHome().findByPrimaryKey("b3_1");
0862:                    String r = b.retrieveA();
0863:                    ArrayList ce = new ArrayList();
0864:                    assertTrue("Bad relations for a3: (required:" + ce
0865:                            + ", found:" + ca + ")", isCollectionEqual(ce, ca));
0866:                    assertNull("Bad not null relation for b3_1", r);
0867:                    // undo
0868:                    a.addInB("b3_1");
0869:                }
0870:                // check to initial state
0871:                checkIsInitialState();
0872:
0873:            }
0874:
0875:            public void testCohRemoveInRelA2BTxNo() throws Exception {
0876:                tCohRemoveInRelA2B(TX_NO);
0877:            }
0878:
0879:            public void testCohRemoveInRelA2BTxCall() throws Exception {
0880:                tCohRemoveInRelA2B(TX_CALL);
0881:            }
0882:
0883:            public void testCohRemoveInRelA2BTxCont() throws Exception {
0884:                tCohRemoveInRelA2B(TX_CONT);
0885:            }
0886:
0887:            public void testCohRemoveInRelA2BTxRb() throws Exception {
0888:                tCohRemoveInRelA2B(TX_RB);
0889:            }
0890:
0891:            /**
0892:             * Remove a bean B which is in a relation.
0893:             * Before: a3 <-> b3_1
0894:             * change: B.remove(b3_1)
0895:             * After:  a3
0896:             *
0897:             */
0898:            public void tCohRemoveB(int tx) throws Exception {
0899:                if (tx == TX_CONT) {
0900:                    // The transaction attribute of the remove method is TX_SUPPORT,
0901:                    // so the transaction cannot be initiate by the container
0902:                    fail("Transaction cannot be initiate by the container for this test");
0903:                }
0904:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0905:                    utx.begin();
0906:                }
0907:                getBHome().remove("b3_1");
0908:                if (tx == TX_CALL) {
0909:                    utx.commit();
0910:                } else if (tx == TX_RB) {
0911:                    utx.rollback();
0912:                }
0913:                if (tx != TX_RB) {
0914:                    // checking
0915:                    ARemote a = getAHome().findByPrimaryKey("a3");
0916:                    Collection ca = a.retrieveB();
0917:                    assertEquals(
0918:                            "Wrong relations size for a3: (expected: 0 found:"
0919:                                    + ca.size(), 0, ca.size());
0920:                    // undo
0921:                    getBHome().create("b3_1");
0922:                    a.addInBInNewTx("b3_1");
0923:                }
0924:                checkIsInitialState();
0925:            }
0926:
0927:            public void testCohRemoveBTxNo() throws Exception {
0928:                tCohRemoveB(TX_NO);
0929:            }
0930:
0931:            public void testCohRemoveBTxCall() throws Exception {
0932:                tCohRemoveB(TX_CALL);
0933:            }
0934:
0935:            public void testCohRemoveBTxRb() throws Exception {
0936:                tCohRemoveB(TX_RB);
0937:            }
0938:
0939:            /**
0940:             * Remove a bean B which is in a relation.
0941:             * Same as tCohRemoveB except that the called remove method is on the bean
0942:             * instead of the home.
0943:             * Before: a3 <-> b3_1
0944:             * change: B.remove(b3_1)
0945:             * After:  a3
0946:             *
0947:             */
0948:            public void tCohBeanRemoveB(int tx) throws Exception {
0949:                if (tx == TX_CONT) {
0950:                    // The transaction attribute of the remove method is TX_SUPPORT,
0951:                    // so the transaction cannot be initiate by the container
0952:                    fail("Transaction cannot be initiate by the container for this test");
0953:                }
0954:                if ((tx == TX_CALL) || (tx == TX_RB)) {
0955:                    utx.begin();
0956:                }
0957:                BRemote b = getBHome().findByPrimaryKey("b3_1");
0958:                b.remove();
0959:                if (tx == TX_CALL) {
0960:                    utx.commit();
0961:                } else if (tx == TX_RB) {
0962:                    utx.rollback();
0963:                }
0964:                if (tx != TX_RB) {
0965:                    // checking
0966:                    ARemote a = getAHome().findByPrimaryKey("a3");
0967:                    Collection ca = a.retrieveB();
0968:                    assertEquals(
0969:                            "Wrong relations size for a3: (expected: 0 found:"
0970:                                    + ca.size(), 0, ca.size());
0971:                    // undo
0972:                    getBHome().create("b3_1");
0973:                    a.addInBInNewTx("b3_1");
0974:                }
0975:                checkIsInitialState();
0976:            }
0977:
0978:            public void testCohBeanRemoveBTxNo() throws Exception {
0979:                tCohBeanRemoveB(TX_NO);
0980:            }
0981:
0982:            public void testCohBeanRemoveBTxCall() throws Exception {
0983:                tCohBeanRemoveB(TX_CALL);
0984:            }
0985:
0986:            public void testCohBeanRemoveBTxRb() throws Exception {
0987:                tCohBeanRemoveB(TX_RB);
0988:            }
0989:
0990:            /**
0991:             * Set a empty relation A2B with 1 element.
0992:             * This added element was already in a other relation.
0993:             * Before: a0
0994:             *         a3 <-> b3_1
0995:             * Change: a0.assignB({b3_1})
0996:             * After:  a0 <-> b3_1
0997:             *         a3
0998:             */
0999:            public void tCohSetOne2A2B(int tx) throws Exception {
1000:                ArrayList ce = new ArrayList();
1001:                ce.add("b3_1");
1002:                if ((tx == TX_CALL) || (tx == TX_RB)) {
1003:                    utx.begin();
1004:                }
1005:                ARemote a = getAHome().findByPrimaryKey("a0");
1006:                if (tx == TX_CONT) {
1007:                    a.assignBInNewTx(ce);
1008:                } else {
1009:                    a.assignB(ce);
1010:                }
1011:                if (tx == TX_CALL) {
1012:                    utx.commit();
1013:                } else if (tx == TX_RB) {
1014:                    utx.rollback();
1015:                }
1016:                if (tx != TX_RB) {
1017:                    // checking
1018:                    Collection ca = a.retrieveB();
1019:                    ARemote a3 = getAHome().findByPrimaryKey("a3");
1020:                    Collection ca3 = a3.retrieveB();
1021:                    BRemote b = getBHome().findByPrimaryKey("b3_1");
1022:                    String r = b.retrieveA();
1023:                    assertTrue("Wrong relations a0 (required:" + ce
1024:                            + ", found:" + ca + ")", isCollectionEqual(ce, ca));
1025:                    assertTrue("Wrong relations for b3_1" + ": found:" + ca3,
1026:                            !ca3.contains("b3_1"));
1027:                    assertEquals("Bad relation for b3_1: ", "a0", r);
1028:                    // undo
1029:                    a.assignB(new ArrayList());
1030:                    a3.addInB("b3_1");
1031:                }
1032:                checkIsInitialState();
1033:            }
1034:
1035:            public void testCohSetOne2A2BTxNo() throws Exception {
1036:                tCohSetOne2A2B(TX_NO);
1037:            }
1038:
1039:            public void testCohSetOne2A2BTxCall() throws Exception {
1040:                tCohSetOne2A2B(TX_CALL);
1041:            }
1042:
1043:            public void testCohSetOne2A2BTxCont() throws Exception {
1044:                tCohSetOne2A2B(TX_CONT);
1045:            }
1046:
1047:            public void testCohSetOne2A2BTxRb() throws Exception {
1048:                tCohSetOne2A2B(TX_RB);
1049:            }
1050:
1051:            /**
1052:             * Add an element to a relation A2B already multiple.
1053:             * The element was already in a relation.
1054:             * Check also the assignement rules for relationships.
1055:             * Before: a1 <-> b1_1
1056:             *            <-> b1_2
1057:             *            <-> b1_3
1058:             *         a3 <-> b3_1
1059:             * Change: a1.addInB(b3_1)
1060:             * After:  a1 <-> b1_1
1061:             *            <-> b1_2
1062:             *            <-> b1_3
1063:             *            <-> b3_1
1064:             *         a3
1065:             *
1066:             * See Spec chapter 10.3.7.3, change example: a1.getB().add(b2m)
1067:             *
1068:             */
1069:            public void tCohAddOneInMultiA2B(int tx) throws Exception {
1070:
1071:                ArrayList ce = new ArrayList();
1072:                ce.add("b1_1");
1073:                ce.add("b1_2");
1074:                ce.add("b1_3");
1075:                String bAdded = "b3_1";
1076:                if ((tx == TX_CALL) || (tx == TX_RB)) {
1077:                    utx.begin();
1078:                }
1079:                ARemote a = getAHome().findByPrimaryKey("a1");
1080:                if (tx == TX_CONT) {
1081:                    a.addInBInNewTx(bAdded);
1082:                } else {
1083:                    a.addInB(bAdded);
1084:                }
1085:                ce.add(bAdded);
1086:                if (tx == TX_CALL) {
1087:                    utx.commit();
1088:                } else if (tx == TX_RB) {
1089:                    utx.rollback();
1090:                }
1091:                if (tx != TX_RB) {
1092:                    // checking
1093:                    Collection ca1 = a.retrieveB();
1094:                    ARemote a3 = getAHome().findByPrimaryKey("a3");
1095:                    Collection ca3 = a3.retrieveB();
1096:                    assertTrue("Bad relations for a1 (required:" + ce
1097:                            + ", found:" + ca1 + ")",
1098:                            isCollectionEqual(ce, ca1));
1099:                    ce = new ArrayList();
1100:                    assertTrue("Bad relations for a3 (required:" + ce
1101:                            + ", found:" + ca3 + ")",
1102:                            isCollectionEqual(ce, ca3));
1103:                    BRemote b = getBHome().findByPrimaryKey(bAdded);
1104:                    assertEquals("Bad relation for b3_1: ", "a1", b.retrieveA());
1105:                    // undo
1106:                    a3.addInB(bAdded);
1107:                }
1108:
1109:                checkIsInitialState();
1110:            }
1111:
1112:            public void testCohAddOneInMultiA2BTxNo() throws Exception {
1113:                tCohAddOneInMultiA2B(TX_NO);
1114:            }
1115:
1116:            public void testCohAddOneInMultiA2BTxCall() throws Exception {
1117:                tCohAddOneInMultiA2B(TX_CALL);
1118:            }
1119:
1120:            public void testCohAddOneInMultiA2BTxCont() throws Exception {
1121:                tCohAddOneInMultiA2B(TX_CONT);
1122:            }
1123:
1124:            public void testCohAddOneInMultiA2BTxRb() throws Exception {
1125:                tCohAddOneInMultiA2B(TX_RB);
1126:            }
1127:
1128:            /*
1129:             * Set a relation to multiple.
1130:             * All of element was already in an other relation.
1131:             * Check also the assignement rules for relationships.
1132:             * Before: a1 <-> b1_1
1133:             *            <-> b1_2
1134:             *            <-> b1_3
1135:             *         a2 <-> b2_1
1136:             *            <-> b2_2
1137:             *            <-> b2_3
1138:             * Change: a1.assignB(a2.retrieveB())
1139:             * After:  a1 <-> b2_1
1140:             *            <-> b2_2
1141:             *            <-> b2_3
1142:             *         a2
1143:             *               b1_1
1144:             *               b1_2
1145:             *               b1_3
1146:             *
1147:             * Spec chapter 10.3.7.3, change example: a1.setB(a2.getB())
1148:             *
1149:             */
1150:            public void tCohSetMultiBisA2B(int tx) throws Exception {
1151:                if ((tx == TX_CALL) || (tx == TX_RB)) {
1152:                    utx.begin();
1153:                }
1154:                ARemote a1 = getAHome().findByPrimaryKey("a1");
1155:                Collection co1 = a1.retrieveB();
1156:                ARemote a2 = getAHome().findByPrimaryKey("a2");
1157:                Collection co2 = a2.retrieveB();
1158:                if (tx == TX_CONT) {
1159:                    a1.assignBInNewTx(co2);
1160:                } else {
1161:                    a1.assignB(co2);
1162:                }
1163:                if (tx == TX_CALL) {
1164:                    utx.commit();
1165:                } else if (tx == TX_RB) {
1166:                    utx.rollback();
1167:                }
1168:                if (tx != TX_RB) {
1169:                    // checking
1170:                    Collection ca1 = a1.retrieveB();
1171:                    assertTrue("Wrong relations for a1 (required:" + co2
1172:                            + ", found:" + ca1 + ")", isCollectionEqual(co2,
1173:                            ca1));
1174:                    Collection ca2 = a2.retrieveB();
1175:                    assertEquals("Wrong relations size for a2: ", 0, ca2.size());
1176:                    BRemote b;
1177:                    b = getBHome().findByPrimaryKey("b1_1");
1178:                    assertNull("Wrong not null relation for b1_1: ", b
1179:                            .retrieveA());
1180:                    b = getBHome().findByPrimaryKey("b1_2");
1181:                    assertNull("Wrong not null relation for b1_2: ", b
1182:                            .retrieveA());
1183:                    b = getBHome().findByPrimaryKey("b1_3");
1184:                    assertNull("Wrong not null relation for b1_3: ", b
1185:                            .retrieveA());
1186:                    b = getBHome().findByPrimaryKey("b2_1");
1187:                    assertEquals("Wrong relation for b2_1: ", "a1", b
1188:                            .retrieveA());
1189:                    b = getBHome().findByPrimaryKey("b2_2");
1190:                    assertEquals("Wrong relation for b2_2: ", "a1", b
1191:                            .retrieveA());
1192:                    b = getBHome().findByPrimaryKey("b2_3");
1193:                    assertEquals("Wrong relation for b2_3: ", "a1", b
1194:                            .retrieveA());
1195:                    // Undo
1196:                    a1.assignB(co1);
1197:                    a2.assignB(co2);
1198:                }
1199:                checkIsInitialState();
1200:            }
1201:
1202:            public void testCohSetMultiBisA2BTxNo() throws Exception {
1203:                tCohSetMultiBisA2B(TX_NO);
1204:            }
1205:
1206:            public void testCohSetMultiBisA2BTxCall() throws Exception {
1207:                tCohSetMultiBisA2B(TX_CALL);
1208:            }
1209:
1210:            public void testCohSetMultiBisA2BTxCont() throws Exception {
1211:                tCohSetMultiBisA2B(TX_CONT);
1212:            }
1213:
1214:            public void testCohSetMultiBisA2BTxRb() throws Exception {
1215:                tCohSetMultiBisA2B(TX_RB);
1216:            }
1217:
1218:            /**
1219:             * This test check it isn't allowed to reset the pk
1220:             * and that the container throw the java.lang.IllegalStateException.
1221:             * See spec 2.0, chapter 10.3.5, page 134.
1222:             */
1223:            public void testResetPkForbidden() throws Exception {
1224:                ARemote a = getAHome().findByPrimaryKey("ax0");
1225:                assertTrue(
1226:                        "IllegalStateException not thrown when a pk value is reset",
1227:                        a.testResetPkForbidden("aY0"));
1228:            }
1229:
1230:            /**
1231:             * Test that we can create a bean and find it in the same transaction.
1232:             */
1233:            public void testCreateFindTx() throws Exception {
1234:                utx.begin();
1235:                ARemote project = getAHome().create("project");
1236:                BRemote role = getBHome().create("role");
1237:                project.addInB("role");
1238:                getBHome().findByName("role", "project");
1239:                utx.rollback();
1240:                checkIsInitialState();
1241:            }
1242:
1243:            /**
1244:             * Test that we can create a bean and find it in the same transaction,
1245:             * using a method in A bean.
1246:             */
1247:            public void testCreateFindTx2() throws Exception {
1248:                utx.begin();
1249:                ARemote project = getAHome().create("project");
1250:                project.addNewB("role");
1251:                getBHome().findByName("role", "project");
1252:                utx.rollback();
1253:                checkIsInitialState();
1254:            }
1255:
1256:            /**
1257:             * Reproduce the bug #300156: Error on creating Array from cmr-collection
1258:             */
1259:            public void testNewArrayListOnCmr() throws Exception {
1260:                ArrayList ce = new ArrayList();
1261:                ce.add("bs2_1");
1262:                ce.add("bs2_2");
1263:                ce.add("bs2_3");
1264:                Collection ca = null;
1265:                ARemote as2 = getAHome().findByPrimaryKey("as2");
1266:                // Test of retrieveB()
1267:                ca = as2.retrieveB();
1268:                assertTrue("Bad relations for as2.retrieveB() (required:" + ce
1269:                        + ", found:" + ca + ")", isCollectionEqual(ce, ca));
1270:                // Test of retrieveBisB()
1271:                ca = as2.retrieveBisB();
1272:                assertTrue("Bad relations for as2.retrieveBisB() (required:"
1273:                        + ce + ", found:" + ca + ")", isCollectionEqual(ce, ca));
1274:            }
1275:
1276:            /**
1277:             * Ensure the javax.ejb.EJBException is thrown when trying
1278:             * to invoke an accessor method on a deleted entitybean object
1279:             */
1280:            public void testRemove1() throws Exception {
1281:                Front fb = fhome.create();
1282:                fb.testRemove1();
1283:
1284:            }
1285:
1286:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.