1 18 package org.apache.struts.taglib.logic; 19 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 import java.util.HashMap ; 23 import java.util.StringTokenizer ; 24 25 import javax.servlet.ServletException ; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.PageContext ; 28 29 import junit.framework.Test; 30 import junit.framework.TestSuite; 31 32 import org.apache.cactus.WebResponse; 33 import org.apache.struts.taglib.SimpleBeanForTesting; 34 import org.apache.struts.taglib.TaglibTestBase; 35 36 37 38 43 public class TestIterateTag extends TaglibTestBase { 44 45 private int iterations = 2; 46 47 52 public TestIterateTag(String theName) { 53 super(theName); 54 } 55 56 61 public static void main(String [] theArgs) { 62 junit.awtui.TestRunner.main(new String [] {TestIterateTag.class.getName()}); 63 } 64 65 69 public static Test suite() { 70 return new TestSuite(TestIterateTag.class); 72 } 73 74 75 84 85 public void testApplicationScopeNameIterateList() 87 throws ServletException , JspException , IOException { 88 89 String testKey = "testApplicationScopeNameIterateList"; 90 91 ArrayList lst = new ArrayList (); 92 for (int i = 0; i < iterations; i++) { 93 lst.add("test" + i); 94 } 95 96 pageContext.setAttribute(testKey, lst, 97 PageContext.APPLICATION_SCOPE); 98 99 IterateTag tag = new IterateTag(); 100 tag.setPageContext(pageContext); 101 tag.setId("theId"); 102 tag.setName(testKey); 103 tag.setScope("application"); 104 105 int iteration = 0; 106 tag.doStartTag(); 107 tag.doInitBody(); 108 do 109 { 110 out.print((String )pageContext.getAttribute("theId")); 111 iteration++; 112 113 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 114 tag.doEndTag(); 115 assertEquals(iterations, iteration); 116 } 117 118 public void endApplicationScopeNameIterateList (WebResponse response){ 119 String output = response.getText(); 120 String compare = ""; 121 for (int i = 0; i < iterations; i++) { 122 compare += "test" + i; 123 } 124 125 output = replace(output,"\r",""); 127 output = replace(output,"\n",""); 128 129 assertEquals(compare, output); 130 } 131 132 public void testSessionScopeNameIterateList() 134 throws ServletException , JspException , IOException { 135 136 String testKey = "testSessionScopeNameIterateList"; 137 138 ArrayList lst = new ArrayList (); 139 for (int i = 0; i < iterations; i++) { 140 lst.add("test" + i); 141 } 142 143 pageContext.setAttribute(testKey, lst, 144 PageContext.SESSION_SCOPE); 145 146 IterateTag tag = new IterateTag(); 147 tag.setPageContext(pageContext); 148 tag.setId("theId"); 149 tag.setName(testKey); 150 tag.setScope("session"); 151 152 int iteration = 0; 153 tag.doStartTag(); 154 tag.doInitBody(); 155 do 156 { 157 out.print((String )pageContext.getAttribute("theId")); 158 iteration++; 159 160 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 161 tag.doEndTag(); 162 assertEquals(iterations, iteration); 163 } 164 165 public void endSessionScopeNameIterateList (WebResponse response){ 166 String output = response.getText(); 167 String compare = ""; 168 for (int i = 0; i < iterations; i++) { 169 compare += "test" + i; 170 } 171 172 output = replace(compare,"\r",""); 174 output = replace(output,"\n",""); 175 176 assertEquals(compare, output); 177 } 178 179 public void testRequestScopeNameIterateList() 181 throws ServletException , JspException , IOException { 182 183 String testKey = "testRequestScopeNameIterateList"; 184 185 ArrayList lst = new ArrayList (); 186 for (int i = 0; i < iterations; i++) { 187 lst.add("test" + i); 188 } 189 190 pageContext.setAttribute(testKey, lst, 191 PageContext.REQUEST_SCOPE); 192 193 IterateTag tag = new IterateTag(); 194 tag.setPageContext(pageContext); 195 tag.setId("theId"); 196 tag.setName(testKey); 197 tag.setScope("request"); 198 199 int iteration = 0; 200 tag.doStartTag(); 201 tag.doInitBody(); 202 do 203 { 204 out.print((String )pageContext.getAttribute("theId")); 205 iteration++; 206 207 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 208 tag.doEndTag(); 209 assertEquals(iterations, iteration); 210 } 211 212 public void endRequestScopeNameIterateList (WebResponse response){ 213 String output = response.getText(); 214 String compare = ""; 215 for (int i = 0; i < iterations; i++) { 216 compare += "test" + i; 217 } 218 219 output = replace(compare,"\r",""); 221 output = replace(output,"\r",""); 222 223 assertEquals(compare, output); 224 } 225 226 227 236 237 public void testApplicationScopePropertyIterateList() 239 throws ServletException , JspException , IOException { 240 241 242 String testKey = "testApplicationScopePropertyIterate"; 243 244 ArrayList lst = new ArrayList (); 245 for (int i = 0; i < iterations; i++) { 246 lst.add("test" + i); 247 } 248 249 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 250 sbft.setList(lst); 251 252 pageContext.setAttribute(testKey, sbft, 253 PageContext.APPLICATION_SCOPE); 254 255 IterateTag tag = new IterateTag(); 256 tag.setPageContext(pageContext); 257 262 tag.setId("theId"); 263 tag.setName(testKey); 264 tag.setScope("application"); 265 tag.setProperty("list"); 266 267 int iteration = 0; 268 tag.doStartTag(); 269 tag.doInitBody(); 270 do 271 { 272 out.print((String )pageContext.getAttribute("theId")); 273 iteration++; 274 275 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 276 tag.doEndTag(); 277 assertEquals(iterations, iteration); 278 } 279 280 public void endApplicationScopePropertyIterateList (WebResponse response){ 281 String output = response.getText(); 282 String compare = ""; 283 for (int i = 0; i < iterations; i++) { 284 compare += "test" + i; 285 } 286 287 output = replace(compare,"\r",""); 289 output = replace(output,"\n",""); 290 291 assertEquals(compare, output); 292 } 293 294 295 public void testSessionScopePropertyIteratesList() 297 throws ServletException , JspException , IOException { 298 299 300 String testKey = "testSessionScopePropertyIterate"; 301 302 ArrayList lst = new ArrayList (); 303 for (int i = 0; i < iterations; i++) { 304 lst.add("test" + i); 305 } 306 307 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 308 sbft.setList(lst); 309 310 pageContext.setAttribute(testKey, sbft, 311 PageContext.SESSION_SCOPE); 312 313 IterateTag tag = new IterateTag(); 314 tag.setPageContext(pageContext); 315 320 tag.setId("theId"); 321 tag.setName(testKey); 322 tag.setScope("session"); 323 tag.setProperty("list"); 324 325 int iteration = 0; 326 tag.doStartTag(); 327 tag.doInitBody(); 328 do 329 { 330 out.print((String )pageContext.getAttribute("theId")); 331 iteration++; 332 333 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 334 tag.doEndTag(); 335 assertEquals(iterations, iteration); 336 } 337 338 public void endSessionScopePropertyIterateList (WebResponse response){ 339 String output = response.getText(); 340 String compare = ""; 341 for (int i = 0; i < iterations; i++) { 342 compare += "test" + i; 343 } 344 345 output = replace(compare,"\r",""); 347 output = replace(output,"\n",""); 348 349 assertEquals(compare, output); 350 } 351 352 353 public void testRequestScopePropertyIteratesList() 355 throws ServletException , JspException , IOException { 356 357 358 String testKey = "testRequestScopePropertyIterate"; 359 360 ArrayList lst = new ArrayList (); 361 for (int i = 0; i < iterations; i++) { 362 lst.add("test" + i); 363 } 364 365 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 366 sbft.setList(lst); 367 368 pageContext.setAttribute(testKey, sbft, 369 PageContext.REQUEST_SCOPE); 370 371 IterateTag tag = new IterateTag(); 372 tag.setPageContext(pageContext); 373 378 tag.setId("theId"); 379 tag.setName(testKey); 380 tag.setScope("request"); 381 tag.setProperty("list"); 382 383 int iteration = 0; 384 tag.doStartTag(); 385 tag.doInitBody(); 386 do 387 { 388 out.print((String )pageContext.getAttribute("theId")); 389 iteration++; 390 391 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 392 tag.doEndTag(); 393 assertEquals(iterations, iteration); 394 } 395 396 public void endRequestScopePropertyIterateList (WebResponse response){ 397 String output = response.getText(); 398 String compare = ""; 399 for (int i = 0; i < iterations; i++) { 400 compare += "test" + i; 401 } 402 403 output = replace(compare,"\r",""); 405 output = replace(output,"\n",""); 406 407 assertEquals(compare, output); 408 } 409 410 411 412 421 422 public void testApplicationScopeNameIterateEnumeration() 424 throws ServletException , JspException , IOException { 425 426 String testKey = "testApplicationScopeNameIterateEnumeration"; 427 428 StringTokenizer st = new StringTokenizer ("Application Scope Name Iterate Enumeration"); 429 430 pageContext.setAttribute(testKey, st, 431 PageContext.APPLICATION_SCOPE); 432 433 IterateTag tag = new IterateTag(); 434 tag.setPageContext(pageContext); 435 tag.setId("theId"); 436 tag.setName(testKey); 437 tag.setScope("application"); 438 439 tag.doStartTag(); 440 tag.doInitBody(); 441 do 442 { 443 out.print((String )pageContext.getAttribute("theId")); 444 445 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 446 tag.doEndTag(); 447 448 } 449 450 public void endApplicationScopeNameIterateEnumeration (WebResponse response){ 451 String output = response.getText(); 452 StringTokenizer st = new StringTokenizer ("Application Scope Name Iterate Enumeration"); 453 String compare = ""; 454 455 while (st.hasMoreTokens()) { 456 compare += st.nextToken(); 457 } 458 459 output = replace(compare,"\r",""); 461 output = replace(output,"\n",""); 462 463 assertEquals(compare, output); 464 } 465 466 public void testSessionScopeNameIterateEnumeration() 468 throws ServletException , JspException , IOException { 469 470 String testKey = "testSessionScopeNameIterateEnumeration"; 471 472 StringTokenizer st = new StringTokenizer ("Session Scope Name Iterate Enumeration"); 473 474 pageContext.setAttribute(testKey, st, 475 PageContext.SESSION_SCOPE); 476 477 IterateTag tag = new IterateTag(); 478 tag.setPageContext(pageContext); 479 tag.setId("theId"); 480 tag.setName(testKey); 481 tag.setScope("session"); 482 483 tag.doStartTag(); 484 tag.doInitBody(); 485 do 486 { 487 out.print((String )pageContext.getAttribute("theId")); 488 489 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 490 tag.doEndTag(); 491 492 } 493 494 public void endSessionScopeNameIterateEnumeration (WebResponse response){ 495 String output = response.getText(); 496 StringTokenizer st = new StringTokenizer ("Session Scope Name Iterate Enumeration"); 497 String compare = ""; 498 499 while (st.hasMoreTokens()) { 500 compare += st.nextToken(); 501 } 502 503 output = replace(compare,"\r",""); 505 output = replace(output,"\n",""); 506 507 assertEquals(compare, output); 508 } 509 510 public void testRequestScopeNameIterateEnumeration() 512 throws ServletException , JspException , IOException { 513 514 String testKey = "testRequestScopeNameIterateEnumeration"; 515 516 StringTokenizer st = new StringTokenizer ("Request Scope Name Iterate Enumeration"); 517 518 pageContext.setAttribute(testKey, st, 519 PageContext.REQUEST_SCOPE); 520 521 IterateTag tag = new IterateTag(); 522 tag.setPageContext(pageContext); 523 tag.setId("theId"); 524 tag.setName(testKey); 525 tag.setScope("request"); 526 527 tag.doStartTag(); 528 tag.doInitBody(); 529 do 530 { 531 out.print((String )pageContext.getAttribute("theId")); 532 533 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 534 tag.doEndTag(); 535 536 } 537 538 public void endRequestScopeNameIterateEnumeration (WebResponse response){ 539 String output = response.getText(); 540 StringTokenizer st = new StringTokenizer ("Request Scope Name Iterate Enumeration"); 541 String compare = ""; 542 543 while (st.hasMoreTokens()) { 544 compare += st.nextToken(); 545 } 546 547 output = replace(compare,"\r",""); 549 output = replace(output,"\n",""); 550 551 assertEquals(compare, output); 552 } 553 554 555 564 565 public void testApplicationScopePropertyIterateEnumeration() 567 throws ServletException , JspException , IOException { 568 569 String testKey = "testApplicationScopePropertyIterateEnumeration"; 570 571 StringTokenizer st = new StringTokenizer ("Application Scope Property Iterate Enumeration"); 572 573 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 574 sbft.setEnumeration(st); 575 576 pageContext.setAttribute(testKey, sbft, 577 PageContext.APPLICATION_SCOPE); 578 579 IterateTag tag = new IterateTag(); 580 tag.setPageContext(pageContext); 581 tag.setId("theId"); 582 tag.setName(testKey); 583 tag.setScope("application"); 584 tag.setProperty("enumeration"); 585 586 tag.doStartTag(); 587 tag.doInitBody(); 588 do 589 { 590 out.print((String )pageContext.getAttribute("theId")); 591 592 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 593 tag.doEndTag(); 594 595 } 596 597 public void endApplicationScopePropertyIterateEnumeration (WebResponse response){ 598 String output = response.getText(); 599 StringTokenizer st = new StringTokenizer ("Application Scope Property Iterate Enumeration"); 600 String compare = ""; 601 602 while (st.hasMoreTokens()) { 603 compare += st.nextToken(); 604 } 605 606 output = replace(compare,"\r",""); 608 output = replace(output,"\n",""); 609 610 assertEquals(compare, output); 611 } 612 613 public void testSessionScopePropertyIterateEnumeration() 615 throws ServletException , JspException , IOException { 616 617 String testKey = "testSessionScopePropertyIterateEnumeration"; 618 619 StringTokenizer st = new StringTokenizer ("Session Scope Property Iterate Enumeration"); 620 621 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 622 sbft.setEnumeration(st); 623 624 pageContext.setAttribute(testKey, sbft, 625 PageContext.SESSION_SCOPE); 626 627 IterateTag tag = new IterateTag(); 628 tag.setPageContext(pageContext); 629 tag.setId("theId"); 630 tag.setName(testKey); 631 tag.setScope("session"); 632 tag.setProperty("enumeration"); 633 634 tag.doStartTag(); 635 tag.doInitBody(); 636 do 637 { 638 out.print((String )pageContext.getAttribute("theId")); 639 640 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 641 tag.doEndTag(); 642 643 } 644 645 public void endSessionScopePropertyIterateEnumeration (WebResponse response){ 646 String output = response.getText(); 647 StringTokenizer st = new StringTokenizer ("Session Scope Property Iterate Enumeration"); 648 String compare = ""; 649 650 while (st.hasMoreTokens()) { 651 compare += st.nextToken(); 652 } 653 654 output = replace(compare,"\r",""); 656 output = replace(output,"\n",""); 657 658 assertEquals(compare, output); 659 } 660 661 public void testRequestScopePropertyIterateEnumeration() 663 throws ServletException , JspException , IOException { 664 665 String testKey = "testRequestScopePropertyIterateEnumeration"; 666 667 StringTokenizer st = new StringTokenizer ("Request Scope Property Iterate Enumeration"); 668 669 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 670 sbft.setEnumeration(st); 671 672 pageContext.setAttribute(testKey, sbft, 673 PageContext.REQUEST_SCOPE); 674 675 IterateTag tag = new IterateTag(); 676 tag.setPageContext(pageContext); 677 tag.setId("theId"); 678 tag.setName(testKey); 679 tag.setScope("request"); 680 tag.setProperty("enumeration"); 681 682 tag.doStartTag(); 683 tag.doInitBody(); 684 do 685 { 686 out.print((String )pageContext.getAttribute("theId")); 687 688 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 689 tag.doEndTag(); 690 691 } 692 693 public void endRequestScopePropertyIterateEnumeration (WebResponse response){ 694 String output = response.getText(); 695 StringTokenizer st = new StringTokenizer ("Request Scope Property Iterate Enumeration"); 696 String compare = ""; 697 698 while (st.hasMoreTokens()) { 699 compare += st.nextToken(); 700 } 701 702 output = replace(compare,"\r",""); 704 output = replace(output,"\n",""); 705 706 assertEquals(compare, output); 707 } 708 709 710 711 712 713 722 723 public void testApplicationScopeNameIterateMap() 725 throws ServletException , JspException , IOException { 726 727 String testKey = "testApplicationScopeNameIterateMap"; 728 729 HashMap map = new HashMap (); 730 for (int i = 0; i < iterations; i++) { 731 map.put("test" + i,"test" + i); 732 } 733 734 pageContext.setAttribute(testKey, map, 735 PageContext.APPLICATION_SCOPE); 736 737 IterateTag tag = new IterateTag(); 738 tag.setPageContext(pageContext); 739 tag.setId("theId"); 740 tag.setName(testKey); 741 tag.setScope("application"); 742 743 int iteration = 0; 744 tag.doStartTag(); 745 tag.doInitBody(); 746 do 747 { 748 out.print(pageContext.getAttribute("theId")); 749 iteration++; 750 751 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 752 tag.doEndTag(); 753 assertEquals(iterations, iteration); 754 } 755 756 public void endApplicationScopeNameIterateMap (WebResponse response){ 757 String output = response.getText(); 758 String compare = ""; 759 for (int i = 0; i < iterations; i++) { 760 compare += "test" + i; 761 } 762 763 output = replace(compare,"\r",""); 765 output = replace(output,"\n",""); 766 767 assertEquals(compare, output); 768 } 769 770 public void testSessionScopeNameIterateMap() 772 throws ServletException , JspException , IOException { 773 774 String testKey = "testSessionScopeNameIterateMap"; 775 776 HashMap map = new HashMap (); 777 for (int i = 0; i < iterations; i++) { 778 map.put("test" + i,"test" + i); 779 } 780 781 pageContext.setAttribute(testKey, map, 782 PageContext.SESSION_SCOPE); 783 784 IterateTag tag = new IterateTag(); 785 tag.setPageContext(pageContext); 786 tag.setId("theId"); 787 tag.setName(testKey); 788 tag.setScope("session"); 789 790 int iteration = 0; 791 tag.doStartTag(); 792 tag.doInitBody(); 793 do 794 { 795 out.print(pageContext.getAttribute("theId")); 796 iteration++; 797 798 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 799 tag.doEndTag(); 800 assertEquals(iterations, iteration); 801 } 802 803 public void endSessionScopeNameIterateMap (WebResponse response){ 804 String output = response.getText(); 805 String compare = ""; 806 for (int i = 0; i < iterations; i++) { 807 compare += "test" + i; 808 } 809 810 output = replace(compare,"\r",""); 812 output = replace(output,"\n",""); 813 814 assertEquals(compare, output); 815 } 816 817 public void testRequestScopeNameIterateMap() 819 throws ServletException , JspException , IOException { 820 821 String testKey = "testRequestScopeNameIterateMap"; 822 823 HashMap map = new HashMap (); 824 for (int i = 0; i < iterations; i++) { 825 map.put("test" + i,"test" + i); 826 } 827 828 pageContext.setAttribute(testKey, map, 829 PageContext.REQUEST_SCOPE); 830 831 IterateTag tag = new IterateTag(); 832 tag.setPageContext(pageContext); 833 tag.setId("theId"); 834 tag.setName(testKey); 835 tag.setScope("request"); 836 837 int iteration = 0; 838 tag.doStartTag(); 839 tag.doInitBody(); 840 do 841 { 842 out.print(pageContext.getAttribute("theId")); 843 iteration++; 844 845 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 846 tag.doEndTag(); 847 assertEquals(iterations, iteration); 848 } 849 850 public void endRequestScopeNameIterateMap (WebResponse response){ 851 String output = response.getText(); 852 String compare = ""; 853 for (int i = 0; i < iterations; i++) { 854 compare += "test" + i; 855 } 856 857 output = replace(compare,"\r",""); 859 output = replace(output,"\n",""); 860 861 assertEquals(compare, output); 862 } 863 864 865 866 867 876 877 public void testApplicationScopePropertyIterateMap() 879 throws ServletException , JspException , IOException { 880 881 String testKey = "testApplicationScopePropertyIterateMap"; 882 883 HashMap map = new HashMap (); 884 for (int i = 0; i < iterations; i++) { 885 map.put("test" + i,"test" + i); 886 } 887 888 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 889 sbft.setMap(map); 890 891 pageContext.setAttribute(testKey, sbft, 892 PageContext.APPLICATION_SCOPE); 893 894 IterateTag tag = new IterateTag(); 895 tag.setPageContext(pageContext); 896 tag.setId("theId"); 897 tag.setName(testKey); 898 tag.setScope("application"); 899 tag.setProperty("map"); 900 901 int iteration = 0; 902 tag.doStartTag(); 903 tag.doInitBody(); 904 do 905 { 906 out.print(pageContext.getAttribute("theId")); 907 iteration++; 908 909 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 910 tag.doEndTag(); 911 assertEquals(iterations, iteration); 912 } 913 914 public void endApplicationScopePropertyIterateMap (WebResponse response){ 915 String output = response.getText(); 916 String compare = ""; 917 for (int i = 0; i < iterations; i++) { 918 compare += "test" + i; 919 } 920 921 output = replace(compare,"\r",""); 923 output = replace(output,"\n",""); 924 925 assertEquals(compare, output); 926 } 927 928 public void testSessionScopePropertyIterateMap() 930 throws ServletException , JspException , IOException { 931 932 String testKey = "testSessionScopePropertyIterateMap"; 933 934 HashMap map = new HashMap (); 935 for (int i = 0; i < iterations; i++) { 936 map.put("test" + i,"test" + i); 937 } 938 939 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 940 sbft.setMap(map); 941 942 pageContext.setAttribute(testKey, sbft, 943 PageContext.SESSION_SCOPE); 944 945 IterateTag tag = new IterateTag(); 946 tag.setPageContext(pageContext); 947 tag.setId("theId"); 948 tag.setName(testKey); 949 tag.setScope("session"); 950 tag.setProperty("map"); 951 952 int iteration = 0; 953 tag.doStartTag(); 954 tag.doInitBody(); 955 do 956 { 957 out.print(pageContext.getAttribute("theId")); 958 iteration++; 959 960 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 961 tag.doEndTag(); 962 assertEquals(iterations, iteration); 963 } 964 965 public void endSessionScopePropertyIterateMap (WebResponse response){ 966 String output = response.getText(); 967 String compare = ""; 968 for (int i = 0; i < iterations; i++) { 969 compare += "test" + i; 970 } 971 972 output = replace(compare,"\r",""); 974 output = replace(output,"\n",""); 975 976 assertEquals(compare, output); 977 } 978 979 public void testRequestScopePropertyIterateMap() 981 throws ServletException , JspException , IOException { 982 983 String testKey = "testRequestScopePropertyIterateMap"; 984 985 HashMap map = new HashMap (); 986 for (int i = 0; i < iterations; i++) { 987 map.put("test" + i,"test" + i); 988 } 989 990 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 991 sbft.setMap(map); 992 993 pageContext.setAttribute(testKey, sbft, 994 PageContext.REQUEST_SCOPE); 995 996 IterateTag tag = new IterateTag(); 997 tag.setPageContext(pageContext); 998 tag.setId("theId"); 999 tag.setName(testKey); 1000 tag.setScope("request"); 1001 tag.setProperty("map"); 1002 1003 int iteration = 0; 1004 tag.doStartTag(); 1005 tag.doInitBody(); 1006 do 1007 { 1008 out.print(pageContext.getAttribute("theId")); 1009 iteration++; 1010 1011 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 1012 tag.doEndTag(); 1013 assertEquals(iterations, iteration); 1014 } 1015 1016 public void endRequestScopePropertyIterateMap (WebResponse response){ 1017 String output = response.getText(); 1018 String compare = ""; 1019 for (int i = 0; i < iterations; i++) { 1020 compare += "test" + i; 1021 } 1022 1023 output = replace(compare,"\r",""); 1025 output = replace(output,"\n",""); 1026 1027 assertEquals(compare, output); 1028 } 1029 1030 1031 1032 1033 1034 1043 1044 public void testApplicationScopeNameIterateArray() 1046 throws ServletException , JspException , IOException { 1047 1048 String testKey = "testApplicationScopeNameIterateArray"; 1049 1050 String [] tst = new String [iterations]; 1051 for (int i = 0; i < tst.length; i++) { 1052 tst[i] = "test" + i; 1053 } 1054 1055 pageContext.setAttribute(testKey, tst, 1056 PageContext.APPLICATION_SCOPE); 1057 1058 IterateTag tag = new IterateTag(); 1059 tag.setPageContext(pageContext); 1060 tag.setId("theId"); 1061 tag.setName(testKey); 1062 tag.setScope("application"); 1063 1064 int iteration = 0; 1065 tag.doStartTag(); 1066 tag.doInitBody(); 1067 do 1068 { 1069 out.print(pageContext.getAttribute("theId")); 1070 iteration++; 1071 1072 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 1073 tag.doEndTag(); 1074 assertEquals(iterations, iteration); 1075 } 1076 1077 public void endApplicationScopeNameIterateArray (WebResponse response){ 1078 String output = response.getText(); 1079 String [] tst = new String [iterations]; 1080 for (int i = 0; i < tst.length; i++) { 1081 tst[i] = "test" + i; 1082 } 1083 1084 String compare = ""; 1085 for (int i = 0; i < iterations; i++) { 1086 compare += tst[i]; 1087 } 1088 1089 output = replace(compare,"\r",""); 1091 output = replace(output,"\n",""); 1092 1093 assertEquals(compare, output); 1094 } 1095 1096 public void testSessionScopeNameIterateArray() 1098 throws ServletException , JspException , IOException { 1099 1100 String testKey = "testSessionScopeNameIterateArray"; 1101 1102 String [] tst = new String [iterations]; 1103 for (int i = 0; i < tst.length; i++) { 1104 tst[i] = "test" + i; 1105 } 1106 1107 pageContext.setAttribute(testKey, tst, 1108 PageContext.SESSION_SCOPE); 1109 1110 IterateTag tag = new IterateTag(); 1111 tag.setPageContext(pageContext); 1112 tag.setId("theId"); 1113 tag.setName(testKey); 1114 tag.setScope("session"); 1115 1116 int iteration = 0; 1117 tag.doStartTag(); 1118 tag.doInitBody(); 1119 do 1120 { 1121 out.print(pageContext.getAttribute("theId")); 1122 iteration++; 1123 1124 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 1125 tag.doEndTag(); 1126 assertEquals(iterations, iteration); 1127 } 1128 1129 public void endSessionScopeNameIterateArray (WebResponse response){ 1130 String output = response.getText(); 1131 String [] tst = new String [iterations]; 1132 for (int i = 0; i < tst.length; i++) { 1133 tst[i] = "test" + i; 1134 } 1135 1136 String compare = ""; 1137 for (int i = 0; i < iterations; i++) { 1138 compare += tst[i]; 1139 } 1140 1141 output = replace(compare,"\r",""); 1143 output = replace(output,"\n",""); 1144 1145 assertEquals(compare, output); 1146 } 1147 1148 public void testRequestScopeNameIterateArray() 1150 throws ServletException , JspException , IOException { 1151 1152 String testKey = "testRequestScopeNameIterateArray"; 1153 1154 String [] tst = new String [iterations]; 1155 for (int i = 0; i < tst.length; i++) { 1156 tst[i] = "test" + i; 1157 } 1158 1159 pageContext.setAttribute(testKey, tst, 1160 PageContext.REQUEST_SCOPE); 1161 1162 IterateTag tag = new IterateTag(); 1163 tag.setPageContext(pageContext); 1164 tag.setId("theId"); 1165 tag.setName(testKey); 1166 tag.setScope("request"); 1167 1168 int iteration = 0; 1169 tag.doStartTag(); 1170 tag.doInitBody(); 1171 do 1172 { 1173 out.print(pageContext.getAttribute("theId")); 1174 iteration++; 1175 1176 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 1177 tag.doEndTag(); 1178 assertEquals(iterations, iteration); 1179 } 1180 1181 public void endRequestScopeNameIterateArray (WebResponse response){ 1182 String output = response.getText(); 1183 String [] tst = new String [iterations]; 1184 for (int i = 0; i < tst.length; i++) { 1185 tst[i] = "test" + i; 1186 } 1187 1188 String compare = ""; 1189 for (int i = 0; i < iterations; i++) { 1190 compare += tst[i]; 1191 } 1192 1193 output = replace(compare,"\r",""); 1195 output = replace(output,"\n",""); 1196 1197 assertEquals(compare, output); 1198 } 1199 1200 1201 1210 1211 public void testApplicationScopePropertyIterateArray() 1213 throws ServletException , JspException , IOException { 1214 1215 String testKey = "testApplicationScopePropertyIterateArray"; 1216 1217 String [] tst = new String [iterations]; 1218 for (int i = 0; i < tst.length; i++) { 1219 tst[i] = "test" + i; 1220 } 1221 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 1222 sbft.setArray(tst); 1223 1224 pageContext.setAttribute(testKey, sbft, 1225 PageContext.APPLICATION_SCOPE); 1226 1227 IterateTag tag = new IterateTag(); 1228 tag.setPageContext(pageContext); 1229 tag.setId("theId"); 1230 tag.setName(testKey); 1231 tag.setScope("application"); 1232 tag.setProperty("array"); 1233 1234 int iteration = 0; 1235 tag.doStartTag(); 1236 tag.doInitBody(); 1237 do 1238 { 1239 out.print(pageContext.getAttribute("theId")); 1240 iteration++; 1241 1242 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 1243 tag.doEndTag(); 1244 assertEquals(iterations, iteration); 1245 } 1246 1247 public void endApplicationScopePropertyIterateArray (WebResponse response){ 1248 String output = response.getText(); 1249 String [] tst = new String [iterations]; 1250 for (int i = 0; i < tst.length; i++) { 1251 tst[i] = "test" + i; 1252 } 1253 1254 String compare = ""; 1255 for (int i = 0; i < iterations; i++) { 1256 compare += tst[i]; 1257 } 1258 1259 output = replace(compare,"\r",""); 1261 output = replace(output,"\n",""); 1262 1263 assertEquals(compare, output); 1264 } 1265 1266 public void testSessionScopePropertyIterateArray() 1268 throws ServletException , JspException , IOException { 1269 1270 String testKey = "testSessionScopePropertyIterateArray"; 1271 1272 String [] tst = new String [iterations]; 1273 for (int i = 0; i < tst.length; i++) { 1274 tst[i] = "test" + i; 1275 } 1276 1277 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 1278 sbft.setArray(tst); 1279 1280 pageContext.setAttribute(testKey, sbft, 1281 PageContext.SESSION_SCOPE); 1282 1283 IterateTag tag = new IterateTag(); 1284 tag.setPageContext(pageContext); 1285 tag.setId("theId"); 1286 tag.setName(testKey); 1287 tag.setScope("session"); 1288 tag.setProperty("array"); 1289 1290 int iteration = 0; 1291 tag.doStartTag(); 1292 tag.doInitBody(); 1293 do 1294 { 1295 out.print(pageContext.getAttribute("theId")); 1296 iteration++; 1297 1298 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 1299 tag.doEndTag(); 1300 assertEquals(iterations, iteration); 1301 } 1302 1303 public void endSessionScopePropertyIterateArray (WebResponse response){ 1304 String output = response.getText(); 1305 String [] tst = new String [iterations]; 1306 for (int i = 0; i < tst.length; i++) { 1307 tst[i] = "test" + i; 1308 } 1309 1310 String compare = ""; 1311 for (int i = 0; i < iterations; i++) { 1312 compare += tst[i]; 1313 } 1314 1315 output = replace(compare,"\r",""); 1317 output = replace(output,"\n",""); 1318 1319 assertEquals(compare, output); 1320 } 1321 1322 public void testRequestScopePropertyIterateArray() 1324 throws ServletException , JspException , IOException { 1325 1326 String testKey = "testRequestScopePropertyIterateArray"; 1327 1328 String [] tst = new String [iterations]; 1329 for (int i = 0; i < tst.length; i++) { 1330 tst[i] = "test" + i; 1331 } 1332 1333 SimpleBeanForTesting sbft = new SimpleBeanForTesting(); 1334 sbft.setArray(tst); 1335 1336 pageContext.setAttribute(testKey, sbft, 1337 PageContext.REQUEST_SCOPE); 1338 1339 IterateTag tag = new IterateTag(); 1340 tag.setPageContext(pageContext); 1341 tag.setId("theId"); 1342 tag.setName(testKey); 1343 tag.setScope("request"); 1344 tag.setProperty("array"); 1345 1346 int iteration = 0; 1347 tag.doStartTag(); 1348 tag.doInitBody(); 1349 do 1350 { 1351 out.print(pageContext.getAttribute("theId")); 1352 iteration++; 1353 1354 } while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG); 1355 tag.doEndTag(); 1356 assertEquals(iterations, iteration); 1357 } 1358 1359 public void endRequestScopePropertyIterateArray (WebResponse response){ 1360 String output = response.getText(); 1361 String [] tst = new String [iterations]; 1362 for (int i = 0; i < tst.length; i++) { 1363 tst[i] = "test" + i; 1364 } 1365 1366 String compare = ""; 1367 for (int i = 0; i < iterations; i++) { 1368 compare += tst[i]; 1369 } 1370 1371 output = replace(compare,"\r",""); 1373 output = replace(output,"\n",""); 1374 1375 assertEquals(compare, output); 1376 } 1377 1378 1379} 1380 | Popular Tags |