1 21 22 package org.opensubsystems.patterns.listdata.logic; 23 24 import java.util.Arrays ; 25 import java.util.List ; 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 48 public abstract class ListControllerTest extends DatabaseTest 49 { 50 52 55 protected ListDatabaseTestUtils m_listTestUtils; 56 57 59 65 public ListControllerTest( 66 String strTestName, 67 ListDatabaseTestUtils listTestUtils 68 ) 69 { 70 super(strTestName); 71 72 m_listTestUtils = listTestUtils; 73 } 74 75 77 82 public void testGetNextPage( 83 ) throws Exception 84 { 85 Object [] data = null; 86 87 try 88 { 89 Object 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 [] listOpResults = getListController().getNextPage(options); 101 ListOptions testOptions = (ListOptions)listOpResults[0]; 102 List lstTestData = (List )listOpResults[1]; 103 104 107 String [] 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 thr) 174 { 175 throw new Exception (thr); 176 } 177 finally 178 { 179 m_listTestUtils.deleteTestData(m_transaction, data); 180 } 181 } 182 183 188 public void testGetNextPageKeepSelected( 189 ) throws Exception 190 { 191 Object [] data = null; 192 193 try 194 { 195 Object parent; 196 ListOptions options; 197 int iEndPos = 5; 198 String [] 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 Object [] listOpResults = getListController().getShowList(options); 207 ListOptions testOptions = (ListOptions)listOpResults[0]; 208 List lstTestData = (List )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 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 StringBuffer sbSelectedIDs = new StringBuffer (); 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 options.setEndPosition(iEndPos); 240 options.setKeepSelected(true); 241 options.setSelectedItemIDs(sbSelectedIDs.toString()); 242 243 listOpResults = getListController().getNextPage(options); 246 testOptions = (ListOptions)listOpResults[0]; 247 lstTestData = (List )listOpResults[1]; 248 249 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 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 thr) 333 { 334 throw new Exception (thr); 335 } 336 finally 337 { 338 m_listTestUtils.deleteTestData(m_transaction, data); 339 } 340 } 341 342 347 public void testGetPrevPage( 348 ) throws Exception 349 { 350 Object [] data = null; 351 352 try 353 { 354 Object 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 [] listOpResults = getListController().getPreviousPage(options); 366 ListOptions testOptions = (ListOptions) listOpResults[0]; 367 List lstTestData = (List ) listOpResults[1]; 368 369 372 String [] 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 thr) 441 { 442 throw new Exception (thr); 443 } 444 finally 445 { 446 m_listTestUtils.deleteTestData(m_transaction, data); 447 } 448 } 449 450 613 618 public void testGetExactPage( 619 ) throws Exception 620 { 621 Object [] data = null; 622 623 try 624 { 625 Object parent; 626 ListOptions options; 627 int iActualPage = 2; 628 629 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 [] listOpResults = getListController().getExactPage(options); 638 ListOptions testOptions = (ListOptions)listOpResults[0]; 639 List lstTestData = (List )listOpResults[1]; 640 641 644 String [] 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 thr) 713 { 714 throw new Exception (thr); 715 } 716 finally 717 { 718 m_listTestUtils.deleteTestData(m_transaction, data); 719 } 720 } 721 722 727 public void testGetExactPageKeepSelected( 728 ) throws Exception 729 { 730 Object [] data = null; 731 732 try 733 { 734 Object parent; 735 ListOptions options; 736 int iActualPage = 2; 737 738 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 [] listOpResults = getListController().getExactPage(options); 747 ListOptions testOptions = (ListOptions)listOpResults[0]; 748 List lstTestData = (List )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 sbSelectedIDs = new StringBuffer (); 755 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 772 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 ) listOpResults[1]; 788 789 792 String [] 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 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 thr) 884 { 885 throw new Exception (thr); 886 } 887 finally 888 { 889 m_listTestUtils.deleteTestData(m_transaction, data); 890 } 891 } 892 893 898 public void testGetSetFilter( 899 ) throws Exception 900 { 901 Object [] data = null; 902 903 try 904 { 905 Object parent; 906 ListOptions options; 907 908 data = m_listTestUtils.insertTestData(m_transaction); 909 parent = data[0]; 910 options = m_listTestUtils.getDefaultListOptions(parent); 911 options.setDefinitionId(options.getDefinitionId()); 919 920 Object [] listOpResults = getListController().getSetDefinition(options); 921 ListOptions testOptions = (ListOptions) listOpResults[0]; 922 List lstTestData = (List ) listOpResults[1]; 923 924 String [] 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 thr) 972 { 973 throw new Exception (thr); 974 } 975 finally 976 { 977 m_listTestUtils.deleteTestData(m_transaction, data); 978 } 979 } 980 981 983 988 public void testGetOrderDesc( 989 ) throws Exception 990 { 991 Object [] data = null; 992 993 try 994 { 995 Object parent; 996 ListOptions options; 997 int iOrderCode = m_listTestUtils.getColumnOneCode(); 998 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 [] listOpResults = getListController().getSetOrder(options); 1009 ListOptions testOptions = (ListOptions)listOpResults[0]; 1010 List lstTestData = (List )listOpResults[1]; 1011 1012 1015 String [] 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 1073 int helpCounter; 1074 int assertCounter; 1075 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 thr) 1103 { 1104 throw new Exception (thr); 1105 } 1106 finally 1107 { 1108 m_listTestUtils.deleteTestData(m_transaction, data); 1109 } 1110 } 1111 1112 1117 public void testGetOrderDescKeepSelected( 1118 ) throws Exception 1119 { 1120 Object [] data = null; 1121 1122 try 1123 { 1124 Object parent; 1125 ListOptions options; 1126 int iOrderCode = m_listTestUtils.getColumnOneCode(); 1127 1131 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 [] listOpResults = getListController().getSetOrder(options); 1140 ListOptions testOptions = (ListOptions) listOpResults[0]; 1141 List lstTestData = (List ) 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 sbSelectedIDs = new StringBuffer (); 1148 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 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 ) listOpResults[1]; 1164 1165 1168 String [] 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 1225 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 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 thr) 1267 { 1268 throw new Exception (thr); 1269 } 1270 finally 1271 { 1272 m_listTestUtils.deleteTestData(m_transaction, data); 1273 } 1274 } 1275 1276 1281 public void testGetOrderAsc( 1282 ) throws Exception 1283 { 1284 Object [] data = null; 1285 1286 try 1287 { 1288 Object parent; 1289 ListOptions options; 1290 int iOrderCode = m_listTestUtils.getColumnOneCode(); 1291 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 [] listOpResults = getListController().getSetOrder(options); 1302 ListOptions testOptions = (ListOptions)listOpResults[0]; 1303 List lstTestData = (List )listOpResults[1]; 1304 1305 1308 String [] 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 1366 int helpCounter; 1367 int assertCounter; 1368 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 thr) 1394 { 1395 throw new Exception (thr); 1396 } 1397 finally 1398 { 1399 m_listTestUtils.deleteTestData(m_transaction, data); 1400 } 1401 } 1402 1403 1408 public void testGetOrderAscKeepSelected( 1409 ) throws Exception 1410 { 1411 Object [] data = null; 1412 1413 try 1414 { 1415 Object parent; 1416 ListOptions options; 1417 int iOrderCode = m_listTestUtils.getColumnOneCode(); 1418 1422 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 [] listOpResults = getListController().getSetOrder(options); 1431 ListOptions testOptions = (ListOptions)listOpResults[0]; 1432 List lstTestData = (List )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 sbSelectedIDs = new StringBuffer (); 1439 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 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 )listOpResults[1]; 1455 1456 1459 String [] 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 1516 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 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 thr) 1557 { 1558 throw new Exception (thr); 1559 } 1560 finally 1561 { 1562 m_listTestUtils.deleteTestData(m_transaction, data); 1563 } 1564 } 1565 1566 1571 public void testGetSetPageSize( 1572 ) throws Exception 1573 { 1574 Object [] data = null; 1575 1576 try 1577 { 1578 Object 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 [] listOpResults = getListController().getSetPageSize(options); 1592 ListOptions testOptions = (ListOptions)listOpResults[0]; 1593 List lstTestData = (List )listOpResults[1]; 1594 1595 1598 String [] 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 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 thr) 1662 { 1663 throw new Exception (thr); 1664 } 1665 finally 1666 { 1667 m_listTestUtils.deleteTestData(m_transaction, data); 1668 } 1669 } 1670 1671 1676 public void testGetSetPageSizeKeepSelected( 1677 ) throws Exception 1678 { 1679 Object [] data = null; 1680 1681 try 1682 { 1683 Object 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 [] listOpResults = getListController().getExactPage(options); 1697 ListOptions testOptions = (ListOptions) listOpResults[0]; 1698 List lstTestData = (List ) 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 sbSelectedIDs = new StringBuffer (); 1705 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 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 )listOpResults[1]; 1732 1733 1736 String [] 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 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 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 thr) 1822 { 1823 throw new Exception (thr); 1824 } 1825 finally 1826 { 1827 m_listTestUtils.deleteTestData(m_transaction, data); 1828 } 1829 } 1830 1831 1836 public void testGetShowList( 1837 ) throws Exception 1838 { 1839 Object [] data = null; 1840 1841 try 1842 { 1843 Object 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 [] listOpResults = getListController().getShowList(options); 1851 ListOptions testOptions = (ListOptions) listOpResults[0]; 1852 List lstTestData = (List ) listOpResults[1]; 1853 1854 String [] 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 thr) 1901 { 1902 throw new Exception (thr); 1903 } 1904 finally 1905 { 1906 m_listTestUtils.deleteTestData(m_transaction, data); 1907 } 1908 } 1909 1910 1915 public void testGetShowListKeepSelected( 1916 ) throws Exception 1917 { 1918 Object [] data = null; 1919 1920 try 1921 { 1922 Object 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 [] listOpResults = getListController().getShowList(options); 1930 ListOptions testOptions = (ListOptions) listOpResults[0]; 1931 List lstTestData = (List ) 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 sbSelectedIDs = new StringBuffer (); 1938 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 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 )listOpResults[1]; 1963 1964 String [] 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 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 thr) 2031 { 2032 throw new Exception (thr); 2033 } 2034 finally 2035 { 2036 m_listTestUtils.deleteTestData(m_transaction, data); 2037 } 2038 } 2039 2040 2045 public void testGetShowListWithPresetSize( 2046 ) throws Exception 2047 { 2048 Object [] data = null; 2049 2050 try 2051 { 2052 Object 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 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 [] listOpResults = getListController().getShowList(options); 2069 ListOptions testOptions = (ListOptions) listOpResults[0]; 2070 List lstTestData = (List ) listOpResults[1]; 2071 2072 String [] 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 thr) 2121 { 2122 throw new Exception (thr); 2123 } 2124 finally 2125 { 2126 m_listTestUtils.deleteTestData(m_transaction, data); 2127 } 2128 } 2129 2130 2135 public void testGetShowListWithPresetSizeKeepSelected( 2136 ) throws Exception 2137 { 2138 Object [] data = null; 2139 2140 try 2141 { 2142 Object 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 [] listOpResults = getListController().getShowList(options); 2152 2153 ListOptions testOptions = (ListOptions) listOpResults[0]; 2154 List lstTestData = (List ) 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 sbSelectedIDs = new StringBuffer (); 2161 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 2177 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 )listOpResults[1]; 2189 2190 String [] 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 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 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 thr) 2262 { 2263 throw new Exception (thr); 2264 } 2265 finally 2266 { 2267 m_listTestUtils.deleteTestData(m_transaction, data); 2268 } 2269 } 2270 2271 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 |