KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty offind
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  */

21
22 package org.objectweb.jonas.jtests.clients.entity;
23
24 import javax.naming.NamingException JavaDoc;
25 import javax.rmi.PortableRemoteObject JavaDoc;
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28 import org.objectweb.jonas.jtests.beans.ejbql.*;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Calendar JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.Date JavaDoc;
33 import java.util.HashSet JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.Set JavaDoc;
36
37 /**
38  * This is an advanced test suite for home interface on entity bean EJBQL.
39  */

40 public class F_EjbqlEC2 extends A_Cmp2Util {
41
42     private static String JavaDoc BEAN_HOME_SESSION_TEST = "EjbqlSessionTestHomeRemote";
43     private static String JavaDoc BEAN_HOME_CUSTOMER = "CustomerHomeRemote";
44     private static String JavaDoc BEAN_HOME_RESERVATION = "ReservationHomeRemote";
45     private static String JavaDoc BEAN_HOME_CRUISE = "CruiseHomeRemote";
46     private static String JavaDoc BEAN_HOME_SHIP = "ShipHomeRemote";
47     private static String JavaDoc BEAN_HOME_CABIN = "CabinHomeRemote";
48     private static String JavaDoc BEAN_HOME_ADDRESS = "AddressHomeRemote";
49
50     protected static SessionTestHomeRemote sessiontesthome = null;
51     protected static CustomerHomeRemote customerhome = null;
52     protected static ReservationHomeRemote reservationhome = null;
53     protected static CruiseHomeRemote cruisehome = null;
54     protected static ShipHomeRemote shiphome = null;
55     protected static CabinHomeRemote cabinhome = null;
56     protected static AddressHomeRemote addresshome = null;
57     protected static CreditCardHomeRemote creditcardhome = null;
58
59     public F_EjbqlEC2(String JavaDoc name) {
60         super(name);
61     }
62
63     protected static boolean isInit = false;
64
65     protected void setUp() {
66         super.setUp();
67         boolean ok = false;
68         int nbtry = 0;
69         while (!ok && nbtry < 3) {
70             if (!isInit) {
71                 // load bean if not loaded yet
72
useBeans("ejbql", false);
73                 // lookup home used in the tests
74

75                 try {
76                     sessiontesthome = (SessionTestHomeRemote)
77                         PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_SESSION_TEST),
78                                                     SessionTestHomeRemote.class);
79                     customerhome = (CustomerHomeRemote)
80                         PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_CUSTOMER),
81                                                     CustomerHomeRemote.class);
82                     shiphome = (ShipHomeRemote)
83                         PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_SHIP),
84                                                     ShipHomeRemote.class);
85                     cruisehome = (CruiseHomeRemote)
86                         PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_CRUISE),
87                                                     CruiseHomeRemote.class);
88                     reservationhome = (ReservationHomeRemote)
89                         PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_RESERVATION),
90                                                     ReservationHomeRemote.class);
91                     cabinhome = (CabinHomeRemote)
92                         PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_CABIN),
93                                                     CabinHomeRemote.class);
94                     addresshome = (AddressHomeRemote)
95                         PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_ADDRESS),
96                                                     AddressHomeRemote.class);
97                 } catch (NamingException JavaDoc e) {
98                     fail("Cannot get bean home: " + e.getMessage());
99                 }
100                 // check if tables have been initialized
101
try {
102                     customerhome.findByPrimaryKey(new Integer JavaDoc(80));
103                 } catch (Exception JavaDoc e) {
104                     // Make the initialization needed for the tests
105
try {
106                         utx.begin();
107                         String JavaDoc cities[] = new String JavaDoc[6];
108                         cities[0] = "Minneapolis"; cities[1] = "St. Paul"; cities[2] = "Rochester";
109                         cities[3] = "Winona"; cities[4] = "Wayzata"; cities[5] = "Eagan";
110                         ShipRemote shipA = null;
111                         CruiseRemote cruiseA = null;
112                         shipA = shiphome.create(new Integer JavaDoc(10772), "Ship A", 30000.0);
113                         cruiseA = cruisehome.create("Cruise A", new Integer JavaDoc(10772));
114                         for (int jj = 1; jj <= 10; jj++) {
115                             ShipRemote ship = shiphome.create(new Integer JavaDoc(jj), "Ship " + jj, 30000.0 + (10000.0 * jj));
116                         }
117                         cruiseA = null;
118                         CruiseRemote cruiseB = null;
119                         ShipRemote ship1 = shiphome.findByPrimaryKey(new Integer JavaDoc(1));
120                         cruiseA = cruisehome.create("Alaska Cruise", new Integer JavaDoc(1));
121                         cruiseB = cruisehome.create("Bohemian Cruise", new Integer JavaDoc(1));
122                         for (int kk = 80; kk <= 99; kk++) {
123                             CustomerRemote customer = null;
124
125                             customer = customerhome.create(new Integer JavaDoc(kk));
126                             customer.setName(new Name("Smith"+kk,"John") );
127                             customer.addPhoneNumber("612-555-12"+kk,(byte) 1);
128
129                             customer.setAddress("10"+kk+" Elm Street",
130                                                 cities[(kk-80)%6],
131                                                 (kk%2==0?"MN":"CA"),
132                                                 "5540"+(kk%5+1));
133                             customer.setHasGoodCredit((kk%4 == 0));
134                             if (kk%4 == 0)
135                                 customer.setCreditCard(new Date JavaDoc(System.currentTimeMillis()+100000), "100001"+kk, "MasterCard", "CA" ,"CETELEM", "rue de jeunet", cities[0], "France", "3888" );
136                         }
137                         // Creating Customers 1-6, each with 2 reservations for 2 cabins
138
Calendar JavaDoc date = Calendar.getInstance();
139                         date.set(2002,10,1);
140
141                         for (int kk=201; kk<207; kk++) {
142                             Collection JavaDoc customers = new ArrayList JavaDoc();
143                             CustomerRemote cust = customerhome.create(new Integer JavaDoc(kk));
144                             cust.setName(new Name("Customer "+kk,"Mike"));
145                             cust.setHasGoodCredit( (kk%2==0) ); // odds are bums
146
cust.setAddress("50"+kk+" Main Street","Minneapolis","MN","5510"+kk);
147                             customers.add(new Integer JavaDoc(kk)); // put this single customer in the collection
148

149                             Collection JavaDoc reservations = new ArrayList JavaDoc();
150
151                             for (int jj=0; jj<2; jj++) {
152
153                                 ReservationRemote reservation = reservationhome.create(cruiseA.getId(), customers);
154                                 reservation.setDate(date.getTime());
155                                 reservation.setAmountPaid(1000*kk+100*jj+2000);
156
157                                 date.add(Calendar.DAY_OF_MONTH, 7);
158
159                                 Set JavaDoc cabins = new HashSet JavaDoc();
160                                 CabinRemote cabin = cabinhome.create(new Integer JavaDoc(1000+kk*100+jj));
161                                 cabin.setDeckLevel(kk-200);
162                                 cabin.setName("Cabin "+kk+"0"+jj+"1");
163
164                                 cabins.add(cabin.getId());
165                                 cabin = cabinhome.create(new Integer JavaDoc(1000+kk*100+10+jj));
166                                 cabin.setDeckLevel(kk-200);
167                                 cabin.setName("Cabin "+kk+"0"+jj+"2");
168
169                                 cabins.add(cabin.getId());
170
171                                 reservation.setAllCabins(cabins); // this reservation has 2 cabins
172

173                             }
174                         }
175                         String JavaDoc fnames[] = new String JavaDoc[5];
176                         fnames[0]="John"; fnames[1]="Paul"; fnames[2]="Ringo";
177                         fnames[3]="Joe"; fnames[4]="Roger";
178
179                         String JavaDoc lnames[] = new String JavaDoc[3];
180                         lnames[0]="Smith"; lnames[1]="Johnson"; lnames[2]="Star";
181                         // Creating Customers 50-69
182
for (int kk=50; kk<=69; kk++) {
183                             CustomerRemote customer = customerhome.create(new Integer JavaDoc(kk));
184                             customer.setName( new Name(lnames[(kk-50)%3], fnames[(kk-50)%5]) );
185                             customer.addPhoneNumber("612-555-12"+kk,(byte)1);
186                             customer.setAddress("10"+kk+" Elm Street",
187                                                 cities[(kk-50)%6],
188                                                 (kk%2==0?"MN":"CA"),
189                                                 "5540"+(kk%5+1));
190                             customer.setHasGoodCredit((kk%4==0));
191
192                             // Some customers will have reservations already on one of the two cruises..
193
if (kk%3!=0) {
194                                 Collection JavaDoc customers = new ArrayList JavaDoc();
195                                 customers.add(customer.getId()); // put this single customer in the collection
196
ReservationRemote reservation = reservationhome.create((kk%3==1?cruiseA.getId():cruiseB.getId()), customers);
197                                 reservation.setDate(date.getTime());
198                                 reservation.setAmountPaid(10*kk+2000);
199                                 date.add(Calendar.DAY_OF_MONTH, 7);
200                             }
201                         }
202
203                         // Creating Customers 100-109
204

205                         for (int kk=100; kk<=109; kk++) {
206                             CustomerRemote customer = customerhome.create(new Integer JavaDoc(kk));
207                             customer.setName( new Name("Lennon"+kk, "Paul") );
208                             customer.addPhoneNumber("666-543-12"+kk,(byte)1);
209
210                             customer.setAddress("10"+kk+" Abbey Road",
211                                                 cities[(kk-100)%6],
212                                                 (kk%2==0?"FL":"WA"),
213                                                 "5540"+(kk%5+1));
214                             customer.setHasGoodCredit((kk%4==0));
215                         }
216
217                     } catch (Exception JavaDoc i) {
218                         i.printStackTrace(System.out);
219                         fail("InitialState creation problem: "+i);
220                     } finally {
221                         try {
222                             utx.commit();
223                         } catch (Exception JavaDoc ii) {
224                         }
225                     }
226                 }
227                 isInit = true;
228             }
229             // Check that all is OK. Sometimes, a test has failed and has corrupted
230
// the bean state in the database. We must unload and reload the bean then.
231
nbtry++;
232             try {
233                 if (initStateOK()) {
234                     ok = true;
235                 }
236             } catch (Exception JavaDoc e) {
237                 e.printStackTrace(System.out);
238             }
239             if (!ok) {
240                 isInit = false;
241                 unloadBeans("ejbql");
242             }
243         }
244     }
245
246
247     /*
248      * Check that we are in the same state as after the tables creation for thoses beans A and B
249      * (ie if it is the initial state)
250      */

251     boolean initStateOK() throws Exception JavaDoc {
252         // just verify that all ejb are correcly created. Nothing about relation here because we testing only ejbql
253
boolean isOk = true;
254
255         msgerror = new StringBuffer JavaDoc();
256
257         ShipRemote ship10772 = shiphome.findByPrimaryKey(new Integer JavaDoc(10772));
258         for (int i=1; i<=10; i++) {
259             ShipRemote ship = shiphome.findByPrimaryKey(new Integer JavaDoc(i));
260         }
261
262         CruiseRemote cruiseA = cruisehome.findByName("Cruise A");
263         CruiseRemote cruiseB = cruisehome.findByName("Alaska Cruise");
264         CruiseRemote cruiseC = cruisehome.findByName("Bohemian Cruise");
265         for (int j=10; j<=12; j++) {
266             CruiseRemote cruise = cruisehome.findByPrimaryKey(new Integer JavaDoc(j));
267         }
268
269         for (int k=80; k<=109; k++) {
270             CustomerRemote customer = customerhome.findByPrimaryKey(new Integer JavaDoc(k));
271         }
272
273         for (int l=201; l<=206; l++) {
274             CustomerRemote customer1 = customerhome.findByPrimaryKey(new Integer JavaDoc(l));
275         }
276
277         for (int p=50; p<=69; p++) {
278             CustomerRemote customer2 = customerhome.findByPrimaryKey(new Integer JavaDoc(p));
279         }
280         for (int kk=201;kk<207;kk++) {
281             for (int jj=0;jj<2;jj++) {
282                 CabinRemote cabin = cabinhome.findByPrimaryKey(new Integer JavaDoc(1000+kk*100+jj));
283                 CabinRemote cabin1 = cabinhome.findByPrimaryKey(new Integer JavaDoc(1000+kk*100+10+jj));
284             }
285         }
286
287         for (int kkh=10;kkh<=34;kkh++) {
288             ReservationRemote reservation = reservationhome.findByPrimaryKey(new Integer JavaDoc(kkh));
289         }
290
291         return isOk;
292     }
293
294     /**
295      * The execution of those two tests failed.
296      */

297     public void testSeries1() throws Exception JavaDoc {
298         testWildcards();
299         testWildcards();
300     }
301
302     /**
303      * Finding Customer having name 'John Smith85'
304      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName = ?1 AND c.firstName = ?2
305      */

306     public void testAnd1() throws Exception JavaDoc {
307         CustomerRemote customer85 = customerhome.findByExactName("Smith85","John");
308         assertEquals("Wrong Customer : ",new Integer JavaDoc(85), customer85.getId());
309         // checkIsInitialState(); not necessary in this test
310
}
311
312     /**
313      * Finding Customer 'Smith90'
314      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName = 'Smith90'
315      */

316     public void testEgalString() throws Exception JavaDoc {
317         CustomerRemote customer90 = customerhome.findSmith90();
318         assertEquals("Wrong Customer : ",new Integer JavaDoc(90), customer90.getId());
319         // checkIsInitialState(); not necessary in this test
320
}
321
322     /**
323      * Finding Customers having GoodCredit
324      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.hasGoodCredit = TRUE
325      */

326     public void testEgalBoolean() throws Exception JavaDoc {
327         Collection JavaDoc mplscustomers = customerhome.findByGoodCredit();
328         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
329         Iterator JavaDoc customer = mplscustomers.iterator();
330         while (customer.hasNext()) {
331             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
332             customers_id.add(customer_remote.getId());
333         }
334         ArrayList JavaDoc result = new ArrayList JavaDoc();
335
336         for (int ii=80;ii<=96;ii=ii+4) {
337             result.add(new Integer JavaDoc(ii));
338         }
339
340         for (int ii=100;ii<=108;ii=ii+4) {
341             result.add(new Integer JavaDoc(ii));
342         }
343         for (int jj=202;jj<=206;jj=jj+2) {
344             result.add(new Integer JavaDoc(jj));
345         }
346
347         for (int kk=52;kk<=68;kk=kk+4) {
348             result.add(new Integer JavaDoc(kk));
349         }
350
351         assertTrue("Wrong result EJBQL Customer.findByGoogCredit() (required:" + result + ", found:" +customers_id
352                    + ")", isCollectionEqual(result, customers_id));
353
354         // checkIsInitialState(); not necessary in this test
355
}
356
357     /**
358      * Finding Customers having City = Minneapolis and STATE= MN
359      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress.city = ?1 AND c.homeAddress.state = ?2
360      */

361     public void testAnd2() throws Exception JavaDoc {
362         Collection JavaDoc mplscustomers = customerhome.findByCity("Minneapolis","MN");
363
364         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
365         Iterator JavaDoc customer = mplscustomers.iterator();
366         while (customer.hasNext()) {
367             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
368             customers_id.add(customer_remote.getId());
369         }
370         ArrayList JavaDoc result = new ArrayList JavaDoc();
371         result.add(new Integer JavaDoc(206));
372         result.add(new Integer JavaDoc(50));
373         result.add(new Integer JavaDoc(56));
374         result.add(new Integer JavaDoc(62));
375         result.add(new Integer JavaDoc(68));
376         result.add(new Integer JavaDoc(80));
377         result.add(new Integer JavaDoc(86));
378         result.add(new Integer JavaDoc(92));
379         result.add(new Integer JavaDoc(98));
380         result.add(new Integer JavaDoc(201));
381         result.add(new Integer JavaDoc(202));
382         result.add(new Integer JavaDoc(203));
383         result.add(new Integer JavaDoc(204));
384         result.add(new Integer JavaDoc(205));
385
386         assertTrue("Wrong result EJBQL Customer.findByCity(Minneapolis,MN) (required:" + result + ", found:" +customers_id
387                    + ")", isCollectionEqual(result, customers_id));
388
389         //checkIsInitialState();not necessary in this test
390
}
391     /**
392      * Finding Customer having a name exactly matching 'Joe Star' &
393      * Finding Customers having a name like 'Jo S' (no wildcards) &
394      * Finding Customers having a name like 'Jo% S%' (with wildcards)
395      * Finding Customers having a name like 'Jo% S%' and living in MN
396      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName = ?1 AND c.firstName = ?2 &
397      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 &
398      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2
399      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 AND c.homeAddress.state = ?3
400      */

401     public void testWildcards() throws Exception JavaDoc {
402         // first test : exactly matching
403
CustomerRemote customer = customerhome.findByExactName("Star","Joe");
404         assertEquals("Wrong Customer for customerhome.findByExactName(Star,Joe);: ",new Integer JavaDoc(58), customer.getId());
405
406         // second test : find with no wildcards
407
Collection JavaDoc customers = customerhome.findByName("S","Jo");
408         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
409         Iterator JavaDoc customerit1 = customers.iterator();
410         while (customerit1.hasNext()) {
411             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customerit1.next(), CustomerRemote.class);
412             customers_id.add(customer_remote.getId());
413         }
414         ArrayList JavaDoc result = new ArrayList JavaDoc();
415         assertTrue("Wrong result EJBQL customerhome.findByName(S,Jo) (required:" + result + ", found:" +customers_id
416                    + ")", isCollectionEqual(result, customers_id));
417
418         // thirdth test : find with no wildcards
419
customers = customerhome.findByName("S%","Jo%");
420         customers_id = new ArrayList JavaDoc();
421         Iterator JavaDoc customerit2 = customers.iterator();
422         while (customerit2.hasNext()) {
423             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customerit2.next(), CustomerRemote.class);
424             customers_id.add(customer_remote.getId());
425         }
426         result = new ArrayList JavaDoc();
427         result.add(new Integer JavaDoc(50));
428         result.add(new Integer JavaDoc(53));
429         result.add(new Integer JavaDoc(55));
430         result.add(new Integer JavaDoc(58));
431         result.add(new Integer JavaDoc(65));
432         result.add(new Integer JavaDoc(68));
433         for (int i=80;i<=99;i++) {
434             result.add(new Integer JavaDoc(i));
435         }
436         assertTrue("Wrong result EJBQL customerhome.findByName(S%,Jo%) (required:" + result + ", found:" +customers_id
437                    + ")", isCollectionEqual(result, customers_id));
438
439         customers = customerhome.findByNameAndState("S%","Jo%","MN");
440         customers_id = new ArrayList JavaDoc();
441         Iterator JavaDoc customerit3 = customers.iterator();
442         while (customerit3.hasNext()) {
443             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customerit3.next(), CustomerRemote.class);
444             customers_id.add(customer_remote.getId());
445         }
446         result = new ArrayList JavaDoc();
447         result.add(new Integer JavaDoc(50));
448         result.add(new Integer JavaDoc(68));
449         result.add(new Integer JavaDoc(58));
450         for (int i=80;i<=99;i=i+2) {
451             result.add(new Integer JavaDoc(i));
452         }
453         assertTrue("Wrong result EJBQL customerhome.findByNameAndState(S%,Jo%,MN) (required:" + result + ", found:" +customers_id
454                    + ")", isCollectionEqual(result, customers_id));
455
456
457         // checkIsInitialState(); not necessary in this test
458
}
459
460     /**
461      * (Bug #300634)
462      * Finding Customers having a name not like 'Jo%' OR not like 'S%'
463      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.lastName NOT LIKE ?1 OR c.firstName NOT LIKE ?2
464      */

465     public void testNotLike() throws Exception JavaDoc {
466         Collection JavaDoc customers = customerhome.findByNotName("S%","Jo%");
467         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
468         Iterator JavaDoc customerit1 = customers.iterator();
469         while (customerit1.hasNext()) {
470             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customerit1.next(), CustomerRemote.class);
471             customers_id.add(customer_remote.getId());
472         }
473         ArrayList JavaDoc result = new ArrayList JavaDoc();
474         result.add(new Integer JavaDoc(51));
475         result.add(new Integer JavaDoc(52));
476         result.add(new Integer JavaDoc(54));
477         result.add(new Integer JavaDoc(56));
478         result.add(new Integer JavaDoc(57));
479         result.add(new Integer JavaDoc(59));
480         for (int i=60;i<=64;i++) {
481             result.add(new Integer JavaDoc(i));
482         }
483         result.add(new Integer JavaDoc(66));
484         result.add(new Integer JavaDoc(67));
485         result.add(new Integer JavaDoc(69));
486         for (int i=100;i<=109;i++) {
487             result.add(new Integer JavaDoc(i));
488         }
489         for (int i=201;i<=206;i++) {
490             result.add(new Integer JavaDoc(i));
491         }
492         assertTrue("Wrong result EJBQL customerhome.findByNotName(S%,Jo%) (required:" + result + ", found:" +customers_id
493                    + ")", isCollectionEqual(result, customers_id));
494
495         // checkIsInitialState(); not necessary in this test
496
}
497
498     /**
499      * Retrieve a collection of all cabins on deck 3
500      * SELECT OBJECT(c) FROM Cabin as c WHERE c.deckLevel = ?1
501      */

502     public void testEgalInteger() throws Exception JavaDoc {
503         Collection JavaDoc cabins = cabinhome.findAllOnDeckLevel(new Integer JavaDoc(3));
504
505         ArrayList JavaDoc cabins_id = new ArrayList JavaDoc();
506         Iterator JavaDoc cabin = cabins.iterator();
507         while (cabin.hasNext()) {
508             CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject.narrow(cabin.next(), CabinRemote.class);
509             cabins_id.add(cabin_remote.getId());
510         }
511         ArrayList JavaDoc result = new ArrayList JavaDoc();
512         result.add(new Integer JavaDoc(21300));
513         result.add(new Integer JavaDoc(21310));
514         result.add(new Integer JavaDoc(21301));
515         result.add(new Integer JavaDoc(21311));
516
517         assertTrue("Wrong result EJBQL cabinhome.findAllOnDeckLevel(new Integer(3))(required:" + result + ", found:" +cabins_id+
518                    ")", isCollectionEqual(result,cabins_id));
519
520         // checkIsInitialState(); not necessary in this test
521
}
522
523     /**
524      * Findng Customers Living in Warm Climates
525      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress.state IN ('FL','TX','AZ','CA')
526      */

527     public void testInWhere() throws Exception JavaDoc {
528         Collection JavaDoc customers = customerhome.findInHotStates();
529
530         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
531         Iterator JavaDoc customer = customers.iterator();
532         while (customer.hasNext()) {
533             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
534             customers_id.add(customer_remote.getId());
535         }
536         ArrayList JavaDoc result = new ArrayList JavaDoc();
537         for (int i=51;i<=69;i=i+2) {
538             result.add(new Integer JavaDoc(i));
539         }
540         for (int j=100;j<=109;j=j+2) {
541             result.add(new Integer JavaDoc(j));
542         }
543         for (int k=81;k<=99;k=k+2) {
544             result.add(new Integer JavaDoc(k));
545         }
546
547         assertTrue("Wrong result EJBQL customerhome.findInHotStates() (required:" + result + ", found:" +customers_id+
548                    ")", isCollectionEqual(result,customers_id));
549
550         // checkIsInitialState(); not necessary in this test
551
}
552
553     /**
554      * Test an IN expression with literals integer
555      * SELECT OBJECT(c) FROM jt2_Cabin as c WHERE c.deckLevel IN ( 1 , 3 , 5 )
556      */

557     public void test2InWhere() throws Exception JavaDoc {
558         Collection JavaDoc cabins = cabinhome.findAllOnDeckLevel1_3_5();
559
560         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
561         Iterator JavaDoc icabins = cabins.iterator();
562         int nb = 0;
563         while (icabins.hasNext()) {
564             CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject.narrow(icabins.next(), CabinRemote.class);
565             nb++;
566             int level = cabin_remote.getDeckLevel();
567             if ((level != 1) && (level != 3) && (level != 5)) {
568                 fail("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_5(5) (level="
569                      + level + ")");
570             }
571         }
572         assertEquals("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_5(5)", 12, nb);
573
574         // checkIsInitialState(); not necessary in this test
575
}
576
577     /**
578      * Test an IN expression with literals integer and an input parameter
579      * SELECT OBJECT(c) FROM jt2_Cabin as c WHERE c.deckLevel IN ( 1 , 3 , ?1 )
580      */

581     public void test3InWhere() throws Exception JavaDoc {
582         Collection JavaDoc cabins = cabinhome.findAllOnDeckLevel1_3_X(5);
583
584         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
585         Iterator JavaDoc icabins = cabins.iterator();
586         int nb = 0;
587         while (icabins.hasNext()) {
588             CabinRemote cabin_remote = (CabinRemote) PortableRemoteObject.narrow(icabins.next(), CabinRemote.class);
589             nb++;
590             int level = cabin_remote.getDeckLevel();
591             if ((level != 1) && (level != 3) && (level != 5)) {
592                 fail("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_X(5) (level="
593                      + level + ")");
594             }
595         }
596         assertEquals("Wrong result EJBQL cabinhome.findAllOnDeckLevel1_3_X(5)", 12, nb);
597
598         // checkIsInitialState(); not necessary in this test
599
}
600
601     /**
602      * Finding Customers Without Reservations
603      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.reservations IS EMPTY
604      */

605     public void testIsEmpty() throws Exception JavaDoc {
606         Collection JavaDoc customers = customerhome.findWithoutReservations();
607
608         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
609         Iterator JavaDoc customer = customers.iterator();
610         while (customer.hasNext()) {
611             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
612             customers_id.add(customer_remote.getId());
613         }
614         ArrayList JavaDoc result = new ArrayList JavaDoc();
615         for (int i=51;i<=69;i=i+3) {
616             result.add(new Integer JavaDoc(i));
617         }
618         for (int i=80;i<=109;i++) {
619             result.add(new Integer JavaDoc(i));
620         }
621
622         assertTrue("Wrong result EJBQL customerhome.findWithoutReservations() (required:"
623                    + result + ", found:" + customers_id + ")",
624                    isCollectionEqual(result,customers_id));
625
626         //checkIsInitialState(); not necessary in this test
627
}
628
629     /**
630      * Finding Customers With Reservations
631      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.reservations IS NOT EMPTY
632      */

633     public void testIsNotEmpty() throws Exception JavaDoc {
634         Collection JavaDoc customers = customerhome.findWithReservations();
635
636         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
637         Iterator JavaDoc customer = customers.iterator();
638         while (customer.hasNext()) {
639             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
640             customers_id.add(customer_remote.getId());
641         }
642         ArrayList JavaDoc result = new ArrayList JavaDoc();
643         for (int i=201;i<=206;i++) {
644             result.add(new Integer JavaDoc(i));
645         }
646         result.add(new Integer JavaDoc(50));
647         result.add(new Integer JavaDoc(52));
648         result.add(new Integer JavaDoc(53));
649         result.add(new Integer JavaDoc(55));
650         result.add(new Integer JavaDoc(56));
651         result.add(new Integer JavaDoc(58));
652         result.add(new Integer JavaDoc(59));
653         result.add(new Integer JavaDoc(61));
654         result.add(new Integer JavaDoc(62));
655         result.add(new Integer JavaDoc(64));
656         result.add(new Integer JavaDoc(65));
657         result.add(new Integer JavaDoc(67));
658         result.add(new Integer JavaDoc(68));
659
660         assertTrue("Wrong result EJBQL customerhome.findWithReservations() (required:"
661                    + result + ", found:" + customers_id + ")",
662                    isCollectionEqual(result,customers_id));
663
664         //checkIsInitialState(); not necessary in this test
665
}
666
667     /**
668      * Test to reproduce bug #300525
669      * Finding Customers Without or With Reservations (equivalent to finding all customers)
670      * SELECT OBJECT(c) FROM jt2_Customer c
671      * WHERE c.reservations IS EMPTY OR c.reservations IS NOT EMPTY
672      */

673     public void testIsEmptyIsNotEmpty() throws Exception JavaDoc {
674         Collection JavaDoc customers = customerhome.findWithOrWithoutReservations();
675
676         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
677         Iterator JavaDoc customer = customers.iterator();
678         while (customer.hasNext()) {
679             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
680             customers_id.add(customer_remote.getId());
681         }
682         ArrayList JavaDoc result = new ArrayList JavaDoc();
683         for (int i=50;i<=69;i++) {
684             result.add(new Integer JavaDoc(i));
685         }
686         for (int i=80;i<=109;i++) {
687             result.add(new Integer JavaDoc(i));
688         }
689         for (int i=201;i<=206;i++) {
690             result.add(new Integer JavaDoc(i));
691         }
692
693         assertTrue("Wrong result EJBQL customerhome.findWithOrWithoutReservations() (required:"
694                    + result + ", found:" + customers_id + ")",
695                    isCollectionEqual(result,customers_id));
696
697         //checkIsInitialState(); not necessary in this test
698
}
699
700     /**
701      * Finding Customers Without Reservations and with good credit
702      * SELECT OBJECT(c) FROM jt2_Customer c
703      * WHERE c.reservations IS EMPTY AND c.hasGoodCredit = true
704      */

705     public void testIsEmptyInExp1() throws Exception JavaDoc {
706         Collection JavaDoc customers = customerhome.findWithoutReservationsAndWithGoodCredit(true);
707
708         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
709         Iterator JavaDoc customer = customers.iterator();
710         while (customer.hasNext()) {
711             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
712             customers_id.add(customer_remote.getId());
713         }
714         ArrayList JavaDoc result = new ArrayList JavaDoc();
715         result.add(new Integer JavaDoc(80));
716         result.add(new Integer JavaDoc(84));
717         result.add(new Integer JavaDoc(88));
718         result.add(new Integer JavaDoc(92));
719         result.add(new Integer JavaDoc(96));
720         result.add(new Integer JavaDoc(60));
721         result.add(new Integer JavaDoc(100));
722         result.add(new Integer JavaDoc(104));
723         result.add(new Integer JavaDoc(108));
724
725         assertTrue("Wrong result EJBQL customerhome.findWithoutReservationsAndWithGoodCredit() (required:"
726                    + result + ", found:" + customers_id + ")",
727                    isCollectionEqual(result,customers_id));
728
729         //checkIsInitialState(); not necessary in this test
730
}
731
732     /**
733      * Finding Customers Without Reservations and with good credit
734      * Test equivalent to testIsEmptyInExp1
735      * SELECT OBJECT(c) FROM jt2_Customer c
736      * WHERE NOT (c.reservations IS NOT EMPTY OR c.hasGoodCredit <> true)
737      */

738     public void testIsEmptyInExp1Bis() throws Exception JavaDoc {
739         Collection JavaDoc customers = customerhome.findBisWithoutReservationsAndWithGoodCredit(true);
740
741         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
742         Iterator JavaDoc customer = customers.iterator();
743         while (customer.hasNext()) {
744             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
745             customers_id.add(customer_remote.getId());
746         }
747         ArrayList JavaDoc result = new ArrayList JavaDoc();
748         result.add(new Integer JavaDoc(80));
749         result.add(new Integer JavaDoc(84));
750         result.add(new Integer JavaDoc(88));
751         result.add(new Integer JavaDoc(92));
752         result.add(new Integer JavaDoc(96));
753         result.add(new Integer JavaDoc(60));
754         result.add(new Integer JavaDoc(100));
755         result.add(new Integer JavaDoc(104));
756         result.add(new Integer JavaDoc(108));
757
758         assertTrue("Wrong result EJBQL customerhome.findBisWithoutReservationsAndWithGoodCredit() (required:"
759                    + result + ", found:" + customers_id + ")",
760                    isCollectionEqual(result,customers_id));
761
762         //checkIsInitialState(); not necessary in this test
763
}
764
765     /**
766      * Finding Customers Without Reservations and with good credit
767      * Test equivalent to testIsEmptyInExp1
768      * SELECT OBJECT(c) FROM jt2_Customer c
769      * WHERE NOT ( NOT (c.reservations IS EMPTY AND c.hasGoodCredit = true) )
770      */

771     public void testIsEmptyInExp1Ter() throws Exception JavaDoc {
772         Collection JavaDoc customers = customerhome.findTerWithoutReservationsAndWithGoodCredit(true);
773
774         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
775         Iterator JavaDoc customer = customers.iterator();
776         while (customer.hasNext()) {
777             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
778             customers_id.add(customer_remote.getId());
779         }
780         ArrayList JavaDoc result = new ArrayList JavaDoc();
781         result.add(new Integer JavaDoc(80));
782         result.add(new Integer JavaDoc(84));
783         result.add(new Integer JavaDoc(88));
784         result.add(new Integer JavaDoc(92));
785         result.add(new Integer JavaDoc(96));
786         result.add(new Integer JavaDoc(60));
787         result.add(new Integer JavaDoc(100));
788         result.add(new Integer JavaDoc(104));
789         result.add(new Integer JavaDoc(108));
790
791         assertTrue("Wrong result EJBQL customerhome.findTerWithoutReservationsAndWithGoodCredit() (required:"
792                    + result + ", found:" + customers_id + ")",
793                    isCollectionEqual(result,customers_id));
794
795         //checkIsInitialState(); not necessary in this test
796
}
797
798     /**
799      * Finding Customers Without Reservations and with good credit
800      * Test equivalent to testIsEmptyInExp1
801      * SELECT OBJECT(c) FROM jt2_Customer c
802      * WHERE NOT (c.hasGoodCredit <> true) AND c.reservations IS EMPTY
803      */

804     public void testIsEmptyInExp1Quad() throws Exception JavaDoc {
805         Collection JavaDoc customers = customerhome.findQuadWithoutReservationsAndWithGoodCredit(true);
806
807         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
808         Iterator JavaDoc customer = customers.iterator();
809         while (customer.hasNext()) {
810             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
811             customers_id.add(customer_remote.getId());
812         }
813         ArrayList JavaDoc result = new ArrayList JavaDoc();
814         result.add(new Integer JavaDoc(80));
815         result.add(new Integer JavaDoc(84));
816         result.add(new Integer JavaDoc(88));
817         result.add(new Integer JavaDoc(92));
818         result.add(new Integer JavaDoc(96));
819         result.add(new Integer JavaDoc(60));
820         result.add(new Integer JavaDoc(100));
821         result.add(new Integer JavaDoc(104));
822         result.add(new Integer JavaDoc(108));
823
824         assertTrue("Wrong result EJBQL customerhome.findQuadWithoutReservationsAndWithGoodCredit() (required:"
825                    + result + ", found:" + customers_id + ")",
826                    isCollectionEqual(result,customers_id));
827
828         //checkIsInitialState(); not necessary in this test
829
}
830
831     /**
832      * Test to reproduce bug #300525
833      * Finding Customers Without Reservations OR with good credit
834      * SELECT OBJECT(c) FROM jt2_Customer c
835      * WHERE c.reservations IS EMPTY OR c.hasGoodCredit == true
836      */

837     public void testIsEmptyInExp2() throws Exception JavaDoc {
838         Collection JavaDoc customers = customerhome.findWithoutReservationsOrWithGoodCredit(true);
839
840         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
841         Iterator JavaDoc customer = customers.iterator();
842         while (customer.hasNext()) {
843             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
844             customers_id.add(customer_remote.getId());
845         }
846         ArrayList JavaDoc result = new ArrayList JavaDoc();
847         for (int i=51;i<=69;i=i+3) {
848             result.add(new Integer JavaDoc(i));
849         }
850         for (int i=80;i<=109;i++) {
851             result.add(new Integer JavaDoc(i));
852         }
853         result.add(new Integer JavaDoc(202));
854         result.add(new Integer JavaDoc(204));
855         result.add(new Integer JavaDoc(206));
856         result.add(new Integer JavaDoc(52));
857         result.add(new Integer JavaDoc(56));
858         result.add(new Integer JavaDoc(64));
859         result.add(new Integer JavaDoc(68));
860
861         assertTrue("Wrong result EJBQL customerhome.findWithoutReservationsOrWithGoodCredit() (required:"
862                    + result + ", found:" + customers_id + ")",
863                    isCollectionEqual(result,customers_id));
864
865         //checkIsInitialState(); not necessary in this test
866
}
867
868     /**
869      * Finding the customer with a specific phone number
870      * SELECT OBJECT(c) FROM jt2_Customer cust WHERE ?1 IS MEMBER OF cust.phoneNumbers
871      * This test is done via a session bean because it need to use Local interfaces.
872      */

873     public void testSimpleMemberOf() throws Exception JavaDoc {
874         SessionTestRemote sTest = sessiontesthome.create();
875         int custId = sTest.getCustomerWithPhone("612-555-1280").intValue();;
876         assertEquals("Wrong result EJBQL session.getCustomerWithPhone(612-555-1280): ",
877                      80, custId);
878
879         // checkIsInitialState(); not necessary in this test
880
}
881
882     /**
883      * Finding Customers On Alaska Cruise
884      * SELECT OBJECT(c) FROM jt2_Customer cust, Cruise cr, IN(cr.reservations) res
885      * WHERE cr = ?1 AND cust MEMBER OF res.customers
886      */

887     public void testMemberOfNavigate() throws Exception JavaDoc {
888         CruiseRemote crA = cruisehome.findByName("Alaska Cruise");
889         Collection JavaDoc customers_id = customerhome.callFindOnCruise(crA.getId());
890
891         ArrayList JavaDoc result = new ArrayList JavaDoc();
892         result.add(new Integer JavaDoc(201));
893         result.add(new Integer JavaDoc(201));
894         result.add(new Integer JavaDoc(202));
895         result.add(new Integer JavaDoc(202));
896         result.add(new Integer JavaDoc(203));
897         result.add(new Integer JavaDoc(203));
898         result.add(new Integer JavaDoc(204));
899         result.add(new Integer JavaDoc(204));
900         result.add(new Integer JavaDoc(205));
901         result.add(new Integer JavaDoc(205));
902         result.add(new Integer JavaDoc(206));
903         result.add(new Integer JavaDoc(206));
904         result.add(new Integer JavaDoc(52));
905         result.add(new Integer JavaDoc(55));
906         result.add(new Integer JavaDoc(58));
907         result.add(new Integer JavaDoc(61));
908         result.add(new Integer JavaDoc(64));
909         result.add(new Integer JavaDoc(67));
910
911         assertTrue("Wrong result EJBQL customerhome.findOnCruise(crA) (required:" + result + ", found:" +customers_id+
912                    ")", isCollectionEqual(result,customers_id));
913
914         // checkIsInitialState(); not necessary in this test
915
}
916
917     /**
918      * Finding ship by tonnage
919      * SELECT OBJECT(c) FROM jt2_Ship s
920      * WHERE s.tonnage = ?1
921      */

922     public void testEgalDouble() throws Exception JavaDoc {
923         Collection JavaDoc ships = shiphome.findByTonnage(new Double JavaDoc(100000));
924
925         ArrayList JavaDoc ships_id = new ArrayList JavaDoc();
926         Iterator JavaDoc ship = ships.iterator();
927         while (ship.hasNext()) {
928             ShipRemote ship_remote = (ShipRemote) PortableRemoteObject.narrow(ship.next(), ShipRemote.class);
929             ships_id.add(ship_remote.getId());
930         }
931         ArrayList JavaDoc result = new ArrayList JavaDoc();
932         result.add(new Integer JavaDoc(7));
933
934
935         assertTrue("Wrong result EJBQL shiphome.findByTonnage(new Double(100000)) (required:" + result + ", found:" +ships_id+ ")", isCollectionEqual(result,ships_id));
936
937         // checkIsInitialState(); not necessary in this test
938
}
939
940
941     /**
942      * Finding ship by tonnage
943      * SELECT OBJECT(c) FROM jt2_Ship s
944      * WHERE s.tonnage BETWEEN ?1 AND ?2
945      */

946     public void testBetweenDouble() throws Exception JavaDoc {
947         Collection JavaDoc ships = shiphome.findByTonnage(new Double JavaDoc(100000),new Double JavaDoc(130000));
948
949         ArrayList JavaDoc ships_id = new ArrayList JavaDoc();
950         Iterator JavaDoc ship = ships.iterator();
951         while (ship.hasNext()) {
952             ShipRemote ship_remote = (ShipRemote) PortableRemoteObject.narrow(ship.next(), ShipRemote.class);
953             ships_id.add(ship_remote.getId());
954         }
955         ArrayList JavaDoc result = new ArrayList JavaDoc();
956         result.add(new Integer JavaDoc(7));
957         result.add(new Integer JavaDoc(8));
958         result.add(new Integer JavaDoc(9));
959         result.add(new Integer JavaDoc(10));
960
961         assertTrue("Wrong result EJBQL shiphome.findByTonnage(new Double(100000),new Double(130000)) (required:" + result + ", found:" +ships_id+ ")", isCollectionEqual(result,ships_id));
962
963         // checkIsInitialState(); not necessary in this test
964
}
965
966     /**
967      * A complex navigation test
968      * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.creditCard.creditCompany.address.city = ?1
969      */

970     public void testNavigate() throws Exception JavaDoc {
971
972
973         Collection JavaDoc customers = customerhome.findAllCreditCardAddress("Minneapolis");
974
975         ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
976         Iterator JavaDoc customer = customers.iterator();
977         while (customer.hasNext()) {
978             CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
979             customers_id.add(customer_remote.getId());
980         }
981         ArrayList JavaDoc result = new ArrayList JavaDoc();
982         result.add(new Integer JavaDoc(80));
983         result.add(new Integer JavaDoc(84));
984         result.add(new Integer JavaDoc(88));
985         result.add(new Integer JavaDoc(92));
986         result.add(new Integer JavaDoc(96));
987
988         assertTrue("Wrong result EJBQL customerhome.findAllCreditCardAddress() (required:" + result + ", found:" +customers_id+
989                    ")", isCollectionEqual(result,customers_id));
990
991         checkIsInitialState();
992
993     }
994
995     /**
996      * An other complex navigation test and the OR operator
997      * SELECT OBJECT(c) FROM jt2_Customer AS c WHERE c.creditCard.number = ?1 OR c.homeAddress.zip = ?2
998      */

999     public void testNavigateOr() throws Exception JavaDoc {
1000
1001
1002        Collection JavaDoc customers = customerhome.findCustWithCCNumOrAddrZip("10000184", "55404");
1003
1004        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1005        Iterator JavaDoc customer = customers.iterator();
1006        while (customer.hasNext()) {
1007            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1008            customers_id.add(customer_remote.getId());
1009        }
1010        ArrayList JavaDoc result = new ArrayList JavaDoc();
1011        result.add(new Integer JavaDoc(84));
1012        result.add(new Integer JavaDoc(88));
1013
1014        assertTrue("Wrong result EJBQL customerhome.findCustWithCCNumOrAddrZip() (required:" + result + ", found:" +customers_id+
1015                   ")", isCollectionEqual(result,customers_id));
1016
1017        checkIsInitialState();
1018
1019    }
1020
1021    /**
1022     * Finding all Customer with reservations (there will be duplication in result if customer has more than one reservation
1023     *
1024     * SELECT OBJECT(c) FROM jt2_Reservation res, IN(res.customers) c
1025     */

1026    public void testInFrom() throws Exception JavaDoc {
1027
1028        Collection JavaDoc customers = customerhome.findAllCustomersWithReservation();
1029
1030        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1031        Iterator JavaDoc customer = customers.iterator();
1032        while (customer.hasNext()) {
1033            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1034            customers_id.add(customer_remote.getId());
1035        }
1036        ArrayList JavaDoc result = new ArrayList JavaDoc();
1037
1038        result.add(new Integer JavaDoc(201));
1039        result.add(new Integer JavaDoc(201));
1040        result.add(new Integer JavaDoc(202));
1041        result.add(new Integer JavaDoc(202));
1042        result.add(new Integer JavaDoc(203));
1043        result.add(new Integer JavaDoc(203));
1044        result.add(new Integer JavaDoc(204));
1045        result.add(new Integer JavaDoc(204));
1046        result.add(new Integer JavaDoc(205));
1047        result.add(new Integer JavaDoc(205));
1048        result.add(new Integer JavaDoc(206));
1049        result.add(new Integer JavaDoc(206));
1050        result.add(new Integer JavaDoc(50));
1051        result.add(new Integer JavaDoc(52));
1052        result.add(new Integer JavaDoc(53));
1053        result.add(new Integer JavaDoc(55));
1054        result.add(new Integer JavaDoc(56));
1055        result.add(new Integer JavaDoc(58));
1056        result.add(new Integer JavaDoc(59));
1057        result.add(new Integer JavaDoc(61));
1058        result.add(new Integer JavaDoc(62));
1059        result.add(new Integer JavaDoc(64));
1060        result.add(new Integer JavaDoc(65));
1061        result.add(new Integer JavaDoc(67));
1062        result.add(new Integer JavaDoc(68));
1063
1064        assertTrue("Wrong result EJBQL customerhome.findAllCustomersWithReservation (required:" + result + ", found:" +customers_id+
1065                   ")", isCollectionEqual(result,customers_id));
1066
1067        // checkIsInitialState(); not necessary in this test
1068
}
1069
1070    /**
1071     * Finding all Customer with reservations (there will not be duplication in result)
1072     *
1073     * SELECT DISTINCT OBJECT(c) FROM jt2_Reservation res, IN(res.customers) c
1074     */

1075    public void testDistinctInFrom() throws Exception JavaDoc {
1076
1077        Collection JavaDoc customers = customerhome.findAllCustomersWithReservationDistinct();
1078
1079        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1080        Iterator JavaDoc customer = customers.iterator();
1081        while (customer.hasNext()) {
1082            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1083            customers_id.add(customer_remote.getId());
1084        }
1085        ArrayList JavaDoc result = new ArrayList JavaDoc();
1086
1087        result.add(new Integer JavaDoc(201));
1088        result.add(new Integer JavaDoc(202));
1089        result.add(new Integer JavaDoc(203));
1090        result.add(new Integer JavaDoc(204));
1091        result.add(new Integer JavaDoc(205));
1092        result.add(new Integer JavaDoc(206));
1093        result.add(new Integer JavaDoc(50));
1094        result.add(new Integer JavaDoc(52));
1095        result.add(new Integer JavaDoc(53));
1096        result.add(new Integer JavaDoc(55));
1097        result.add(new Integer JavaDoc(56));
1098        result.add(new Integer JavaDoc(58));
1099        result.add(new Integer JavaDoc(59));
1100        result.add(new Integer JavaDoc(61));
1101        result.add(new Integer JavaDoc(62));
1102        result.add(new Integer JavaDoc(64));
1103        result.add(new Integer JavaDoc(65));
1104        result.add(new Integer JavaDoc(67));
1105        result.add(new Integer JavaDoc(68));
1106
1107        assertTrue("Wrong result EJBQL customerhome.findAllCustomersWithReservationDistinct (required:" + result + ", found:" +customers_id+
1108                   ")", isCollectionEqual(result,customers_id));
1109
1110        // checkIsInitialState(); not necessary in this test
1111
}
1112
1113    /**
1114     * Test for feature #300040
1115     * Finding Customer by address
1116     *
1117     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress = ?1
1118     */

1119    public void _testBeanAsParameter() throws Exception JavaDoc {
1120
1121        AddressRemote add = addresshome.findByPrimaryKey(new Integer JavaDoc(10));
1122
1123        Collection JavaDoc customers = customerhome.findByAddress(add);
1124
1125        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1126        Iterator JavaDoc customer = customers.iterator();
1127        while (customer.hasNext()) {
1128            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1129            customers_id.add(customer_remote.getId());
1130        }
1131        ArrayList JavaDoc result = new ArrayList JavaDoc();
1132
1133        result.add(new Integer JavaDoc(80));
1134
1135        assertTrue("Wrong result EJBQL customerhome.findByAddress(add)(required:" + result + ", found:" +customers_id+
1136                   ")", isCollectionEqual(result,customers_id));
1137
1138        // checkIsInitialState(); not necessary in this test
1139
}
1140
1141    /**
1142     * Test for feature #300040
1143     * Finding Customer by address
1144     *
1145     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress = ?1
1146     */

1147    public void _testBeanNullAsParameter() throws Exception JavaDoc {
1148
1149        Collection JavaDoc customers = customerhome.findByAddress(null);
1150
1151        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1152        Iterator JavaDoc customer = customers.iterator();
1153        while (customer.hasNext()) {
1154            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1155            customers_id.add(customer_remote.getId());
1156        }
1157        ArrayList JavaDoc result = new ArrayList JavaDoc();
1158
1159        assertTrue("Wrong result EJBQL customerhome.findByAddress(add)(required:" + result + ", found:" +customers_id+
1160                   ")", isCollectionEqual(result,customers_id));
1161
1162        // checkIsInitialState(); not necessary in this test
1163
}
1164
1165    /**
1166     * Finding All Customer
1167     *
1168     * SELECT OBJECT(c) FROM jt2_Customer AS c
1169     */

1170    public void testFindCustomerAll() throws Exception JavaDoc {
1171
1172        Collection JavaDoc customers = customerhome.findCustomersAll();
1173
1174        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1175        Iterator JavaDoc customer = customers.iterator();
1176        while (customer.hasNext()) {
1177            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1178            customers_id.add(customer_remote.getId());
1179        }
1180        ArrayList JavaDoc result = new ArrayList JavaDoc();
1181
1182        for (int i=80;i<=99;i++) {
1183            result.add(new Integer JavaDoc(i));
1184        }
1185        for (int j=201;j<=206;j++) {
1186            result.add(new Integer JavaDoc(j));
1187        }
1188        for (int k=50;k<=69;k++) {
1189            result.add(new Integer JavaDoc(k));
1190        }
1191        for (int l=100;l<=109;l++) {
1192            result.add(new Integer JavaDoc(l));
1193        }
1194
1195        assertTrue("Wrong result EJBQL customerhome.findCustomersAll()(required:" + result + ", found:" +customers_id+
1196                   ")", isCollectionEqual(result,customers_id));
1197
1198        // checkIsInitialState(); not necessary in this test
1199
}
1200
1201    /**
1202     * Finding Customers by AddressId
1203     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress.id = ?1
1204     */

1205    public void testFindCustByAddrId() throws Exception JavaDoc {
1206        Collection JavaDoc customers = customerhome.findByAddressId(new Integer JavaDoc(10));
1207
1208        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1209        Iterator JavaDoc customer = customers.iterator();
1210        while (customer.hasNext()) {
1211            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1212            customers_id.add(customer_remote.getId());
1213        }
1214        ArrayList JavaDoc result = new ArrayList JavaDoc();
1215        result.add(new Integer JavaDoc(80));
1216
1217        assertTrue("Wrong result EJBQL customerhome.findByAddressId(10) (required:" + result + ", found:" +customers_id+
1218                   ")", isCollectionEqual(result,customers_id));
1219
1220        // checkIsInitialState(); not necessary in this test
1221
}
1222
1223    /**
1224     * Bug #300626
1225     * SELECT OBJECT(a) FROM jt2_Address AS a
1226     * WHERE a.homecustomer.lastName = 'Smith80'
1227     * AND a.homecustomer.creditCard.id = 10
1228     * AND a.homecustomer.creditCard.creditCompany.name = 'CETELEM'
1229     * AND a.homecustomer.creditCard.creditCompany.id = 10
1230     */

1231    public void testAddrQuery300626() throws Exception JavaDoc {
1232        AddressRemote a = addresshome.findQuery300626();
1233        assertEquals("Wrong result EJBQL : addresshome.findQuery300626()", 10, a.getId().intValue());
1234    }
1235
1236    /**
1237     * Finding Customers by AddressLocal
1238     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress = ?1
1239     */

1240    public void testBeanLocalAsParameter() throws Exception JavaDoc {
1241        Collection JavaDoc customers = customerhome.callFindByAddressLocal(new Integer JavaDoc(10));
1242
1243        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1244        Iterator JavaDoc customer = customers.iterator();
1245        while (customer.hasNext()) {
1246            customers_id.add((Integer JavaDoc)customer.next());
1247        }
1248        ArrayList JavaDoc result = new ArrayList JavaDoc();
1249        result.add(new Integer JavaDoc(80));
1250
1251        assertTrue("Wrong result EJBQL customerhome.callFindByAddressLocal(10) (required:" + result + ", found:" +customers_id+
1252                   ")", isCollectionEqual(result,customers_id));
1253
1254        // checkIsInitialState(); not necessary in this test
1255
}
1256
1257    /**
1258     * Finding Customers by AddressLocal
1259     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.homeAddress = ?1
1260     */

1261    public void testBeanLocalNullAsParameter() throws Exception JavaDoc {
1262        Collection JavaDoc customers = customerhome.callFindByAddressLocal(null);
1263
1264        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1265        Iterator JavaDoc customer = customers.iterator();
1266        while (customer.hasNext()) {
1267            customers_id.add((Integer JavaDoc)customer.next());
1268        }
1269        ArrayList JavaDoc result = new ArrayList JavaDoc();
1270
1271        assertTrue("Wrong result EJBQL customerhome.callFindByAddressLocal(null) (required:" + result + ", found:" +customers_id+
1272                   ")", isCollectionEqual(result,customers_id));
1273
1274        // checkIsInitialState(); not necessary in this test
1275
}
1276
1277    /**
1278     * Test a finder method
1279     * - which have no parameter and which have its name starts with 'findAll',
1280     * - but which not means "findAll".
1281     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.firstName LIKE 'Mike'
1282     */

1283    public void testFindAllMike() throws Exception JavaDoc {
1284        Collection JavaDoc customers = customerhome.findAllMike();
1285        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1286        Iterator JavaDoc customer = customers.iterator();
1287        while (customer.hasNext()) {
1288            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1289            assertEquals("findAllMike() wrong result: ",
1290                         "Mike", customer_remote.getName().getFirstName());
1291        }
1292    }
1293
1294    /**
1295     * Test a finder method with the IS NOT NULL operator on a cmr field.
1296     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.creditCard IS NOT NULL
1297     */

1298    public void testIsNull1() throws Exception JavaDoc {
1299        Collection JavaDoc customers = customerhome.findCustomersWithCreditCard();
1300        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1301        Iterator JavaDoc customer = customers.iterator();
1302        while (customer.hasNext()) {
1303            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1304            customers_id.add(customer_remote.getId());
1305        }
1306        ArrayList JavaDoc resExpected = new ArrayList JavaDoc();
1307        resExpected.add(new Integer JavaDoc(80));
1308        resExpected.add(new Integer JavaDoc(84));
1309        resExpected.add(new Integer JavaDoc(88));
1310        resExpected.add(new Integer JavaDoc(92));
1311        resExpected.add(new Integer JavaDoc(96));
1312        assertTrue("Wrong result EJBQL customerhome.findCustomersWithCreditCard (required:"
1313                   + resExpected + ", found:" + customers_id + ")",
1314                   isCollectionEqual(resExpected,customers_id));
1315    }
1316
1317    /**
1318     * Test a finder method with the IS NULL operator on a cmr field.
1319     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.creditCard IS NULL
1320     */

1321    public void testIsNull1bis() throws Exception JavaDoc {
1322        Collection JavaDoc customers = customerhome.findCustomersWithOutCreditCard();
1323        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1324        Iterator JavaDoc customer = customers.iterator();
1325        while (customer.hasNext()) {
1326            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1327            customers_id.add(customer_remote.getId());
1328        }
1329        ArrayList JavaDoc resExpected = new ArrayList JavaDoc();
1330        for (int i = 50; i <= 69; i++) {
1331            resExpected.add(new Integer JavaDoc(i));
1332        }
1333        for (int i = 81; i <= 83; i++) {
1334            resExpected.add(new Integer JavaDoc(i));
1335        }
1336        for (int i = 85; i <= 87; i++) {
1337            resExpected.add(new Integer JavaDoc(i));
1338        }
1339        for (int i = 89; i <= 91; i++) {
1340            resExpected.add(new Integer JavaDoc(i));
1341        }
1342        for (int i = 93; i <= 95; i++) {
1343            resExpected.add(new Integer JavaDoc(i));
1344        }
1345        for (int i = 97; i <= 109; i++) {
1346            resExpected.add(new Integer JavaDoc(i));
1347        }
1348        for (int i = 201; i <= 206; i++) {
1349            resExpected.add(new Integer JavaDoc(i));
1350        }
1351        assertTrue("Wrong result EJBQL customerhome.findCustomersWithOutCreditCard (required:"
1352                   + resExpected + ", found:" + customers_id + ")",
1353                   isCollectionEqual(resExpected,customers_id));
1354    }
1355
1356    /**
1357     * Test a finder method with the IS NULL operator on a cmr field in an expression.
1358     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.firstName = ?1 AND c.creditCard IS NULL
1359     */

1360    public void testIsNull1ter() throws Exception JavaDoc {
1361        Collection JavaDoc customers = customerhome.findCustomersXWithOutCreditCard("John");
1362        assertEquals("Wrong result EJBQL customerhome.findCustomersXWithOutCreditCard: ", 19, customers.size());
1363
1364    }
1365
1366    /**
1367     * Test a finder method with the IS NOT NULL operator on a cmr field with a complex navigation.
1368     * SELECT OBJECT(c) FROM jt2_Customer c WHERE c.creditCard.creditCompany IS NOT NULL
1369     */

1370    public void testIsNull2() throws Exception JavaDoc {
1371        Collection JavaDoc customers = customerhome.findCustomersWithCreditCompany();
1372        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1373        Iterator JavaDoc customer = customers.iterator();
1374        while (customer.hasNext()) {
1375            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1376            customers_id.add(customer_remote.getId());
1377        }
1378        ArrayList JavaDoc resExpected = new ArrayList JavaDoc();
1379        resExpected.add(new Integer JavaDoc(80));
1380        resExpected.add(new Integer JavaDoc(84));
1381        resExpected.add(new Integer JavaDoc(88));
1382        resExpected.add(new Integer JavaDoc(92));
1383        resExpected.add(new Integer JavaDoc(96));
1384        assertTrue("Wrong result EJBQL customerhome.findCustomersWithCreditCompany (required:"
1385                   + resExpected + ", found:" + customers_id + ")",
1386                   isCollectionEqual(resExpected,customers_id));
1387    }
1388
1389    /**
1390     * Test a finder method with the IS NULL operator on a parameter which is a bean null.
1391     * SELECT OBJECT(c) FROM jt2_Customer c WHERE ?1 IS NULL
1392     */

1393    public void testIsNull3() throws Exception JavaDoc {
1394        Collection JavaDoc customers = customerhome.callFindByParameterIsNull(null);
1395        assertEquals("Wrong result EJBQL customerhome.callFindByParameterIsNull(null): ",
1396                     56, customers.size());
1397    }
1398
1399    /**
1400     * Test a finder method with the IS NULL operator on a parameter which is a bean not null.
1401     * SELECT OBJECT(c) FROM jt2_Customer c WHERE ?1 IS NULL
1402     */

1403    public void testIsNull3bis() throws Exception JavaDoc {
1404        Collection JavaDoc customers = customerhome.callFindByParameterIsNull(new Integer JavaDoc(10));
1405        assertEquals("Wrong result EJBQL customerhome.callFindByParameterIsNull(): ",
1406                     0, customers.size());
1407    }
1408
1409    /**
1410     * Select the lastName of a customer
1411     * SELECT c.lastName FROM jt2_Customer AS c WHERE c.id = ?1
1412     */

1413    public void testCustEjbSelectLastName() throws Exception JavaDoc {
1414        assertEquals("Wrong ejbSelectLastName for c.id=80: ",
1415                     "Smith80", customerhome.selectLastName(new Integer JavaDoc(80)));
1416    }
1417
1418    /**
1419     * Select the city of the address of a customer
1420     * SELECT c.homeAddress.city FROM jt2_Customer AS c WHERE c.id = ?1
1421     */

1422    public void testCustEjbSelectAddrCity() throws Exception JavaDoc {
1423        assertEquals("Wrong ejbSelectAddrCity for c.id=80: ",
1424                     "Minneapolis", customerhome.selectAddrCity(new Integer JavaDoc(80)));
1425    }
1426
1427    /**
1428     * Select the deckLevel of a cabin
1429     * SELECT c.deckLevel FROM jt2_Cabin AS c WHERE c.id = ?1
1430     */

1431    public void testCabinEjbSelectDeckLevel() throws Exception JavaDoc {
1432        assertEquals("Wrong ejbSelectDeckLevel for c.id=21100: ",
1433                     1, cabinhome.selectDeckLevel(new Integer JavaDoc(21100)));
1434    }
1435
1436    /**
1437     * Select the firstName of all the customers.
1438     * SELECT c.firstName FROM jt2_Customer AS c
1439     */

1440    public void testCustEjbSelectFirstName() throws Exception JavaDoc {
1441        Set JavaDoc lfn = customerhome.selectFirstName();
1442        Iterator JavaDoc ilfn = lfn.iterator();
1443        StringBuffer JavaDoc slfn = new StringBuffer JavaDoc();
1444        while (ilfn.hasNext()) {
1445            slfn = slfn.append((String JavaDoc) ilfn.next() + ",");
1446        }
1447        assertEquals("Wrong ejbSelectFirstName() number results (" + slfn.toString() + "): ",
1448                     6, lfn.size());
1449        if (!lfn.contains("John")
1450            || !lfn.contains("Mike")
1451            || !lfn.contains("Paul")
1452            || !lfn.contains("Ringo")
1453            || !lfn.contains("Roger")
1454            || !lfn.contains("Joe")) {
1455            fail("Wrong ejbSelectFirstName() result (" + slfn.toString()
1456                 + "): does not contain 'John', 'Mike' or 'Paul' or 'Ringo' or 'Roger' or 'Joe'");
1457        }
1458    }
1459
1460    /**
1461     * Select the DISTINCT firstName of all the customers.
1462     * SELECT DISTINCT c.firstName FROM jt2_Customer AS c
1463     */

1464    public void testCustEjbSelectDistinctFirstName() throws Exception JavaDoc {
1465        Collection JavaDoc lfn = customerhome.selectDistinctFirstName();
1466        assertEquals("Wrong ejbSelectDistinctFirstName() number results (" + lfn.toString() + "): ",
1467                     6, lfn.size());
1468        if (!lfn.contains("John")
1469            || !lfn.contains("Mike")
1470            || !lfn.contains("Paul")
1471            || !lfn.contains("Ringo")
1472            || !lfn.contains("Roger")
1473            || !lfn.contains("Joe")) {
1474            fail("Wrong ejbSelectDistinctDistinctFirstName() result (" + lfn.toString()
1475                 + "): does not contain 'John', 'Mike' or 'Paul' or 'Ringo' or 'Roger' or 'Joe'");
1476        }
1477    }
1478
1479    /**
1480     * Select the address of a customer
1481     * An ejbSelect with a local bean as result
1482     * SELECT c.homeAddress FROM jt2_Customer AS c WHERE c.id = ?1
1483     */

1484    public void testCustEjbSelectAddr() throws Exception JavaDoc {
1485        assertEquals("Wrong ejbSelectAddr for c.id=80: ",
1486                     new Integer JavaDoc(10), customerhome.selectAddr(new Integer JavaDoc(80)));
1487    }
1488
1489    /**
1490     * Select the addresses of the company of the credit card of all the customers.
1491     * An ejbSelect with a collection of local bean as result
1492     * SELECT c.creditCard.creditCompany.address FROM jt2_Customer c
1493     */

1494    public void testCustEjbSelectAllCreditCartAddr() throws Exception JavaDoc {
1495        Collection JavaDoc addr = customerhome.selectAllCreditCardAddr();
1496        StringBuffer JavaDoc sAddr = new StringBuffer JavaDoc();
1497        Iterator JavaDoc iAddr = addr.iterator();
1498        while (iAddr.hasNext()) {
1499            sAddr = sAddr.append(((Integer JavaDoc) iAddr.next()).toString() + ",");
1500        }
1501        ArrayList JavaDoc eAddr = new ArrayList JavaDoc();
1502        eAddr.add(new Integer JavaDoc(11));
1503        eAddr.add(new Integer JavaDoc(16));
1504        eAddr.add(new Integer JavaDoc(21));
1505        eAddr.add(new Integer JavaDoc(26));
1506        eAddr.add(new Integer JavaDoc(31));
1507        assertTrue("Wrong ejbSelectCreditCardAddr: (" + sAddr + "): ",
1508                   isCollectionEqual(eAddr, addr));
1509    }
1510
1511    /**
1512     * Select the adresses of all 'roger' customers.
1513     * An ejbSelect with a collection of local bean as result
1514     * SELECT c.homeAddress FROM jt2_Customer c WHERE c.firstName = 'Roger'
1515     */

1516    public void testCustEjbSelectRogerAddr() throws Exception JavaDoc {
1517        Collection JavaDoc addr = customerhome.selectRogerAddr();
1518        StringBuffer JavaDoc sAddr = new StringBuffer JavaDoc();
1519        Iterator JavaDoc iAddr = addr.iterator();
1520        while (iAddr.hasNext()) {
1521            sAddr = sAddr.append(((Integer JavaDoc) iAddr.next()).toString() + ",");
1522        }
1523        ArrayList JavaDoc eAddr = new ArrayList JavaDoc();
1524        eAddr.add(new Integer JavaDoc(45));
1525        eAddr.add(new Integer JavaDoc(50));
1526        eAddr.add(new Integer JavaDoc(55));
1527        eAddr.add(new Integer JavaDoc(60));
1528        assertTrue("Wrong ejbCustSelectRogerAddr: (" + sAddr + "): ",
1529                   isCollectionEqual(eAddr, addr));
1530    }
1531
1532    /**
1533     * Find all the customers ordered by their lastname.
1534     * SELECT OBJECT(c) FROM jt2_Customer c ORDER BY c.lastName
1535     */

1536    public void testSimpleOrderBy() throws Exception JavaDoc {
1537        Collection JavaDoc customers = customerhome.findAllOrderByLastname();
1538        assertEquals("Wrong customers number for customerhome.findAllOrderByLastname(): ",
1539                     56, customers.size());
1540        Iterator JavaDoc ci = customers.iterator();
1541        String JavaDoc previous = ((CustomerRemote) PortableRemoteObject.narrow(ci.next(), CustomerRemote.class)).getName().getLastName();
1542        while (ci.hasNext()) {
1543            String JavaDoc lname = ((CustomerRemote) PortableRemoteObject.narrow(ci.next(), CustomerRemote.class)).getName().getLastName();
1544            assertTrue("Wrong ordered (previous=" + previous + ",current=" + lname + ")",
1545                       previous.compareTo(lname)<=0);
1546            previous = lname;
1547        }
1548    }
1549
1550    /**
1551     * Find all the customers ordered by their lastname (desc) and firstname (asc).
1552     * SELECT OBJECT(c) FROM jt2_Customer c ORDER BY c.lastName DESC, c.firstName ASC
1553     */

1554    public void testOrderByDescAsc() throws Exception JavaDoc {
1555        Collection JavaDoc customers = customerhome.findAllOrderByDescLastnameAscFirstname();
1556        assertEquals("Wrong customers number for customerhome.findAllOrderByLastname(): ",
1557                     56, customers.size());
1558        Iterator JavaDoc ci = customers.iterator();
1559        Name previous = ((CustomerRemote) PortableRemoteObject.narrow(ci.next(), CustomerRemote.class)).getName();
1560        while (ci.hasNext()) {
1561            Name current = ((CustomerRemote) PortableRemoteObject.narrow(ci.next(), CustomerRemote.class)).getName();
1562            assertTrue("Wrong ordered (previous=" + previous + ",current=" + current + ")",
1563                       previous.getLastName().compareTo(current.getLastName())>=0);
1564            if (previous.getLastName().equals(current.getLastName())) {
1565                assertTrue("Wrong ordered (previous=" + previous + ",current=" + current + ")",
1566                           previous.getFirstName().compareTo(current.getFirstName())<=0);
1567            }
1568            previous = current;
1569        }
1570
1571    }
1572
1573    /**
1574     * Find the reservations ordered by their amountPaid.
1575     * The DISTINCT aggregate is used to reproduce the bug #300527
1576     * SELECT DISTINCT OBJECT(r) FROM jt2_Reservation AS r ORDER BY r.amountPaid
1577     * (bug #300527)
1578     */

1579    public void testOrderBy2() throws Exception JavaDoc {
1580        Collection JavaDoc reservations = reservationhome.findOrderedRsrv();
1581        assertEquals("Wrong reservations number for reservationhome.findOrderedRsrv(): ",
1582                     25, reservations.size());
1583    }
1584
1585    /**
1586     * Get the average of the tonnage of all the ships.
1587     * SELECT AVG(s.tonnage) FROM jt2_Ship AS s
1588     */

1589    public void testAverageofTonnage() throws Exception JavaDoc {
1590        assertEquals("AverageofTonnage: ", 80000.0D, shiphome.getAverageOfTonnage(), 0.1);
1591    }
1592
1593    /**
1594     * Get the count of reservations.
1595     * SELECT COUNT(r) FROM jt2_Reservations AS r
1596     */

1597    public void testCountOfReservations() throws Exception JavaDoc {
1598        assertEquals("CountOfReservations: ", 25L, reservationhome.getCountOfReservations());
1599    }
1600
1601    /**
1602     * bug #300723
1603     * Get the count of customers with a given id
1604     * SELECT COUNT(c) FROM jt2_Customer AS c WHERE c.id = ?1
1605     */

1606    public void testCountOfCustomersWithId1() throws Exception JavaDoc {
1607        assertEquals("CountOfCustomersWithId1: ", 1L, customerhome.getCountCustomersWithId1(new Integer JavaDoc(82)));
1608    }
1609
1610    /**
1611     * bug #300723
1612     * Get the count of customers with a given id
1613     * SELECT COUNT(c) FROM jt2_Customer AS c WHERE c.id = ?1
1614     */

1615    public void testCountOfCustomersWithId2() throws Exception JavaDoc {
1616        assertEquals("CountOfCustomersWithId2: ", 1L, customerhome.getCountCustomersWithId2(82));
1617    }
1618
1619    /**
1620     * Get the count of customers with a firstname 'Ringo'
1621     * SELECT COUNT(c) FROM jt2_Customer AS c WHERE c.firstName = 'Ringo'
1622     */

1623    public void testCountOfCustomersRingo() throws Exception JavaDoc {
1624        assertEquals("CountOfCustomersRingo: ", 4L, customerhome.getCountCustomersRingo());
1625    }
1626
1627    /**
1628     * Get the customer with a given id
1629     * SELECT c FROM jt2_Customer AS c WHERE c.id = ?1
1630     */

1631    public void testCustFindById() throws Exception JavaDoc {
1632        assertEquals("CustFindById: ", new Integer JavaDoc(82), customerhome.findById(new Integer JavaDoc(82)).getId());
1633    }
1634
1635    /**
1636     * Get the min value of the amount of the reservations.
1637     * SELECT MIN(r.amountPaid) FROM jt2_Reservations AS r
1638     */

1639    public void testMinAmountOfReservations() throws Exception JavaDoc {
1640        assertEquals("testMinAmountOfReservations: ",
1641                     2500.0, reservationhome.getMinAmountOfReservations(), 0.1);
1642    }
1643
1644    /**
1645     * (Bug #300635)
1646     * Get the min value of the amount of the reservations for the cruise name.
1647     * SELECT MIN(r.amountPaid) FROM jt2_Reservations AS r WHERE r.cruise.name = ?1
1648     */

1649    public void testMinAmountForCruise() throws Exception JavaDoc {
1650        assertEquals("testMinAmountForCruise(Alaska Cruise): ",
1651                     2520.0, reservationhome.getMinAmountForCruise("Alaska Cruise"), 0.1);
1652    }
1653
1654    /**
1655     * Get the values of the amounts of the reservations for the cruise name.
1656     * SELECT r.amountPaid FROM jt2_Reservations AS r WHERE r.cruise.name = ?1
1657     */

1658    public void testAmountsForCruise() throws Exception JavaDoc {
1659        assertEquals("testAmountsForCruise(Alaska Cruise): ",
1660                     18, reservationhome.getAmountsForCruise("Alaska Cruise").size());
1661    }
1662
1663    /**
1664     * Get the max value of the amount of the reservations.
1665     * SELECT MAX(r.amountPaid) FROM jt2_Reservations AS r
1666     */

1667    public void testMaxAmountOfReservations() throws Exception JavaDoc {
1668        assertEquals("testMaxAmountOfReservations: ",
1669                     208100.0, reservationhome.getMaxAmountOfReservations(), 0.1);
1670    }
1671
1672    /**
1673     * Get the count of all the reservations for a specific customer.
1674     * SELECT COUNT(r) FROM jt2_Reservation AS r WHERE ?1 MEMBER OF r.customers
1675     * (bug #300280)
1676     */

1677    public void testCountOfReservationsForCustomer() throws Exception JavaDoc {
1678        assertEquals("CountOfReservationsForCustomer: ",
1679                     2L, reservationhome.getCountOfReservationsForCustomer(new Integer JavaDoc(202)));
1680    }
1681
1682    /**
1683     * Get the amount paid of all the reservations for a specific customer.
1684     * SELECT SUM(r.amountPaid) FROM jt2_Reservation AS r WHERE ?1 MEMBER OF r.customers
1685     * (bug #300280)
1686     */

1687    public void testAmountOfReservationsForCustomer() throws Exception JavaDoc {
1688        assertEquals("AmountOfReservationsForCustomer: ",
1689                     408100.0, reservationhome.getAmountOfReservationsForCustomer(new Integer JavaDoc(202)), 0.1);
1690    }
1691
1692    /**
1693     * Get the count of credit card for customers
1694     * SELECT COUNT(c.creditCard) FROM jt2_Customer AS c
1695     * The result must be equivalent to
1696     * SELECT COUNT(c.creditCard) FROM jt2_Customer AS c WHERE c.creditCard IS NOT NULL
1697     */

1698    public void testCustomersCountCreditCard() throws Exception JavaDoc {
1699        assertEquals("CustomersCountCreditCard: ", 5, customerhome.getCountCreditCard());
1700    }
1701
1702    /**
1703     * Get the list of the number of the credit card for customers
1704     * SELECT DISTINCT c.creditCard.number FROM jt2_Customer AS c ORDER BY c.creditCard.number
1705     */

1706    public void testCustomersCreditCardNumbers() throws Exception JavaDoc {
1707        assertEquals("CustomersCreditCardNumbers: ", 5, customerhome.getCreditCardNumbers().size());
1708    }
1709
1710
1711    /**
1712     * Find all the addresses
1713     * SELECT OBJECT(a) FROM jt2_Address AS a
1714     */

1715    public void testFindAllAddresses() throws Exception JavaDoc {
1716        Collection JavaDoc addresses = addresshome.findAllAddress();
1717        Iterator JavaDoc iAddr = addresses.iterator();
1718        int nbAddr = 0;
1719        while (iAddr.hasNext()) {
1720            nbAddr++;
1721            iAddr.next();
1722        }
1723        assertEquals("testFindAllAddresses: ", 61, nbAddr);
1724    }
1725
1726    /**
1727     * Get all the cities of addresses
1728     * SELECT a.city FROM jt2_Address AS a
1729     */

1730    public void testAddrGetAllCities() throws Exception JavaDoc {
1731        assertEquals("testAddrGetAllCities: ", 61, addresshome.getAllCities().size());
1732    }
1733
1734    /**
1735     * Get all the creditCompanies of addresses
1736     * SELECT a.creditCompany FROM jt2_Address AS a
1737     */

1738    public void testAddrGetAllCreditCompanies() throws Exception JavaDoc {
1739        assertEquals("testAddrGetAllCreditCompanies: ", 5, addresshome.getAllCreditCompanies().size());
1740    }
1741
1742    /**
1743     * Get all the creditCompany names of addresses.
1744     * This is a test about Null Values in the Query Result.
1745     * If the result of the query corresponds to a cmr-field or cmp-field not defined in term of java primitive type,
1746     * the container must include null value in the result.
1747     * See the EJB Specification version 2.1, chapter 11.2.7.1
1748     * SELECT a.creditCompany.name FROM jt2_Address AS a
1749     * (bug #3001174)
1750     */

1751    public void testAddrGetAllCreditCompanyNames() throws Exception JavaDoc {
1752        assertEquals("testAddrGetAllCreditCompanyNames: ", 61, addresshome.getAllCreditCompanyNames().size());
1753    }
1754
1755    /**
1756     * Get all the creditCompany id of addresses.
1757     * This is a test about Null Values in the Query Result.
1758     * If the result of the query corresponds to a cmp-field not defined in term of java primitive type,
1759     * the container must include null value in the result.
1760     * See the EJB Specification version 2.1, chapter 11.2.7.1
1761     * SELECT a.creditCompany.id FROM jt2_Address AS a
1762     * (bug #301174)
1763     */

1764    public void testAddrGetAllCreditCompanyIds() throws Exception JavaDoc {
1765        assertEquals("testAddrGetAllCreditCompanyIds: ", 61, addresshome.getAllCreditCompanyIds().size());
1766    }
1767
1768    /**
1769     * Get all the creditCompany id of addresses.
1770     * This is a test about Null Values in the Query Result.
1771     * If the result of the query corresponds to a cmp-field defined in term of java primitive type,
1772     * the container must not include null value in the result.
1773     * See the EJB Specification version 2.1, chapter 11.2.7.1
1774     * SELECT a.creditCompany.num FROM jt2_Address AS a
1775     * (bug #301174)
1776     */

1777    public void testAddrGetAllCreditCompanyNums() throws Exception JavaDoc {
1778        assertEquals("testAddrGetAllCreditCompanyNums: ", 5, addresshome.getAllCreditCompanyNums().size());
1779    }
1780
1781
1782    /**
1783     * Get the count of cities for addresses
1784     * SELECT COUNT(a.city) FROM jt2_Address AS a
1785     */

1786    public void testAddrCountOfCities() throws Exception JavaDoc {
1787        assertEquals("testAddrCountOfCities: ", 61L, addresshome.getCountOfCities());
1788    }
1789
1790    /**
1791     * Get the count of DISTINCT cities for addresses
1792     * SELECT COUNT(DISTINCT a.city) FROM jt2_Address AS a
1793     */

1794    public void testAddrCountOfDistinctCities() throws Exception JavaDoc {
1795        assertEquals("testAddrCountOfDistinctCities: ", 6L, addresshome.getCountOfDistinctCities());
1796    }
1797
1798    /**
1799     * Find the reservations with lesser amount.
1800     * SELECT DISTINCT OBJECT(r1) FROM jt2_Reservation AS r1, jt2_Reservation AS r2
1801     * WHERE r1.amountPaid &lt; r2.amountPaid AND r2.id = 26
1802     */

1803    public void testFindResWithLesserAmount() throws Exception JavaDoc {
1804        Collection JavaDoc reservations = reservationhome.findReservationsWithLesserAmount();
1805        assertEquals("Wrong reservations number for reservationhome.findReservationsWithLesserAmount(): ",
1806                     4, reservations.size());
1807    }
1808
1809    /**
1810     * Finding All Customer with a limiter startAt range
1811     *
1812     * SELECT OBJECT(c) FROM jt2_Customer AS c WHERE c.id > 0 ORDER BY c.id LIMIT ?1
1813     */

1814    public void testFindCustAllLimit_1() throws Exception JavaDoc {
1815
1816        Collection JavaDoc customers = customerhome.findAllWithLimit_1(40);
1817
1818        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1819        Iterator JavaDoc customer = customers.iterator();
1820        while (customer.hasNext()) {
1821            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1822            customers_id.add(customer_remote.getId());
1823        }
1824        ArrayList JavaDoc result = new ArrayList JavaDoc();
1825        for (int l=100;l<=109;l++) {
1826            result.add(new Integer JavaDoc(l));
1827        }
1828        for (int j=201;j<=206;j++) {
1829            result.add(new Integer JavaDoc(j));
1830        }
1831
1832        assertTrue("Wrong result EJBQL customerhome.findAllWithLimit_1()(required:" + result + ", found:" +customers_id+
1833                   ")", isCollectionEqual(result,customers_id));
1834
1835        // checkIsInitialState(); not necessary in this test
1836
}
1837
1838    /**
1839     * Finding All Customer with a limiter startAt range and a size range
1840     *
1841     * SELECT OBJECT(c) FROM jt2_Customer AS c ORDER BY c.id LIMIT ?1, 5
1842     */

1843    public void testFindCustAllLimit_2() throws Exception JavaDoc {
1844
1845        Collection JavaDoc customers = customerhome.findAllWithLimit_2(40);
1846
1847        ArrayList JavaDoc customers_id = new ArrayList JavaDoc();
1848        Iterator JavaDoc customer = customers.iterator();
1849        while (customer.hasNext()) {
1850            CustomerRemote customer_remote = (CustomerRemote) PortableRemoteObject.narrow(customer.next(), CustomerRemote.class);
1851            customers_id.add(customer_remote.getId());
1852        }
1853        ArrayList JavaDoc result = new ArrayList JavaDoc();
1854        for (int l=100;l<=104;l++) {
1855            result.add(new Integer JavaDoc(l));
1856        }
1857
1858        assertTrue("Wrong result EJBQL customerhome.findAllWithLimit_2()(required:" + result + ", found:" +customers_id+
1859                   ")", isCollectionEqual(result,customers_id));
1860
1861        // checkIsInitialState(); not necessary in this test
1862
}
1863
1864
1865
1866    public static Test suite() {
1867        return new TestSuite(F_EjbqlEC2.class);
1868    }
1869
1870    public static void main (String JavaDoc args[]) {
1871        String JavaDoc testtorun = null;
1872        // Get args
1873
for (int argn = 0; argn < args.length; argn++) {
1874            String JavaDoc s_arg = args[argn];
1875            Integer JavaDoc i_arg;
1876            if (s_arg.equals("-n")) {
1877                testtorun = args[++argn];
1878            }
1879        }
1880        if (testtorun == null) {
1881            junit.textui.TestRunner.run(suite());
1882        } else {
1883            junit.textui.TestRunner.run(new F_EjbqlEC2(testtorun));
1884        }
1885    }
1886}
1887
1888
Popular Tags