IteratorGeneratorTagTestpublic class IteratorGeneratorTagTest extends AbstractTagTest Test case for IteratorGeneratorTag. |
Methods Summary |
---|
public com.opensymphony.xwork2.Action | getAction()
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 void | testGeneratorBasic()
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 void | testGeneratorWithConverter()
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 void | testGeneratorWithCount()
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 void | testGeneratorWithId()
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 void | testGeneratorWithSeparator()
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);
|
|