FileDocCategorySizeDatePackage
SubsetIteratorTagTest.javaAPI DocExample10302Mon Jul 23 13:26:16 BST 2007org.apache.struts2.views.jsp

SubsetIteratorTagTest

public class SubsetIteratorTagTest extends AbstractTagTest
Test case for SubsetIteratorTag.

Fields Summary
Constructors Summary
Methods Summary
public com.opensymphony.xwork2.ActiongetAction()

        return new ActionSupport() {
            public List getMyList() {
                List l = new ArrayList();
                l.add(new Integer(1));
                l.add(new Integer(2));
                l.add(new Integer(3));
                l.add(new Integer(4));
                l.add(new Integer(5));
                return l;
            }

            public Integer[] getMyArray() {
                Integer[] integers = new Integer[5];
                integers[0] = new Integer(1);
                integers[1] = new Integer(2);
                integers[2] = new Integer(3);
                integers[3] = new Integer(4);
                integers[4] = new Integer(5);
                return integers;
            }

            public Decider getMyDecider() {
                return new Decider() {
                    public boolean decide(Object element) throws Exception {
                        int integer = ((Integer)element).intValue();
                        return (((integer % 2) == 0)?true:false);
                    }
                };
            }
        };
    
public voidtestBasic()

        { // List as Source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myList");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer(1));
            assertEquals(subsetIterator.next(), new Integer(2));
            assertEquals(subsetIterator.next(), new Integer(3));
            assertEquals(subsetIterator.next(), new Integer(4));
            assertEquals(subsetIterator.next(), new Integer(5));
        }

        { // Array as Source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myArray");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer(1));
            assertEquals(subsetIterator.next(), new Integer(2));
            assertEquals(subsetIterator.next(), new Integer(3));
            assertEquals(subsetIterator.next(), new Integer(4));
            assertEquals(subsetIterator.next(), new Integer(5));
        }
    
public voidtestWIthStartAndCountAttribute()

        { // List as source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myList");
            tag.setStart("3");
            tag.setCount("3");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer("4"));
            assertEquals(subsetIterator.next(), new Integer("5"));
        }

        {   // Array as source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myArray");
            tag.setStart("3");
            tag.setCount("3");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer("4"));
            assertEquals(subsetIterator.next(), new Integer("5"));
        }
    
public voidtestWithCountAttribute()

        { // List as source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myList");
            tag.setCount("3");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer(1));
            assertEquals(subsetIterator.next(), new Integer(2));
            assertEquals(subsetIterator.next(), new Integer(3));
        }

        { // array as source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myArray");
            tag.setCount("3");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer(1));
            assertEquals(subsetIterator.next(), new Integer(2));
            assertEquals(subsetIterator.next(), new Integer(3));
        }
    
public voidtestWithDecider()

        {   // List as source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myList");
            tag.setDecider("myDecider");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer(2));
            assertEquals(subsetIterator.next(), new Integer(4));
        }

        {   // Array As source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myList");
            tag.setDecider("myDecider");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer(2));
            assertEquals(subsetIterator.next(), new Integer(4));
        }
    
public voidtestWithId()

        {   // List as Source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myList");
            tag.setId("myPageContextId1");

            tag.doStartTag();
            Iterator subsetIterator1 = (Iterator) stack.findValue("top");
            tag.doEndTag();

            Iterator subsetIterator2 = (Iterator) pageContext.getAttribute("myPageContextId1");

            assertNotNull(subsetIterator1);
            assertNotNull(subsetIterator2);
            assertEquals(subsetIterator1, subsetIterator2);
            assertEquals(subsetIterator2.next(), new Integer(1));
            assertEquals(subsetIterator2.next(), new Integer(2));
            assertEquals(subsetIterator2.next(), new Integer(3));
            assertEquals(subsetIterator2.next(), new Integer(4));
            assertEquals(subsetIterator2.next(), new Integer(5));
        }

        {   // Array as source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myArray");
            tag.setId("myPageContextId2");

            tag.doStartTag();
            Iterator subsetIterator1 = (Iterator) stack.findValue("top");
            tag.doEndTag();

            Iterator subsetIterator2 = (Iterator) pageContext.getAttribute("myPageContextId2");

            assertNotNull(subsetIterator1);
            assertNotNull(subsetIterator2);
            assertEquals(subsetIterator1, subsetIterator2);
            assertEquals(subsetIterator2.next(), new Integer(1));
            assertEquals(subsetIterator2.next(), new Integer(2));
            assertEquals(subsetIterator2.next(), new Integer(3));
            assertEquals(subsetIterator2.next(), new Integer(4));
            assertEquals(subsetIterator2.next(), new Integer(5));
        }
    
public voidtestWithStartAttribute()

        { // List as source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myList");
            tag.setStart("3");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer(4));
            assertEquals(subsetIterator.next(), new Integer(5));
        }

        { // Array as source
            SubsetIteratorTag tag = new SubsetIteratorTag();
            tag.setPageContext(pageContext);
            tag.setSource("myArray");
            tag.setStart("3");

            tag.doStartTag();
            Iterator subsetIterator = (Iterator) stack.findValue("top");
            tag.doEndTag();

            assertEquals(subsetIterator.next(), new Integer(4));
            assertEquals(subsetIterator.next(), new Integer(5));
        }