ComponentTestpublic class ComponentTest extends org.apache.struts2.views.jsp.AbstractTagTest Test case for method findAncestor(Class) in Component and some commons
test cases for Component in general. |
Methods Summary |
---|
public void | testAppendIteratorDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
AppendIteratorTag tag = new AppendIteratorTag();
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testBeanComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
BeanTag tag = new BeanTag();
tag.setName("org.apache.struts2.util.Counter");
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail();
}
| public void | testElseComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
ElseTag tag = new ElseTag();
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testElseIfComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
ElseIfTag tag = new ElseIfTag();
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testFindAncestorTest()
Property property = new Property(stack);
Form form = new Form(stack, request, response);
ActionComponent actionComponent = new ActionComponent(stack, request, response);
Anchor anchor = new Anchor(stack, request, response);
Form form2 = new Form(stack, request, response);
TextField textField = new TextField(stack, request, response);
Stack stack = property.getComponentStack();
Iterator i = stack.iterator();
try {
// component stack
assertEquals(property.getComponentStack().size(), 6);
assertEquals(i.next(), property);
assertEquals(i.next(), form);
assertEquals(i.next(), actionComponent);
assertEquals(i.next(), anchor);
assertEquals(i.next(), form2);
assertEquals(i.next(), textField);
// property
assertNull(property.findAncestor(Component.class));
// form
assertEquals(form.findAncestor(Component.class), property);
assertEquals(form.findAncestor(Property.class), property);
// action
assertEquals(actionComponent.findAncestor(Component.class), form);
assertEquals(actionComponent.findAncestor(Property.class), property);
assertEquals(actionComponent.findAncestor(Form.class), form);
// anchor
assertEquals(anchor.findAncestor(Component.class), actionComponent);
assertEquals(anchor.findAncestor(ActionComponent.class), actionComponent);
assertEquals(anchor.findAncestor(Form.class), form);
assertEquals(anchor.findAncestor(Property.class), property);
// form2
assertEquals(form2.findAncestor(Component.class), anchor);
assertEquals(form2.findAncestor(Anchor.class), anchor);
assertEquals(form2.findAncestor(ActionComponent.class), actionComponent);
assertEquals(form2.findAncestor(Form.class), form);
assertEquals(form2.findAncestor(Property.class), property);
// textField
assertEquals(textField.findAncestor(Component.class), form2);
assertEquals(textField.findAncestor(Form.class), form2);
assertEquals(textField.findAncestor(Anchor.class), anchor);
assertEquals(textField.findAncestor(ActionComponent.class), actionComponent);
assertEquals(textField.findAncestor(Property.class), property);
}
finally {
property.getComponentStack().pop();
property.getComponentStack().pop();
property.getComponentStack().pop();
property.getComponentStack().pop();
property.getComponentStack().pop();
}
| public void | testI18nComponentDisposeItselfFromComponentStack()
stack.getContext().put(ActionContext.LOCALE, Locale.getDefault());
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
LocalizedTextUtil.addDefaultResourceBundle("org.apache.struts2.components.temp");
I18nTag tag = new I18nTag();
tag.setName("org.apache.struts2.components.tempo");
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testIfComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
IfTag tag = new IfTag();
tag.setTest("false");
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testIteratorComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
IteratorTag tag = new IteratorTag();
tag.setValue("{1,2}");
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
int endIt = tag.doAfterBody();
while(TagSupport.EVAL_BODY_AGAIN == endIt) {
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
endIt = tag.doAfterBody();
}
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testMergeIteratorComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
MergeIteratorTag tag = new MergeIteratorTag();
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testPropertyComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
PropertyTag tag = new PropertyTag();
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testPushComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
PushTag tag = new PushTag();
tag.setValue("'aaaa'");
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testSetComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
SetTag tag = new SetTag();
tag.setName("name");
tag.setValue("'value'");
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testTextComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
TextTag tag = new TextTag();
tag.setName("some.i18n.key");
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testURLComponentDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
URLTag tag = new URLTag();
tag.setPageContext(pageContext);
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
| public void | testUpDownSelectDisposeItselfFromComponentStack()
TextFieldTag t = new TextFieldTag();
t.setPageContext(pageContext);
t.setName("textFieldName");
UpDownSelectTag tag = new UpDownSelectTag();
tag.setId("myId");
tag.setPageContext(pageContext);
tag.setName("updownselectName");
tag.setList("{}");
try {
t.doStartTag();
tag.doStartTag();
assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
tag.doEndTag();
assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
t.doEndTag();
}
catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
|
|