KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > listdata > logic > ListControllerTest


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ListControllerTest.java,v 1.15 2007/02/01 07:26:17 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.patterns.listdata.logic;
23
24 import java.util.Arrays JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.opensubsystems.core.data.DataObject;
28 import org.opensubsystems.core.error.OSSException;
29 import org.opensubsystems.core.logic.ControllerManager;
30 import org.opensubsystems.core.persist.db.DatabaseTest;
31 import org.opensubsystems.patterns.listdata.data.ListDefinition;
32 import org.opensubsystems.patterns.listdata.data.ListOptions;
33 import org.opensubsystems.patterns.listdata.persist.db.ListDatabaseTestUtils;
34
35 /**
36  * Generic list controller tests that should apply to any data objects that
37  * implement the list data patter and are be accesible by pages. When you
38  * implement new data object, which needs to be accessible by pages, derive new
39  * class from this class and just pass the list test utilities specific to your
40  * data object. Then using your new class you can execute all list tests for your
41  * new data object.
42  *
43  * @version $Id: ListControllerTest.java,v 1.15 2007/02/01 07:26:17 bastafidli Exp $
44  * @author Julo Legeny
45  * @code.reviewer Miro Halas
46  * @code.reviewed 1.8 2005/11/04 00:20:15 jlegeny
47  */

48 public abstract class ListControllerTest extends DatabaseTest
49 {
50    // Attributes ///////////////////////////////////////////////////////////////
51

52    /**
53     * Utility class used to generate data for controller test.
54     */

55    protected ListDatabaseTestUtils m_listTestUtils;
56    
57    // Constructor //////////////////////////////////////////////////////////////
58

59    /**
60     * Constructor.
61     *
62     * @param strTestName - name of the test
63     * @param listTestUtils - utilities used during test
64     */

65    public ListControllerTest(
66       String JavaDoc strTestName,
67       ListDatabaseTestUtils listTestUtils
68    )
69    {
70       super(strTestName);
71       
72       m_listTestUtils = listTestUtils;
73    }
74       
75    // Tests ////////////////////////////////////////////////////////////////////
76

77    /**
78     * Test of method getNextPage
79     *
80     * @throws Exception - an error has occured
81     */

82    public void testGetNextPage(
83    ) throws Exception JavaDoc
84    {
85       Object JavaDoc[] data = null;
86       
87       try
88       {
89          Object JavaDoc parent;
90          ListOptions options;
91          int iEndPos = 5;
92          
93          data = m_listTestUtils.insertTestData(m_transaction);
94          parent = data[0];
95          options = m_listTestUtils.getDefaultListOptions(parent);
96          options.setClientOrderCode(1);
97          options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
98          options.setEndPosition(iEndPos);
99          
100          Object JavaDoc[] listOpResults = getListController().getNextPage(options);
101          ListOptions testOptions = (ListOptions)listOpResults[0];
102          List JavaDoc lstTestData = (List JavaDoc)listOpResults[1];
103          
104          // m_listTestUtils.printDebug(lstTestData);
105
// m_listTestUtils.printDebug(testOptions);
106

107          String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
108          
109          assertNotNull("Selected data object list is null", lstTestData);
110          assertEquals("ActualListSize is incorrectly set",
111                       arrExpectedData.length,
112                       testOptions.getActualListSize());
113          if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
114             < options.getPageSize())
115          {
116             assertEquals("Number of selected items is incorrect",
117                          (arrExpectedData.length - testOptions.getBeginPosition()
118                             + 1),
119                          lstTestData.size());
120          }
121          else
122          {
123             assertEquals("Number of selected items is incorrect",
124                          options.getPageSize(),
125                          lstTestData.size());
126          }
127          if (((iEndPos + 1) <= arrExpectedData.length)
128             && (options.getPageSize() < arrExpectedData.length))
129          {
130             assertEquals("BeginPosition is incorrectly set",
131                          (iEndPos + 1),
132                          testOptions.getBeginPosition());
133          }
134          else
135          {
136              if (options.getPageSize() >= arrExpectedData.length)
137              {
138                 assertEquals("BeginPosition is incorrectly set",
139                              1, testOptions.getBeginPosition());
140              }
141              else
142              {
143                 assertEquals("BeginPosition is incorrectly set",
144                              arrExpectedData.length - options.getPageSize() + 1,
145                              testOptions.getBeginPosition());
146              }
147          }
148          assertTrue("EndPosition is incorrectly set",
149                     ((testOptions.getBeginPosition() + options.getPageSize() - 1)
150                        == testOptions.getEndPosition()
151                     || (testOptions.getEndPosition() == arrExpectedData.length)));
152          
153          assertEquals("ActualPage is incorrectly set",
154                       (((testOptions.getBeginPosition() + options.getPageSize() - 2)
155                         / options.getPageSize()) + 1),
156                       testOptions.getActualPage());
157
158          int helpCounter;
159          int assertCounter;
160          for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
161               assertCounter < testOptions.getEndPosition();
162               assertCounter++, helpCounter++)
163          {
164             assertEquals("The retrieved element #" + helpCounter +
165                          " is not correct",
166                          arrExpectedData[assertCounter],
167                          m_listTestUtils.getColumnOneValue(
168                             (DataObject)lstTestData.get(helpCounter)
169                          ));
170             
171          }
172       }
173       catch (Throwable JavaDoc thr)
174       {
175          throw new Exception JavaDoc(thr);
176       }
177       finally
178       {
179          m_listTestUtils.deleteTestData(m_transaction, data);
180       }
181    }
182
183    /**
184     * Test of method getNextPage with keeping selected items
185     *
186     * @throws Exception - an error has occured
187     */

188    public void testGetNextPageKeepSelected(
189    ) throws Exception JavaDoc
190    {
191       Object JavaDoc[] data = null;
192       
193       try
194       {
195          Object JavaDoc parent;
196          ListOptions options;
197          int iEndPos = 5;
198          String JavaDoc[] arrExpectedData;
199          
200          data = m_listTestUtils.insertTestData(m_transaction);
201          parent = data[0];
202          options = m_listTestUtils.getDefaultListOptions(parent);
203          arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
204          
205          // Retrieve 1st page and select first 3 items.
206
Object JavaDoc[] listOpResults = getListController().getShowList(options);
207          ListOptions testOptions = (ListOptions)listOpResults[0];
208          List JavaDoc lstTestData = (List JavaDoc)listOpResults[1];
209          
210          assertNotNull("Selected data object list is null", lstTestData);
211          assertTrue("Test assumption is that the default list option select" +
212                     " at least 4 items.", 4 <= lstTestData.size());
213          
214          // Make sure that our operation has retrieved the items we thought
215
// it will retrieve
216
assertEquals("The selected item 1 is incorrect",
217                       arrExpectedData[0],
218                       m_listTestUtils.getColumnOneValue(
219                          (DataObject)lstTestData.get(0)));
220          assertEquals("The selected item 2 is correct",
221                       arrExpectedData[1],
222                       m_listTestUtils.getColumnOneValue(
223                          (DataObject)lstTestData.get(1)));
224          assertEquals("The selected item 3 is not correct",
225                       arrExpectedData[2],
226                       m_listTestUtils.getColumnOneValue(
227                          (DataObject)lstTestData.get(2)));
228          
229          // Construct string of selected IDs
230
StringBuffer JavaDoc sbSelectedIDs = new StringBuffer JavaDoc();
231          sbSelectedIDs.append(((DataObject)lstTestData.get(0)).getId());
232          sbSelectedIDs.append(",");
233          sbSelectedIDs.append(((DataObject)lstTestData.get(1)).getId());
234          sbSelectedIDs.append(",");
235          sbSelectedIDs.append(((DataObject)lstTestData.get(2)).getId());
236
237          // Now select items starting beyond the fifth item but still keep the
238
// few selected items
239
options.setEndPosition(iEndPos);
240          options.setKeepSelected(true);
241          options.setSelectedItemIDs(sbSelectedIDs.toString());
242
243          // Retrieve next page expecting that the three selected items will be
244
// selected as well
245
listOpResults = getListController().getNextPage(options);
246          testOptions = (ListOptions)listOpResults[0];
247          lstTestData = (List JavaDoc)listOpResults[1];
248
249          // m_listTestUtils.printDebug(lstTestData);
250
// m_listTestUtils.printDebug(testOptions);
251

252          assertNotNull("Selected data object list is null", lstTestData);
253          assertEquals("ActualListSize is incorrectly set",
254                       arrExpectedData.length,
255                       testOptions.getActualListSize());
256          if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
257             < options.getPageSize())
258          {
259             assertEquals("Number of selected items is incorrect",
260                          (arrExpectedData.length - testOptions.getBeginPosition()
261                             + 1),
262                          lstTestData.size());
263          }
264          else
265          {
266             assertEquals("Number of selected items is incorrect",
267                          options.getPageSize(),
268                          lstTestData.size() - 3);
269          }
270          if (((iEndPos + 1) <= arrExpectedData.length)
271             && (options.getPageSize() < arrExpectedData.length))
272          {
273             assertEquals("BeginPosition is incorrectly set",
274                          (iEndPos + 1),
275                          testOptions.getBeginPosition());
276          }
277          else
278          {
279              if (options.getPageSize() >= arrExpectedData.length)
280              {
281                 assertEquals("BeginPosition is incorrectly set",
282                              1, testOptions.getBeginPosition());
283              }
284              else
285              {
286                 assertEquals("BeginPosition is incorrectly set",
287                              arrExpectedData.length - options.getPageSize() + 1,
288                              testOptions.getBeginPosition());
289              }
290          }
291          assertTrue("EndPosition is incorrectly set",
292                     ((testOptions.getBeginPosition() + options.getPageSize() - 1)
293                        == testOptions.getEndPosition()
294                     || (testOptions.getEndPosition() == arrExpectedData.length)));
295          
296          assertEquals("ActualPage is incorrectly set",
297                       (((testOptions.getBeginPosition() + options.getPageSize() - 2)
298                         / options.getPageSize()) + 1),
299                       testOptions.getActualPage());
300
301          // Test the previously selected items that have to be located at the
302
// first three positions
303
assertEquals("The selected item 1 is incorrect",
304                       arrExpectedData[0],
305                       m_listTestUtils.getColumnOneValue(
306                          (DataObject)lstTestData.get(0)));
307          assertEquals("The selected item 2 is correct",
308                       arrExpectedData[1],
309                       m_listTestUtils.getColumnOneValue(
310                          (DataObject)lstTestData.get(1)));
311          assertEquals("The selected item 3 is not correct",
312                       arrExpectedData[2],
313                       m_listTestUtils.getColumnOneValue(
314                          (DataObject)lstTestData.get(2)));
315          
316          int helpCounter;
317          int assertCounter;
318          for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
319              assertCounter < testOptions.getEndPosition();
320              assertCounter++, helpCounter++)
321          {
322             assertEquals("The retrieved element #" + helpCounter +
323                          " is not correct",
324                          arrExpectedData[assertCounter],
325                          m_listTestUtils.getColumnOneValue(
326                             (DataObject)lstTestData.get(3 + helpCounter)
327                          ));
328             
329          }
330          
331       }
332       catch (Throwable JavaDoc thr)
333       {
334          throw new Exception JavaDoc(thr);
335       }
336       finally
337       {
338          m_listTestUtils.deleteTestData(m_transaction, data);
339       }
340    }
341
342    /**
343     * Test of method getPrevPage
344     *
345     * @throws Exception - an error has occured
346     */

347    public void testGetPrevPage(
348    ) throws Exception JavaDoc
349    {
350       Object JavaDoc[] data = null;
351       
352       try
353       {
354          Object JavaDoc parent;
355          ListOptions options;
356          int iBeginPos = 5;
357          
358          data = m_listTestUtils.insertTestData(m_transaction);
359          parent = data[0];
360          options = m_listTestUtils.getDefaultListOptions(parent);
361          options.setClientOrderCode(1);
362          options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
363          options.setBeginPosition(iBeginPos);
364          
365          Object JavaDoc[] listOpResults = getListController().getPreviousPage(options);
366          ListOptions testOptions = (ListOptions) listOpResults[0];
367          List JavaDoc lstTestData = (List JavaDoc) listOpResults[1];
368          
369          //m_listTestUtils.printDebug(lstTestData);
370
//m_listTestUtils.printDebug(testOptions);
371

372          String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
373          
374          assertNotNull("Selected data object list is null", lstTestData);
375          assertEquals("ActualListSize is incorrectly set",
376                       arrExpectedData.length,
377                       testOptions.getActualListSize());
378          if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
379              < options.getPageSize())
380          {
381             assertEquals("Number of selected items is incorrect",
382                          (arrExpectedData.length - testOptions.getBeginPosition()
383                             + 1),
384                          lstTestData.size());
385          }
386          else
387          {
388             assertEquals("Number of selected items is incorrect",
389                          options.getPageSize(),
390                          lstTestData.size());
391          }
392          
393          if (iBeginPos > options.getPageSize())
394          {
395             assertEquals("EndPosition is incorrectly set",
396                          (iBeginPos - 1),
397                          testOptions.getEndPosition());
398          }
399          else
400          {
401             if (options.getPageSize() < arrExpectedData.length)
402             {
403                assertEquals("EndPosition is incorrectly set",
404                             options.getPageSize(),
405                             testOptions.getEndPosition());
406             }
407             else
408             {
409                assertEquals("EndPosition is incorrectly set",
410                             arrExpectedData.length,
411                             testOptions.getEndPosition());
412             }
413          }
414
415          assertTrue("BeginPosition is incorrectly set",
416                     ((testOptions.getBeginPosition() + options.getPageSize() - 1)
417                        == testOptions.getEndPosition()
418                     || (testOptions.getEndPosition() == arrExpectedData.length)));
419          
420          assertEquals("ActualPage is incorrectly set",
421                       (((testOptions.getBeginPosition() + options.getPageSize() - 2)
422                         / options.getPageSize()) + 1),
423                       testOptions.getActualPage());
424
425          int helpCounter;
426          int assertCounter;
427          for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
428              assertCounter < testOptions.getEndPosition();
429              assertCounter++, helpCounter++)
430          {
431             assertEquals("The retrieved element #" + helpCounter +
432                          " is not correct",
433                          arrExpectedData[assertCounter],
434                          m_listTestUtils.getColumnOneValue(
435                             (DataObject)lstTestData.get(helpCounter)
436                          ));
437             
438          }
439       }
440       catch (Throwable JavaDoc thr)
441       {
442          throw new Exception JavaDoc(thr);
443       }
444       finally
445       {
446          m_listTestUtils.deleteTestData(m_transaction, data);
447       }
448    }
449
450 // TODO: For Julo: This test seems to be incorrect because it doesnt check that
451
// ther eis more than 6 selected items
452
// TODO: For Julo: We should really test here that these items have the
453
// same ids as the ones we have selected above
454
// /**
455
// * Test of method getPrevPage with keeping selected items
456
// *
457
// * @throws Exception - an error has occured
458
// */
459
// public void testGetPrevPageKeepSelected(
460
// ) throws Exception
461
// {
462
// Object[] data = null;
463
//
464
// try
465
// {
466
// Object parent;
467
// ListOptions options;
468
// int iBeginPos = 5;
469
//
470
// data = m_listTestUtils.doInsert(m_transaction);
471
// parent = data[0];
472
// options = m_listTestUtils.getDefaultListOptions(parent);
473
//
474
// // Retrieve page starting with 6th item
475
// options.setBeginPosition(iBeginPos);
476
// options.setClientOrderCode(1);
477
// options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
478
//
479
// Object[] listOpResults = getListController().getNextPage(options);
480
// ListOptions testOptions = (ListOptions) listOpResults[0];
481
// List lstTestData = (List) listOpResults[1];
482
//
483
// assertNotNull("Selected data object list is null", lstTestData);
484
// assertTrue("Test assumption is that the default list option select" +
485
// " at least 10 items.", 10 <= lstTestData.size());
486
//
487
// StringBuffer sbSelectedIDs = new StringBuffer();
488
// // construct string of selected IDs
489
// sbSelectedIDs.append(((DataObject)lstTestData.get(0)).getId());
490
// sbSelectedIDs.append(",");
491
// sbSelectedIDs.append(((DataObject)lstTestData.get(1)).getId());
492
// sbSelectedIDs.append(",");
493
// sbSelectedIDs.append(((DataObject)lstTestData.get(2)).getId());
494
// sbSelectedIDs.append(",");
495
// sbSelectedIDs.append(((DataObject)lstTestData.get(7)).getId());
496
// sbSelectedIDs.append(",");
497
// sbSelectedIDs.append(((DataObject)lstTestData.get(8)).getId());
498
// sbSelectedIDs.append(",");
499
// sbSelectedIDs.append(((DataObject)lstTestData.get(9)).getId());
500
//
501
// // Retrieve previous page with 6 selected items. There should be
502
// // retrieved 1 item from previous page and other 5 items are contained
503
// // in the new selected page.
504
// int iActualPage = 2;
505
// iBeginPos = 5;
506
// options.setActualPage(iActualPage);
507
// options.setBeginPosition(iBeginPos);
508
// options.setClientOrderCode(1);
509
// options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
510
// options.setKeepSelected(true);
511
// options.setSelectedItemIDs(sbSelectedIDs.toString());
512
//
513
// listOpResults = getListController().getPreviousPage(options);
514
// testOptions = (ListOptions) listOpResults[0];
515
// lstTestData = (List) listOpResults[1];
516
//
517
// //m_listTestUtils.printDebug(lstTestData);
518
// //m_listTestUtils.printDebug(testOptions);
519
//
520
// String[] arrExpectedData = m_listTestUtils.getDefaultResultListColumnOne();
521
//
522
// assertNotNull("Selected data object list is null", lstTestData);
523
// assertEquals("ActualListSize is incorrectly set",
524
// arrExpectedData.length,
525
// testOptions.getActualListSize());
526
// if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
527
// < options.getPageSize())
528
// {
529
// assertEquals("Number of selected items is incorrect",
530
// (arrExpectedData.length - testOptions.getBeginPosition() + 1),
531
// lstTestData.size());
532
// }
533
// else
534
// {
535
// assertEquals("Number of selected items is incorrect",
536
// options.getPageSize(),
537
// lstTestData.size() - 1);
538
// }
539
//
540
// if (iBeginPos > options.getPageSize())
541
// {
542
// assertEquals("End position is updated by incorrect number 1",
543
// (iBeginPos - 1),
544
// testOptions.getEndPosition());
545
// }
546
// else
547
// {
548
// if (options.getPageSize() < arrExpectedData.length)
549
// {
550
// assertEquals("End position is updated by incorrect number 2",
551
// options.getPageSize(),
552
// testOptions.getEndPosition());
553
// }
554
// else
555
// {
556
// assertEquals("End position is updated by incorrect number 2",
557
// arrExpectedData.length,
558
// testOptions.getEndPosition());
559
// }
560
// }
561
//
562
// assertTrue("Begin position is updated by incorrect number",
563
// ((testOptions.getBeginPosition() + options.getPageSize() - 1)
564
// == testOptions.getEndPosition()
565
// || (testOptions.getEndPosition() == arrExpectedData.length)));
566
//
567
// assertEquals("Actual page is updated by incorrect number",
568
// (((testOptions.getBeginPosition() + options.getPageSize() - 2)
569
// / options.getPageSize()) + 1),
570
// testOptions.getActualPage());
571
//
572
// // test selected items
573
// assertEquals("The Object List for selected item 1 is not correct",
574
// arrExpectedData[10], m_listTestUtils.getColumnOneValue((DataObject)
575
// lstTestData.get(0)));
576
// assertEquals("The Object List for selected item 2 is not correct",
577
// arrExpectedData[1], m_listTestUtils.getColumnOneValue((DataObject)
578
// lstTestData.get(2)));
579
// assertEquals("The Object List for selected item 3 is not correct",
580
// arrExpectedData[2], m_listTestUtils.getColumnOneValue((DataObject)
581
// lstTestData.get(3)));
582
// assertEquals("The Object List for selected item 4 is not correct",
583
// arrExpectedData[3], m_listTestUtils.getColumnOneValue((DataObject)
584
// lstTestData.get(4)));
585
// assertEquals("The Object List for selected item 5 is not correct",
586
// arrExpectedData[8], m_listTestUtils.getColumnOneValue((DataObject)
587
// lstTestData.get(9)));
588
// assertEquals("The Object List for selected item 6 is not correct",
589
// arrExpectedData[9], m_listTestUtils.getColumnOneValue((DataObject)
590
// lstTestData.get(10)));
591
//
592
// int helpCounter = 0;
593
// for (int assertCounter = (testOptions.getBeginPosition() - 1);
594
// assertCounter < testOptions.getEndPosition();
595
// assertCounter++)
596
// {
597
// assertEquals("The Object List is not correct",
598
// arrExpectedData[assertCounter],
599
// m_listTestUtils.getColumnOneValue((DataObject)
600
// lstTestData.get(1 + helpCounter++)));
601
// }
602
// }
603
// catch (Throwable thr)
604
// {
605
// throw new Exception(thr);
606
// }
607
// finally
608
// {
609
// m_listTestUtils.doDelete(m_connection, m_transaction, data);
610
// }
611
// }
612

613    /**
614     * Test of method getExactPage
615     *
616     * @throws Exception - an error has occured
617     */

618    public void testGetExactPage(
619    ) throws Exception JavaDoc
620    {
621       Object JavaDoc[] data = null;
622       
623       try
624       {
625          Object JavaDoc parent;
626          ListOptions options;
627          int iActualPage = 2;
628          
629          // We test for different page than 1 since 1st page is always loaded
630
data = m_listTestUtils.insertTestData(m_transaction);
631          parent = data[0];
632          options = m_listTestUtils.getDefaultListOptions(parent);
633          options.setClientOrderCode(1);
634          options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
635          options.setActualPage(iActualPage);
636          
637          Object JavaDoc[] listOpResults = getListController().getExactPage(options);
638          ListOptions testOptions = (ListOptions)listOpResults[0];
639          List JavaDoc lstTestData = (List JavaDoc)listOpResults[1];
640          
641          //m_listTestUtils.printDebug(lstTestData);
642
//m_listTestUtils.printDebug(testOptions);
643

644          String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
645          
646          assertNotNull("Selected data object list is null", lstTestData);
647          assertEquals("ActualListSize is incorrectly set",
648                       arrExpectedData.length,
649                       testOptions.getActualListSize());
650          if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
651              < options.getPageSize())
652          {
653             assertEquals("Number of selected items is incorrect",
654                         (arrExpectedData.length - testOptions.getBeginPosition()
655                            + 1),
656                         lstTestData.size());
657          }
658          else
659          {
660             assertEquals("Number of selected items is incorrect",
661                          options.getPageSize(),
662                          lstTestData.size());
663          }
664          
665          if ((iActualPage - 1) * options.getPageSize() < arrExpectedData.length)
666          {
667             assertEquals("BeginPosition is incorrectly set",
668                          ((iActualPage - 1) * options.getPageSize()) + 1,
669                          testOptions.getBeginPosition());
670          }
671          else
672          {
673             assertEquals("BeginPosition is incorrectly set",
674                          ((arrExpectedData.length / options.getPageSize())
675                             * options.getPageSize()) + 1,
676                          testOptions.getBeginPosition());
677          }
678          
679          assertTrue("EndPosition is incorrectly set",
680                     ((testOptions.getBeginPosition() + options.getPageSize() - 1)
681                        == testOptions.getEndPosition()
682                     || (testOptions.getEndPosition() == arrExpectedData.length)));
683          
684          if ((iActualPage - 1) * options.getPageSize() < arrExpectedData.length)
685          {
686             assertEquals("ActualPage is incorrectly set",
687                          iActualPage,
688                          testOptions.getActualPage());
689          }
690          else
691          {
692             assertEquals("ActualPage is incorrectly set",
693                          (((testOptions.getBeginPosition() + options.getPageSize() - 2)
694                             / options.getPageSize()) + 1),
695                          testOptions.getActualPage());
696          }
697
698          int helpCounter;
699          int assertCounter;
700          for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
701               assertCounter < testOptions.getEndPosition();
702               assertCounter++, helpCounter++)
703          {
704             assertEquals("The retrieved element #" + helpCounter +
705                          " is not correct",
706                          arrExpectedData[assertCounter],
707                          m_listTestUtils.getColumnOneValue(
708                             (DataObject)lstTestData.get(helpCounter)
709                          ));
710          }
711       }
712       catch (Throwable JavaDoc thr)
713       {
714          throw new Exception JavaDoc(thr);
715       }
716       finally
717       {
718          m_listTestUtils.deleteTestData(m_transaction, data);
719       }
720    }
721
722    /**
723     * Test of method getExactPage with keeping selected items
724     *
725     * @throws Exception - an error has occured
726     */

727    public void testGetExactPageKeepSelected(
728    ) throws Exception JavaDoc
729    {
730       Object JavaDoc[] data = null;
731       
732       try
733       {
734          Object JavaDoc parent;
735          ListOptions options;
736          int iActualPage = 2;
737          
738          // We test for different page than 1 since 1st page is always loaded
739
data = m_listTestUtils.insertTestData(m_transaction);
740          parent = data[0];
741          options = m_listTestUtils.getDefaultListOptions(parent);
742          options.setClientOrderCode(1);
743          options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
744          options.setActualPage(iActualPage);
745          
746          Object JavaDoc[] listOpResults = getListController().getExactPage(options);
747          ListOptions testOptions = (ListOptions)listOpResults[0];
748          List JavaDoc lstTestData = (List JavaDoc)listOpResults[1];
749
750          assertNotNull("Selected data object list is null", lstTestData);
751          assertTrue("Test assumption is that the default list option select" +
752                     " at least 10 items.", 10 <= lstTestData.size());
753          
754          StringBuffer JavaDoc sbSelectedIDs = new StringBuffer JavaDoc();
755          // construct string of selected IDs
756
sbSelectedIDs.append(((DataObject)lstTestData.get(0)).getId());
757          sbSelectedIDs.append(",");
758          sbSelectedIDs.append(((DataObject)lstTestData.get(1)).getId());
759          sbSelectedIDs.append(",");
760          sbSelectedIDs.append(((DataObject)lstTestData.get(2)).getId());
761          sbSelectedIDs.append(",");
762          sbSelectedIDs.append(((DataObject)lstTestData.get(7)).getId());
763          sbSelectedIDs.append(",");
764          sbSelectedIDs.append(((DataObject)lstTestData.get(8)).getId());
765          sbSelectedIDs.append(",");
766          sbSelectedIDs.append(((DataObject)lstTestData.get(9)).getId());
767
768          // Retrieve exact page with selected 6 items. There should be retrieved
769
// 3 item from previous page and other 3 items are contained in the new
770
// selected page.
771

772          // TODO: For Julo: Here is an assumption that the previous page size
773
// contains three of the above items, but we never set the page size
774
// above. This may not work on all page sizes.
775

776          int iPageSize = 15;
777          iActualPage = 1;
778          options.setActualPage(iActualPage);
779          options.setPageSize(iPageSize);
780          options.setClientOrderCode(1);
781          options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
782          options.setKeepSelected(true);
783          options.setSelectedItemIDs(sbSelectedIDs.toString());
784
785          listOpResults = getListController().getPreviousPage(options);
786          testOptions = (ListOptions) listOpResults[0];
787          lstTestData = (List JavaDoc) listOpResults[1];
788
789          //m_listTestUtils.printDebug(lstTestData);
790
//m_listTestUtils.printDebug(testOptions);
791

792          String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
793          
794          assertNotNull("Selected data object list is null", lstTestData);
795          assertEquals("ActualListSize is incorrectly set",
796                       arrExpectedData.length,
797                       testOptions.getActualListSize());
798          if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
799              < options.getPageSize())
800          {
801             assertEquals("Number of selected items is incorrect",
802                         (arrExpectedData.length - testOptions.getBeginPosition() + 1),
803                         lstTestData.size());
804          }
805          else
806          {
807             assertEquals("Number of selected items is incorrect",
808                         options.getPageSize(),
809                         lstTestData.size() - 3);
810          }
811          
812          if ((iActualPage - 1) * options.getPageSize() < arrExpectedData.length)
813          {
814             assertEquals("BeginPosition is incorrectly set",
815                          ((iActualPage - 1) * options.getPageSize()) + 1,
816                          testOptions.getBeginPosition());
817          }
818          else
819          {
820             assertEquals("BeginPosition is incorrectly set",
821                          ((arrExpectedData.length / options.getPageSize())
822                             * options.getPageSize()) + 1,
823                          testOptions.getBeginPosition());
824          }
825          
826          assertTrue("EndPosition is incorrectly set",
827                     ((testOptions.getBeginPosition() + options.getPageSize() - 1)
828                        == testOptions.getEndPosition()
829                     || (testOptions.getEndPosition() == arrExpectedData.length)));
830          
831          if ((iActualPage - 1) * options.getPageSize() < arrExpectedData.length)
832          {
833             assertEquals("ActualPage is incorrectly set",
834                          iActualPage,
835                          testOptions.getActualPage());
836          }
837          else
838          {
839             assertEquals("ActualPage is incorrectly set",
840                          (((testOptions.getBeginPosition() + options.getPageSize() - 2)
841                            / options.getPageSize()) + 1),
842                          testOptions.getActualPage());
843          }
844
845          // TODO: For Julo: This test just doesn't make sense. Where to the
846
// indexes of the items come from?
847
// TODO: For Julo: We should really test here that these items have the
848
// same ids as the ones we have selected above
849
assertEquals("The Object List for selected item 1 is not correct",
850                         arrExpectedData[17], m_listTestUtils.getColumnOneValue((DataObject)
851                            lstTestData.get(0)));
852          assertEquals("The Object List for selected item 2 is not correct",
853                         arrExpectedData[18], m_listTestUtils.getColumnOneValue((DataObject)
854                            lstTestData.get(1)));
855          assertEquals("The Object List for selected item 3 is not correct",
856                         arrExpectedData[19], m_listTestUtils.getColumnOneValue((DataObject)
857                            lstTestData.get(2)));
858          assertEquals("The Object List for selected item 4 is not correct",
859                         arrExpectedData[10], m_listTestUtils.getColumnOneValue((DataObject)
860                            lstTestData.get(13)));
861          assertEquals("The Object List for selected item 5 is not correct",
862                         arrExpectedData[11], m_listTestUtils.getColumnOneValue((DataObject)
863                            lstTestData.get(14)));
864          assertEquals("The Object List for selected item 6 is not correct",
865                         arrExpectedData[12], m_listTestUtils.getColumnOneValue((DataObject)
866                            lstTestData.get(15)));
867          
868          int helpCounter;
869          int assertCounter;
870          for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
871               assertCounter < testOptions.getEndPosition();
872               assertCounter++, helpCounter++)
873          {
874             assertEquals("The retrieved element #" + helpCounter +
875                          " is not correct",
876                          arrExpectedData[assertCounter],
877                          m_listTestUtils.getColumnOneValue(
878                             (DataObject)lstTestData.get(helpCounter + 3)
879                          ));
880             
881          }
882       }
883       catch (Throwable JavaDoc thr)
884       {
885          throw new Exception JavaDoc(thr);
886       }
887       finally
888       {
889          m_listTestUtils.deleteTestData(m_transaction, data);
890       }
891    }
892
893    /**
894     * Test of method getSetFilter
895     *
896     * @throws Exception - an error has occured
897     */

898    public void testGetSetFilter(
899    ) throws Exception JavaDoc
900    {
901       Object JavaDoc[] data = null;
902       
903       try
904       {
905          Object JavaDoc parent;
906          ListOptions options;
907          
908          data = m_listTestUtils.insertTestData(m_transaction);
909          parent = data[0];
910          options = m_listTestUtils.getDefaultListOptions(parent);
911          // TODO: For Julo: This methods really doesn't test anything
912
// we should have some different options, for example
913
// change ordering from asc to desc or change page size of somethign else
914
// and then use the modified options
915
// actually what we should do is retrieve the result for original options
916
// and then result for the modified options and test that they changes in
917
// predictable way (e.g. first was asc and second the elements are desc)
918
options.setDefinitionId(options.getDefinitionId());
919
920          Object JavaDoc[] listOpResults = getListController().getSetDefinition(options);
921          ListOptions testOptions = (ListOptions) listOpResults[0];
922          List JavaDoc lstTestData = (List JavaDoc) listOpResults[1];
923          
924          String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
925
926          assertNotNull("Selected data object list is null", lstTestData);
927          assertEquals("ActualListSize is incorrectly set",
928                       arrExpectedData.length,
929                       testOptions.getActualListSize());
930
931          assertEquals("BeginPosition should be set to 1",
932                       1, testOptions.getBeginPosition());
933
934          assertTrue("EndPosition should be set to PageSize or total number of items",
935                     (testOptions.getPageSize() == testOptions.getEndPosition())
936                     || (arrExpectedData.length == testOptions.getEndPosition()));
937
938          assertEquals("ActualPage should be set to 1",
939                       1, testOptions.getActualPage());
940
941          if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
942              < options.getPageSize())
943          {
944             assertEquals("Number of selected items is incorrect",
945                          (arrExpectedData.length - testOptions.getBeginPosition()
946                             + 1),
947                          lstTestData.size());
948          }
949          else
950          {
951             assertEquals("Number of selected items is incorrect",
952                          options.getPageSize(),
953                          lstTestData.size());
954          }
955
956          int helpCounter;
957          int assertCounter;
958          for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
959               assertCounter < testOptions.getEndPosition();
960               assertCounter++, helpCounter++)
961          {
962             assertEquals("The retrieved element #" + helpCounter +
963                          " is not correct",
964                          arrExpectedData[assertCounter],
965                          m_listTestUtils.getColumnOneValue(
966                             (DataObject)lstTestData.get(helpCounter)
967                          ));
968             
969          }
970       }
971       catch (Throwable JavaDoc thr)
972       {
973          throw new Exception JavaDoc(thr);
974       }
975       finally
976       {
977          m_listTestUtils.deleteTestData(m_transaction, data);
978       }
979    }
980
981    // TODO: Missing test for testGetSetFilter with keep seleted if that is possible
982

983    /**
984     * Test of method getOrder - descending order
985     *
986     * @throws Exception - an error has occured
987     */

988    public void testGetOrderDesc(
989    ) throws Exception JavaDoc
990    {
991       Object JavaDoc[] data = null;
992       
993       try
994       {
995          Object JavaDoc parent;
996          ListOptions options;
997          int iOrderCode = m_listTestUtils.getColumnOneCode();
998          // TODO: For Julo: We may want to split this into two tests, one for
999
// column 1 and the other for column 2
1000
//int iOrderCode = m_listTestUtils.getColumnTwoCode();
1001

1002         data = m_listTestUtils.insertTestData(m_transaction);
1003         parent = data[0];
1004         options = m_listTestUtils.getDefaultListOptions(parent);
1005         options.setOrdering(new int[] {iOrderCode},
1006                                  ListDefinition.ORDER_DESCENDING_ARRAY);
1007         
1008         Object JavaDoc[] listOpResults = getListController().getSetOrder(options);
1009         ListOptions testOptions = (ListOptions)listOpResults[0];
1010         List JavaDoc lstTestData = (List JavaDoc)listOpResults[1];
1011         
1012         //m_listTestUtils.printDebug(lstTestData);
1013
//m_listTestUtils.printDebug(testOptions);
1014

1015         String JavaDoc[] arrExpectedData = null;
1016         if (iOrderCode == m_listTestUtils.getColumnOneCode())
1017         {
1018            arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
1019         }
1020         else
1021         {
1022            arrExpectedData = m_listTestUtils.getDefaultResultListColumnTwo();
1023         }
1024        
1025         assertEquals("ActualListSize is incorrectly set",
1026                      arrExpectedData.length,
1027                      testOptions.getActualListSize());
1028
1029         assertTrue("OrderCode is incorrectly set",
1030                    Arrays.equals(new int[] {iOrderCode},
1031                                  testOptions.getOrderColumnCodes()));
1032
1033         assertTrue("OrderDirection is incorrectly set",
1034                    Arrays.equals(ListDefinition.ORDER_DESCENDING_ARRAY,
1035                                  testOptions.getOrderDirections()));
1036
1037         assertEquals("ClientOrderCode is incorrectly set",
1038                      iOrderCode, testOptions.getClientOrderCode());
1039
1040         assertEquals("ClientOrderDirection is incorrectly set",
1041                      ListDefinition.ORDER_DESCENDING,
1042                      testOptions.getClientOrderDirection());
1043
1044         assertEquals("ActualPage is incorrectly set",
1045                      1, testOptions.getActualPage());
1046
1047         assertEquals("BeginPosition is incorrectly set",
1048                      1, testOptions.getBeginPosition());
1049
1050         if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
1051             < options.getPageSize())
1052         {
1053            assertEquals("Number of selected items is incorrect",
1054                         (arrExpectedData.length - testOptions.getBeginPosition()
1055                            + 1),
1056                         lstTestData.size());
1057         }
1058         else
1059         {
1060            assertEquals("Number of selected items is incorrect",
1061                         options.getPageSize(),
1062                         lstTestData.size());
1063         }
1064        
1065         assertTrue("EndPosition is incorrectly set",
1066                    ((testOptions.getBeginPosition() + options.getPageSize() - 1)
1067                       == testOptions.getEndPosition()
1068                    || (testOptions.getEndPosition() == arrExpectedData.length)));
1069         
1070         // int oneC = m_listTestUtils.getColumnOneCode();
1071
// int twoC = m_listTestUtils.getColumnTwoCode();
1072

1073         int helpCounter;
1074         int assertCounter;
1075         // Descending test
1076
for (assertCounter = arrExpectedData.length - 1, helpCounter = 0;
1077              (assertCounter > (arrExpectedData.length - options.getPageSize())
1078                 && (assertCounter > 0));
1079              assertCounter--, helpCounter++)
1080         {
1081            if (iOrderCode == m_listTestUtils.getColumnOneCode())
1082            {
1083               
1084               assertEquals("The retrieved element #" + helpCounter +
1085                            " is not correct",
1086                            arrExpectedData[assertCounter],
1087                            m_listTestUtils.getColumnOneValue(
1088                               (DataObject)lstTestData.get(helpCounter)
1089                            ));
1090            }
1091            else if (iOrderCode == m_listTestUtils.getColumnTwoCode())
1092            {
1093               assertEquals("The retrieved element #" + helpCounter +
1094                            " is not correct",
1095                            arrExpectedData[assertCounter],
1096                            m_listTestUtils.getColumnTwoValue(
1097                               (DataObject)lstTestData.get(helpCounter)
1098                            ));
1099            }
1100         }
1101      }
1102      catch (Throwable JavaDoc thr)
1103      {
1104         throw new Exception JavaDoc(thr);
1105      }
1106      finally
1107      {
1108         m_listTestUtils.deleteTestData(m_transaction, data);
1109      }
1110   }
1111
1112   /**
1113    * Test of method getOrder - descending order keeping selected items
1114    *
1115    * @throws Exception - an error has occured
1116    */

1117   public void testGetOrderDescKeepSelected(
1118   ) throws Exception JavaDoc
1119   {
1120      Object JavaDoc[] data = null;
1121      
1122      try
1123      {
1124         Object JavaDoc parent;
1125         ListOptions options;
1126         int iOrderCode = m_listTestUtils.getColumnOneCode();
1127         // TODO: For Julo: We may want to split this into two tests, one for
1128
// column 1 and the other for column 2
1129
//int iOrderCode = m_listTestUtils.getColumnTwoCode();
1130

1131         // First retrieve some data in ascending order so that we can select
1132
// them
1133
data = m_listTestUtils.insertTestData(m_transaction);
1134         parent = data[0];
1135         options = m_listTestUtils.getDefaultListOptions(parent);
1136         options.setOrdering(new int[] {iOrderCode},
1137                                  ListDefinition.ORDER_ASCENDING_ARRAY);
1138         
1139         Object JavaDoc[] listOpResults = getListController().getSetOrder(options);
1140         ListOptions testOptions = (ListOptions) listOpResults[0];
1141         List JavaDoc lstTestData = (List JavaDoc) listOpResults[1];
1142
1143         assertNotNull("Selected data object list is null", lstTestData);
1144         assertTrue("Test assumption is that the default list option select" +
1145                    " at least 3 items.", 3 <= lstTestData.size());
1146         
1147         StringBuffer JavaDoc sbSelectedIDs = new StringBuffer JavaDoc();
1148         // construct string of selected IDs
1149
sbSelectedIDs.append(((DataObject)lstTestData.get(0)).getId());
1150         sbSelectedIDs.append(",");
1151         sbSelectedIDs.append(((DataObject)lstTestData.get(1)).getId());
1152         sbSelectedIDs.append(",");
1153         sbSelectedIDs.append(((DataObject)lstTestData.get(2)).getId());
1154
1155         // Retrieve the list in reverse order together with the 3 selected
1156
// items.
1157
options.setOrdering(new int[] {iOrderCode},
1158                                  ListDefinition.ORDER_DESCENDING_ARRAY);
1159         options.setKeepSelected(true);
1160         options.setSelectedItemIDs(sbSelectedIDs.toString());
1161         listOpResults = getListController().getSetOrder(options);
1162         testOptions = (ListOptions) listOpResults[0];
1163         lstTestData = (List JavaDoc) listOpResults[1];
1164
1165         //m_listTestUtils.printDebug(lstTestData);
1166
//m_listTestUtils.printDebug(testOptions);
1167

1168         String JavaDoc[] arrExpectedData = null;
1169         if (iOrderCode == m_listTestUtils.getColumnOneCode())
1170         {
1171            arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
1172         }
1173         else
1174         {
1175            arrExpectedData = m_listTestUtils.getDefaultResultListColumnTwo();
1176         }
1177        
1178         assertEquals("ActualListSize is incorrectly set",
1179                      arrExpectedData.length,
1180                      testOptions.getActualListSize());
1181
1182         assertTrue("OrderCode is incorrectly set",
1183                    Arrays.equals(new int[] {iOrderCode},
1184                                  testOptions.getOrderColumnCodes()));
1185
1186         assertTrue("OrderDirection is incorrectly set",
1187                    Arrays.equals(ListDefinition.ORDER_DESCENDING_ARRAY,
1188                                  testOptions.getOrderDirections()));
1189
1190         assertEquals("ClientOrderCode is incorrectly set",
1191                      iOrderCode, testOptions.getClientOrderCode());
1192
1193         assertEquals("ClientOrderDirection is incorrectly set",
1194                      ListDefinition.ORDER_DESCENDING,
1195                      testOptions.getClientOrderDirection());
1196
1197         assertEquals("ActualPage is incorrectly set",
1198                      1, testOptions.getActualPage());
1199
1200         assertEquals("BeginPosition is incorrectly set",
1201                      1, testOptions.getBeginPosition());
1202
1203         if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
1204             < options.getPageSize())
1205         {
1206            assertEquals("Number of selected items is incorrect",
1207                        (arrExpectedData.length - testOptions.getBeginPosition() + 1),
1208                        lstTestData.size());
1209         }
1210         else
1211         {
1212            assertEquals("Number of selected items is incorrect",
1213                        options.getPageSize(),
1214                        lstTestData.size() - 3);
1215         }
1216        
1217         assertTrue("EndPosition is incorrectly set",
1218                    ((testOptions.getBeginPosition() + options.getPageSize() - 1)
1219                       == testOptions.getEndPosition()
1220                    || (testOptions.getEndPosition() == arrExpectedData.length)));
1221         
1222         // int oneC = m_listTestUtils.getColumnOneCode();
1223
// int twoC = m_listTestUtils.getColumnTwoCode();
1224

1225         // TODO: For Julo: We should really test here that these items have the
1226
// same ids as the ones we have selected above
1227
// test selected items
1228
assertEquals("The Object List for selected item 1 is not correct",
1229                        arrExpectedData[2], m_listTestUtils.getColumnOneValue((DataObject)
1230                           lstTestData.get(0)));
1231         assertEquals("The Object List for selected item 2 is not correct",
1232                        arrExpectedData[1], m_listTestUtils.getColumnOneValue((DataObject)
1233                           lstTestData.get(1)));
1234         assertEquals("The Object List for selected item 3 is not correct",
1235                        arrExpectedData[0], m_listTestUtils.getColumnOneValue((DataObject)
1236                           lstTestData.get(2)));
1237
1238         int helpCounter;
1239         int assertCounter;
1240         // Descending test
1241
for (assertCounter = arrExpectedData.length - 1, helpCounter = 0;
1242              (assertCounter > (arrExpectedData.length - options.getPageSize())
1243                 && (assertCounter > 0));
1244              assertCounter--, helpCounter++)
1245         {
1246            if (iOrderCode == m_listTestUtils.getColumnOneCode())
1247            {
1248               assertEquals("The retrieved element #" + (3 + helpCounter) +
1249                            " is not correct",
1250                            arrExpectedData[assertCounter],
1251                            m_listTestUtils.getColumnOneValue(
1252                               (DataObject)lstTestData.get(3 + helpCounter)
1253                            ));
1254            }
1255            else if (iOrderCode == m_listTestUtils.getColumnTwoCode())
1256            {
1257               assertEquals("The retrieved element #" + (3 + helpCounter) +
1258                            " is not correct",
1259                            arrExpectedData[assertCounter],
1260                            m_listTestUtils.getColumnTwoValue(
1261                               (DataObject)lstTestData.get(3 + helpCounter)
1262                            ));
1263            }
1264         }
1265      }
1266      catch (Throwable JavaDoc thr)
1267      {
1268         throw new Exception JavaDoc(thr);
1269      }
1270      finally
1271      {
1272         m_listTestUtils.deleteTestData(m_transaction, data);
1273      }
1274   }
1275
1276   /**
1277    * Test of method getOrder - ascending order
1278    *
1279    * @throws Exception - an error has occured
1280    */

1281   public void testGetOrderAsc(
1282   ) throws Exception JavaDoc
1283   {
1284      Object JavaDoc[] data = null;
1285      
1286      try
1287      {
1288         Object JavaDoc parent;
1289         ListOptions options;
1290         int iOrderCode = m_listTestUtils.getColumnOneCode();
1291         // TODO: For Julo: We may want to split this into two tests, one for
1292
// column 1 and the other for column 2
1293
//int iOrderCode = m_listTestUtils.getColumnTwoCode();
1294

1295         data = m_listTestUtils.insertTestData(m_transaction);
1296         parent = data[0];
1297         options = m_listTestUtils.getDefaultListOptions(parent);
1298         options.setOrdering(new int[] {iOrderCode},
1299                                  ListDefinition.ORDER_ASCENDING_ARRAY);
1300         
1301         Object JavaDoc[] listOpResults = getListController().getSetOrder(options);
1302         ListOptions testOptions = (ListOptions)listOpResults[0];
1303         List JavaDoc lstTestData = (List JavaDoc)listOpResults[1];
1304         
1305         //m_listTestUtils.printDebug(lstTestData);
1306
//m_listTestUtils.printDebug(testOptions);
1307

1308         String JavaDoc[] arrExpectedData = null;
1309         if (iOrderCode == m_listTestUtils.getColumnOneCode())
1310         {
1311            arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
1312         }
1313         else
1314         {
1315            arrExpectedData = m_listTestUtils.getDefaultResultListColumnTwo();
1316         }
1317        
1318         assertEquals("ActualListSize is incorrectly set",
1319                      arrExpectedData.length,
1320                      testOptions.getActualListSize());
1321
1322         assertTrue("OrderCode is incorrectly set",
1323                    Arrays.equals(new int[] {iOrderCode},
1324                                  testOptions.getOrderColumnCodes()));
1325
1326         assertTrue("OrderDirection is incorrectly set",
1327                    Arrays.equals(ListDefinition.ORDER_ASCENDING_ARRAY,
1328                                  testOptions.getOrderDirections()));
1329
1330         assertEquals("ClientOrderCode is incorrectly set",
1331                      iOrderCode, testOptions.getClientOrderCode());
1332
1333         assertEquals("ClientOrderDirection is incorrectly set",
1334                      ListDefinition.ORDER_ASCENDING,
1335                      testOptions.getClientOrderDirection());
1336
1337         assertEquals("ActualPage is incorrectly set",
1338                      1, testOptions.getActualPage());
1339
1340         assertEquals("BeginPosition is incorrectly set",
1341                      1, testOptions.getBeginPosition());
1342
1343         if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
1344             < options.getPageSize())
1345         {
1346            assertEquals("Number of selected items is incorrect",
1347                        (arrExpectedData.length - testOptions.getBeginPosition()
1348                           + 1),
1349                        lstTestData.size());
1350         }
1351         else
1352         {
1353            assertEquals("Number of selected items is incorrect",
1354                         options.getPageSize(),
1355                         lstTestData.size());
1356         }
1357        
1358         assertTrue("EndPosition is incorrectly set",
1359                   ((testOptions.getBeginPosition() + options.getPageSize() - 1)
1360                      == testOptions.getEndPosition()
1361                   || (testOptions.getEndPosition() == arrExpectedData.length)));
1362         
1363         // int oneC = m_listTestUtils.getColumnOneCode();
1364
// int twoC = m_listTestUtils.getColumnTwoCode();
1365

1366         int helpCounter;
1367         int assertCounter;
1368         // Ascending test
1369
for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
1370             assertCounter < testOptions.getEndPosition();
1371             assertCounter++, helpCounter++)
1372         {
1373            if (iOrderCode == m_listTestUtils.getColumnOneCode())
1374            {
1375               assertEquals("The retrieved element #" + helpCounter +
1376                            " is not correct",
1377                            arrExpectedData[assertCounter],
1378                            m_listTestUtils.getColumnOneValue(
1379                               (DataObject)lstTestData.get(helpCounter)
1380                            ));
1381            }
1382            else if (iOrderCode == m_listTestUtils.getColumnTwoCode())
1383            {
1384               assertEquals("The retrieved element #" + helpCounter +
1385                            " is not correct",
1386                            arrExpectedData[assertCounter],
1387                            m_listTestUtils.getColumnTwoValue(
1388                               (DataObject)lstTestData.get(helpCounter)
1389                            ));
1390            }
1391         }
1392      }
1393      catch (Throwable JavaDoc thr)
1394      {
1395         throw new Exception JavaDoc(thr);
1396      }
1397      finally
1398      {
1399         m_listTestUtils.deleteTestData(m_transaction, data);
1400      }
1401   }
1402
1403   /**
1404    * Test of method getOrder - ascending order keeping selected items
1405    *
1406    * @throws Exception - an error has occured
1407    */

1408   public void testGetOrderAscKeepSelected(
1409   ) throws Exception JavaDoc
1410   {
1411      Object JavaDoc[] data = null;
1412      
1413      try
1414      {
1415         Object JavaDoc parent;
1416         ListOptions options;
1417         int iOrderCode = m_listTestUtils.getColumnOneCode();
1418         // TODO: For Julo: We may want to split this into two tests, one for
1419
// column 1 and the other for column 2
1420
//int iOrderCode = m_listTestUtils.getColumnTwoCode();
1421

1422         // First retrieve some data in descending order so that we can select
1423
// them
1424
data = m_listTestUtils.insertTestData(m_transaction);
1425         parent = data[0];
1426         options = m_listTestUtils.getDefaultListOptions(parent);
1427         options.setOrdering(new int[] {iOrderCode},
1428                                  ListDefinition.ORDER_DESCENDING_ARRAY);
1429         
1430         Object JavaDoc[] listOpResults = getListController().getSetOrder(options);
1431         ListOptions testOptions = (ListOptions)listOpResults[0];
1432         List JavaDoc lstTestData = (List JavaDoc)listOpResults[1];
1433
1434         assertNotNull("Selected data object list is null", lstTestData);
1435         assertTrue("Test assumption is that the default list option select" +
1436                    " at least 3 items.", 3 <= lstTestData.size());
1437         
1438         StringBuffer JavaDoc sbSelectedIDs = new StringBuffer JavaDoc();
1439         // construct string of selected IDs
1440
sbSelectedIDs.append(((DataObject)lstTestData.get(0)).getId());
1441         sbSelectedIDs.append(",");
1442         sbSelectedIDs.append(((DataObject)lstTestData.get(1)).getId());
1443         sbSelectedIDs.append(",");
1444         sbSelectedIDs.append(((DataObject)lstTestData.get(2)).getId());
1445
1446         // Retrieve the list in reverse order together with the 3 selected
1447
// items.
1448
options.setOrdering(new int[] {iOrderCode},
1449                                  ListDefinition.ORDER_ASCENDING_ARRAY);
1450         options.setKeepSelected(true);
1451         options.setSelectedItemIDs(sbSelectedIDs.toString());
1452         listOpResults = getListController().getSetOrder(options);
1453         testOptions = (ListOptions)listOpResults[0];
1454         lstTestData = (List JavaDoc)listOpResults[1];
1455
1456         //m_listTestUtils.printDebug(lstTestData);
1457
//m_listTestUtils.printDebug(testOptions);
1458

1459         String JavaDoc[] arrExpectedData = null;
1460         if (iOrderCode == m_listTestUtils.getColumnOneCode())
1461         {
1462            arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
1463         }
1464         else
1465         {
1466            arrExpectedData = m_listTestUtils.getDefaultResultListColumnTwo();
1467         }
1468        
1469         assertEquals("ActualListSize is incorrectly set",
1470                      arrExpectedData.length,
1471                      testOptions.getActualListSize());
1472
1473         assertTrue("OrderCode is incorrectly set",
1474                    Arrays.equals(new int[] {iOrderCode},
1475                                  testOptions.getOrderColumnCodes()));
1476
1477         assertTrue("OrderDirection is incorrectly set",
1478                    Arrays.equals(ListDefinition.ORDER_ASCENDING_ARRAY,
1479                                  testOptions.getOrderDirections()));
1480
1481         assertEquals("ClientOrderCode is incorrectly set",
1482                      iOrderCode, testOptions.getClientOrderCode());
1483
1484         assertEquals("ClientOrderDirection is incorrectly set",
1485                      ListDefinition.ORDER_ASCENDING,
1486                      testOptions.getClientOrderDirection());
1487
1488         assertEquals("ActualPage is incorrectly set",
1489                      1, testOptions.getActualPage());
1490
1491         assertEquals("BeginPosition is incorrectly set",
1492                      1, testOptions.getBeginPosition());
1493
1494         if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
1495             < options.getPageSize())
1496         {
1497            assertEquals("Number of selected items is incorrect",
1498                         (arrExpectedData.length - testOptions.getBeginPosition() + 1),
1499                         lstTestData.size());
1500         }
1501         else
1502         {
1503            assertEquals("Number of selected items is incorrect",
1504                         options.getPageSize(),
1505                         lstTestData.size() - 3);
1506         }
1507        
1508         assertTrue("EndPosition is incorrectly set",
1509                    ((testOptions.getBeginPosition() + options.getPageSize() - 1)
1510                       == testOptions.getEndPosition()
1511                    || (testOptions.getEndPosition() == arrExpectedData.length)));
1512         
1513         // int oneC = m_listTestUtils.getColumnOneCode();
1514
// int twoC = m_listTestUtils.getColumnTwoCode();
1515

1516         // TODO: For Julo: We should really test here that these items have the
1517
// same ids as the ones we have selected above
1518
// test selected items
1519
assertEquals("The Object List for selected item 1 is not correct",
1520                        arrExpectedData[22], m_listTestUtils.getColumnOneValue((DataObject)
1521                           lstTestData.get(0)));
1522         assertEquals("The Object List for selected item 2 is not correct",
1523                        arrExpectedData[23], m_listTestUtils.getColumnOneValue((DataObject)
1524                           lstTestData.get(1)));
1525         assertEquals("The Object List for selected item 3 is not correct",
1526                        arrExpectedData[24], m_listTestUtils.getColumnOneValue((DataObject)
1527                           lstTestData.get(2)));
1528
1529         int helpCounter;
1530         int assertCounter;
1531         // Ascending test
1532
for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
1533             assertCounter < testOptions.getEndPosition();
1534             assertCounter++, helpCounter++)
1535         {
1536            if (iOrderCode == m_listTestUtils.getColumnOneCode())
1537            {
1538               assertEquals("The retrieved element #" + (3 + helpCounter) +
1539                            " is not correct",
1540                            arrExpectedData[assertCounter],
1541                            m_listTestUtils.getColumnOneValue(
1542                               (DataObject)lstTestData.get(3 + helpCounter)
1543                            ));
1544            }
1545            else if (iOrderCode == m_listTestUtils.getColumnTwoCode())
1546            {
1547               assertEquals("The retrieved element #" + (3 + helpCounter) +
1548                            " is not correct",
1549                            arrExpectedData[assertCounter],
1550                            m_listTestUtils.getColumnTwoValue(
1551                               (DataObject)lstTestData.get(3 + helpCounter)
1552                            ));
1553            }
1554         }
1555      }
1556      catch (Throwable JavaDoc thr)
1557      {
1558         throw new Exception JavaDoc(thr);
1559      }
1560      finally
1561      {
1562         m_listTestUtils.deleteTestData(m_transaction, data);
1563      }
1564   }
1565
1566   /**
1567    * Test of method getSetPageSize
1568    *
1569    * @throws Exception - an error has occured
1570    */

1571   public void testGetSetPageSize(
1572   ) throws Exception JavaDoc
1573   {
1574      Object JavaDoc[] data = null;
1575      
1576      try
1577      {
1578         Object JavaDoc parent;
1579         ListOptions options;
1580         int iPageSize = 5;
1581         int iBeginPos = 10;
1582         
1583         data = m_listTestUtils.insertTestData(m_transaction);
1584         parent = data[0];
1585         options = m_listTestUtils.getDefaultListOptions(parent);
1586         options.setClientOrderCode(0);
1587         options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
1588         options.setPageSize(iPageSize);
1589         options.setBeginPosition(iBeginPos);
1590         
1591         Object JavaDoc[] listOpResults = getListController().getSetPageSize(options);
1592         ListOptions testOptions = (ListOptions)listOpResults[0];
1593         List JavaDoc lstTestData = (List JavaDoc)listOpResults[1];
1594         
1595         //m_listTestUtils.printDebug(lstTestData);
1596
//m_listTestUtils.printDebug(testOptions);
1597

1598         String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
1599          
1600         assertNotNull("Selected data object list is null", lstTestData);
1601         assertEquals("ActualListSize is incorrectly set",
1602                      arrExpectedData.length,
1603                      testOptions.getActualListSize());
1604         
1605          assertEquals("First visible item is incorrectly set",
1606                       options.getFirstVisibleItem(),
1607                       testOptions.getFirstVisibleItem());
1608          
1609          if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
1610              < options.getPageSize())
1611          {
1612             assertEquals("Number of selected items is incorrect",
1613                         (arrExpectedData.length - testOptions.getBeginPosition()
1614                            + 1),
1615                         lstTestData.size());
1616          }
1617          else
1618          {
1619             assertEquals("Number of selected items is incorrect",
1620                          options.getPageSize(),
1621                          lstTestData.size());
1622          }
1623         
1624          // TODO: For Julo: Missing test for begin position
1625

1626          assertTrue("EndPosition is incorrectly set",
1627                     ((testOptions.getBeginPosition() + options.getPageSize() - 1)
1628                        == testOptions.getEndPosition()
1629                     || (testOptions.getEndPosition()
1630                         == arrExpectedData.length)));
1631         
1632          if ((options.getActualPage() - 1) * options.getPageSize()
1633              < arrExpectedData.length)
1634          {
1635             assertEquals("ActualPage is incorrectly set",
1636                          options.getActualPage(),
1637                          testOptions.getActualPage());
1638          }
1639          else
1640          {
1641             assertEquals("ActualPage is incorrectly set",
1642                          (((testOptions.getBeginPosition() + options.getPageSize() - 2)
1643                             / options.getPageSize()) + 1),
1644                          testOptions.getActualPage());
1645          }
1646
1647          int helpCounter;
1648          int assertCounter;
1649          for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
1650              assertCounter < testOptions.getEndPosition();
1651              assertCounter++, helpCounter++)
1652          {
1653             assertEquals("The retrieved element #" + helpCounter +
1654                          " is not correct",
1655                          arrExpectedData[assertCounter],
1656                          m_listTestUtils.getColumnOneValue(
1657                             (DataObject)lstTestData.get(helpCounter)
1658                          ));
1659          }
1660      }
1661      catch (Throwable JavaDoc thr)
1662      {
1663         throw new Exception JavaDoc(thr);
1664      }
1665      finally
1666      {
1667         m_listTestUtils.deleteTestData(m_transaction, data);
1668      }
1669   }
1670   
1671   /**
1672    * Test of method getSetPageSize keeping selected items
1673    *
1674    * @throws Exception - an error has occured
1675    */

1676   public void testGetSetPageSizeKeepSelected(
1677   ) throws Exception JavaDoc
1678   {
1679      Object JavaDoc[] data = null;
1680      
1681      try
1682      {
1683         Object JavaDoc parent;
1684         ListOptions options;
1685         int iPageSize = 15;
1686         int iBeginPos = 1;
1687         
1688         data = m_listTestUtils.insertTestData(m_transaction);
1689         parent = data[0];
1690         options = m_listTestUtils.getDefaultListOptions(parent);
1691         options.setClientOrderCode(0);
1692         options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
1693         options.setPageSize(iPageSize);
1694         options.setBeginPosition(iBeginPos);
1695         
1696         Object JavaDoc[] listOpResults = getListController().getExactPage(options);
1697         ListOptions testOptions = (ListOptions) listOpResults[0];
1698         List JavaDoc lstTestData = (List JavaDoc) listOpResults[1];
1699         
1700         assertNotNull("Selected data object list is null", lstTestData);
1701         assertTrue("Test assumption is that the default list option select" +
1702                    " at least 10 items.", 10 <= lstTestData.size());
1703         
1704         StringBuffer JavaDoc sbSelectedIDs = new StringBuffer JavaDoc();
1705         // construct string of selected IDs
1706
sbSelectedIDs.append(((DataObject)lstTestData.get(0)).getId());
1707         sbSelectedIDs.append(",");
1708         sbSelectedIDs.append(((DataObject)lstTestData.get(1)).getId());
1709         sbSelectedIDs.append(",");
1710         sbSelectedIDs.append(((DataObject)lstTestData.get(2)).getId());
1711         sbSelectedIDs.append(",");
1712         sbSelectedIDs.append(((DataObject)lstTestData.get(7)).getId());
1713         sbSelectedIDs.append(",");
1714         sbSelectedIDs.append(((DataObject)lstTestData.get(8)).getId());
1715         sbSelectedIDs.append(",");
1716         sbSelectedIDs.append(((DataObject)lstTestData.get(9)).getId());
1717
1718         // Retrieve data for page with new size together with previosly selected
1719
// 6 items.
1720
iPageSize = 5;
1721         iBeginPos = 5;
1722         options.setBeginPosition(iBeginPos);
1723         options.setPageSize(iPageSize);
1724         options.setClientOrderCode(1);
1725         options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
1726         options.setKeepSelected(true);
1727         options.setSelectedItemIDs(sbSelectedIDs.toString());
1728
1729         listOpResults = getListController().getSetPageSize(options);
1730         testOptions = (ListOptions)listOpResults[0];
1731         lstTestData = (List JavaDoc)listOpResults[1];
1732
1733         //m_listTestUtils.printDebug(lstTestData);
1734
//m_listTestUtils.printDebug(testOptions);
1735

1736         String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
1737          
1738         assertNotNull("Selected data object list is null", lstTestData);
1739         assertEquals("ActualListSize is incorrectly set",
1740                      arrExpectedData.length,
1741                      testOptions.getActualListSize());
1742
1743         assertEquals("First visible item is incorrectly set",
1744                      options.getFirstVisibleItem(),
1745                      testOptions.getFirstVisibleItem());
1746
1747          if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
1748              < options.getPageSize())
1749          {
1750             assertEquals("Number of selected items is incorrect",
1751                          (arrExpectedData.length - testOptions.getBeginPosition()
1752                             + 1),
1753                          lstTestData.size());
1754          }
1755          else
1756          {
1757             assertEquals("Number of selected items is incorrect",
1758                          options.getPageSize(),
1759                          lstTestData.size() - 4);
1760          }
1761         
1762          // TODO: For Julo: Missing test for begin position
1763

1764          assertTrue("EndPosition is incorrectly set",
1765                     ((testOptions.getBeginPosition() + options.getPageSize() - 1)
1766                        == testOptions.getEndPosition()
1767                     || (testOptions.getEndPosition()
1768                         == arrExpectedData.length)));
1769         
1770          if ((options.getActualPage() - 1) * options.getPageSize()
1771              < arrExpectedData.length)
1772          {
1773             assertEquals("ActualPage is incorrectly set",
1774                          options.getActualPage(),
1775                          testOptions.getActualPage());
1776          }
1777          else
1778          {
1779             assertEquals("ActualPage is incorrectly set",
1780                          (((testOptions.getBeginPosition() + options.getPageSize() - 2)
1781                             / options.getPageSize()) + 1),
1782                          testOptions.getActualPage());
1783          }
1784
1785          // TODO: For Julo: We should really test here that these items have the
1786
// same ids as the ones we have selected above
1787
// test selected items
1788
assertEquals("The Object List for selected item 1 is not correct",
1789                        arrExpectedData[0], m_listTestUtils.getColumnOneValue((DataObject)
1790                           lstTestData.get(0)));
1791         assertEquals("The Object List for selected item 2 is not correct",
1792                        arrExpectedData[1], m_listTestUtils.getColumnOneValue((DataObject)
1793                           lstTestData.get(1)));
1794         assertEquals("The Object List for selected item 3 is not correct",
1795                        arrExpectedData[2], m_listTestUtils.getColumnOneValue((DataObject)
1796                           lstTestData.get(2)));
1797         assertEquals("The Object List for selected item 4 is not correct",
1798                        arrExpectedData[7], m_listTestUtils.getColumnOneValue((DataObject)
1799                           lstTestData.get(7)));
1800         assertEquals("The Object List for selected item 5 is not correct",
1801                        arrExpectedData[8], m_listTestUtils.getColumnOneValue((DataObject)
1802                           lstTestData.get(8)));
1803         assertEquals("The Object List for selected item 6 is not correct",
1804                        arrExpectedData[9], m_listTestUtils.getColumnOneValue((DataObject)
1805                           lstTestData.get(3)));
1806         
1807         int helpCounter;
1808         int assertCounter;
1809         for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
1810              assertCounter < testOptions.getEndPosition();
1811              assertCounter++, helpCounter++)
1812         {
1813            assertEquals("The retrieved element #" + helpCounter +
1814                         " is not correct",
1815                         arrExpectedData[assertCounter],
1816                         m_listTestUtils.getColumnOneValue(
1817                            (DataObject)lstTestData.get(4 + helpCounter)
1818                         ));
1819         }
1820      }
1821      catch (Throwable JavaDoc thr)
1822      {
1823         throw new Exception JavaDoc(thr);
1824      }
1825      finally
1826      {
1827         m_listTestUtils.deleteTestData(m_transaction, data);
1828      }
1829   }
1830
1831   /**
1832    * Test of method getShowList
1833    *
1834    * @throws Exception - an error has occured
1835    */

1836   public void testGetShowList(
1837   ) throws Exception JavaDoc
1838   {
1839      Object JavaDoc[] data = null;
1840      
1841      try
1842      {
1843         Object JavaDoc parent;
1844         ListOptions options;
1845         
1846         data = m_listTestUtils.insertTestData(m_transaction);
1847         parent = data[0];
1848         options = m_listTestUtils.getDefaultListOptions(parent);
1849         
1850         Object JavaDoc[] listOpResults = getListController().getShowList(options);
1851         ListOptions testOptions = (ListOptions) listOpResults[0];
1852         List JavaDoc lstTestData = (List JavaDoc) listOpResults[1];
1853
1854         String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
1855
1856         assertNotNull("Selected data object list is null", lstTestData);
1857         assertEquals("ActualListSize is incorrectly set",
1858                      arrExpectedData.length,
1859                      testOptions.getActualListSize());
1860         
1861         if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
1862             < options.getPageSize())
1863         {
1864            assertEquals("Number of selected items is incorrect",
1865                         (arrExpectedData.length - testOptions.getBeginPosition()
1866                            + 1),
1867                         lstTestData.size());
1868         }
1869         else
1870         {
1871            assertEquals("Number of selected items is incorrect",
1872                         options.getPageSize(),
1873                         lstTestData.size());
1874         }
1875      
1876         assertEquals("BeginPosition is incorrectly set",
1877                      1, testOptions.getBeginPosition());
1878         assertTrue("EndPosition is incorrectly set",
1879                    (testOptions.getPageSize() == testOptions.getEndPosition())
1880                    || (arrExpectedData.length == testOptions.getEndPosition()));
1881
1882         assertEquals("ActualPage is incorrectly set",
1883                      1, testOptions.getActualPage());
1884         
1885         int helpCounter;
1886         int assertCounter;
1887         
1888         for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
1889              assertCounter < testOptions.getEndPosition();
1890              assertCounter++, helpCounter++)
1891         {
1892            assertEquals("The retrieved element #" + helpCounter +
1893                         " is not correct",
1894                         arrExpectedData[assertCounter],
1895                         m_listTestUtils.getColumnOneValue(
1896                            (DataObject)lstTestData.get(helpCounter)
1897                         ));
1898         }
1899      }
1900      catch (Throwable JavaDoc thr)
1901      {
1902         throw new Exception JavaDoc(thr);
1903      }
1904      finally
1905      {
1906         m_listTestUtils.deleteTestData(m_transaction, data);
1907      }
1908   }
1909   
1910   /**
1911    * Test of method getShowList keeping selected items
1912    *
1913    * @throws Exception - an error has occured
1914    */

1915   public void testGetShowListKeepSelected(
1916   ) throws Exception JavaDoc
1917   {
1918      Object JavaDoc[] data = null;
1919      
1920      try
1921      {
1922         Object JavaDoc parent;
1923         ListOptions options;
1924         
1925         data = m_listTestUtils.insertTestData(m_transaction);
1926         parent = data[0];
1927         options = m_listTestUtils.getDefaultListOptions(parent);
1928         
1929         Object JavaDoc[] listOpResults = getListController().getShowList(options);
1930         ListOptions testOptions = (ListOptions) listOpResults[0];
1931         List JavaDoc lstTestData = (List JavaDoc) listOpResults[1];
1932
1933         assertNotNull("Selected data object list is null", lstTestData);
1934         assertTrue("Test assumption is that the default list option select" +
1935                    " at least 10 items.", 10 <= lstTestData.size());
1936         
1937         StringBuffer JavaDoc sbSelectedIDs = new StringBuffer JavaDoc();
1938         // construct string of selected IDs
1939
sbSelectedIDs.append(((DataObject)lstTestData.get(0)).getId());
1940         sbSelectedIDs.append(",");
1941         sbSelectedIDs.append(((DataObject)lstTestData.get(1)).getId());
1942         sbSelectedIDs.append(",");
1943         sbSelectedIDs.append(((DataObject)lstTestData.get(2)).getId());
1944         sbSelectedIDs.append(",");
1945         sbSelectedIDs.append(((DataObject)lstTestData.get(7)).getId());
1946         sbSelectedIDs.append(",");
1947         sbSelectedIDs.append(((DataObject)lstTestData.get(8)).getId());
1948         sbSelectedIDs.append(",");
1949         sbSelectedIDs.append(((DataObject)lstTestData.get(9)).getId());
1950
1951         // Retrieve page with the above selected 6 items even if they all
1952
// wouldn't be normally on the page.
1953
int iPageSize = 5;
1954         options.setPageSize(iPageSize);
1955         options.setClientOrderCode(1);
1956         options.setClientOrderDirection(ListDefinition.ORDER_ASCENDING);
1957         options.setKeepSelected(true);
1958         options.setSelectedItemIDs(sbSelectedIDs.toString());
1959
1960         listOpResults = getListController().getShowList(options);
1961         testOptions = (ListOptions)listOpResults[0];
1962         lstTestData = (List JavaDoc)listOpResults[1];
1963
1964         String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
1965
1966         assertNotNull("Selected data object list is null", lstTestData);
1967         assertEquals("ActualListSize is incorrectly set",
1968                      arrExpectedData.length,
1969                      testOptions.getActualListSize());
1970         
1971         if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
1972             < options.getPageSize())
1973         {
1974            assertEquals("Number of selected items is incorrect",
1975                        (arrExpectedData.length - testOptions.getBeginPosition() + 1),
1976                        lstTestData.size());
1977         }
1978         else
1979         {
1980            assertEquals("Number of selected items is incorrect",
1981                        options.getPageSize(),
1982                        lstTestData.size() - 3);
1983         }
1984      
1985         assertEquals("BeginPosition is incorrectly set",
1986                      1, testOptions.getBeginPosition());
1987         assertTrue("EndPosition is incorrectly set",
1988                     (testOptions.getPageSize() == testOptions.getEndPosition())
1989                     || (arrExpectedData.length == testOptions.getEndPosition()));
1990
1991         assertEquals("ActualPage is incorrectly set",
1992                      1, testOptions.getActualPage());
1993
1994         // TODO: For Julo: We should really test here that these items have the
1995
// same ids as the ones we have selected above
1996
// test selected items
1997
assertEquals("The Object List for selected item 1 is not correct",
1998                        arrExpectedData[0], m_listTestUtils.getColumnOneValue((DataObject)
1999                           lstTestData.get(3)));
2000         assertEquals("The Object List for selected item 2 is not correct",
2001                        arrExpectedData[1], m_listTestUtils.getColumnOneValue((DataObject)
2002                           lstTestData.get(4)));
2003         assertEquals("The Object List for selected item 3 is not correct",
2004                        arrExpectedData[2], m_listTestUtils.getColumnOneValue((DataObject)
2005                           lstTestData.get(5)));
2006         assertEquals("The Object List for selected item 4 is not correct",
2007                        arrExpectedData[7], m_listTestUtils.getColumnOneValue((DataObject)
2008                           lstTestData.get(0)));
2009         assertEquals("The Object List for selected item 5 is not correct",
2010                        arrExpectedData[8], m_listTestUtils.getColumnOneValue((DataObject)
2011                           lstTestData.get(1)));
2012         assertEquals("The Object List for selected item 6 is not correct",
2013                        arrExpectedData[9], m_listTestUtils.getColumnOneValue((DataObject)
2014                           lstTestData.get(2)));
2015
2016         int helpCounter;
2017         int assertCounter;
2018         for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
2019             assertCounter < testOptions.getEndPosition();
2020             assertCounter++, helpCounter++)
2021         {
2022            assertEquals("The retrieved element #" + helpCounter +
2023                         " is not correct",
2024                         arrExpectedData[assertCounter],
2025                         m_listTestUtils.getColumnOneValue(
2026                            (DataObject)lstTestData.get(3 + helpCounter)
2027                         ));
2028         }
2029      }
2030      catch (Throwable JavaDoc thr)
2031      {
2032         throw new Exception JavaDoc(thr);
2033      }
2034      finally
2035      {
2036         m_listTestUtils.deleteTestData(m_transaction, data);
2037      }
2038   }
2039
2040   /**
2041    * Test of method getShowList
2042    *
2043    * @throws Exception - an error has occured
2044    */

2045   public void testGetShowListWithPresetSize(
2046   ) throws Exception JavaDoc
2047   {
2048      Object JavaDoc[] data = null;
2049      
2050      try
2051      {
2052         Object JavaDoc parent;
2053         ListOptions options;
2054         int iOriginalPageSize;
2055         int iChangedPageSize;
2056         
2057         data = m_listTestUtils.insertTestData(m_transaction);
2058         parent = data[0];
2059         options = m_listTestUtils.getDefaultListOptions(parent);
2060         
2061         // Now set the size to something else
2062
iOriginalPageSize = options.getPageSize();
2063         options.setPageSize(options.getPageSize() / 2);
2064         iChangedPageSize = options.getPageSize();
2065         assertTrue("Page size should have changed.",
2066                    iOriginalPageSize != iChangedPageSize);
2067         
2068         Object JavaDoc[] listOpResults = getListController().getShowList(options);
2069         ListOptions testOptions = (ListOptions) listOpResults[0];
2070         List JavaDoc lstTestData = (List JavaDoc) listOpResults[1];
2071
2072         String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
2073
2074         assertNotNull("Selected data object list is null", lstTestData);
2075         assertEquals("ActualListSize is incorrectly set",
2076                      arrExpectedData.length,
2077                      testOptions.getActualListSize());
2078         
2079         if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
2080             < options.getPageSize())
2081         {
2082            assertEquals("Number of selected items is incorrect",
2083                        (arrExpectedData.length - testOptions.getBeginPosition()
2084                           + 1),
2085                        lstTestData.size());
2086         }
2087         else
2088         {
2089            assertEquals("Number of selected items is incorrect",
2090                        options.getPageSize(),
2091                        lstTestData.size());
2092         }
2093      
2094         assertEquals("PageSize is incorrectly set",
2095                      iChangedPageSize, testOptions.getPageSize());
2096         assertEquals("BeginPosition is incorrectly set",
2097                      1, testOptions.getBeginPosition());
2098         assertTrue("EndPosition is incorrectly set",
2099                    (testOptions.getPageSize() == testOptions.getEndPosition())
2100                    || (arrExpectedData.length == testOptions.getEndPosition()));
2101         
2102         assertEquals("ActualPage is incorrectly set",
2103                      1, testOptions.getActualPage());
2104         
2105         int helpCounter;
2106         int assertCounter;
2107         
2108         for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
2109              assertCounter < testOptions.getEndPosition();
2110              assertCounter++, helpCounter++)
2111         {
2112            assertEquals("The retrieved element #" + helpCounter +
2113                         " is not correct",
2114                         arrExpectedData[assertCounter],
2115                         m_listTestUtils.getColumnOneValue(
2116                            (DataObject)lstTestData.get(helpCounter)
2117                         ));
2118         }
2119      }
2120      catch (Throwable JavaDoc thr)
2121      {
2122         throw new Exception JavaDoc(thr);
2123      }
2124      finally
2125      {
2126         m_listTestUtils.deleteTestData(m_transaction, data);
2127      }
2128   }
2129   
2130   /**
2131    * Test of method getShowList keeping selected items
2132    *
2133    * @throws Exception - an error has occured
2134    */

2135   public void testGetShowListWithPresetSizeKeepSelected(
2136   ) throws Exception JavaDoc
2137   {
2138      Object JavaDoc[] data = null;
2139      
2140      try
2141      {
2142         Object JavaDoc parent;
2143         ListOptions options;
2144         int iOriginalPageSize;
2145         int iChangedPageSize;
2146         
2147         data = m_listTestUtils.insertTestData(m_transaction);
2148         parent = data[0];
2149         options = m_listTestUtils.getDefaultListOptions(parent);
2150
2151         Object JavaDoc[] listOpResults = getListController().getShowList(options);
2152         
2153         ListOptions testOptions = (ListOptions) listOpResults[0];
2154         List JavaDoc lstTestData = (List JavaDoc) listOpResults[1];
2155
2156         assertNotNull("Selected data object list is null", lstTestData);
2157         assertTrue("Test assumption is that the default list option select" +
2158                    " at least 10 items.", 10 <= lstTestData.size());
2159         
2160         StringBuffer JavaDoc sbSelectedIDs = new StringBuffer JavaDoc();
2161         // construct string of selected IDs
2162
sbSelectedIDs.append(((DataObject)lstTestData.get(0)).getId());
2163         sbSelectedIDs.append(",");
2164         sbSelectedIDs.append(((DataObject)lstTestData.get(1)).getId());
2165         sbSelectedIDs.append(",");
2166         sbSelectedIDs.append(((DataObject)lstTestData.get(2)).getId());
2167         sbSelectedIDs.append(",");
2168         sbSelectedIDs.append(((DataObject)lstTestData.get(7)).getId());
2169         sbSelectedIDs.append(",");
2170         sbSelectedIDs.append(((DataObject)lstTestData.get(8)).getId());
2171         sbSelectedIDs.append(",");
2172         sbSelectedIDs.append(((DataObject)lstTestData.get(9)).getId());
2173
2174         // Retrieve page with the above selected 6 items even if they all
2175
// wouldn't be normally on the page.
2176

2177         // Now set the size to something else
2178
iOriginalPageSize = options.getPageSize();
2179         options.setPageSize(options.getPageSize() / 2);
2180         iChangedPageSize = options.getPageSize();
2181         assertTrue("Page size should have changed.",
2182                    iOriginalPageSize != iChangedPageSize);
2183         options.setKeepSelected(true);
2184         options.setSelectedItemIDs(sbSelectedIDs.toString());
2185
2186         listOpResults = getListController().getShowList(options);
2187         testOptions = (ListOptions)listOpResults[0];
2188         lstTestData = (List JavaDoc)listOpResults[1];
2189
2190         String JavaDoc[] arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne();
2191
2192         assertNotNull("Selected data object list is null", lstTestData);
2193         assertEquals("ActualListSize is incorrectly set",
2194                      arrExpectedData.length,
2195                      testOptions.getActualListSize());
2196         
2197         if ((arrExpectedData.length - testOptions.getBeginPosition() + 1)
2198             < options.getPageSize())
2199         {
2200            assertEquals("Number of selected items is incorrect",
2201                        (arrExpectedData.length - testOptions.getBeginPosition()
2202                           + 1),
2203                        lstTestData.size());
2204         }
2205         else
2206         {
2207            assertEquals("Number of selected items is incorrect",
2208                        options.getPageSize(),
2209                        lstTestData.size() - 3);
2210         }
2211      
2212         assertEquals("PageSize is incorrectly set",
2213                      iChangedPageSize, testOptions.getPageSize());
2214
2215         assertEquals("BeginPosition is incorrectly set",
2216                      1, testOptions.getBeginPosition());
2217         assertTrue("EndPosition is incorrectly set",
2218                    (testOptions.getPageSize() == testOptions.getEndPosition())
2219                    || (arrExpectedData.length == testOptions.getEndPosition()));
2220
2221         assertEquals("ActualPage is incorrectly set",
2222                      1, testOptions.getActualPage());
2223
2224         // test selected items
2225
assertEquals("The Object List for selected item 1 is not correct",
2226                        arrExpectedData[0], m_listTestUtils.getColumnOneValue((DataObject)
2227                           lstTestData.get(3)));
2228         assertEquals("The Object List for selected item 2 is not correct",
2229                        arrExpectedData[1], m_listTestUtils.getColumnOneValue((DataObject)
2230                           lstTestData.get(4)));
2231         assertEquals("The Object List for selected item 3 is not correct",
2232                        arrExpectedData[2], m_listTestUtils.getColumnOneValue((DataObject)
2233                           lstTestData.get(5)));
2234         assertEquals("The Object List for selected item 4 is not correct",
2235                        arrExpectedData[7], m_listTestUtils.getColumnOneValue((DataObject)
2236                           lstTestData.get(0)));
2237         assertEquals("The Object List for selected item 5 is not correct",
2238                        arrExpectedData[8], m_listTestUtils.getColumnOneValue((DataObject)
2239                           lstTestData.get(1)));
2240         assertEquals("The Object List for selected item 6 is not correct",
2241                        arrExpectedData[9], m_listTestUtils.getColumnOneValue((DataObject)
2242                           lstTestData.get(2)));
2243
2244         // TODO: For Julo: We should really test here that these items have the
2245
// same ids as the ones we have selected above
2246
// test selected items
2247
int helpCounter;
2248         int assertCounter;
2249         for (assertCounter = (testOptions.getBeginPosition() - 1), helpCounter = 0;
2250              assertCounter < testOptions.getEndPosition();
2251              assertCounter++, helpCounter++)
2252         {
2253            assertEquals("The retrieved element #" + helpCounter +
2254                         " is not correct",
2255                         arrExpectedData[assertCounter],
2256                         m_listTestUtils.getColumnOneValue(
2257                           (DataObject)lstTestData.get(3 + helpCounter)
2258                         ));
2259         }
2260      }
2261      catch (Throwable JavaDoc thr)
2262      {
2263         throw new Exception JavaDoc(thr);
2264      }
2265      finally
2266      {
2267         m_listTestUtils.deleteTestData(m_transaction, data);
2268      }
2269   }
2270
2271   /**
2272    * Get list controller to use during this test. This is in separate method
2273    * so it can be overriden and derived list controller can be supplied
2274    * forexample implementing security ;-).
2275    *
2276    * @return ListController - instance of controller to use to test
2277    * @throws OSSException - an error has occured
2278    */

2279   protected ListController getListController(
2280   ) throws OSSException
2281   {
2282      ListController controller;
2283      
2284      controller = (ListController)ControllerManager.getInstance(ListController.class);
2285      
2286      return controller;
2287   }
2288}
2289
Popular Tags