SubsetIteratorTagTestpublic class SubsetIteratorTagTest extends AbstractTagTest Test case for SubsetIteratorTag. |
Methods Summary |
---|
public com.opensymphony.xwork2.Action | getAction()
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 void | testBasic()
{ // 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 void | testWIthStartAndCountAttribute()
{ // 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 void | testWithCountAttribute()
{ // 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 void | testWithDecider()
{ // 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 void | testWithId()
{ // 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 void | testWithStartAttribute()
{ // 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));
}
|
|