FileDocCategorySizeDatePackage
ComponentTest.javaAPI DocExample3852Mon Jul 23 13:26:16 BST 2007org.apache.struts2.views.jsp.ui

ComponentTest

public class ComponentTest extends org.apache.struts2.views.jsp.AbstractUITagTest

Fields Summary
Constructors Summary
Methods Summary
public voidtestIdIsEvaluatedAgainstStack1()
Test that id attribute is evaludated against the Ognl Stack.

throws
Exception

        TestAction testAction = (TestAction) action;
        testAction.setFoo("myFooValue");

        TextFieldTag tag = new TextFieldTag();
        tag.setPageContext(pageContext);
        tag.setLabel("mylabel");
        tag.setName("myname");
        tag.setValue("foo");
        tag.setId("%{foo}");

        tag.doStartTag();
        tag.doEndTag();

        verify(ComponentTag.class.getResource("Component-2.txt"));
    
public voidtestIdIsEvaludatedAgainstStack2()

        TestAction testAction = (TestAction) action;
        testAction.setFoo("myFooValue");

        TextFieldTag tag = new TextFieldTag();
        tag.setPageContext(pageContext);
        tag.setLabel("mylabel");
        tag.setName("myname");
        tag.setValue("foo");
        tag.setId("foo");

        tag.doStartTag();
        tag.doEndTag();

        verify(ComponentTag.class.getResource("Component-3.txt"));
    
public voidtestSimple()
Note -- this test uses empty.vm, so it's basically clear

        TestAction testAction = (TestAction) action;
        testAction.setFoo("bar");

        ComponentTag tag = new ComponentTag();
        tag.setPageContext(pageContext);
        tag.setLabel("mylabel");
        tag.setName("myname");
        tag.setValue("foo");

        tag.doStartTag();
        tag.doEndTag();

        verify(ComponentTag.class.getResource("Component-1.txt"));
    
public voidtestWithParam()
executes a component test passing in a custom parameter. it also executes calling a custom template using an absolute reference.

        TestAction testAction = (TestAction) action;
        testAction.setFoo("bar");

        ComponentTag tag = new ComponentTag();
        tag.setPageContext(pageContext);
        tag.setLabel("mylabel");
        tag.setName("myname");
        tag.setValue("foo");
        tag.setTheme("test");
        tag.setTemplate("Component");

        tag.doStartTag();
        tag.getComponent().addParameter("hello", "world");
        tag.getComponent().addParameter("argle", "bargle");
        tag.getComponent().addParameter("glip", "glop");
        tag.getComponent().addParameter("array", new String[]{"a", "b", "c"});
        tag.getComponent().addParameter("obj", tag);
        tag.doEndTag();

        //        System.out.println(writer);
        verify(ComponentTag.class.getResource("Component-param.txt"));