Source Code Cross Referenced for F_EjbqlEC2.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-2005 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 offind
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:         */package org.objectweb.jonas.jtests.clients.entity;
0021:
0022:        import javax.naming.NamingException;
0023:        import javax.rmi.PortableRemoteObject;
0024:        import junit.framework.Test;
0025:        import junit.framework.TestSuite;
0026:        import org.objectweb.jonas.jtests.beans.ejbql.*;
0027:        import java.util.ArrayList;
0028:        import java.util.Calendar;
0029:        import java.util.Collection;
0030:        import java.util.Date;
0031:        import java.util.HashSet;
0032:        import java.util.Iterator;
0033:        import java.util.Set;
0034:
0035:        /**
0036:         * This is an advanced test suite for home interface on entity bean EJBQL.
0037:         */
0038:        public class F_EjbqlEC2 extends A_Cmp2Util {
0039:
0040:            private static String BEAN_HOME_SESSION_TEST = "EjbqlSessionTestHomeRemote";
0041:            private static String BEAN_HOME_CUSTOMER = "CustomerHomeRemote";
0042:            private static String BEAN_HOME_RESERVATION = "ReservationHomeRemote";
0043:            private static String BEAN_HOME_CRUISE = "CruiseHomeRemote";
0044:            private static String BEAN_HOME_SHIP = "ShipHomeRemote";
0045:            private static String BEAN_HOME_CABIN = "CabinHomeRemote";
0046:            private static String BEAN_HOME_ADDRESS = "AddressHomeRemote";
0047:
0048:            protected static SessionTestHomeRemote sessiontesthome = null;
0049:            protected static CustomerHomeRemote customerhome = null;
0050:            protected static ReservationHomeRemote reservationhome = null;
0051:            protected static CruiseHomeRemote cruisehome = null;
0052:            protected static ShipHomeRemote shiphome = null;
0053:            protected static CabinHomeRemote cabinhome = null;
0054:            protected static AddressHomeRemote addresshome = null;
0055:            protected static CreditCardHomeRemote creditcardhome = null;
0056:
0057:            public F_EjbqlEC2(String name) {
0058:                super (name);
0059:            }
0060:
0061:            protected boolean isInit = false;
0062:
0063:            protected void setUp() {
0064:                super .setUp();
0065:                boolean ok = false;
0066:                int nbtry = 0;
0067:                while (!ok && nbtry < 3) {
0068:                    if (!isInit) {
0069:                        // load bean if not loaded yet
0070:                        useBeans("ejbql", false);
0071:                        // lookup home used in the tests
0072:
0073:                        try {
0074:                            sessiontesthome = (SessionTestHomeRemote) PortableRemoteObject
0075:                                    .narrow(
0076:                                            ictx.lookup(BEAN_HOME_SESSION_TEST),
0077:                                            SessionTestHomeRemote.class);
0078:                            customerhome = (CustomerHomeRemote) PortableRemoteObject
0079:                                    .narrow(ictx.lookup(BEAN_HOME_CUSTOMER),
0080:                                            CustomerHomeRemote.class);
0081:                            shiphome = (ShipHomeRemote) PortableRemoteObject
0082:                                    .narrow(ictx.lookup(BEAN_HOME_SHIP),
0083:                                            ShipHomeRemote.class);
0084:                            cruisehome = (CruiseHomeRemote) PortableRemoteObject
0085:                                    .narrow(ictx.lookup(BEAN_HOME_CRUISE),
0086:                                            CruiseHomeRemote.class);
0087:                            reservationhome = (ReservationHomeRemote) PortableRemoteObject
0088:                                    .narrow(ictx.lookup(BEAN_HOME_RESERVATION),
0089:                                            ReservationHomeRemote.class);
0090:                            cabinhome = (CabinHomeRemote) PortableRemoteObject
0091:                                    .narrow(ictx.lookup(BEAN_HOME_CABIN),
0092:                                            CabinHomeRemote.class);
0093:                            addresshome = (AddressHomeRemote) PortableRemoteObject
0094:                                    .narrow(ictx.lookup(BEAN_HOME_ADDRESS),
0095:                                            AddressHomeRemote.class);
0096:                        } catch (NamingException e) {
0097:                            fail("Cannot get bean home: " + e.getMessage());
0098:                        }
0099:                        // check if tables have been initialized
0100:                        try {
0101:                            customerhome.findByPrimaryKey(new Integer(80));
0102:                        } catch (Exception e) {
0103:                            // Make the initialization needed for the tests
0104:                            try {
0105:                                utx.begin();
0106:                                String cities[] = new String[6];
0107:                                cities[0] = "Minneapolis";
0108:                                cities[1] = "St. Paul";
0109:                                cities[2] = "Rochester";
0110:                                cities[3] = "Winona";
0111:                                cities[4] = "Wayzata";
0112:                                cities[5] = "Eagan";
0113:                                ShipRemote shipA = null;
0114:                                CruiseRemote cruiseA = null;
0115:                                shipA = shiphome.create(new Integer(10772),
0116:                                        "Ship A", 30000.0);
0117:                                cruiseA = cruisehome.create("Cruise A",
0118:                                        new Integer(10772));
0119:                                for (int jj = 1; jj <= 10; jj++) {
0120:                                    ShipRemote ship = shiphome.create(
0121:                                            new Integer(jj), "Ship " + jj,
0122:                                            30000.0 + (10000.0 * jj));
0123:                                }
0124:                                cruiseA = null;
0125:                                CruiseRemote cruiseB = null;
0126:                                ShipRemote ship1 = shiphome
0127:                                        .findByPrimaryKey(new Integer(1));
0128:                                cruiseA = cruisehome.create("Alaska Cruise",
0129:                                        new Integer(1));
0130:                                cruiseB = cruisehome.create("Bohemian Cruise",
0131:                                        new Integer(1));
0132:                                for (int kk = 80; kk <= 99; kk++) {
0133:                                    CustomerRemote customer = null;
0134:
0135:                                    customer = customerhome.create(new Integer(
0136:                                            kk));
0137:                                    customer.setName(new Name("Smith" + kk,
0138:                                            "John"));
0139:                                    customer.addPhoneNumber("612-555-12" + kk,
0140:                                            (byte) 1);
0141:
0142:                                    customer.setAddress("10" + kk
0143:                                            + " Elm Street",
0144:                                            cities[(kk - 80) % 6],
0145:                                            (kk % 2 == 0 ? "MN" : "CA"), "5540"
0146:                                                    + (kk % 5 + 1));
0147:                                    customer.setHasGoodCredit((kk % 4 == 0));
0148:                                    if (kk % 4 == 0)
0149:                                        customer.setCreditCard(new Date(System
0150:                                                .currentTimeMillis() + 100000),
0151:                                                "100001" + kk, "MasterCard",
0152:                                                "CA", "CETELEM",
0153:                                                "rue de jeunet", cities[0],
0154:                                                "France", "3888");
0155:                                }
0156:                                // Creating Customers 1-6, each with 2 reservations for 2 cabins
0157:                                Calendar date = Calendar.getInstance();
0158:                                date.set(2002, 10, 1);
0159:
0160:                                for (int kk = 201; kk < 207; kk++) {
0161:                                    Collection customers = new ArrayList();
0162:                                    CustomerRemote cust = customerhome
0163:                                            .create(new Integer(kk));
0164:                                    cust.setName(new Name("Customer " + kk,
0165:                                            "Mike"));
0166:                                    cust.setHasGoodCredit((kk % 2 == 0)); // odds are bums
0167:                                    cust.setAddress("50" + kk + " Main Street",
0168:                                            "Minneapolis", "MN", "5510" + kk);
0169:                                    customers.add(new Integer(kk)); // put this single customer in the collection
0170:
0171:                                    Collection reservations = new ArrayList();
0172:
0173:                                    for (int jj = 0; jj < 2; jj++) {
0174:
0175:                                        ReservationRemote reservation = reservationhome
0176:                                                .create(cruiseA.getId(),
0177:                                                        customers);
0178:                                        reservation.setDate(date.getTime());
0179:                                        reservation.setAmountPaid(1000 * kk
0180:                                                + 100 * jj + 2000);
0181:
0182:                                        date.add(Calendar.DAY_OF_MONTH, 7);
0183:
0184:                                        Set cabins = new HashSet();
0185:                                        CabinRemote cabin = cabinhome
0186:                                                .create(new Integer(1000 + kk
0187:                                                        * 100 + jj));
0188:                                        cabin.setDeckLevel(kk - 200);
0189:                                        cabin.setName("Cabin " + kk + "0" + jj
0190:                                                + "1");
0191:
0192:                                        cabins.add(cabin.getId());
0193:                                        cabin = cabinhome.create(new Integer(
0194:                                                1000 + kk * 100 + 10 + jj));
0195:                                        cabin.setDeckLevel(kk - 200);
0196:                                        cabin.setName("Cabin " + kk + "0" + jj
0197:                                                + "2");
0198:
0199:                                        cabins.add(cabin.getId());
0200:
0201:                                        reservation.setAllCabins(cabins); // this reservation has 2 cabins
0202:
0203:                                    }
0204:                                }
0205:                                String fnames[] = new String[5];
0206:                                fnames[0] = "John";
0207:                                fnames[1] = "Paul";
0208:                                fnames[2] = "Ringo";
0209:                                fnames[3] = "Joe";
0210:                                fnames[4] = "Roger";
0211:
0212:                                String lnames[] = new String[3];
0213:                                lnames[0] = "Smith";
0214:                                lnames[1] = "Johnson";
0215:                                lnames[2] = "Star";
0216:                                // Creating Customers 50-69
0217:                                for (int kk = 50; kk <= 69; kk++) {
0218:                                    CustomerRemote customer = customerhome
0219:                                            .create(new Integer(kk));
0220:                                    customer.setName(new Name(
0221:                                            lnames[(kk - 50) % 3],
0222:                                            fnames[(kk - 50) % 5]));
0223:                                    customer.addPhoneNumber("612-555-12" + kk,
0224:                                            (byte) 1);
0225:                                    customer.setAddress("10" + kk
0226:                                            + " Elm Street",
0227:                                            cities[(kk - 50) % 6],
0228:                                            (kk % 2 == 0 ? "MN" : "CA"), "5540"
0229:                                                    + (kk % 5 + 1));
0230:                                    customer.setHasGoodCredit((kk % 4 == 0));
0231:
0232:                                    // Some customers will have reservations already on one of the two cruises..
0233:                                    if (kk % 3 != 0) {
0234:                                        Collection customers = new ArrayList();
0235:                                        customers.add(customer.getId()); // put this single customer in the collection
0236:                                        ReservationRemote reservation = reservationhome
0237:                                                .create((kk % 3 == 1 ? cruiseA
0238:                                                        .getId() : cruiseB
0239:                                                        .getId()), customers);
0240:                                        reservation.setDate(date.getTime());
0241:                                        reservation
0242:                                                .setAmountPaid(10 * kk + 2000);
0243:                                        date.add(Calendar.DAY_OF_MONTH, 7);
0244:                                    }
0245:                                }
0246:
0247:                                // Creating Customers 100-109
0248:
0249:                                for (int kk = 100; kk <= 109; kk++) {
0250:                                    CustomerRemote customer = customerhome
0251:                                            .create(new Integer(kk));
0252:                                    customer.setName(new Name("Lennon" + kk,
0253:                                            "Paul"));
0254:                                    customer.addPhoneNumber("666-543-12" + kk,
0255:                                            (byte) 1);
0256:
0257:                                    customer.setAddress("10" + kk
0258:                                            + " Abbey Road",
0259:                                            cities[(kk - 100) % 6],
0260:                                            (kk % 2 == 0 ? "FL" : "WA"), "5540"
0261:                                                    + (kk % 5 + 1));
0262:                                    customer.setHasGoodCredit((kk % 4 == 0));
0263:                                }
0264:
0265:                            } catch (Exception i) {
0266:                                i.printStackTrace(System.out);
0267:                                fail("InitialState creation problem: " + i);
0268:                            } finally {
0269:                                try {
0270:                                    utx.commit();
0271:                                } catch (Exception ii) {
0272:                                }
0273:                            }
0274:                        }
0275:                        isInit = true;
0276:                    }
0277:                    // Check that all is OK. Sometimes, a test has failed and has corrupted
0278:                    // the bean state in the database. We must unload and reload the bean then.
0279:                    nbtry++;
0280:                    try {
0281:                        if (initStateOK()) {
0282:                            ok = true;
0283:                        }
0284:                    } catch (Exception e) {
0285:                        e.printStackTrace(System.out);
0286:                    }
0287:                    if (!ok) {
0288:                        isInit = false;
0289:                        unloadBeans("ejbql");
0290:                    }
0291:                }
0292:            }
0293:
0294:            /*
0295:             * Check that we are in the same state as after the tables creation for thoses beans A and B
0296:             * (ie if it is the initial state)
0297:             */
0298:            boolean initStateOK() throws Exception {
0299:                // just verify that all ejb are correcly created. Nothing about relation here because we testing only ejbql
0300:                boolean isOk = true;
0301:
0302:                msgerror = new StringBuffer();
0303:
0304:                ShipRemote ship10772 = shiphome.findByPrimaryKey(new Integer(
0305:                        10772));
0306:                for (int i = 1; i <= 10; i++) {
0307:                    ShipRemote ship = shiphome.findByPrimaryKey(new Integer(i));
0308:                }
0309:
0310:                CruiseRemote cruiseA = cruisehome.findByName("Cruise A");
0311:                CruiseRemote cruiseB = cruisehome.findByName("Alaska Cruise");
0312:                CruiseRemote cruiseC = cruisehome.findByName("Bohemian Cruise");
0313:                for (int j = 10; j <= 12; j++) {
0314:                    CruiseRemote cruise = cruisehome
0315:                            .findByPrimaryKey(new Integer(j));
0316:                }
0317:
0318:                for (int k = 80; k <= 109; k++) {
0319:                    CustomerRemote customer = customerhome
0320:                            .findByPrimaryKey(new Integer(k));
0321:                }
0322:
0323:                for (int l = 201; l <= 206; l++) {
0324:                    CustomerRemote customer1 = customerhome
0325:                            .findByPrimaryKey(new Integer(l));
0326:                }
0327:
0328:                for (int p = 50; p <= 69; p++) {
0329:                    CustomerRemote customer2 = customerhome
0330:                            .findByPrimaryKey(new Integer(p));
0331:                }
0332:                for (int kk = 201; kk < 207; kk++) {
0333:                    for (int jj = 0; jj < 2; jj++) {
0334:                        CabinRemote cabin = cabinhome
0335:                                .findByPrimaryKey(new Integer(1000 + kk * 100
0336:                                        + jj));
0337:                        CabinRemote cabin1 = cabinhome
0338:                                .findByPrimaryKey(new Integer(1000 + kk * 100
0339:                                        + 10 + jj));
0340:                    }
0341:                }
0342:
0343:                for (int kkh = 10; kkh <= 34; kkh++) {
0344:                    ReservationRemote reservation = reservationhome
0345:                            .findByPrimaryKey(new Integer(kkh));
0346:                }
0347:
0348:                return isOk;
0349:            }
0350:
0351:            /**
0352:             * The execution of those two tests failed.
0353:             */
0354:            public void testSeries1() throws Exception {
0355:                testWildcards();
0356:                testWildcards();
0357:            }
0358:
0359:            /**
0360:             * 	Finding Customer having name 'John Smith85'
0361:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName = ?1 AND c.firstName = ?2
0362:             */
0363:            public void testAnd1() throws Exception {
0364:                CustomerRemote customer85 = customerhome.findByExactName(
0365:                        "Smith85", "John");
0366:                assertEquals("Wrong Customer : ", new Integer(85), customer85
0367:                        .getId());
0368:                // checkIsInitialState(); not necessary in this test
0369:            }
0370:
0371:            /**
0372:             * 	Finding Customer 'Smith90'
0373:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName = 'Smith90'
0374:             */
0375:            public void testEgalString() throws Exception {
0376:                CustomerRemote customer90 = customerhome.findSmith90();
0377:                assertEquals("Wrong Customer : ", new Integer(90), customer90
0378:                        .getId());
0379:                // checkIsInitialState(); not necessary in this test
0380:            }
0381:
0382:            /**
0383:             * 	Finding Customers having GoodCredit
0384:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.hasGoodCredit = TRUE
0385:             */
0386:            public void testEgalBoolean() throws Exception {
0387:                Collection mplscustomers = customerhome.findByGoodCredit();
0388:                ArrayList customers_id = new ArrayList();
0389:                Iterator customer = mplscustomers.iterator();
0390:                while (customer.hasNext()) {
0391:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0392:                            .narrow(customer.next(), CustomerRemote.class);
0393:                    customers_id.add(customer_remote.getId());
0394:                }
0395:                ArrayList result = new ArrayList();
0396:
0397:                for (int ii = 80; ii <= 96; ii = ii + 4) {
0398:                    result.add(new Integer(ii));
0399:                }
0400:
0401:                for (int ii = 100; ii <= 108; ii = ii + 4) {
0402:                    result.add(new Integer(ii));
0403:                }
0404:                for (int jj = 202; jj <= 206; jj = jj + 2) {
0405:                    result.add(new Integer(jj));
0406:                }
0407:
0408:                for (int kk = 52; kk <= 68; kk = kk + 4) {
0409:                    result.add(new Integer(kk));
0410:                }
0411:
0412:                assertTrue(
0413:                        "Wrong result EJBQL Customer.findByGoogCredit() (required:"
0414:                                + result + ", found:" + customers_id + ")",
0415:                        isCollectionEqual(result, customers_id));
0416:
0417:                // checkIsInitialState();  not necessary in this test
0418:            }
0419:
0420:            /**
0421:             * 	Finding Customers having City = Minneapolis and STATE= MN
0422:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress.city = ?1 AND c.homeAddress.state = ?2
0423:             */
0424:            public void testAnd2() throws Exception {
0425:                Collection mplscustomers = customerhome.findByCity(
0426:                        "Minneapolis", "MN");
0427:
0428:                ArrayList customers_id = new ArrayList();
0429:                Iterator customer = mplscustomers.iterator();
0430:                while (customer.hasNext()) {
0431:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0432:                            .narrow(customer.next(), CustomerRemote.class);
0433:                    customers_id.add(customer_remote.getId());
0434:                }
0435:                ArrayList result = new ArrayList();
0436:                result.add(new Integer(206));
0437:                result.add(new Integer(50));
0438:                result.add(new Integer(56));
0439:                result.add(new Integer(62));
0440:                result.add(new Integer(68));
0441:                result.add(new Integer(80));
0442:                result.add(new Integer(86));
0443:                result.add(new Integer(92));
0444:                result.add(new Integer(98));
0445:                result.add(new Integer(201));
0446:                result.add(new Integer(202));
0447:                result.add(new Integer(203));
0448:                result.add(new Integer(204));
0449:                result.add(new Integer(205));
0450:
0451:                assertTrue(
0452:                        "Wrong result EJBQL Customer.findByCity(Minneapolis,MN) (required:"
0453:                                + result + ", found:" + customers_id + ")",
0454:                        isCollectionEqual(result, customers_id));
0455:
0456:                //checkIsInitialState();not necessary in this test
0457:            }
0458:
0459:            /**
0460:             * 	Finding Customer having a name exactly matching 'Joe Star' &
0461:             *  Finding Customers having a name like 'Jo S' (no wildcards) &
0462:             *  Finding Customers having a name like 'Jo% S%' (with wildcards)
0463:             *  Finding Customers having a name like 'Jo% S%' and living in MN
0464:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName = ?1 AND c.firstName = ?2 &
0465:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 &
0466:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2
0467:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 AND c.homeAddress.state = ?3
0468:             */
0469:            public void testWildcards() throws Exception {
0470:                // first test : exactly matching
0471:                CustomerRemote customer = customerhome.findByExactName("Star",
0472:                        "Joe");
0473:                assertEquals(
0474:                        "Wrong Customer for customerhome.findByExactName(Star,Joe);: ",
0475:                        new Integer(58), customer.getId());
0476:
0477:                // second test : find with no wildcards
0478:                Collection customers = customerhome.findByName("S", "Jo");
0479:                ArrayList customers_id = new ArrayList();
0480:                Iterator customerit1 = customers.iterator();
0481:                while (customerit1.hasNext()) {
0482:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0483:                            .narrow(customerit1.next(), CustomerRemote.class);
0484:                    customers_id.add(customer_remote.getId());
0485:                }
0486:                ArrayList result = new ArrayList();
0487:                assertTrue(
0488:                        "Wrong result EJBQL customerhome.findByName(S,Jo) (required:"
0489:                                + result + ", found:" + customers_id + ")",
0490:                        isCollectionEqual(result, customers_id));
0491:
0492:                // thirdth test : find with no wildcards
0493:                customers = customerhome.findByName("S%", "Jo%");
0494:                customers_id = new ArrayList();
0495:                Iterator customerit2 = customers.iterator();
0496:                while (customerit2.hasNext()) {
0497:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0498:                            .narrow(customerit2.next(), CustomerRemote.class);
0499:                    customers_id.add(customer_remote.getId());
0500:                }
0501:                result = new ArrayList();
0502:                result.add(new Integer(50));
0503:                result.add(new Integer(53));
0504:                result.add(new Integer(55));
0505:                result.add(new Integer(58));
0506:                result.add(new Integer(65));
0507:                result.add(new Integer(68));
0508:                for (int i = 80; i <= 99; i++) {
0509:                    result.add(new Integer(i));
0510:                }
0511:                assertTrue(
0512:                        "Wrong result EJBQL customerhome.findByName(S%,Jo%) (required:"
0513:                                + result + ", found:" + customers_id + ")",
0514:                        isCollectionEqual(result, customers_id));
0515:
0516:                customers = customerhome.findByNameAndState("S%", "Jo%", "MN");
0517:                customers_id = new ArrayList();
0518:                Iterator customerit3 = customers.iterator();
0519:                while (customerit3.hasNext()) {
0520:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0521:                            .narrow(customerit3.next(), CustomerRemote.class);
0522:                    customers_id.add(customer_remote.getId());
0523:                }
0524:                result = new ArrayList();
0525:                result.add(new Integer(50));
0526:                result.add(new Integer(68));
0527:                result.add(new Integer(58));
0528:                for (int i = 80; i <= 99; i = i + 2) {
0529:                    result.add(new Integer(i));
0530:                }
0531:                assertTrue(
0532:                        "Wrong result EJBQL customerhome.findByNameAndState(S%,Jo%,MN) (required:"
0533:                                + result + ", found:" + customers_id + ")",
0534:                        isCollectionEqual(result, customers_id));
0535:
0536:                // checkIsInitialState(); not necessary in this test
0537:            }
0538:
0539:            /**
0540:             * (Bug #300634)
0541:             *  Finding Customers having a name not like 'Jo%' OR not like 'S%'
0542:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName NOT LIKE ?1 OR c.firstName NOT LIKE ?2
0543:             */
0544:            public void testNotLike() throws Exception {
0545:                Collection customers = customerhome.findByNotName("S%", "Jo%");
0546:                ArrayList customers_id = new ArrayList();
0547:                Iterator customerit1 = customers.iterator();
0548:                while (customerit1.hasNext()) {
0549:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0550:                            .narrow(customerit1.next(), CustomerRemote.class);
0551:                    customers_id.add(customer_remote.getId());
0552:                }
0553:                ArrayList result = new ArrayList();
0554:                result.add(new Integer(51));
0555:                result.add(new Integer(52));
0556:                result.add(new Integer(54));
0557:                result.add(new Integer(56));
0558:                result.add(new Integer(57));
0559:                result.add(new Integer(59));
0560:                for (int i = 60; i <= 64; i++) {
0561:                    result.add(new Integer(i));
0562:                }
0563:                result.add(new Integer(66));
0564:                result.add(new Integer(67));
0565:                result.add(new Integer(69));
0566:                for (int i = 100; i <= 109; i++) {
0567:                    result.add(new Integer(i));
0568:                }
0569:                for (int i = 201; i <= 206; i++) {
0570:                    result.add(new Integer(i));
0571:                }
0572:                assertTrue(
0573:                        "Wrong result EJBQL customerhome.findByNotName(S%,Jo%) (required:"
0574:                                + result + ", found:" + customers_id + ")",
0575:                        isCollectionEqual(result, customers_id));
0576:
0577:                // checkIsInitialState(); not necessary in this test
0578:            }
0579:
0580:            /**
0581:             * 	Retrieve a collection of all cabins on deck 3
0582:             *  SELECT OBJECT(c) FROM Cabin as c WHERE c.deckLevel = ?1
0583:             */
0584:            public void testEgalInteger() throws Exception {
0585:                Collection cabins = cabinhome
0586:                        .findAllOnDeckLevel(new Integer(3));
0587:
0588:                ArrayList cabins_id = new ArrayList();
0589:                Iterator cabin = cabins.iterator();
0590:                while (cabin.hasNext()) {
0591:                    CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject
0592:                            .narrow(cabin.next(), CabinRemote.class);
0593:                    cabins_id.add(cabin_remote.getId());
0594:                }
0595:                ArrayList result = new ArrayList();
0596:                result.add(new Integer(21300));
0597:                result.add(new Integer(21310));
0598:                result.add(new Integer(21301));
0599:                result.add(new Integer(21311));
0600:
0601:                assertTrue(
0602:                        "Wrong result EJBQL  cabinhome.findAllOnDeckLevel(new Integer(3))(required:"
0603:                                + result + ", found:" + cabins_id + ")",
0604:                        isCollectionEqual(result, cabins_id));
0605:
0606:                // checkIsInitialState();  not necessary in this test
0607:            }
0608:
0609:            /**
0610:             * 	Findng Customers Living in Warm Climates
0611:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress.state IN ('FL','TX','AZ','CA')
0612:             */
0613:            public void testInWhere() throws Exception {
0614:                Collection customers = customerhome.findInHotStates();
0615:
0616:                ArrayList customers_id = new ArrayList();
0617:                Iterator customer = customers.iterator();
0618:                while (customer.hasNext()) {
0619:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0620:                            .narrow(customer.next(), CustomerRemote.class);
0621:                    customers_id.add(customer_remote.getId());
0622:                }
0623:                ArrayList result = new ArrayList();
0624:                for (int i = 51; i <= 69; i = i + 2) {
0625:                    result.add(new Integer(i));
0626:                }
0627:                for (int j = 100; j <= 109; j = j + 2) {
0628:                    result.add(new Integer(j));
0629:                }
0630:                for (int k = 81; k <= 99; k = k + 2) {
0631:                    result.add(new Integer(k));
0632:                }
0633:
0634:                assertTrue(
0635:                        "Wrong result EJBQL customerhome.findInHotStates() (required:"
0636:                                + result + ", found:" + customers_id + ")",
0637:                        isCollectionEqual(result, customers_id));
0638:
0639:                // checkIsInitialState();  not necessary in this test
0640:            }
0641:
0642:            /**
0643:             * 	Test an IN expression with literals integer
0644:             *  SELECT OBJECT(c) FROM jt2_Cabin as c WHERE c.deckLevel IN ( 1 , 3 , 5 )
0645:             */
0646:            public void test2InWhere() throws Exception {
0647:                Collection cabins = cabinhome.findAllOnDeckLevel1_3_5();
0648:
0649:                ArrayList customers_id = new ArrayList();
0650:                Iterator icabins = cabins.iterator();
0651:                int nb = 0;
0652:                while (icabins.hasNext()) {
0653:                    CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject
0654:                            .narrow(icabins.next(), CabinRemote.class);
0655:                    nb++;
0656:                    int level = cabin_remote.getDeckLevel();
0657:                    if ((level != 1) && (level != 3) && (level != 5)) {
0658:                        fail("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_5(5) (level="
0659:                                + level + ")");
0660:                    }
0661:                }
0662:                assertEquals(
0663:                        "Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_5(5)",
0664:                        12, nb);
0665:
0666:                // checkIsInitialState();  not necessary in this test
0667:            }
0668:
0669:            /**
0670:             * 	Test an IN expression with literals integer and an input parameter
0671:             *  SELECT OBJECT(c) FROM jt2_Cabin as c WHERE c.deckLevel IN ( 1 , 3 , ?1 )
0672:             */
0673:            public void test3InWhere() throws Exception {
0674:                Collection cabins = cabinhome.findAllOnDeckLevel1_3_X(5);
0675:
0676:                ArrayList customers_id = new ArrayList();
0677:                Iterator icabins = cabins.iterator();
0678:                int nb = 0;
0679:                while (icabins.hasNext()) {
0680:                    CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject
0681:                            .narrow(icabins.next(), CabinRemote.class);
0682:                    nb++;
0683:                    int level = cabin_remote.getDeckLevel();
0684:                    if ((level != 1) && (level != 3) && (level != 5)) {
0685:                        fail("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_X(5) (level="
0686:                                + level + ")");
0687:                    }
0688:                }
0689:                assertEquals(
0690:                        "Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_X(5)",
0691:                        12, nb);
0692:
0693:                // checkIsInitialState();  not necessary in this test
0694:            }
0695:
0696:            /**
0697:             * 	Finding Customers Without Reservations
0698:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.reservations IS EMPTY
0699:             */
0700:            public void testIsEmpty() throws Exception {
0701:                Collection customers = customerhome.findWithoutReservations();
0702:
0703:                ArrayList customers_id = new ArrayList();
0704:                Iterator customer = customers.iterator();
0705:                while (customer.hasNext()) {
0706:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0707:                            .narrow(customer.next(), CustomerRemote.class);
0708:                    customers_id.add(customer_remote.getId());
0709:                }
0710:                ArrayList result = new ArrayList();
0711:                for (int i = 51; i <= 69; i = i + 3) {
0712:                    result.add(new Integer(i));
0713:                }
0714:                for (int i = 80; i <= 109; i++) {
0715:                    result.add(new Integer(i));
0716:                }
0717:
0718:                assertTrue(
0719:                        "Wrong result EJBQL customerhome.findWithoutReservations() (required:"
0720:                                + result + ", found:" + customers_id + ")",
0721:                        isCollectionEqual(result, customers_id));
0722:
0723:                //checkIsInitialState(); not necessary in this test
0724:            }
0725:
0726:            /**
0727:             * 	Finding Customers With Reservations
0728:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.reservations IS NOT EMPTY
0729:             */
0730:            public void testIsNotEmpty() throws Exception {
0731:                Collection customers = customerhome.findWithReservations();
0732:
0733:                ArrayList customers_id = new ArrayList();
0734:                Iterator customer = customers.iterator();
0735:                while (customer.hasNext()) {
0736:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0737:                            .narrow(customer.next(), CustomerRemote.class);
0738:                    customers_id.add(customer_remote.getId());
0739:                }
0740:                ArrayList result = new ArrayList();
0741:                for (int i = 201; i <= 206; i++) {
0742:                    result.add(new Integer(i));
0743:                }
0744:                result.add(new Integer(50));
0745:                result.add(new Integer(52));
0746:                result.add(new Integer(53));
0747:                result.add(new Integer(55));
0748:                result.add(new Integer(56));
0749:                result.add(new Integer(58));
0750:                result.add(new Integer(59));
0751:                result.add(new Integer(61));
0752:                result.add(new Integer(62));
0753:                result.add(new Integer(64));
0754:                result.add(new Integer(65));
0755:                result.add(new Integer(67));
0756:                result.add(new Integer(68));
0757:
0758:                assertTrue(
0759:                        "Wrong result EJBQL customerhome.findWithReservations() (required:"
0760:                                + result + ", found:" + customers_id + ")",
0761:                        isCollectionEqual(result, customers_id));
0762:
0763:                //checkIsInitialState(); not necessary in this test
0764:            }
0765:
0766:            /**
0767:             * Test to reproduce bug #300525
0768:             * 	Finding Customers Without or With Reservations (equivalent to finding all customers)
0769:             *  SELECT OBJECT(c) FROM jt2_Customer c
0770:             *    WHERE c.reservations IS EMPTY OR c.reservations IS NOT EMPTY
0771:             */
0772:            public void testIsEmptyIsNotEmpty() throws Exception {
0773:                Collection customers = customerhome
0774:                        .findWithOrWithoutReservations();
0775:
0776:                ArrayList customers_id = new ArrayList();
0777:                Iterator customer = customers.iterator();
0778:                while (customer.hasNext()) {
0779:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0780:                            .narrow(customer.next(), CustomerRemote.class);
0781:                    customers_id.add(customer_remote.getId());
0782:                }
0783:                ArrayList result = new ArrayList();
0784:                for (int i = 50; i <= 69; i++) {
0785:                    result.add(new Integer(i));
0786:                }
0787:                for (int i = 80; i <= 109; i++) {
0788:                    result.add(new Integer(i));
0789:                }
0790:                for (int i = 201; i <= 206; i++) {
0791:                    result.add(new Integer(i));
0792:                }
0793:
0794:                assertTrue(
0795:                        "Wrong result EJBQL customerhome.findWithOrWithoutReservations() (required:"
0796:                                + result + ", found:" + customers_id + ")",
0797:                        isCollectionEqual(result, customers_id));
0798:
0799:                //checkIsInitialState(); not necessary in this test
0800:            }
0801:
0802:            /**
0803:             * 	Finding Customers Without Reservations and with good credit
0804:             *  SELECT OBJECT(c) FROM jt2_Customer c
0805:             *    WHERE c.reservations IS EMPTY AND c.hasGoodCredit = true
0806:             */
0807:            public void testIsEmptyInExp1() throws Exception {
0808:                Collection customers = customerhome
0809:                        .findWithoutReservationsAndWithGoodCredit(true);
0810:
0811:                ArrayList customers_id = new ArrayList();
0812:                Iterator customer = customers.iterator();
0813:                while (customer.hasNext()) {
0814:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0815:                            .narrow(customer.next(), CustomerRemote.class);
0816:                    customers_id.add(customer_remote.getId());
0817:                }
0818:                ArrayList result = new ArrayList();
0819:                result.add(new Integer(80));
0820:                result.add(new Integer(84));
0821:                result.add(new Integer(88));
0822:                result.add(new Integer(92));
0823:                result.add(new Integer(96));
0824:                result.add(new Integer(60));
0825:                result.add(new Integer(100));
0826:                result.add(new Integer(104));
0827:                result.add(new Integer(108));
0828:
0829:                assertTrue(
0830:                        "Wrong result EJBQL customerhome.findWithoutReservationsAndWithGoodCredit() (required:"
0831:                                + result + ", found:" + customers_id + ")",
0832:                        isCollectionEqual(result, customers_id));
0833:
0834:                //checkIsInitialState(); not necessary in this test
0835:            }
0836:
0837:            /**
0838:             * 	Finding Customers Without Reservations and with good credit
0839:             *  Test equivalent to testIsEmptyInExp1
0840:             *  SELECT OBJECT(c) FROM jt2_Customer c
0841:             *    WHERE NOT (c.reservations IS NOT EMPTY OR c.hasGoodCredit <> true)
0842:             */
0843:            public void testIsEmptyInExp1Bis() throws Exception {
0844:                Collection customers = customerhome
0845:                        .findBisWithoutReservationsAndWithGoodCredit(true);
0846:
0847:                ArrayList customers_id = new ArrayList();
0848:                Iterator customer = customers.iterator();
0849:                while (customer.hasNext()) {
0850:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0851:                            .narrow(customer.next(), CustomerRemote.class);
0852:                    customers_id.add(customer_remote.getId());
0853:                }
0854:                ArrayList result = new ArrayList();
0855:                result.add(new Integer(80));
0856:                result.add(new Integer(84));
0857:                result.add(new Integer(88));
0858:                result.add(new Integer(92));
0859:                result.add(new Integer(96));
0860:                result.add(new Integer(60));
0861:                result.add(new Integer(100));
0862:                result.add(new Integer(104));
0863:                result.add(new Integer(108));
0864:
0865:                assertTrue(
0866:                        "Wrong result EJBQL customerhome.findBisWithoutReservationsAndWithGoodCredit() (required:"
0867:                                + result + ", found:" + customers_id + ")",
0868:                        isCollectionEqual(result, customers_id));
0869:
0870:                //checkIsInitialState(); not necessary in this test
0871:            }
0872:
0873:            /**
0874:             * 	Finding Customers Without Reservations and with good credit
0875:             *  Test equivalent to testIsEmptyInExp1
0876:             *  SELECT OBJECT(c) FROM jt2_Customer c
0877:             *    WHERE NOT ( NOT (c.reservations IS EMPTY AND c.hasGoodCredit = true) )
0878:             */
0879:            public void testIsEmptyInExp1Ter() throws Exception {
0880:                Collection customers = customerhome
0881:                        .findTerWithoutReservationsAndWithGoodCredit(true);
0882:
0883:                ArrayList customers_id = new ArrayList();
0884:                Iterator customer = customers.iterator();
0885:                while (customer.hasNext()) {
0886:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0887:                            .narrow(customer.next(), CustomerRemote.class);
0888:                    customers_id.add(customer_remote.getId());
0889:                }
0890:                ArrayList result = new ArrayList();
0891:                result.add(new Integer(80));
0892:                result.add(new Integer(84));
0893:                result.add(new Integer(88));
0894:                result.add(new Integer(92));
0895:                result.add(new Integer(96));
0896:                result.add(new Integer(60));
0897:                result.add(new Integer(100));
0898:                result.add(new Integer(104));
0899:                result.add(new Integer(108));
0900:
0901:                assertTrue(
0902:                        "Wrong result EJBQL customerhome.findTerWithoutReservationsAndWithGoodCredit() (required:"
0903:                                + result + ", found:" + customers_id + ")",
0904:                        isCollectionEqual(result, customers_id));
0905:
0906:                //checkIsInitialState(); not necessary in this test
0907:            }
0908:
0909:            /**
0910:             * 	Finding Customers Without Reservations and with good credit
0911:             *  Test equivalent to testIsEmptyInExp1
0912:             *  SELECT OBJECT(c) FROM jt2_Customer c
0913:             *    WHERE NOT (c.hasGoodCredit <> true) AND c.reservations IS EMPTY
0914:             */
0915:            public void testIsEmptyInExp1Quad() throws Exception {
0916:                Collection customers = customerhome
0917:                        .findQuadWithoutReservationsAndWithGoodCredit(true);
0918:
0919:                ArrayList customers_id = new ArrayList();
0920:                Iterator customer = customers.iterator();
0921:                while (customer.hasNext()) {
0922:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0923:                            .narrow(customer.next(), CustomerRemote.class);
0924:                    customers_id.add(customer_remote.getId());
0925:                }
0926:                ArrayList result = new ArrayList();
0927:                result.add(new Integer(80));
0928:                result.add(new Integer(84));
0929:                result.add(new Integer(88));
0930:                result.add(new Integer(92));
0931:                result.add(new Integer(96));
0932:                result.add(new Integer(60));
0933:                result.add(new Integer(100));
0934:                result.add(new Integer(104));
0935:                result.add(new Integer(108));
0936:
0937:                assertTrue(
0938:                        "Wrong result EJBQL customerhome.findQuadWithoutReservationsAndWithGoodCredit() (required:"
0939:                                + result + ", found:" + customers_id + ")",
0940:                        isCollectionEqual(result, customers_id));
0941:
0942:                //checkIsInitialState(); not necessary in this test
0943:            }
0944:
0945:            /**
0946:             * Test to reproduce bug #300525
0947:             * 	Finding Customers Without Reservations OR with good credit
0948:             *  SELECT OBJECT(c) FROM jt2_Customer c
0949:             *    WHERE c.reservations IS EMPTY OR c.hasGoodCredit == true
0950:             */
0951:            public void testIsEmptyInExp2() throws Exception {
0952:                Collection customers = customerhome
0953:                        .findWithoutReservationsOrWithGoodCredit(true);
0954:
0955:                ArrayList customers_id = new ArrayList();
0956:                Iterator customer = customers.iterator();
0957:                while (customer.hasNext()) {
0958:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
0959:                            .narrow(customer.next(), CustomerRemote.class);
0960:                    customers_id.add(customer_remote.getId());
0961:                }
0962:                ArrayList result = new ArrayList();
0963:                for (int i = 51; i <= 69; i = i + 3) {
0964:                    result.add(new Integer(i));
0965:                }
0966:                for (int i = 80; i <= 109; i++) {
0967:                    result.add(new Integer(i));
0968:                }
0969:                result.add(new Integer(202));
0970:                result.add(new Integer(204));
0971:                result.add(new Integer(206));
0972:                result.add(new Integer(52));
0973:                result.add(new Integer(56));
0974:                result.add(new Integer(64));
0975:                result.add(new Integer(68));
0976:
0977:                assertTrue(
0978:                        "Wrong result EJBQL customerhome.findWithoutReservationsOrWithGoodCredit() (required:"
0979:                                + result + ", found:" + customers_id + ")",
0980:                        isCollectionEqual(result, customers_id));
0981:
0982:                //checkIsInitialState(); not necessary in this test
0983:            }
0984:
0985:            /**
0986:             * 	Finding the customer with a specific phone number
0987:             *  SELECT OBJECT(c) FROM jt2_Customer cust WHERE ?1 IS MEMBER OF cust.phoneNumbers
0988:             * This test is done via a session bean because it need to use Local interfaces.
0989:             */
0990:            public void testSimpleMemberOf() throws Exception {
0991:                SessionTestRemote sTest = sessiontesthome.create();
0992:                int custId = sTest.getCustomerWithPhone("612-555-1280")
0993:                        .intValue();
0994:                ;
0995:                assertEquals(
0996:                        "Wrong result EJBQL session.getCustomerWithPhone(612-555-1280): ",
0997:                        80, custId);
0998:
0999:                // checkIsInitialState(); not necessary in this test
1000:            }
1001:
1002:            /**
1003:             * 	Finding Customers On Alaska Cruise
1004:             *  SELECT OBJECT(c) FROM jt2_Customer cust, Cruise cr, IN(cr.reservations) res
1005:             *  WHERE cr = ?1 AND cust MEMBER OF res.customers
1006:             */
1007:            public void testMemberOfNavigate() throws Exception {
1008:                CruiseRemote crA = cruisehome.findByName("Alaska Cruise");
1009:                Collection customers_id = customerhome.callFindOnCruise(crA
1010:                        .getId());
1011:
1012:                ArrayList result = new ArrayList();
1013:                result.add(new Integer(201));
1014:                result.add(new Integer(202));
1015:                result.add(new Integer(203));
1016:                result.add(new Integer(204));
1017:                result.add(new Integer(205));
1018:                result.add(new Integer(206));
1019:                result.add(new Integer(52));
1020:                result.add(new Integer(55));
1021:                result.add(new Integer(58));
1022:                result.add(new Integer(61));
1023:                result.add(new Integer(64));
1024:                result.add(new Integer(67));
1025:
1026:                assertTrue(
1027:                        "Wrong result EJBQL customerhome.findOnCruise(crA) (required:"
1028:                                + result + ", found:" + customers_id + ")",
1029:                        isCollectionEqual(result, customers_id));
1030:
1031:                // checkIsInitialState(); not necessary in this test
1032:            }
1033:
1034:            /**
1035:             * 	Finding ship by tonnage
1036:             *  SELECT OBJECT(c) FROM jt2_Ship s
1037:             *  WHERE s.tonnage = ?1
1038:             */
1039:            public void testEgalDouble() throws Exception {
1040:                Collection ships = shiphome.findByTonnage(new Double(100000));
1041:
1042:                ArrayList ships_id = new ArrayList();
1043:                Iterator ship = ships.iterator();
1044:                while (ship.hasNext()) {
1045:                    ShipRemote ship_remote = (ShipRemote) PortableRemoteObject
1046:                            .narrow(ship.next(), ShipRemote.class);
1047:                    ships_id.add(ship_remote.getId());
1048:                }
1049:                ArrayList result = new ArrayList();
1050:                result.add(new Integer(7));
1051:
1052:                assertTrue(
1053:                        "Wrong result EJBQL shiphome.findByTonnage(new Double(100000)) (required:"
1054:                                + result + ", found:" + ships_id + ")",
1055:                        isCollectionEqual(result, ships_id));
1056:
1057:                // checkIsInitialState(); not necessary in this test
1058:            }
1059:
1060:            /**
1061:             * 	Finding ship by tonnage
1062:             *  SELECT OBJECT(c) FROM jt2_Ship s
1063:             *  WHERE s.tonnage BETWEEN ?1 AND ?2
1064:             */
1065:            public void testBetweenDouble() throws Exception {
1066:                Collection ships = shiphome.findByTonnage(new Double(100000),
1067:                        new Double(130000));
1068:
1069:                ArrayList ships_id = new ArrayList();
1070:                Iterator ship = ships.iterator();
1071:                while (ship.hasNext()) {
1072:                    ShipRemote ship_remote = (ShipRemote) PortableRemoteObject
1073:                            .narrow(ship.next(), ShipRemote.class);
1074:                    ships_id.add(ship_remote.getId());
1075:                }
1076:                ArrayList result = new ArrayList();
1077:                result.add(new Integer(7));
1078:                result.add(new Integer(8));
1079:                result.add(new Integer(9));
1080:                result.add(new Integer(10));
1081:
1082:                assertTrue(
1083:                        "Wrong result EJBQL shiphome.findByTonnage(new Double(100000),new Double(130000)) (required:"
1084:                                + result + ", found:" + ships_id + ")",
1085:                        isCollectionEqual(result, ships_id));
1086:
1087:                // checkIsInitialState(); not necessary in this test
1088:            }
1089:
1090:            /**
1091:             * A complex navigation test
1092:             * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.creditCard.creditCompany.address.city = ?1
1093:             */
1094:            public void testNavigate() throws Exception {
1095:
1096:                Collection customers = customerhome
1097:                        .findAllCreditCardAddress("Minneapolis");
1098:
1099:                ArrayList customers_id = new ArrayList();
1100:                Iterator customer = customers.iterator();
1101:                while (customer.hasNext()) {
1102:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1103:                            .narrow(customer.next(), CustomerRemote.class);
1104:                    customers_id.add(customer_remote.getId());
1105:                }
1106:                ArrayList result = new ArrayList();
1107:                result.add(new Integer(80));
1108:                result.add(new Integer(84));
1109:                result.add(new Integer(88));
1110:                result.add(new Integer(92));
1111:                result.add(new Integer(96));
1112:
1113:                assertTrue(
1114:                        "Wrong result EJBQL customerhome.findAllCreditCardAddress() (required:"
1115:                                + result + ", found:" + customers_id + ")",
1116:                        isCollectionEqual(result, customers_id));
1117:
1118:                checkIsInitialState();
1119:
1120:            }
1121:
1122:            /**
1123:             * An other complex navigation test and the OR operator
1124:             * SELECT OBJECT(c) FROM jt2_Customer AS c WHERE c.creditCard.number = ?1 OR c.homeAddress.zip = ?2
1125:             */
1126:            public void testNavigateOr() throws Exception {
1127:
1128:                Collection customers = customerhome.findCustWithCCNumOrAddrZip(
1129:                        "10000184", "55404");
1130:
1131:                ArrayList customers_id = new ArrayList();
1132:                Iterator customer = customers.iterator();
1133:                while (customer.hasNext()) {
1134:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1135:                            .narrow(customer.next(), CustomerRemote.class);
1136:                    customers_id.add(customer_remote.getId());
1137:                }
1138:                ArrayList result = new ArrayList();
1139:                result.add(new Integer(84));
1140:                result.add(new Integer(88));
1141:
1142:                assertTrue(
1143:                        "Wrong result EJBQL customerhome.findCustWithCCNumOrAddrZip() (required:"
1144:                                + result + ", found:" + customers_id + ")",
1145:                        isCollectionEqual(result, customers_id));
1146:
1147:                checkIsInitialState();
1148:
1149:            }
1150:
1151:            /**
1152:             * 	Finding all Customer with reservations (there will be duplication in result if customer has more than one reservation
1153:             *
1154:             *  SELECT OBJECT(c) FROM jt2_Reservation res, IN(res.customers) c
1155:             */
1156:            public void testInFrom() throws Exception {
1157:
1158:                Collection customers = customerhome
1159:                        .findAllCustomersWithReservation();
1160:
1161:                ArrayList customers_id = new ArrayList();
1162:                Iterator customer = customers.iterator();
1163:                while (customer.hasNext()) {
1164:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1165:                            .narrow(customer.next(), CustomerRemote.class);
1166:                    customers_id.add(customer_remote.getId());
1167:                }
1168:                ArrayList result = new ArrayList();
1169:
1170:                result.add(new Integer(201));
1171:                result.add(new Integer(201));
1172:                result.add(new Integer(202));
1173:                result.add(new Integer(202));
1174:                result.add(new Integer(203));
1175:                result.add(new Integer(203));
1176:                result.add(new Integer(204));
1177:                result.add(new Integer(204));
1178:                result.add(new Integer(205));
1179:                result.add(new Integer(205));
1180:                result.add(new Integer(206));
1181:                result.add(new Integer(206));
1182:                result.add(new Integer(50));
1183:                result.add(new Integer(52));
1184:                result.add(new Integer(53));
1185:                result.add(new Integer(55));
1186:                result.add(new Integer(56));
1187:                result.add(new Integer(58));
1188:                result.add(new Integer(59));
1189:                result.add(new Integer(61));
1190:                result.add(new Integer(62));
1191:                result.add(new Integer(64));
1192:                result.add(new Integer(65));
1193:                result.add(new Integer(67));
1194:                result.add(new Integer(68));
1195:
1196:                assertTrue(
1197:                        "Wrong result EJBQL customerhome.findAllCustomersWithReservation (required:"
1198:                                + result + ", found:" + customers_id + ")",
1199:                        isCollectionEqual(result, customers_id));
1200:
1201:                // checkIsInitialState();  not necessary in this test
1202:            }
1203:
1204:            /**
1205:             * 	Finding all Customer with reservations (there will not be duplication in result)
1206:             *
1207:             *  SELECT DISTINCT OBJECT(c) FROM jt2_Reservation res, IN(res.customers) c
1208:             */
1209:            public void testDistinctInFrom() throws Exception {
1210:
1211:                Collection customers = customerhome
1212:                        .findAllCustomersWithReservationDistinct();
1213:
1214:                ArrayList customers_id = new ArrayList();
1215:                Iterator customer = customers.iterator();
1216:                while (customer.hasNext()) {
1217:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1218:                            .narrow(customer.next(), CustomerRemote.class);
1219:                    customers_id.add(customer_remote.getId());
1220:                }
1221:                ArrayList result = new ArrayList();
1222:
1223:                result.add(new Integer(201));
1224:                result.add(new Integer(202));
1225:                result.add(new Integer(203));
1226:                result.add(new Integer(204));
1227:                result.add(new Integer(205));
1228:                result.add(new Integer(206));
1229:                result.add(new Integer(50));
1230:                result.add(new Integer(52));
1231:                result.add(new Integer(53));
1232:                result.add(new Integer(55));
1233:                result.add(new Integer(56));
1234:                result.add(new Integer(58));
1235:                result.add(new Integer(59));
1236:                result.add(new Integer(61));
1237:                result.add(new Integer(62));
1238:                result.add(new Integer(64));
1239:                result.add(new Integer(65));
1240:                result.add(new Integer(67));
1241:                result.add(new Integer(68));
1242:
1243:                assertTrue(
1244:                        "Wrong result EJBQL customerhome.findAllCustomersWithReservationDistinct (required:"
1245:                                + result + ", found:" + customers_id + ")",
1246:                        isCollectionEqual(result, customers_id));
1247:
1248:                // checkIsInitialState(); not necessary in this test
1249:            }
1250:
1251:            /**
1252:             * Test for feature #300040
1253:             * 	Finding Customer by address
1254:             *
1255:             * 	SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress = ?1
1256:             */
1257:            public void _testBeanAsParameter() throws Exception {
1258:
1259:                AddressRemote add = addresshome
1260:                        .findByPrimaryKey(new Integer(10));
1261:
1262:                Collection customers = customerhome.findByAddress(add);
1263:
1264:                ArrayList customers_id = new ArrayList();
1265:                Iterator customer = customers.iterator();
1266:                while (customer.hasNext()) {
1267:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1268:                            .narrow(customer.next(), CustomerRemote.class);
1269:                    customers_id.add(customer_remote.getId());
1270:                }
1271:                ArrayList result = new ArrayList();
1272:
1273:                result.add(new Integer(80));
1274:
1275:                assertTrue(
1276:                        "Wrong result EJBQL customerhome.findByAddress(add)(required:"
1277:                                + result + ", found:" + customers_id + ")",
1278:                        isCollectionEqual(result, customers_id));
1279:
1280:                // checkIsInitialState(); not necessary in this test
1281:            }
1282:
1283:            /**
1284:             * Test for feature #300040
1285:             * 	Finding Customer by address
1286:             *
1287:             * 	SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress = ?1
1288:             */
1289:            public void _testBeanNullAsParameter() throws Exception {
1290:
1291:                Collection customers = customerhome.findByAddress(null);
1292:
1293:                ArrayList customers_id = new ArrayList();
1294:                Iterator customer = customers.iterator();
1295:                while (customer.hasNext()) {
1296:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1297:                            .narrow(customer.next(), CustomerRemote.class);
1298:                    customers_id.add(customer_remote.getId());
1299:                }
1300:                ArrayList result = new ArrayList();
1301:
1302:                assertTrue(
1303:                        "Wrong result EJBQL customerhome.findByAddress(add)(required:"
1304:                                + result + ", found:" + customers_id + ")",
1305:                        isCollectionEqual(result, customers_id));
1306:
1307:                // checkIsInitialState(); not necessary in this test
1308:            }
1309:
1310:            /**
1311:             * 	Finding All Customer
1312:             *
1313:             * 	SELECT OBJECT(c) FROM jt2_Customer AS c
1314:             */
1315:            public void testFindCustomerAll() throws Exception {
1316:
1317:                Collection customers = customerhome.findCustomersAll();
1318:
1319:                ArrayList customers_id = new ArrayList();
1320:                Iterator customer = customers.iterator();
1321:                while (customer.hasNext()) {
1322:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1323:                            .narrow(customer.next(), CustomerRemote.class);
1324:                    customers_id.add(customer_remote.getId());
1325:                }
1326:                ArrayList result = new ArrayList();
1327:
1328:                for (int i = 80; i <= 99; i++) {
1329:                    result.add(new Integer(i));
1330:                }
1331:                for (int j = 201; j <= 206; j++) {
1332:                    result.add(new Integer(j));
1333:                }
1334:                for (int k = 50; k <= 69; k++) {
1335:                    result.add(new Integer(k));
1336:                }
1337:                for (int l = 100; l <= 109; l++) {
1338:                    result.add(new Integer(l));
1339:                }
1340:
1341:                assertTrue(
1342:                        "Wrong result EJBQL customerhome.findCustomersAll()(required:"
1343:                                + result + ", found:" + customers_id + ")",
1344:                        isCollectionEqual(result, customers_id));
1345:
1346:                // checkIsInitialState(); not necessary in this test
1347:            }
1348:
1349:            /**
1350:             * 	Finding Customers by AddressId
1351:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress.id = ?1
1352:             */
1353:            public void testFindCustByAddrId() throws Exception {
1354:                Collection customers = customerhome
1355:                        .findByAddressId(new Integer(10));
1356:
1357:                ArrayList customers_id = new ArrayList();
1358:                Iterator customer = customers.iterator();
1359:                while (customer.hasNext()) {
1360:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1361:                            .narrow(customer.next(), CustomerRemote.class);
1362:                    customers_id.add(customer_remote.getId());
1363:                }
1364:                ArrayList result = new ArrayList();
1365:                result.add(new Integer(80));
1366:
1367:                assertTrue(
1368:                        "Wrong result EJBQL customerhome.findByAddressId(10) (required:"
1369:                                + result + ", found:" + customers_id + ")",
1370:                        isCollectionEqual(result, customers_id));
1371:
1372:                // checkIsInitialState(); not necessary in this test
1373:            }
1374:
1375:            /**
1376:             * Bug #300626
1377:             * SELECT OBJECT(a) FROM jt2_Address AS a
1378:             *		  WHERE a.homecustomer.lastName = 'Smith80'
1379:             *		  AND a.homecustomer.creditCard.id = 10
1380:             *		  AND a.homecustomer.creditCard.creditCompany.name = 'CETELEM'
1381:             *		  AND a.homecustomer.creditCard.creditCompany.id = 10
1382:             */
1383:            public void testAddrQuery300626() throws Exception {
1384:                AddressRemote a = addresshome.findQuery300626();
1385:                assertEquals(
1386:                        "Wrong result EJBQL : addresshome.findQuery300626()",
1387:                        10, a.getId().intValue());
1388:            }
1389:
1390:            /**
1391:             * 	Finding Customers by AddressLocal
1392:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress = ?1
1393:             */
1394:            public void testBeanLocalAsParameter() throws Exception {
1395:                Collection customers = customerhome
1396:                        .callFindByAddressLocal(new Integer(10));
1397:
1398:                ArrayList customers_id = new ArrayList();
1399:                Iterator customer = customers.iterator();
1400:                while (customer.hasNext()) {
1401:                    customers_id.add((Integer) customer.next());
1402:                }
1403:                ArrayList result = new ArrayList();
1404:                result.add(new Integer(80));
1405:
1406:                assertTrue(
1407:                        "Wrong result EJBQL customerhome.callFindByAddressLocal(10) (required:"
1408:                                + result + ", found:" + customers_id + ")",
1409:                        isCollectionEqual(result, customers_id));
1410:
1411:                // checkIsInitialState(); not necessary in this test
1412:            }
1413:
1414:            /**
1415:             * 	Finding Customers by AddressLocal
1416:             *  SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress = ?1
1417:             */
1418:            public void testBeanLocalNullAsParameter() throws Exception {
1419:                Collection customers = customerhome
1420:                        .callFindByAddressLocal(null);
1421:
1422:                ArrayList customers_id = new ArrayList();
1423:                Iterator customer = customers.iterator();
1424:                while (customer.hasNext()) {
1425:                    customers_id.add((Integer) customer.next());
1426:                }
1427:                ArrayList result = new ArrayList();
1428:
1429:                assertTrue(
1430:                        "Wrong result EJBQL customerhome.callFindByAddressLocal(null) (required:"
1431:                                + result + ", found:" + customers_id + ")",
1432:                        isCollectionEqual(result, customers_id));
1433:
1434:                // checkIsInitialState(); not necessary in this test
1435:            }
1436:
1437:            /**
1438:             * Test a finder method
1439:             * - which have no parameter and which have its name starts with 'findAll',
1440:             * - but which not means "findAll".
1441:             * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.firstName LIKE 'Mike'
1442:             */
1443:            public void testFindAllMike() throws Exception {
1444:                Collection customers = customerhome.findAllMike();
1445:                ArrayList customers_id = new ArrayList();
1446:                Iterator customer = customers.iterator();
1447:                while (customer.hasNext()) {
1448:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1449:                            .narrow(customer.next(), CustomerRemote.class);
1450:                    assertEquals("findAllMike() wrong result: ", "Mike",
1451:                            customer_remote.getName().getFirstName());
1452:                }
1453:            }
1454:
1455:            /**
1456:             * Test a finder method with the IS NOT NULL operator on a cmr field.
1457:             * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.creditCard IS NOT NULL
1458:             */
1459:            public void testIsNull1() throws Exception {
1460:                Collection customers = customerhome
1461:                        .findCustomersWithCreditCard();
1462:                ArrayList customers_id = new ArrayList();
1463:                Iterator customer = customers.iterator();
1464:                while (customer.hasNext()) {
1465:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1466:                            .narrow(customer.next(), CustomerRemote.class);
1467:                    customers_id.add(customer_remote.getId());
1468:                }
1469:                ArrayList resExpected = new ArrayList();
1470:                resExpected.add(new Integer(80));
1471:                resExpected.add(new Integer(84));
1472:                resExpected.add(new Integer(88));
1473:                resExpected.add(new Integer(92));
1474:                resExpected.add(new Integer(96));
1475:                assertTrue(
1476:                        "Wrong result EJBQL customerhome.findCustomersWithCreditCard (required:"
1477:                                + resExpected + ", found:" + customers_id + ")",
1478:                        isCollectionEqual(resExpected, customers_id));
1479:            }
1480:
1481:            /**
1482:             * Test a finder method with the IS NULL operator on a cmr field.
1483:             * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.creditCard IS NULL
1484:             */
1485:            public void testIsNull1bis() throws Exception {
1486:                Collection customers = customerhome
1487:                        .findCustomersWithOutCreditCard();
1488:                ArrayList customers_id = new ArrayList();
1489:                Iterator customer = customers.iterator();
1490:                while (customer.hasNext()) {
1491:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1492:                            .narrow(customer.next(), CustomerRemote.class);
1493:                    customers_id.add(customer_remote.getId());
1494:                }
1495:                ArrayList resExpected = new ArrayList();
1496:                for (int i = 50; i <= 69; i++) {
1497:                    resExpected.add(new Integer(i));
1498:                }
1499:                for (int i = 81; i <= 83; i++) {
1500:                    resExpected.add(new Integer(i));
1501:                }
1502:                for (int i = 85; i <= 87; i++) {
1503:                    resExpected.add(new Integer(i));
1504:                }
1505:                for (int i = 89; i <= 91; i++) {
1506:                    resExpected.add(new Integer(i));
1507:                }
1508:                for (int i = 93; i <= 95; i++) {
1509:                    resExpected.add(new Integer(i));
1510:                }
1511:                for (int i = 97; i <= 109; i++) {
1512:                    resExpected.add(new Integer(i));
1513:                }
1514:                for (int i = 201; i <= 206; i++) {
1515:                    resExpected.add(new Integer(i));
1516:                }
1517:                assertTrue(
1518:                        "Wrong result EJBQL customerhome.findCustomersWithOutCreditCard (required:"
1519:                                + resExpected + ", found:" + customers_id + ")",
1520:                        isCollectionEqual(resExpected, customers_id));
1521:            }
1522:
1523:            /**
1524:             * Test a finder method with the IS NULL operator on a cmr field in an expression.
1525:             * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.firstName = ?1 AND c.creditCard IS NULL
1526:             */
1527:            public void testIsNull1ter() throws Exception {
1528:                Collection customers = customerhome
1529:                        .findCustomersXWithOutCreditCard("John");
1530:                assertEquals(
1531:                        "Wrong result EJBQL customerhome.findCustomersXWithOutCreditCard: ",
1532:                        19, customers.size());
1533:
1534:            }
1535:
1536:            /**
1537:             * Test a finder method with the IS NOT NULL operator on a cmr field with a complex navigation.
1538:             * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.creditCard.creditCompany IS NOT NULL
1539:             */
1540:            public void testIsNull2() throws Exception {
1541:                Collection customers = customerhome
1542:                        .findCustomersWithCreditCompany();
1543:                ArrayList customers_id = new ArrayList();
1544:                Iterator customer = customers.iterator();
1545:                while (customer.hasNext()) {
1546:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
1547:                            .narrow(customer.next(), CustomerRemote.class);
1548:                    customers_id.add(customer_remote.getId());
1549:                }
1550:                ArrayList resExpected = new ArrayList();
1551:                resExpected.add(new Integer(80));
1552:                resExpected.add(new Integer(84));
1553:                resExpected.add(new Integer(88));
1554:                resExpected.add(new Integer(92));
1555:                resExpected.add(new Integer(96));
1556:                assertTrue(
1557:                        "Wrong result EJBQL customerhome.findCustomersWithCreditCompany (required:"
1558:                                + resExpected + ", found:" + customers_id + ")",
1559:                        isCollectionEqual(resExpected, customers_id));
1560:            }
1561:
1562:            /**
1563:             * Test a finder method with the IS NULL operator on a parameter which is a bean null.
1564:             * SELECT OBJECT(c) FROM jt2_Customer c WHERE ?1 IS NULL
1565:             */
1566:            public void testIsNull3() throws Exception {
1567:                Collection customers = customerhome
1568:                        .callFindByParameterIsNull(null);
1569:                assertEquals(
1570:                        "Wrong result EJBQL customerhome.callFindByParameterIsNull(null): ",
1571:                        56, customers.size());
1572:            }
1573:
1574:            /**
1575:             * Test a finder method with the IS NULL operator on a parameter which is a bean not null.
1576:             * SELECT OBJECT(c) FROM jt2_Customer c WHERE ?1 IS NULL
1577:             */
1578:            public void testIsNull3bis() throws Exception {
1579:                Collection customers = customerhome
1580:                        .callFindByParameterIsNull(new Integer(10));
1581:                assertEquals(
1582:                        "Wrong result EJBQL customerhome.callFindByParameterIsNull(): ",
1583:                        0, customers.size());
1584:            }
1585:
1586:            /**
1587:             * Select the lastName of a customer
1588:             * SELECT c.lastName FROM jt2_Customer AS c WHERE c.id = ?1
1589:             */
1590:            public void testCustEjbSelectLastName() throws Exception {
1591:                assertEquals("Wrong ejbSelectLastName for c.id=80: ",
1592:                        "Smith80", customerhome.selectLastName(new Integer(80)));
1593:            }
1594:
1595:            /**
1596:             * Select the city of the address of a customer
1597:             * SELECT c.homeAddress.city FROM jt2_Customer AS c WHERE c.id = ?1
1598:             */
1599:            public void testCustEjbSelectAddrCity() throws Exception {
1600:                assertEquals("Wrong ejbSelectAddrCity for c.id=80: ",
1601:                        "Minneapolis", customerhome.selectAddrCity(new Integer(
1602:                                80)));
1603:            }
1604:
1605:            /**
1606:             * Select the deckLevel of a cabin
1607:             * SELECT c.deckLevel FROM jt2_Cabin AS c WHERE c.id = ?1
1608:             */
1609:            public void testCabinEjbSelectDeckLevel() throws Exception {
1610:                assertEquals("Wrong ejbSelectDeckLevel for c.id=21100: ", 1,
1611:                        cabinhome.selectDeckLevel(new Integer(21100)));
1612:            }
1613:
1614:            /**
1615:             * Select the firstName of all the customers.
1616:             * SELECT c.firstName FROM jt2_Customer AS c
1617:             */
1618:            public void testCustEjbSelectFirstName() throws Exception {
1619:                Set lfn = customerhome.selectFirstName();
1620:                Iterator ilfn = lfn.iterator();
1621:                StringBuffer slfn = new StringBuffer();
1622:                while (ilfn.hasNext()) {
1623:                    slfn = slfn.append((String) ilfn.next() + ",");
1624:                }
1625:                assertEquals("Wrong ejbSelectFirstName() number results ("
1626:                        + slfn.toString() + "): ", 6, lfn.size());
1627:                if (!lfn.contains("John") || !lfn.contains("Mike")
1628:                        || !lfn.contains("Paul") || !lfn.contains("Ringo")
1629:                        || !lfn.contains("Roger") || !lfn.contains("Joe")) {
1630:                    fail("Wrong ejbSelectFirstName() result ("
1631:                            + slfn.toString()
1632:                            + "): does not contain 'John', 'Mike' or 'Paul' or 'Ringo' or 'Roger' or 'Joe'");
1633:                }
1634:            }
1635:
1636:            /**
1637:             * Select the DISTINCT firstName of all the customers.
1638:             * SELECT DISTINCT c.firstName FROM jt2_Customer AS c
1639:             */
1640:            public void testCustEjbSelectDistinctFirstName() throws Exception {
1641:                Collection lfn = customerhome.selectDistinctFirstName();
1642:                assertEquals(
1643:                        "Wrong ejbSelectDistinctFirstName() number results ("
1644:                                + lfn.toString() + "): ", 6, lfn.size());
1645:                if (!lfn.contains("John") || !lfn.contains("Mike")
1646:                        || !lfn.contains("Paul") || !lfn.contains("Ringo")
1647:                        || !lfn.contains("Roger") || !lfn.contains("Joe")) {
1648:                    fail("Wrong ejbSelectDistinctDistinctFirstName() result ("
1649:                            + lfn.toString()
1650:                            + "): does not contain 'John', 'Mike' or 'Paul' or 'Ringo' or 'Roger' or 'Joe'");
1651:                }
1652:            }
1653:
1654:            /**
1655:             * Select the address of a customer
1656:             * An ejbSelect with a local bean as result
1657:             * SELECT c.homeAddress FROM jt2_Customer AS c WHERE c.id = ?1
1658:             */
1659:            public void testCustEjbSelectAddr() throws Exception {
1660:                assertEquals("Wrong ejbSelectAddr for c.id=80: ", new Integer(
1661:                        10), customerhome.selectAddr(new Integer(80)));
1662:            }
1663:
1664:            /**
1665:             * Select the addresses of the company of the credit card of all the customers.
1666:             * An ejbSelect with a collection of local bean as result
1667:             * SELECT c.creditCard.creditCompany.address FROM jt2_Customer c
1668:             */
1669:            public void testCustEjbSelectAllCreditCartAddr() throws Exception {
1670:                Collection addr = customerhome.selectAllCreditCardAddr();
1671:                StringBuffer sAddr = new StringBuffer();
1672:                Iterator iAddr = addr.iterator();
1673:                while (iAddr.hasNext()) {
1674:                    sAddr = sAddr.append(((Integer) iAddr.next()).toString()
1675:                            + ",");
1676:                }
1677:                ArrayList eAddr = new ArrayList();
1678:                eAddr.add(new Integer(11));
1679:                eAddr.add(new Integer(16));
1680:                eAddr.add(new Integer(21));
1681:                eAddr.add(new Integer(26));
1682:                eAddr.add(new Integer(31));
1683:                assertTrue("Wrong ejbSelectCreditCardAddr: (" + sAddr + "): ",
1684:                        isCollectionEqual(eAddr, addr));
1685:            }
1686:
1687:            /**
1688:             * Select the adresses of all 'roger' customers.
1689:             * An ejbSelect with a collection of local bean as result
1690:             * SELECT c.homeAddress FROM jt2_Customer c WHERE c.firstName = 'Roger'
1691:             */
1692:            public void testCustEjbSelectRogerAddr() throws Exception {
1693:                Collection addr = customerhome.selectRogerAddr();
1694:                StringBuffer sAddr = new StringBuffer();
1695:                Iterator iAddr = addr.iterator();
1696:                while (iAddr.hasNext()) {
1697:                    sAddr = sAddr.append(((Integer) iAddr.next()).toString()
1698:                            + ",");
1699:                }
1700:                ArrayList eAddr = new ArrayList();
1701:                eAddr.add(new Integer(45));
1702:                eAddr.add(new Integer(50));
1703:                eAddr.add(new Integer(55));
1704:                eAddr.add(new Integer(60));
1705:                assertTrue("Wrong ejbCustSelectRogerAddr: (" + sAddr + "): ",
1706:                        isCollectionEqual(eAddr, addr));
1707:            }
1708:
1709:            /**
1710:             * Find all the customers ordered by their lastname.
1711:             * SELECT OBJECT(c) FROM jt2_Customer c ORDER BY c.lastName
1712:             */
1713:            public void testSimpleOrderBy() throws Exception {
1714:                Collection customers = customerhome.findAllOrderByLastname();
1715:                assertEquals(
1716:                        "Wrong customers number for customerhome.findAllOrderByLastname(): ",
1717:                        56, customers.size());
1718:                Iterator ci = customers.iterator();
1719:                String previous = ((CustomerRemote) PortableRemoteObject
1720:                        .narrow(ci.next(), CustomerRemote.class)).getName()
1721:                        .getLastName();
1722:                while (ci.hasNext()) {
1723:                    String lname = ((CustomerRemote) PortableRemoteObject
1724:                            .narrow(ci.next(), CustomerRemote.class)).getName()
1725:                            .getLastName();
1726:                    assertTrue("Wrong ordered (previous=" + previous
1727:                            + ",current=" + lname + ")", previous
1728:                            .compareTo(lname) <= 0);
1729:                    previous = lname;
1730:                }
1731:            }
1732:
1733:            /**
1734:             * Find all the customers ordered by their lastname (desc) and firstname (asc).
1735:             * SELECT OBJECT(c) FROM jt2_Customer c ORDER BY c.lastName DESC, c.firstName ASC
1736:             */
1737:            public void testOrderByDescAsc() throws Exception {
1738:                Collection customers = customerhome
1739:                        .findAllOrderByDescLastnameAscFirstname();
1740:                assertEquals(
1741:                        "Wrong customers number for customerhome.findAllOrderByLastname(): ",
1742:                        56, customers.size());
1743:                Iterator ci = customers.iterator();
1744:                Name previous = ((CustomerRemote) PortableRemoteObject.narrow(
1745:                        ci.next(), CustomerRemote.class)).getName();
1746:                while (ci.hasNext()) {
1747:                    Name current = ((CustomerRemote) PortableRemoteObject
1748:                            .narrow(ci.next(), CustomerRemote.class)).getName();
1749:                    assertTrue("Wrong ordered (previous=" + previous
1750:                            + ",current=" + current + ")",
1751:                            previous.getLastName().compareTo(
1752:                                    current.getLastName()) >= 0);
1753:                    if (previous.getLastName().equals(current.getLastName())) {
1754:                        assertTrue("Wrong ordered (previous=" + previous
1755:                                + ",current=" + current + ")", previous
1756:                                .getFirstName().compareTo(
1757:                                        current.getFirstName()) <= 0);
1758:                    }
1759:                    previous = current;
1760:                }
1761:
1762:            }
1763:
1764:            /**
1765:             * Find the reservations ordered by their amountPaid.
1766:             * The DISTINCT aggregate is used to reproduce the bug #300527
1767:             * SELECT DISTINCT OBJECT(r) FROM jt2_Reservation AS r ORDER BY r.amountPaid
1768:             * (bug #300527)
1769:             */
1770:            public void testOrderBy2() throws Exception {
1771:                Collection reservations = reservationhome.findOrderedRsrv();
1772:                assertEquals(
1773:                        "Wrong reservations number for reservationhome.findOrderedRsrv(): ",
1774:                        25, reservations.size());
1775:            }
1776:
1777:            /**
1778:             * Get the average of the tonnage of all the ships.
1779:             * SELECT AVG(s.tonnage) FROM jt2_Ship AS s
1780:             */
1781:            public void testAverageofTonnage() throws Exception {
1782:                assertEquals("AverageofTonnage: ", 80000.0D, shiphome
1783:                        .getAverageOfTonnage(), 0.1);
1784:            }
1785:
1786:            /**
1787:             * Get the count of reservations.
1788:             * SELECT COUNT(r) FROM jt2_Reservations AS r
1789:             */
1790:            public void testCountOfReservations() throws Exception {
1791:                assertEquals("CountOfReservations: ", 25L, reservationhome
1792:                        .getCountOfReservations());
1793:            }
1794:
1795:            /**
1796:             * bug #300723
1797:             * Get the count of customers with a given id
1798:             * SELECT COUNT(c) FROM jt2_Customer AS c WHERE c.id = ?1
1799:             */
1800:            public void testCountOfCustomersWithId1() throws Exception {
1801:                assertEquals("CountOfCustomersWithId1: ", 1L, customerhome
1802:                        .getCountCustomersWithId1(new Integer(82)));
1803:            }
1804:
1805:            /**
1806:             * bug #300723
1807:             * Get the count of customers with a given id
1808:             * SELECT COUNT(c) FROM jt2_Customer AS c WHERE c.id = ?1
1809:             */
1810:            public void testCountOfCustomersWithId2() throws Exception {
1811:                assertEquals("CountOfCustomersWithId2: ", 1L, customerhome
1812:                        .getCountCustomersWithId2(82));
1813:            }
1814:
1815:            /**
1816:             * Get the count of customers with a firstname 'Ringo'
1817:             * SELECT COUNT(c) FROM jt2_Customer AS c WHERE c.firstName = 'Ringo'
1818:             */
1819:            public void testCountOfCustomersRingo() throws Exception {
1820:                assertEquals("CountOfCustomersRingo: ", 4L, customerhome
1821:                        .getCountCustomersRingo());
1822:            }
1823:
1824:            /**
1825:             * Get the customer with a given id
1826:             * SELECT c FROM jt2_Customer AS c WHERE c.id = ?1
1827:             */
1828:            public void testCustFindById() throws Exception {
1829:                assertEquals("CustFindById: ", new Integer(82), customerhome
1830:                        .findById(new Integer(82)).getId());
1831:            }
1832:
1833:            /**
1834:             * Get the min value of the amount of the reservations.
1835:             * SELECT MIN(r.amountPaid) FROM jt2_Reservations AS r
1836:             */
1837:            public void testMinAmountOfReservations() throws Exception {
1838:                assertEquals("testMinAmountOfReservations: ", 2500.0,
1839:                        reservationhome.getMinAmountOfReservations(), 0.1);
1840:            }
1841:
1842:            /**
1843:             * (Bug #300635)
1844:             * Get the min value of the amount of the reservations for the cruise name.
1845:             * SELECT MIN(r.amountPaid) FROM jt2_Reservations AS r WHERE r.cruise.name = ?1
1846:             */
1847:            public void testMinAmountForCruise() throws Exception {
1848:                assertEquals("testMinAmountForCruise(Alaska Cruise): ", 2520.0,
1849:                        reservationhome.getMinAmountForCruise("Alaska Cruise"),
1850:                        0.1);
1851:            }
1852:
1853:            /**
1854:             * Get the values of the amounts of the reservations for the cruise name.
1855:             * SELECT r.amountPaid FROM jt2_Reservations AS r WHERE r.cruise.name = ?1
1856:             */
1857:            public void testAmountsForCruise() throws Exception {
1858:                assertEquals("testAmountsForCruise(Alaska Cruise): ", 18,
1859:                        reservationhome.getAmountsForCruise("Alaska Cruise")
1860:                                .size());
1861:            }
1862:
1863:            /**
1864:             * Get the max value of the amount of the reservations.
1865:             * SELECT MAX(r.amountPaid) FROM jt2_Reservations AS r
1866:             */
1867:            public void testMaxAmountOfReservations() throws Exception {
1868:                assertEquals("testMaxAmountOfReservations: ", 208100.0,
1869:                        reservationhome.getMaxAmountOfReservations(), 0.1);
1870:            }
1871:
1872:            /**
1873:             * Get the count of all the reservations for a specific customer.
1874:             * SELECT COUNT(r) FROM jt2_Reservation AS r WHERE ?1 MEMBER OF r.customers
1875:             * (bug #300280)
1876:             */
1877:            public void testCountOfReservationsForCustomer() throws Exception {
1878:                assertEquals("CountOfReservationsForCustomer: ", 2L,
1879:                        reservationhome
1880:                                .getCountOfReservationsForCustomer(new Integer(
1881:                                        202)));
1882:            }
1883:
1884:            /**
1885:             * Get the amount paid of all the reservations for a specific customer.
1886:             * SELECT SUM(r.amountPaid) FROM jt2_Reservation AS r WHERE ?1 MEMBER OF r.customers
1887:             * (bug #300280)
1888:             */
1889:            public void testAmountOfReservationsForCustomer() throws Exception {
1890:                assertEquals(
1891:                        "AmountOfReservationsForCustomer: ",
1892:                        408100.0,
1893:                        reservationhome
1894:                                .getAmountOfReservationsForCustomer(new Integer(
1895:                                        202)), 0.1);
1896:            }
1897:
1898:            /**
1899:             * Get the count of credit card for customers
1900:             * SELECT COUNT(c.creditCard) FROM jt2_Customer AS c
1901:             * The result must be equivalent to
1902:             *    SELECT COUNT(c.creditCard) FROM jt2_Customer AS c WHERE c.creditCard IS NOT NULL
1903:             */
1904:            public void testCustomersCountCreditCard() throws Exception {
1905:                assertEquals("CustomersCountCreditCard: ", 5, customerhome
1906:                        .getCountCreditCard());
1907:            }
1908:
1909:            /**
1910:             * Get the list of the number of the credit card for customers
1911:             * SELECT DISTINCT c.creditCard.number FROM jt2_Customer AS c ORDER BY c.creditCard.number
1912:             */
1913:            public void testCustomersCreditCardNumbers() throws Exception {
1914:                assertEquals("CustomersCreditCardNumbers: ", 5, customerhome
1915:                        .getCreditCardNumbers().size());
1916:            }
1917:
1918:            /**
1919:             * Find all the addresses
1920:             * SELECT OBJECT(a) FROM jt2_Address AS a
1921:             */
1922:            public void testFindAllAddresses() throws Exception {
1923:                Collection addresses = addresshome.findAllAddress();
1924:                Iterator iAddr = addresses.iterator();
1925:                int nbAddr = 0;
1926:                while (iAddr.hasNext()) {
1927:                    nbAddr++;
1928:                    iAddr.next();
1929:                }
1930:                assertEquals("testFindAllAddresses: ", 61, nbAddr);
1931:            }
1932:
1933:            /**
1934:             * Get all the cities of addresses
1935:             * SELECT a.city FROM jt2_Address AS a
1936:             */
1937:            public void testAddrGetAllCities() throws Exception {
1938:                assertEquals("testAddrGetAllCities: ", 61, addresshome
1939:                        .getAllCities().size());
1940:            }
1941:
1942:            /**
1943:             * Get all the creditCompanies of addresses
1944:             * SELECT a.creditCompany FROM jt2_Address AS a
1945:             */
1946:            public void testAddrGetAllCreditCompanies() throws Exception {
1947:                assertEquals("testAddrGetAllCreditCompanies: ", 5, addresshome
1948:                        .getAllCreditCompanies().size());
1949:            }
1950:
1951:            /**
1952:             * Get all the creditCompany names of addresses.
1953:             * This is a test about Null Values in the Query Result.
1954:             * If the result of the query corresponds to a cmr-field or cmp-field not defined in term of java primitive type,
1955:             * the container must include null value in the result.
1956:             * See the EJB Specification version 2.1, chapter 11.2.7.1
1957:             * SELECT a.creditCompany.name FROM jt2_Address AS a
1958:             * (bug #3001174)
1959:             */
1960:            public void testAddrGetAllCreditCompanyNames() throws Exception {
1961:                assertEquals("testAddrGetAllCreditCompanyNames: ", 61,
1962:                        addresshome.getAllCreditCompanyNames().size());
1963:            }
1964:
1965:            /**
1966:             * Get all the creditCompany id of addresses.
1967:             * This is a test about Null Values in the Query Result.
1968:             * If the result of the query corresponds to a cmp-field not defined in term of java primitive type,
1969:             * the container must include null value in the result.
1970:             * See the EJB Specification version 2.1, chapter 11.2.7.1
1971:             * SELECT a.creditCompany.id FROM jt2_Address AS a
1972:             * (bug #301174)
1973:             */
1974:            public void testAddrGetAllCreditCompanyIds() throws Exception {
1975:                assertEquals("testAddrGetAllCreditCompanyIds: ", 61,
1976:                        addresshome.getAllCreditCompanyIds().size());
1977:            }
1978:
1979:            /**
1980:             * Get all the creditCompany id of addresses.
1981:             * This is a test about Null Values in the Query Result.
1982:             * If the result of the query corresponds to a cmp-field defined in term of java primitive type,
1983:             * the container must not include null value in the result.
1984:             * See the EJB Specification version 2.1, chapter 11.2.7.1
1985:             * SELECT a.creditCompany.num FROM jt2_Address AS a
1986:             * (bug #301174)
1987:             */
1988:            public void testAddrGetAllCreditCompanyNums() throws Exception {
1989:                assertEquals("testAddrGetAllCreditCompanyNums: ", 5,
1990:                        addresshome.getAllCreditCompanyNums().size());
1991:            }
1992:
1993:            /**
1994:             * Get the count of cities for addresses
1995:             * SELECT COUNT(a.city) FROM jt2_Address AS a
1996:             */
1997:            public void testAddrCountOfCities() throws Exception {
1998:                assertEquals("testAddrCountOfCities: ", 61L, addresshome
1999:                        .getCountOfCities());
2000:            }
2001:
2002:            /**
2003:             * Get the count of DISTINCT cities for addresses
2004:             * SELECT COUNT(DISTINCT a.city) FROM jt2_Address AS a
2005:             */
2006:            public void testAddrCountOfDistinctCities() throws Exception {
2007:                assertEquals("testAddrCountOfDistinctCities: ", 6L, addresshome
2008:                        .getCountOfDistinctCities());
2009:            }
2010:
2011:            /**
2012:             * Find the reservations with lesser amount.
2013:             * SELECT DISTINCT OBJECT(r1) FROM jt2_Reservation AS r1, jt2_Reservation AS r2
2014:             * WHERE r1.amountPaid &lt; r2.amountPaid AND r2.id = 26
2015:             */
2016:            public void testFindResWithLesserAmount() throws Exception {
2017:                Collection reservations = reservationhome
2018:                        .findReservationsWithLesserAmount();
2019:                assertEquals(
2020:                        "Wrong reservations number for reservationhome.findReservationsWithLesserAmount(): ",
2021:                        4, reservations.size());
2022:            }
2023:
2024:            /**
2025:             * 	Finding All Customer with a limiter startAt range
2026:             *
2027:             * 	SELECT OBJECT(c) FROM jt2_Customer AS c WHERE c.id > 0 ORDER BY c.id LIMIT ?1
2028:             */
2029:            public void testFindCustAllLimit_1() throws Exception {
2030:
2031:                Collection customers = customerhome.findAllWithLimit_1(40);
2032:
2033:                ArrayList customers_id = new ArrayList();
2034:                Iterator customer = customers.iterator();
2035:                while (customer.hasNext()) {
2036:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
2037:                            .narrow(customer.next(), CustomerRemote.class);
2038:                    customers_id.add(customer_remote.getId());
2039:                }
2040:                ArrayList result = new ArrayList();
2041:                for (int l = 100; l <= 109; l++) {
2042:                    result.add(new Integer(l));
2043:                }
2044:                for (int j = 201; j <= 206; j++) {
2045:                    result.add(new Integer(j));
2046:                }
2047:
2048:                assertTrue(
2049:                        "Wrong result EJBQL customerhome.findAllWithLimit_1()(required:"
2050:                                + result + ", found:" + customers_id + ")",
2051:                        isCollectionEqual(result, customers_id));
2052:
2053:                // checkIsInitialState(); not necessary in this test
2054:            }
2055:
2056:            /**
2057:             * 	Finding All Customer with a limiter startAt range and a size range
2058:             *
2059:             * 	SELECT OBJECT(c) FROM jt2_Customer AS c ORDER BY c.id LIMIT ?1, 5
2060:             */
2061:            public void testFindCustAllLimit_2() throws Exception {
2062:
2063:                Collection customers = customerhome.findAllWithLimit_2(40);
2064:
2065:                ArrayList customers_id = new ArrayList();
2066:                Iterator customer = customers.iterator();
2067:                while (customer.hasNext()) {
2068:                    CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject
2069:                            .narrow(customer.next(), CustomerRemote.class);
2070:                    customers_id.add(customer_remote.getId());
2071:                }
2072:                ArrayList result = new ArrayList();
2073:                for (int l = 100; l <= 104; l++) {
2074:                    result.add(new Integer(l));
2075:                }
2076:
2077:                assertTrue(
2078:                        "Wrong result EJBQL customerhome.findAllWithLimit_2()(required:"
2079:                                + result + ", found:" + customers_id + ")",
2080:                        isCollectionEqual(result, customers_id));
2081:
2082:                // checkIsInitialState(); not necessary in this test
2083:            }
2084:
2085:            public static Test suite() {
2086:                return new TestSuite(F_EjbqlEC2.class);
2087:            }
2088:
2089:            public static void main(String args[]) {
2090:                String testtorun = null;
2091:                // Get args
2092:                for (int argn = 0; argn < args.length; argn++) {
2093:                    String s_arg = args[argn];
2094:                    Integer i_arg;
2095:                    if (s_arg.equals("-n")) {
2096:                        testtorun = args[++argn];
2097:                    }
2098:                }
2099:                if (testtorun == null) {
2100:                    junit.textui.TestRunner.run(suite());
2101:                } else {
2102:                    junit.textui.TestRunner.run(new F_EjbqlEC2(testtorun));
2103:                }
2104:            }
2105:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.