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

ElseTagTest

public class ElseTagTest extends org.apache.struts2.StrutsTestCase

Fields Summary
ElseTag
elseTag
com.mockobjects.servlet.MockPageContext
pageContext
com.opensymphony.xwork2.util.ValueStack
stack
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        // create the needed objects
        elseTag = new ElseTag();
        stack = ValueStackFactory.getFactory().createValueStack();

        // create the mock http servlet request
        StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();

        // NOTE: in Struts Tag library, TagUtil gets stack from request, which will be set
        //       when request going through the FilterDispatcher --> DispatcherUtil etc. route
        request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);

        StrutsMockServletContext servletContext = new StrutsMockServletContext();
        servletContext.setServletInfo("not-weblogic");

        // create the mock page context
        pageContext = new StrutsMockPageContext();
        pageContext.setRequest(request);
        pageContext.setServletContext(servletContext);
        pageContext.setJspWriter(new MockJspWriter());
    
public voidtestTestFalse()

        stack.getContext().put(If.ANSWER, new Boolean(false));

        int result = 0;

        try {
            elseTag.setPageContext(pageContext);
            result = elseTag.doStartTag();
            elseTag.doEndTag();
        } catch (JspException e) {
            e.printStackTrace();
            fail();
        }
        assertEquals(TagSupport.EVAL_BODY_INCLUDE, result);
    
public voidtestTestNull()

        elseTag.setPageContext(pageContext);

        int result = 0;

        try {
            result = elseTag.doStartTag();
        } catch (JspException e) {
            e.printStackTrace();
            fail();
        }

        assertEquals(TagSupport.SKIP_BODY, result);
    
public voidtestTestTrue()

        stack.getContext().put(If.ANSWER, new Boolean(true));
        elseTag.setPageContext(pageContext);

        int result = 0;

        try {
            result = elseTag.doStartTag();
        } catch (JspException e) {
            e.printStackTrace();
            fail();
        }

        assertEquals(TagSupport.SKIP_BODY, result);