Source Code Cross Referenced for F_FamilyEC2.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:         * $Id: F_FamilyEC2.java 9490 2006-09-04 11:54:12Z durieuxp $
0022:         * --------------------------------------------------------------------------
0023:         */
0024:
0025:        package org.objectweb.jonas.jtests.clients.entity;
0026:
0027:        import java.util.Collection;
0028:        import java.util.Iterator;
0029:
0030:        import javax.naming.NamingException;
0031:        import javax.rmi.PortableRemoteObject;
0032:
0033:        import junit.framework.Assert;
0034:        import junit.framework.Test;
0035:        import junit.framework.TestSuite;
0036:
0037:        import org.objectweb.jonas.jtests.beans.relation.family.People;
0038:        import org.objectweb.jonas.jtests.beans.relation.family.PeopleHome;
0039:        import org.objectweb.jonas.jtests.util.JTestCase;
0040:
0041:        /**
0042:         * This test suite tests relations on beans of the same type.
0043:         * Relations used are OOB, OMU, OMB.
0044:         * It uses the bean family only.
0045:         * Each test is independant from each other, since DataBase is
0046:         * cleaned up after each test (See teardown).
0047:         * @author Philippe Durieux
0048:         */
0049:        public class F_FamilyEC2 extends JTestCase {
0050:
0051:            /**
0052:             * Reference on the remote Home
0053:             */
0054:            private static PeopleHome home = null;
0055:
0056:            /**
0057:             * Standard constructor
0058:             */
0059:            public F_FamilyEC2(String name) {
0060:                super (name);
0061:            }
0062:
0063:            protected boolean isInit = false;
0064:
0065:            /**
0066:             * setup is called before each test case.
0067:             * If not initialized, load the family bean and lookup the Home.
0068:             */
0069:            protected void setUp() {
0070:                super .setUp();
0071:                if (!isInit) {
0072:                    useBeans("family", false);
0073:                    try {
0074:                        home = (PeopleHome) PortableRemoteObject.narrow(ictx
0075:                                .lookup("FamilyHome"), PeopleHome.class);
0076:                    } catch (NamingException e) {
0077:                        fail("Cannot get bean home: " + e.getMessage());
0078:                    }
0079:                    isInit = true;
0080:                }
0081:            }
0082:
0083:            /**
0084:             * teardown is called after each test case.
0085:             * Notes for debugging :
0086:             * To see DataBase state after a test is passed :
0087:             * Replace the cleanall() by sync(false).
0088:             */
0089:            protected void tearDown() throws Exception {
0090:                cleanall();
0091:            }
0092:
0093:            /**
0094:             * Cleanup all the family after each test, to make tests independant.
0095:             * Use transaction to avoid known bugs during cleanup.
0096:             * (With no transaction -> 1 remove will fail)
0097:             */
0098:            private void cleanall() throws Exception {
0099:                debug("remove all beans");
0100:
0101:                // Start the Transaction. In case a Transaction is still running,
0102:                // roll it back first and start a new one.
0103:                try {
0104:                    utx.begin();
0105:                } catch (Exception e) {
0106:                    debug("rollback first and start a new tx");
0107:                    utx.rollback();
0108:                    utx.begin();
0109:                }
0110:
0111:                // In case there is a problem during remove, we must unload
0112:                // the bean to restart properly.
0113:                try {
0114:                    Collection c = home.findAll();
0115:                    for (Iterator i = c.iterator(); i.hasNext();) {
0116:                        People p = (People) PortableRemoteObject.narrow(i
0117:                                .next(), People.class);
0118:                        debug("removing " + p.getName());
0119:                        p.remove();
0120:                    }
0121:                    utx.commit();
0122:                } catch (Exception e) {
0123:                    error("Exception in cleanup: " + e);
0124:                    try {
0125:                        utx.rollback();
0126:                    } catch (Exception f) {
0127:                        error("Exception during rollback: " + f);
0128:                    } finally {
0129:                        unloadBeans("family");
0130:                        isInit = false;
0131:                    }
0132:                }
0133:            }
0134:
0135:            // ---------------------------------------------------------------
0136:            // Set of the tests that are passed automatically.
0137:            // ---------------------------------------------------------------
0138:
0139:            /**
0140:             * Test that a create can be done after a remove outside tx.
0141:             * This test should pass.
0142:             */
0143:            public void testRemoveHTCreateIT() throws Exception {
0144:                home.create("Edouard", null, null);
0145:                home.create("Philomene", null, null);
0146:                home.remove("Edouard");
0147:                utx.begin();
0148:                home.create("Edouard", null, null);
0149:                home.union("Edouard", "Philomene");
0150:                utx.commit();
0151:            }
0152:
0153:            /**
0154:             * Test that a create can be done after a remove outside tx.
0155:             * This test should pass.
0156:             */
0157:            public void testRemoveHTCreateIT1() throws Exception {
0158:                home.create("Edouard", null, null);
0159:                home.remove("Edouard");
0160:                utx.begin();
0161:                home.create("Edouard", null, null);
0162:                utx.commit();
0163:            }
0164:
0165:            /**
0166:             * This test should pass.
0167:             */
0168:            public void testRemoveFatherTx() throws Exception {
0169:                build1920();
0170:                People p1 = home.create("Edouard2", "Edouard", "Philomene");
0171:                utx.begin();
0172:                home.remove("Edouard");
0173:                utx.commit();
0174:                Assert.assertTrue("Edouard2 has no father", p1.hasNoFather());
0175:            }
0176:
0177:            /**
0178:             * This test should pass.
0179:             */
0180:            public void testRemoveFather() throws Exception {
0181:                build1920();
0182:                People p1 = home.create("Edouard2", "Edouard", "Philomene");
0183:                home.remove("Edouard");
0184:                Assert.assertTrue("Edouard2 has no father", p1.hasNoFather());
0185:            }
0186:
0187:            /**
0188:             * This test should pass.
0189:             */
0190:            public void testRemoveMother() throws Exception {
0191:                build1920();
0192:                People p1 = home.create("Sylvain", "Edouard", "Philomene");
0193:                home.remove("Edouard");
0194:                home.remove("Philomene");
0195:                Assert.assertTrue("Sylvain is orphan", p1.isOrphan());
0196:            }
0197:
0198:            /**
0199:             * This test should pass.
0200:             */
0201:            public void testRemoveMotherTx() throws Exception {
0202:                utx.begin();
0203:                build1920();
0204:                People p1 = home.create("Sylvain", "Edouard", "Philomene");
0205:                home.remove("Edouard");
0206:                home.remove("Philomene");
0207:                utx.commit();
0208:                Assert.assertTrue("Sylvain is orphan", p1.isOrphan());
0209:            }
0210:
0211:            /**
0212:             * Test the findAll without transaction.
0213:             */
0214:            public void testFindAll() throws Exception {
0215:                Collection c = home.findAll();
0216:                home.create("Bob", null, null);
0217:                home.create("Jack", "Bob", null);
0218:                People p3 = home.findByPrimaryKey("Bob");
0219:                int n = p3.kidNumber();
0220:                Collection c3 = home.findAll();
0221:                Assert.assertEquals("findAll 3", 2, c3.size());
0222:            }
0223:
0224:            /**
0225:             * This test should pass now.
0226:             * The problem was that the finder method looks in the Database, and
0227:             * that the data has not been written, because outside transaction.
0228:             */
0229:            public void testManChildren() throws Exception {
0230:                build1920();
0231:                build1940();
0232:                People p3 = home.findByPrimaryKey("Ernest");
0233:                Assert.assertEquals("Ernest's children", 3, p3.kidNumber());
0234:            }
0235:
0236:            /**
0237:             * This test should pass now (bug fixed in create HT)
0238:             */
0239:            public void testRollbackUnion() throws Exception {
0240:                home.create("Ernest", null, null);
0241:                home.create("Simone", null, null);
0242:                home.create("Monette", "Ernest", "Simone");
0243:                home.create("Sylvain", null, null);
0244:                utx.begin();
0245:                home.union("Sylvain", "Monette");
0246:                utx.rollback();
0247:                People p3 = home.findByPrimaryKey("Monette");
0248:                Assert.assertTrue("Monette not orphan", !p3.isOrphan());
0249:            }
0250:
0251:            /**
0252:             * This test should pass.
0253:             */
0254:            public void testRollbackDivorce() throws Exception {
0255:                home.create("Ernest", null, null);
0256:                home.create("Simone", null, null);
0257:                home.create("Monette", "Ernest", "Simone");
0258:                home.create("Sylvain", null, null);
0259:                home.union("Sylvain", "Monette");
0260:                People p3 = home.create("Philippe", "Sylvain", "Monette");
0261:                People p1 = home.create("Sylvie", null, null);
0262:                home.union("Philippe", "Sylvie");
0263:                utx.begin();
0264:                home.divorce("Philippe", "Sylvie");
0265:                utx.rollback();
0266:                Assert.assertTrue("Philippe not orphan", !p3.isOrphan());
0267:                Assert.assertTrue("Philippe not single", !p3.isSingle());
0268:                Assert.assertTrue("Sylvie not single", !p1.isSingle());
0269:            }
0270:
0271:            /**
0272:             * This test should pass.
0273:             */
0274:            public void testDivorce() throws Exception {
0275:                home.create("Sylvain", null, null);
0276:                home.create("Simone", null, null);
0277:                People p2 = home.create("Philippe", "Sylvain", "Simone");
0278:                People p6 = home.create("Pascale", "Sylvain", "Simone");
0279:                People p5 = home.create("Sylvie", null, null);
0280:                People p4 = home.create("Catherine", null, null);
0281:                home.union("Philippe", "Sylvie");
0282:                People p3 = home.create("Thomas", "Philippe", "Sylvie");
0283:                home.divorce("Philippe", "Sylvie");
0284:                People p1 = home.create("Nathan", "Philippe", "Catherine");
0285:                Assert.assertTrue("Philippe single", p2.isSingle());
0286:                Assert.assertTrue("Sylvie single", p5.isSingle());
0287:                Assert.assertTrue("Nathan son of Philippe", p1.myFather()
0288:                        .getName().equals("Philippe"));
0289:                Assert.assertTrue("Nathan son of Catherine", p1.myMother()
0290:                        .getName().equals("Catherine"));
0291:                Assert.assertTrue("Nathan and Thomas", p3
0292:                        .brotherSisterOf("Nathan"));
0293:                Assert.assertTrue("Philippe and Pascale", p2
0294:                        .brotherSisterOf("Pascale"));
0295:            }
0296:
0297:            /**
0298:             * This test should pass
0299:             */
0300:            public void testRemoveRb() throws Exception {
0301:                home.create("Ernest", null, null);
0302:                home.create("Monette", "Ernest", null);
0303:                home.create("Philippe", null, "Monette");
0304:                utx.begin();
0305:                home.remove("Ernest");
0306:                utx.rollback();
0307:                People p2 = home.findByPrimaryKey("Monette");
0308:                Assert.assertEquals("Monette's children", 1, p2.kidNumber());
0309:            }
0310:
0311:            /**
0312:             * This test should pass
0313:             */
0314:            public void testRemoveRb2() throws Exception {
0315:                home.create("Ernest", null, null);
0316:                home.create("Monette", "Ernest", null);
0317:                home.create("Philippe", null, "Monette");
0318:                utx.begin();
0319:                home.remove("Monette");
0320:                utx.rollback();
0321:                People p2 = home.findByPrimaryKey("Monette");
0322:                Assert.assertEquals("Monette's children", 1, p2.kidNumber());
0323:            }
0324:
0325:            /**
0326:             * This test should pass
0327:             */
0328:            public void testRemoveRb3() throws Exception {
0329:                home.create("Ernest", null, null);
0330:                home.create("Monette", "Ernest", null);
0331:                home.create("Philippe", null, "Monette");
0332:                utx.begin();
0333:                home.remove("Philippe");
0334:                utx.rollback();
0335:                People p2 = home.findByPrimaryKey("Monette");
0336:                Assert.assertEquals("Monette's children", 1, p2.kidNumber());
0337:            }
0338:
0339:            /**
0340:             * Same than testRemoveRb, with a sync before transaction.
0341:             * This test should pass
0342:             */
0343:            public void testRemoveRbSync() throws Exception {
0344:                home.create("Ernest", null, null);
0345:                home.create("Monette", "Ernest", null);
0346:                home.create("Philippe", null, "Monette");
0347:                sync(false);
0348:                utx.begin();
0349:                home.remove("Ernest");
0350:                utx.rollback();
0351:                People p2 = home.findByPrimaryKey("Monette");
0352:                Assert.assertEquals("Monette's children", 1, p2.kidNumber());
0353:            }
0354:
0355:            /**
0356:             * This test a create followed by a home method that will
0357:             * be rolled back (pb with reusing of contexts)
0358:             */
0359:            public void testCreateHomeRB() throws Exception {
0360:                home.create("Lucien", null, null);
0361:                utx.begin();
0362:                home.create("Odette", null, null);
0363:                home.union("Lucien", "Odette");
0364:                utx.rollback();
0365:                home.create("Odette", null, null);
0366:            }
0367:
0368:            // -------------------------------------------------------------------------
0369:            // Tests different states, with different transaction contexts
0370:            // Always build 1920 before 1940, 1940 before 1960, ...
0371:            // All these tests can be run independantly.
0372:            // For debugging : To check database state, see tearDown().
0373:            // -------------------------------------------------------------------------
0374:
0375:            public void test1920() throws Exception {
0376:                build1920();
0377:                check1920();
0378:            }
0379:
0380:            public void test1920co() throws Exception {
0381:                utx.begin();
0382:                build1920();
0383:                utx.commit();
0384:                check1920();
0385:            }
0386:
0387:            public void test1920rb() throws Exception {
0388:                utx.begin();
0389:                build1920();
0390:                utx.rollback();
0391:                build1920();
0392:                check1920();
0393:            }
0394:
0395:            public void test1920rb1() throws Exception {
0396:                build1920();
0397:                utx.begin();
0398:                build1940();
0399:                utx.rollback();
0400:                check1920();
0401:            }
0402:
0403:            public void test1920rb2() throws Exception {
0404:                build1920();
0405:                utx.begin();
0406:                build1940();
0407:                build1960();
0408:                build1980();
0409:                build1990();
0410:                utx.rollback();
0411:                check1920();
0412:            }
0413:
0414:            public void test1940() throws Exception {
0415:                build1920();
0416:                build1940();
0417:                check1940();
0418:            }
0419:
0420:            public void test1940co() throws Exception {
0421:                utx.begin();
0422:                build1920();
0423:                build1940();
0424:                utx.commit();
0425:                check1940();
0426:            }
0427:
0428:            public void test1940co2() throws Exception {
0429:                build1920();
0430:                utx.begin();
0431:                build1940();
0432:                utx.commit();
0433:                check1940();
0434:            }
0435:
0436:            public void test1940rb() throws Exception {
0437:                build1920();
0438:                build1940();
0439:                utx.begin();
0440:                build1960();
0441:                utx.rollback();
0442:                check1940();
0443:            }
0444:
0445:            public void test1940rb2() throws Exception {
0446:                utx.begin();
0447:                build1920();
0448:                build1940();
0449:                utx.commit();
0450:                utx.begin();
0451:                build1960();
0452:                utx.rollback();
0453:                check1940();
0454:            }
0455:
0456:            public void test1940rb3() throws Exception {
0457:                build1920();
0458:                utx.begin();
0459:                build1940();
0460:                utx.commit();
0461:                utx.begin();
0462:                build1960();
0463:                build1980();
0464:                build1990();
0465:                utx.rollback();
0466:                check1940();
0467:            }
0468:
0469:            public void test1940rb4() throws Exception {
0470:                utx.begin();
0471:                build1920();
0472:                utx.rollback();
0473:                build1920();
0474:                check1920();
0475:                utx.begin();
0476:                build1940();
0477:                utx.rollback();
0478:                check1920();
0479:                build1940();
0480:                check1940();
0481:            }
0482:
0483:            public void test1960() throws Exception {
0484:                build1920();
0485:                build1940();
0486:                build1960();
0487:                check1960();
0488:            }
0489:
0490:            public void test1960co() throws Exception {
0491:                utx.begin();
0492:                build1920();
0493:                build1940();
0494:                build1960();
0495:                utx.commit();
0496:                check1960();
0497:            }
0498:
0499:            public void test1960co1() throws Exception {
0500:                build1920();
0501:                utx.begin();
0502:                build1940();
0503:                build1960();
0504:                utx.commit();
0505:                check1960();
0506:            }
0507:
0508:            public void test1960co2() throws Exception {
0509:                build1920();
0510:                utx.begin();
0511:                build1940();
0512:                utx.commit();
0513:                build1960();
0514:                check1960();
0515:            }
0516:
0517:            public void test1960rb() throws Exception {
0518:                build1920();
0519:                utx.begin();
0520:                build1940();
0521:                utx.commit();
0522:                utx.begin();
0523:                build1960();
0524:                build1980();
0525:                utx.rollback();
0526:                build1960();
0527:                check1960();
0528:            }
0529:
0530:            public void test1960rb1() throws Exception {
0531:                build1920();
0532:                build1940();
0533:                build1960();
0534:                utx.begin();
0535:                build1980();
0536:                utx.rollback();
0537:                check1960();
0538:            }
0539:
0540:            public void test1960rb2() throws Exception {
0541:                build1920();
0542:                utx.begin();
0543:                build1940();
0544:                build1960();
0545:                utx.commit();
0546:                utx.begin();
0547:                build1980();
0548:                utx.rollback();
0549:                check1960();
0550:            }
0551:
0552:            public void test1960rb3() throws Exception {
0553:                utx.begin();
0554:                build1920();
0555:                build1940();
0556:                utx.commit();
0557:                build1960();
0558:                utx.begin();
0559:                build1980();
0560:                utx.rollback();
0561:                check1960();
0562:            }
0563:
0564:            public void test1960rb4() throws Exception {
0565:                build1920();
0566:                utx.begin();
0567:                build1940();
0568:                build1960();
0569:                utx.commit();
0570:                utx.begin();
0571:                build1980();
0572:                build1990();
0573:                utx.rollback();
0574:                check1960();
0575:            }
0576:
0577:            public void test1980() throws Exception {
0578:                build1920();
0579:                build1940();
0580:                build1960();
0581:                build1980();
0582:                check1980();
0583:            }
0584:
0585:            public void test1980co() throws Exception {
0586:                utx.begin();
0587:                build1920();
0588:                build1940();
0589:                build1960();
0590:                build1980();
0591:                utx.commit();
0592:                check1980();
0593:            }
0594:
0595:            public void test1980co1() throws Exception {
0596:                build1920();
0597:                build1940();
0598:                utx.begin();
0599:                build1960();
0600:                utx.commit();
0601:                build1980();
0602:                check1980();
0603:            }
0604:
0605:            public void test1980co2() throws Exception {
0606:                build1920();
0607:                utx.begin();
0608:                build1940();
0609:                build1960();
0610:                utx.commit();
0611:                build1980();
0612:                check1980();
0613:            }
0614:
0615:            public void test1980rb() throws Exception {
0616:                build1920();
0617:                build1940();
0618:                build1960();
0619:                build1980();
0620:                utx.begin();
0621:                build1990();
0622:                utx.rollback();
0623:                check1980();
0624:            }
0625:
0626:            public void test1980rb2() throws Exception {
0627:                build1920();
0628:                build1940();
0629:                utx.begin();
0630:                build1960();
0631:                utx.commit();
0632:                build1980();
0633:                utx.begin();
0634:                build1990();
0635:                utx.rollback();
0636:                check1980();
0637:            }
0638:
0639:            public void test1980rb3() throws Exception {
0640:                build1920();
0641:                utx.begin();
0642:                build1940();
0643:                build1960();
0644:                build1980();
0645:                utx.commit();
0646:                utx.begin();
0647:                build1990();
0648:                utx.rollback();
0649:                check1980();
0650:            }
0651:
0652:            public void test1980rb4() throws Exception {
0653:                build1920();
0654:                build1940();
0655:                build1960();
0656:                utx.begin();
0657:                build1980();
0658:                utx.commit();
0659:                utx.begin();
0660:                build1990();
0661:                utx.rollback();
0662:                check1980();
0663:            }
0664:
0665:            public void test1980rb5() throws Exception {
0666:                build1920();
0667:                build1940();
0668:                build1960();
0669:                build1980();
0670:                utx.begin();
0671:                build1990();
0672:                build2000();
0673:                utx.rollback();
0674:                check1980();
0675:            }
0676:
0677:            public void test1980rb5s() throws Exception {
0678:                build1920();
0679:                build1940();
0680:                build1960();
0681:                build1980();
0682:                sync(false);
0683:                utx.begin();
0684:                build1990();
0685:                build2000();
0686:                utx.rollback();
0687:                check1980();
0688:            }
0689:
0690:            public void test1980rb5s2() throws Exception {
0691:                build1920();
0692:                build1940();
0693:                build1960();
0694:                sync(false);
0695:                build1980();
0696:                utx.begin();
0697:                build1990();
0698:                build2000();
0699:                utx.rollback();
0700:                check1980();
0701:            }
0702:
0703:            public void test1980rb5s3() throws Exception {
0704:                build1920();
0705:                build1940();
0706:                build1960();
0707:                build1980();
0708:                utx.begin();
0709:                build1990();
0710:                sync(false);
0711:                build2000();
0712:                utx.rollback();
0713:                check1980();
0714:            }
0715:
0716:            public void test1990() throws Exception {
0717:                build1920();
0718:                build1940();
0719:                build1960();
0720:                build1980();
0721:                build1990();
0722:                check1990();
0723:            }
0724:
0725:            public void test1990co() throws Exception {
0726:                utx.begin();
0727:                build1920();
0728:                build1940();
0729:                build1960();
0730:                build1980();
0731:                build1990();
0732:                utx.commit();
0733:                check1990();
0734:            }
0735:
0736:            public void test1990co1() throws Exception {
0737:                build1920();
0738:                build1940();
0739:                utx.begin();
0740:                build1960();
0741:                build1980();
0742:                build1990();
0743:                utx.commit();
0744:                check1990();
0745:            }
0746:
0747:            public void test1990co2() throws Exception {
0748:                build1920();
0749:                utx.begin();
0750:                build1940();
0751:                build1960();
0752:                utx.commit();
0753:                build1980();
0754:                build1990();
0755:                check1990();
0756:            }
0757:
0758:            public void test1990co3() throws Exception {
0759:                utx.begin();
0760:                build1920();
0761:                build1940();
0762:                utx.commit();
0763:                build1960();
0764:                build1980();
0765:                build1990();
0766:                check1990();
0767:            }
0768:
0769:            public void test1990rb() throws Exception {
0770:                build1920();
0771:                build1940();
0772:                build1960();
0773:                build1980();
0774:                build1990();
0775:                utx.begin();
0776:                build2000();
0777:                utx.rollback();
0778:                check1990();
0779:            }
0780:
0781:            public void test1990rb2() throws Exception {
0782:                build1920();
0783:                build1940();
0784:                build1960();
0785:                build1980();
0786:                utx.begin();
0787:                build1990();
0788:                utx.commit();
0789:                utx.begin();
0790:                build2000();
0791:                utx.rollback();
0792:                check1990();
0793:            }
0794:
0795:            public void test1990rb3() throws Exception {
0796:                build1920();
0797:                build1940();
0798:                utx.begin();
0799:                build1960();
0800:                build1980();
0801:                utx.commit();
0802:                build1990();
0803:                utx.begin();
0804:                build2000();
0805:                utx.rollback();
0806:                check1990();
0807:            }
0808:
0809:            public void test2000() throws Exception {
0810:                build1920();
0811:                build1940();
0812:                build1960();
0813:                build1980();
0814:                build1990();
0815:                build2000();
0816:                check2000();
0817:            }
0818:
0819:            public void test2000co() throws Exception {
0820:                utx.begin();
0821:                build1920();
0822:                build1940();
0823:                build1960();
0824:                build1980();
0825:                build1990();
0826:                build2000();
0827:                utx.commit();
0828:                check2000();
0829:            }
0830:
0831:            public void test2000co2() throws Exception {
0832:                build1920();
0833:                build1940();
0834:                utx.begin();
0835:                build1960();
0836:                build1980();
0837:                build1990();
0838:                build2000();
0839:                utx.commit();
0840:                check2000();
0841:            }
0842:
0843:            public void test2000co3() throws Exception {
0844:                build1920();
0845:                build1940();
0846:                utx.begin();
0847:                build1960();
0848:                build1980();
0849:                build1990();
0850:                utx.commit();
0851:                build2000();
0852:                check2000();
0853:            }
0854:
0855:            public void test2000co4() throws Exception {
0856:                utx.begin();
0857:                build1920();
0858:                utx.commit();
0859:                build1940();
0860:                utx.begin();
0861:                build1960();
0862:                build1980();
0863:                build1990();
0864:                utx.commit();
0865:                build2000();
0866:                check2000();
0867:            }
0868:
0869:            public void test2000co5() throws Exception {
0870:                utx.begin();
0871:                build1920();
0872:                utx.commit();
0873:                build1940();
0874:                build1960();
0875:                utx.begin();
0876:                build1980();
0877:                utx.commit();
0878:                build1990();
0879:                build2000();
0880:                check2000();
0881:            }
0882:
0883:            // --------------------------------------------------------------------------
0884:            // These tests print data on stdout, there are not passed automatically.
0885:            // --------------------------------------------------------------------------
0886:
0887:            public void vtestP1() throws Exception {
0888:                build1920();
0889:                build1940();
0890:                printAncestors(home.findByPrimaryKey("Sylvain"));
0891:            }
0892:
0893:            public void vtestP2() throws Exception {
0894:                build1920();
0895:                build1940();
0896:                build1960();
0897:                printAncestors(home.findByPrimaryKey("Philippe"));
0898:            }
0899:
0900:            public void vtestP3() throws Exception {
0901:                build1920();
0902:                build1940();
0903:                build1960();
0904:                build1980();
0905:                printAncestors(home.findByPrimaryKey("Isabelle"));
0906:            }
0907:
0908:            // --------------------------------------------------------------------------
0909:            // private methods to build family, and check state is OK.
0910:            // --------------------------------------------------------------------------
0911:
0912:            private void build1920() throws Exception {
0913:                debug("Build 1920");
0914:                home.create("Edouard", null, null);
0915:                home.create("Philomene", null, null);
0916:                home.create("Ernest", null, null);
0917:                home.create("Simone", null, null);
0918:                home.create("Lucienne", null, null);
0919:            }
0920:
0921:            private void check1920() throws Exception {
0922:                debug("Check 1920");
0923:                People p1 = home.findByPrimaryKey("Edouard");
0924:                Assert.assertTrue("Edouard is single", p1.isSingle());
0925:                People p2 = home.findByPrimaryKey("Ernest");
0926:                Assert.assertTrue("Ernest is single", p2.isSingle());
0927:                People p3 = home.findByPrimaryKey("Philomene");
0928:                Assert.assertTrue("Philomene is single", p3.isSingle());
0929:                People p4 = home.findByPrimaryKey("Simone");
0930:                Assert.assertTrue("Simone is single", p4.isSingle());
0931:            }
0932:
0933:            private void build1940() throws Exception {
0934:                debug("Build 1940");
0935:                home.union("Edouard", "Philomene");
0936:                home.union("Ernest", "Simone");
0937:                home.create("Edouard2", "Edouard", "Philomene");
0938:                home.create("Genevieve", null, null);
0939:                home.create("Odette", "Edouard", "Philomene");
0940:                home.create("Lucien", null, null);
0941:                home.create("Blanche", "Edouard", "Philomene");
0942:                home.create("Paul", null, null);
0943:                home.create("Sylvain", "Edouard", "Philomene");
0944:                home.create("Tines", "Ernest", "Simone");
0945:                home.create("Suzanne", null, null);
0946:                home.create("Monette", "Ernest", "Simone");
0947:                home.create("Francis", null, null);
0948:                home.create("Marose", "Ernest", "Simone");
0949:            }
0950:
0951:            private void check1940() throws Exception {
0952:                debug("Check 1940");
0953:                People p1 = home.findByPrimaryKey("Edouard");
0954:                People p2 = p1.mySpouse();
0955:                People p3 = home.findByPrimaryKey("Ernest");
0956:                People p4 = p3.mySpouse();
0957:                Assert.assertTrue("Edouard is married", p2.getName().equals(
0958:                        "Philomene"));
0959:                Assert.assertTrue("Philomene is married", p2.mySpouse()
0960:                        .getName().equals("Edouard"));
0961:                Assert.assertEquals("Simone's children", 3, p4.kidNumber());
0962:            }
0963:
0964:            private void build1960() throws Exception {
0965:                debug("Build 1960");
0966:                home.create("Pierre", "Ernest", "Simone");
0967:                home.union("Lucien", "Odette");
0968:                home.union("Paul", "Blanche");
0969:                home.union("Sylvain", "Monette");
0970:                home.union("Tines", "Suzanne");
0971:                home.union("Francis", "Marose");
0972:                home.create("Jean Paul", null, null);
0973:                home.create("Chantal", "Edouard2", "Genevieve");
0974:                home.create("Daniel", "Lucien", "Odette");
0975:                home.create("Genevieve2", "Edouard2", "Genevieve");
0976:                home.create("Marie Paule", "Paul", "Blanche");
0977:                home.create("Emmanuel", null, null);
0978:                home.create("Dominique", null, null);
0979:                home.create("Philippe", "Sylvain", "Monette");
0980:                home.create("Michel", "Edouard2", "Genevieve");
0981:                home.create("Pascale", "Sylvain", "Monette");
0982:                home.create("Veronique", "Francis", "Marose");
0983:                home.create("Francois", "Tines", "Suzanne");
0984:                home.create("Monique", null, null);
0985:                home.create("Roch", null, null);
0986:                home.create("Florence", "Francis", "Marose");
0987:                home.create("Sylvie", null, null);
0988:                home.create("Catherine", null, "Lucienne");
0989:            }
0990:
0991:            private void check1960() throws Exception {
0992:                debug("Check 1960");
0993:                People p1 = home.findByPrimaryKey("Ernest");
0994:                People p2 = home.findByPrimaryKey("Monette");
0995:                People p3 = home.findByPrimaryKey("Francois");
0996:                Assert.assertTrue("Monette is married", p2.mySpouse().getName()
0997:                        .equals("Sylvain"));
0998:                Assert.assertEquals("Monette's children", 2, p2.kidNumber());
0999:                Assert.assertTrue("Monette has a father", p2.myFather()
1000:                        .getName().equals("Ernest"));
1001:                Assert.assertTrue("Francois has a mother", p3.myMother()
1002:                        .getName().equals("Suzanne"));
1003:            }
1004:
1005:            private void build1980() throws Exception {
1006:                debug("Build 1980");
1007:                home.create("Thierry", "Tines", "Suzanne");
1008:                home.create("Valerie", "Francis", "Marose");
1009:                home.create("Jerome", "Francis", "Marose");
1010:                home.union("Pierre", "Chantal");
1011:                home.remove("Edouard");
1012:                home.remove("Philomene");
1013:                home.remove("Simone");
1014:                home.union("Jean Paul", "Veronique");
1015:                home.union("Dominique", "Genevieve2");
1016:                home.create("Isabelle", "Pierre", "Chantal");
1017:                home.create("Wilfried", "Pierre", "Chantal");
1018:                home.union("Roch", "Florence");
1019:            }
1020:
1021:            private void check1980() throws Exception {
1022:                debug("Check 1980");
1023:                People p1 = home.findByPrimaryKey("Marose");
1024:                People p2 = home.findByPrimaryKey("Sylvain");
1025:                People p3 = home.findByPrimaryKey("Philippe");
1026:                People p4 = home.findByPrimaryKey("Jerome");
1027:                People p5 = home.findByPrimaryKey("Ernest");
1028:                Assert.assertEquals("Marose's children", 4, p1.kidNumber());
1029:                Assert.assertTrue("Sylvain is orphan", p2.isOrphan());
1030:                Assert.assertTrue("Philippe and Pascale", p3
1031:                        .brotherSisterOf("Pascale"));
1032:                Assert.assertTrue("Jerome and Veronique", p4
1033:                        .brotherSisterOf("Veronique"));
1034:                Assert.assertTrue("Ernest single", p5.isSingle());
1035:            }
1036:
1037:            private void build1990() throws Exception {
1038:                debug("Build 1990");
1039:                home.union("Emmanuel", "Pascale");
1040:                home.union("Philippe", "Sylvie");
1041:                home.union("Francois", "Monique");
1042:                home.create("Lucie", "Jean Paul", "Veronique");
1043:                home.create("Amandine", "Emmanuel", "Pascale");
1044:                home.create("Julien", "Emmanuel", "Pascale");
1045:                home.create("Thomas", "Philippe", "Sylvie");
1046:                home.create("Florent", "Philippe", "Sylvie");
1047:                home.create("Fanny", "Emmanuel", "Pascale");
1048:                home.divorce("Roch", "Florence");
1049:                home.create("Charles Guillaume", "Francois", "Monique");
1050:                home.create("Pierre Olivier", "Francois", "Monique");
1051:            }
1052:
1053:            private void check1990() throws Exception {
1054:                debug("Check 1990");
1055:                People p2 = home.findByPrimaryKey("Monette");
1056:                People p3 = home.findByPrimaryKey("Pascale");
1057:                Assert.assertEquals("Monette's children", 2, p2.kidNumber());
1058:                Assert.assertEquals("Pascale's children", 3, p3.kidNumber());
1059:            }
1060:
1061:            private void build2000() throws Exception {
1062:                debug("Build 2000");
1063:                home.divorce("Philippe", "Sylvie");
1064:                home.divorce("Jean Paul", "Veronique");
1065:                home.remove("Ernest");
1066:                home.create("Nathan", "Philippe", "Catherine");
1067:            }
1068:
1069:            private void check2000() throws Exception {
1070:                debug("Check 2000");
1071:                People p1 = home.findByPrimaryKey("Nathan");
1072:                People p2 = home.findByPrimaryKey("Philippe");
1073:                People p3 = home.findByPrimaryKey("Thomas");
1074:                People p4 = home.findByPrimaryKey("Catherine");
1075:                People p5 = home.findByPrimaryKey("Sylvie");
1076:                People p6 = home.findByPrimaryKey("Pascale");
1077:                People p7 = home.findByPrimaryKey("Monette");
1078:                Assert.assertTrue("Philippe single", p2.isSingle());
1079:                Assert.assertTrue("Sylvie single", p5.isSingle());
1080:                Assert.assertTrue("Nathan son of Philippe", p1.myFather()
1081:                        .getName().equals("Philippe"));
1082:                Assert.assertTrue("Nathan son of Catherine", p1.myMother()
1083:                        .getName().equals("Catherine"));
1084:                Assert.assertTrue("Nathan and Thomas", p3
1085:                        .brotherSisterOf("Nathan"));
1086:                Assert.assertTrue("Monette orphan", p7.isOrphan());
1087:                Assert.assertTrue("Philippe and Pascale", p2
1088:                        .brotherSisterOf("Pascale"));
1089:            }
1090:
1091:            private void printParents(People p) throws Exception {
1092:                People father = p.myFather();
1093:                People mother = p.myMother();
1094:                System.out.print(p.getName() + "\t--->\t");
1095:                System.out.print(father != null ? father.getName() : "-");
1096:                System.out.print("\t");
1097:                System.out.println(mother != null ? mother.getName() : "-");
1098:            }
1099:
1100:            private void printAncestors(People p) throws Exception {
1101:                if (p != null) {
1102:                    printParents(p);
1103:                    printAncestors(p.myFather());
1104:                    printAncestors(p.myMother());
1105:                }
1106:            }
1107:
1108:            protected static void callTest(String testname) throws Exception {
1109:                JTestCase.callTest("entity.F_FamilyEC2", testname);
1110:            }
1111:
1112:            /**
1113:             * Run tests for perf mesures
1114:             */
1115:            protected static void perfs() throws Exception {
1116:                callTest("testEmpty");
1117:                callTest("test1920");
1118:                callTest("test1940");
1119:                callTest("test1960");
1120:                callTest("test1980");
1121:                callTest("test1990");
1122:                callTest("test2000");
1123:                callTest("test1920co");
1124:                callTest("test1940co");
1125:                callTest("test1960co");
1126:                callTest("test1980co");
1127:                callTest("test1990co");
1128:                callTest("test2000co");
1129:            }
1130:
1131:            /**
1132:             * Run a selected set of the test cases
1133:             * F10 pass (should fails) but cleanup fails !!!
1134:             */
1135:            public static Test suite2() {
1136:                TestSuite suite = new TestSuite();
1137:                suite.addTest(new F_FamilyEC2("testF6"));
1138:                suite.addTest(new F_FamilyEC2("testF8"));
1139:                suite.addTest(new F_FamilyEC2("testF9"));
1140:                suite.addTest(new F_FamilyEC2("testF10"));
1141:                return suite;
1142:            }
1143:
1144:            /**
1145:             * Run a selected set of the test cases
1146:             */
1147:            public static Test suite1() {
1148:                TestSuite suite = new TestSuite();
1149:                suite.addTest(new F_FamilyEC2("testF11"));
1150:                suite.addTest(new F_FamilyEC2("testF12"));
1151:                suite.addTest(new F_FamilyEC2("testF13"));
1152:                suite.addTest(new F_FamilyEC2("testF14"));
1153:                suite.addTest(new F_FamilyEC2("testF15"));
1154:                suite.addTest(new F_FamilyEC2("testF16"));
1155:                suite.addTest(new F_FamilyEC2("testF17"));
1156:                suite.addTest(new F_FamilyEC2("testF18"));
1157:                suite.addTest(new F_FamilyEC2("testF19"));
1158:                return suite;
1159:            }
1160:
1161:            /**
1162:             * Run all the tests of this suite.
1163:             */
1164:            public static Test suite() {
1165:                return new TestSuite(F_FamilyEC2.class);
1166:            }
1167:
1168:            public static void main(String args[]) throws Exception {
1169:                String testtorun = null;
1170:
1171:                // Get args
1172:                for (int argn = 0; argn < args.length; argn++) {
1173:                    String sarg = args[argn];
1174:                    if (sarg.equals("-n")) {
1175:                        testtorun = args[++argn];
1176:                    }
1177:                }
1178:                if (testtorun == null) {
1179:                    junit.textui.TestRunner.run(suite());
1180:                } else {
1181:                    if (testtorun.equals("perfs")) {
1182:                        perfs();
1183:                    } else if (testtorun.equals("suite1")) {
1184:                        junit.textui.TestRunner.run(suite1());
1185:                    } else if (testtorun.equals("suite2")) {
1186:                        junit.textui.TestRunner.run(suite2());
1187:                    } else {
1188:                        junit.textui.TestRunner.run(new F_FamilyEC2(testtorun));
1189:                    }
1190:                }
1191:            }
1192:
1193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.