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

IteratorGeneratorTagTest

public class IteratorGeneratorTagTest extends AbstractTagTest
Test case for IteratorGeneratorTag.

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

        return new ActionSupport() {
            public Converter getMyConverter() {
                return new Converter() {
                    public Object convert(String value) throws Exception {
                        return "myConverter-"+value;
                    }
                };
            }

            public int getMyCount() {
                return 3;
            }
        };
    
public voidtestGeneratorBasic()

        IteratorGeneratorTag tag = new IteratorGeneratorTag();

        tag.setPageContext(pageContext);
        tag.setVal("%{'aaa,bbb,ccc,ddd,eee'}");
        tag.doStartTag();
        Object topOfStack = stack.findValue("top");


        assertTrue(topOfStack instanceof Iterator);
        // 1
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "aaa");
        // 2
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "bbb");
        // 3
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "ccc");
        // 4
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "ddd");
        // 5
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(),"eee");

        assertFalse(((Iterator)topOfStack).hasNext());

        tag.doEndTag();
        Object afterTopOfStack = stack.findValue("top");


        assertNotSame(afterTopOfStack, topOfStack);
    
public voidtestGeneratorWithConverter()

        IteratorGeneratorTag tag = new IteratorGeneratorTag();

        tag.setPageContext(pageContext);
        tag.setVal("%{'aaa, bbb, ccc, ddd, eee'}");
        tag.setConverter("myConverter");
        tag.doStartTag();
        Object topOfStack = stack.findValue("top");
        tag.doEndTag();
        Object afterTopOfStack = stack.findValue("top");

        assertTrue(topOfStack instanceof Iterator);
        // 1.
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "myConverter-aaa");
        // 2
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "myConverter-bbb");
        // 3
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "myConverter-ccc");
        // 4.
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "myConverter-ddd");
        // 5.
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "myConverter-eee");

        assertFalse(((Iterator)topOfStack).hasNext());
        assertNotSame(afterTopOfStack, topOfStack);
    
public voidtestGeneratorWithCount()

        IteratorGeneratorTag tag = new IteratorGeneratorTag();

        tag.setPageContext(pageContext);
        tag.setVal("%{'aaa,bbb,ccc,ddd,eee'}");
        tag.setCount("myCount");
        tag.doStartTag();
        Object topOfStack = stack.findValue("top");
        tag.doEndTag();
        Object afterTopOfStack = stack.findValue("top");


        assertTrue(topOfStack instanceof Iterator);
        // 1
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "aaa");
        // 2
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "bbb");
        // 3.
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "ccc");

        assertFalse(((Iterator)topOfStack).hasNext());
        assertNotSame(topOfStack, afterTopOfStack);
    
public voidtestGeneratorWithId()

        IteratorGeneratorTag tag = new IteratorGeneratorTag();
        tag.setPageContext(pageContext);
        tag.setVal("%{'aaa,bbb,ccc,ddd,eee'}");
        tag.setId("myPageContextAttId");
        tag.doStartTag();
        tag.doEndTag();

        Object pageContextIterator = pageContext.getAttribute("myPageContextAttId");

        assertTrue(pageContextIterator instanceof Iterator);
        // 1
        assertTrue(((Iterator)pageContextIterator).hasNext());
        assertEquals(((Iterator)pageContextIterator).next(), "aaa");
        // 2.
        assertTrue(((Iterator)pageContextIterator).hasNext());
        assertEquals(((Iterator)pageContextIterator).next(), "bbb");
        // 3.
        assertTrue(((Iterator)pageContextIterator).hasNext());
        assertEquals(((Iterator)pageContextIterator).next(), "ccc");
        // 4
        assertTrue(((Iterator)pageContextIterator).hasNext());
        assertEquals(((Iterator)pageContextIterator).next(), "ddd");
        // 5
        assertTrue(((Iterator)pageContextIterator).hasNext());
        assertEquals(((Iterator)pageContextIterator).next(), "eee");

        assertFalse(((Iterator)pageContextIterator).hasNext());
    
public voidtestGeneratorWithSeparator()

        IteratorGeneratorTag tag = new IteratorGeneratorTag();

        tag.setPageContext(pageContext);
        tag.setVal("%{'aaa|bbb|ccc|ddd|eee'}");
        tag.setSeparator("|");
        tag.doStartTag();
        Object topOfStack = stack.findValue("top");
        tag.doEndTag();
        Object afterTopOfStack = stack.findValue("top");

        assertTrue(topOfStack instanceof Iterator);
        // 1
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "aaa");
        // 2
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "bbb");
        // 3
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "ccc");
        // 4
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "ddd");
        // 5
        assertTrue(((Iterator)topOfStack).hasNext());
        assertEquals(((Iterator)topOfStack).next(), "eee");

        assertFalse(((Iterator)topOfStack).hasNext());
        assertNotSame(afterTopOfStack, topOfStack);