Search in sources :

Example 1 with MockJspWriter

use of com.mockobjects.servlet.MockJspWriter in project struts by apache.

the class ElseIfTagTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    stack = ActionContext.getContext().getValueStack();
    jspWriter = new MockJspWriter();
    StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
    StrutsMockServletContext servletContext = new StrutsMockServletContext();
    servletContext.setServletInfo("not-weblogic");
    pageContext = new MockPageContext();
    pageContext.setJspWriter(jspWriter);
    pageContext.setRequest(request);
    pageContext.setServletContext(servletContext);
    request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
}
Also used : MockJspWriter(com.mockobjects.servlet.MockJspWriter) MockPageContext(com.mockobjects.servlet.MockPageContext)

Example 2 with MockJspWriter

use of com.mockobjects.servlet.MockJspWriter in project struts by apache.

the class TextTagTest method testDefaultMessageOk.

public void testDefaultMessageOk() throws Exception {
    // NOTE:
    // simulate the condition
    // <s:text name="some.invalid.key">My Default Message</s:text>
    StrutsMockBodyContent mockBodyContent = new StrutsMockBodyContent(new MockJspWriter());
    mockBodyContent.setString("Sample Of Default Message");
    tag.setBodyContent(mockBodyContent);
    tag.setName("some.invalid.key.so.we.should.get.the.default.message");
    int startStatus = tag.doStartTag();
    tag.doEndTag();
    assertEquals(startStatus, BodyTag.EVAL_BODY_BUFFERED);
    assertEquals("Sample Of Default Message", writer.toString());
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    TextTag freshTag = new TextTag();
    freshTag.setPageContext(pageContext);
    assertFalse("Tag state after doEndTag() under default tag clear state is equal to new Tag with pageContext/parent set.  " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
Also used : MockJspWriter(com.mockobjects.servlet.MockJspWriter)

Example 3 with MockJspWriter

use of com.mockobjects.servlet.MockJspWriter in project struts by apache.

the class TextTagTest method testDefaultMessageOk_clearTagStateSet.

public void testDefaultMessageOk_clearTagStateSet() throws Exception {
    // NOTE:
    // simulate the condition
    // <s:text name="some.invalid.key">My Default Message</s:text>
    StrutsMockBodyContent mockBodyContent = new StrutsMockBodyContent(new MockJspWriter());
    mockBodyContent.setString("Sample Of Default Message");
    // Explicitly request tag state clearing.
    tag.setPerformClearTagStateForTagPoolingServers(true);
    tag.setBodyContent(mockBodyContent);
    tag.setName("some.invalid.key.so.we.should.get.the.default.message");
    int startStatus = tag.doStartTag();
    // Ensure component tag state clearing is set true (to match tag).
    setComponentTagClearTagState(tag, true);
    tag.doEndTag();
    assertEquals(startStatus, BodyTag.EVAL_BODY_BUFFERED);
    assertEquals("Sample Of Default Message", writer.toString());
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    TextTag freshTag = new TextTag();
    freshTag.setPerformClearTagStateForTagPoolingServers(true);
    freshTag.setPageContext(pageContext);
    assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set.  " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
Also used : MockJspWriter(com.mockobjects.servlet.MockJspWriter)

Example 4 with MockJspWriter

use of com.mockobjects.servlet.MockJspWriter in project struts by apache.

the class IfTagTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // create the needed objects
    tag = new IfTag();
    stack = ActionContext.getContext().getValueStack();
    // create the mock http servlet request
    StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
    request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
    // create the mock page context
    pageContext = new MockPageContext();
    pageContext.setRequest(request);
    pageContext.setJspWriter(new MockJspWriter());
    // associate the tag with the mock page request
    tag.setPageContext(pageContext);
}
Also used : MockPageContext(com.mockobjects.servlet.MockPageContext) MockJspWriter(com.mockobjects.servlet.MockJspWriter)

Example 5 with MockJspWriter

use of com.mockobjects.servlet.MockJspWriter in project struts by apache.

the class PropertyTagTest method testDefaultValue_clearTagStateSet.

public void testDefaultValue_clearTagStateSet() {
    PropertyTag tag = new PropertyTag();
    Foo foo = new Foo();
    stack.push(foo);
    MockJspWriter jspWriter = new MockJspWriter();
    jspWriter.setExpectedData("TEST");
    MockPageContext pageContext = new MockPageContext();
    pageContext.setJspWriter(jspWriter);
    pageContext.setRequest(request);
    // Explicitly request tag state clearing.
    tag.setPerformClearTagStateForTagPoolingServers(true);
    tag.setPageContext(pageContext);
    tag.setValue("title");
    tag.setDefault("TEST");
    try {
        tag.doStartTag();
        // Ensure component tag state clearing is set true (to match tag).
        setComponentTagClearTagState(tag, true);
    } catch (JspException e) {
        e.printStackTrace();
        fail();
    }
    request.verify();
    jspWriter.verify();
    pageContext.verify();
    try {
        tag.doEndTag();
    } catch (JspException e) {
        e.printStackTrace();
        fail();
    }
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    PropertyTag freshTag = new PropertyTag();
    freshTag.setPerformClearTagStateForTagPoolingServers(true);
    freshTag.setPageContext(pageContext);
    assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set.  " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", objectsAreReflectionEqual(tag, freshTag));
}
Also used : JspException(javax.servlet.jsp.JspException) MockJspWriter(com.mockobjects.servlet.MockJspWriter) MockPageContext(com.mockobjects.servlet.MockPageContext)

Aggregations

MockJspWriter (com.mockobjects.servlet.MockJspWriter)34 MockPageContext (com.mockobjects.servlet.MockPageContext)27 JspException (javax.servlet.jsp.JspException)10 ParamTag (org.apache.struts2.views.jsp.ParamTag)2 StrutsMockBodyContent (org.apache.struts2.views.jsp.StrutsMockBodyContent)2 MockBodyContent (com.mockobjects.servlet.MockBodyContent)1 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)1 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 HashMap (java.util.HashMap)1 PortletContext (javax.portlet.PortletContext)1 PortletMode (javax.portlet.PortletMode)1 PortletURL (javax.portlet.PortletURL)1 RenderRequest (javax.portlet.RenderRequest)1 RenderResponse (javax.portlet.RenderResponse)1 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 PageContext (javax.servlet.jsp.PageContext)1 Dispatcher (org.apache.struts2.dispatcher.Dispatcher)1 ActionMapping (org.apache.struts2.dispatcher.mapper.ActionMapping)1