Search in sources :

Example 1 with TestAction

use of org.apache.struts2.TestAction in project struts by apache.

the class ActionTagTest method testActionTagWithNamespace.

public void testActionTagWithNamespace() {
    request.setupGetServletPath(TestConfigurationProvider.TEST_NAMESPACE + "/" + "foo.action");
    ActionTag tag = new ActionTag();
    tag.setPageContext(pageContext);
    tag.setName(TestConfigurationProvider.TEST_NAMESPACE_ACTION);
    tag.setVar(TestConfigurationProvider.TEST_NAMESPACE_ACTION);
    try {
        tag.doStartTag();
        ActionComponent ac = ((ActionComponent) tag.component);
        tag.doEndTag();
        ActionProxy proxy = ac.getProxy();
        Object o = pageContext.findAttribute(TestConfigurationProvider.TEST_NAMESPACE_ACTION);
        assertTrue(o instanceof TestAction);
        assertEquals(TestConfigurationProvider.TEST_NAMESPACE, proxy.getNamespace());
    } catch (JspException ex) {
        ex.printStackTrace();
        fail();
    }
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    ActionTag freshTag = new ActionTag();
    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 : JspException(javax.servlet.jsp.JspException) ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionComponent(org.apache.struts2.components.ActionComponent) TestAction(org.apache.struts2.TestAction)

Example 2 with TestAction

use of org.apache.struts2.TestAction in project struts by apache.

the class ActionTagTest method testSimpleWithctionMethodInOriginalURI_clearTagStateSet.

public void testSimpleWithctionMethodInOriginalURI_clearTagStateSet() {
    request.setupGetServletPath("/foo!foo.action");
    ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", "testAction");
    container.inject(config.getInterceptors().get(0).getInterceptor());
    ActionTag tag = new ActionTag();
    // Explicitly request tag state clearing.
    tag.setPerformClearTagStateForTagPoolingServers(true);
    tag.setPageContext(pageContext);
    tag.setName("testAction");
    tag.setVar("testAction");
    int stackSize = stack.size();
    try {
        tag.doStartTag();
        // Ensure component tag state clearing is set true (to match tag).
        setComponentTagClearTagState(tag, true);
        tag.addParameter("foo", "myFoo");
        tag.doEndTag();
        assertEquals(stack.size(), ActionContext.getContext().getValueStack().size());
        assertEquals("myFoo", stack.findValue("#testAction.foo"));
        assertEquals(stackSize, stack.size());
        Object o = pageContext.findAttribute("testAction");
        assertTrue(o instanceof TestAction);
        assertEquals("myFoo", ((TestAction) o).getFoo());
        assertEquals(Action.SUCCESS, ((TestAction) o).getResult());
    } catch (JspException ex) {
        ex.printStackTrace();
        fail();
    }
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    ActionTag freshTag = new ActionTag();
    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 : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) JspException(javax.servlet.jsp.JspException) TestAction(org.apache.struts2.TestAction)

Example 3 with TestAction

use of org.apache.struts2.TestAction in project struts by apache.

the class ActionTagTest method testSimple.

public void testSimple() {
    request.setupGetServletPath("/foo.action");
    ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", "testAction");
    container.inject(config.getInterceptors().get(0).getInterceptor());
    ActionTag tag = new ActionTag();
    tag.setPageContext(pageContext);
    tag.setName("testAction");
    tag.setVar("testAction");
    int stackSize = stack.size();
    try {
        tag.doStartTag();
        tag.addParameter("foo", "myFoo");
        tag.doEndTag();
        assertEquals(stack.size(), ActionContext.getContext().getValueStack().size());
        assertEquals("myFoo", stack.findValue("#testAction.foo"));
        assertEquals(stackSize, stack.size());
        Object o = pageContext.findAttribute("testAction");
        assertTrue(o instanceof TestAction);
        assertEquals("myFoo", ((TestAction) o).getFoo());
        assertEquals(Action.SUCCESS, ((TestAction) o).getResult());
    } catch (JspException ex) {
        ex.printStackTrace();
        fail();
    }
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    ActionTag freshTag = new ActionTag();
    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 : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) JspException(javax.servlet.jsp.JspException) TestAction(org.apache.struts2.TestAction)

Example 4 with TestAction

use of org.apache.struts2.TestAction in project struts by apache.

the class ActionTagTest method testSimple_clearTagStateSet.

public void testSimple_clearTagStateSet() {
    request.setupGetServletPath("/foo.action");
    ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", "testAction");
    container.inject(config.getInterceptors().get(0).getInterceptor());
    ActionTag tag = new ActionTag();
    // Explicitly request tag state clearing.
    tag.setPerformClearTagStateForTagPoolingServers(true);
    tag.setPageContext(pageContext);
    tag.setName("testAction");
    tag.setVar("testAction");
    int stackSize = stack.size();
    try {
        tag.doStartTag();
        // Ensure component tag state clearing is set true (to match tag).
        setComponentTagClearTagState(tag, true);
        tag.addParameter("foo", "myFoo");
        tag.doEndTag();
        assertEquals(stack.size(), ActionContext.getContext().getValueStack().size());
        assertEquals("myFoo", stack.findValue("#testAction.foo"));
        assertEquals(stackSize, stack.size());
        Object o = pageContext.findAttribute("testAction");
        assertTrue(o instanceof TestAction);
        assertEquals("myFoo", ((TestAction) o).getFoo());
        assertEquals(Action.SUCCESS, ((TestAction) o).getResult());
    } catch (JspException ex) {
        ex.printStackTrace();
        fail();
    }
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    ActionTag freshTag = new ActionTag();
    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 : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) JspException(javax.servlet.jsp.JspException) TestAction(org.apache.struts2.TestAction)

Example 5 with TestAction

use of org.apache.struts2.TestAction in project struts by apache.

the class ActionTagTest method testSimpleWithActionMethodInOriginalURI.

public void testSimpleWithActionMethodInOriginalURI() {
    request.setupGetServletPath("/foo!foo.action");
    ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", "testAction");
    container.inject(config.getInterceptors().get(0).getInterceptor());
    ActionTag tag = new ActionTag();
    tag.setPageContext(pageContext);
    tag.setName("testAction");
    tag.setVar("testAction");
    int stackSize = stack.size();
    try {
        tag.doStartTag();
        tag.addParameter("foo", "myFoo");
        tag.doEndTag();
        assertEquals(stack.size(), ActionContext.getContext().getValueStack().size());
        assertEquals("myFoo", stack.findValue("#testAction.foo"));
        assertEquals(stackSize, stack.size());
        Object o = pageContext.findAttribute("testAction");
        assertTrue(o instanceof TestAction);
        assertEquals("myFoo", ((TestAction) o).getFoo());
        assertEquals(Action.SUCCESS, ((TestAction) o).getResult());
    } catch (JspException ex) {
        ex.printStackTrace();
        fail();
    }
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    ActionTag freshTag = new ActionTag();
    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 : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) JspException(javax.servlet.jsp.JspException) TestAction(org.apache.struts2.TestAction)

Aggregations

TestAction (org.apache.struts2.TestAction)263 ArrayList (java.util.ArrayList)59 List (java.util.List)42 Collection (java.util.Collection)21 LinkedHashMap (java.util.LinkedHashMap)10 HashMap (java.util.HashMap)6 JspException (javax.servlet.jsp.JspException)6 ActionTag (org.apache.struts2.views.jsp.ActionTag)6 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)5 NumberFormat (java.text.NumberFormat)4 ParamTag (org.apache.struts2.views.jsp.ParamTag)4 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)3 Locale (java.util.Locale)3 ActionMapping (org.apache.struts2.dispatcher.mapper.ActionMapping)3 Mock (com.mockobjects.dynamic.Mock)2 MockJspWriter (com.mockobjects.servlet.MockJspWriter)2 ActionContext (com.opensymphony.xwork2.ActionContext)2 ActionProxy (com.opensymphony.xwork2.ActionProxy)2 SecurityMemberAccess (com.opensymphony.xwork2.ognl.SecurityMemberAccess)2 Member (java.lang.reflect.Member)2