FileDocCategorySizeDatePackage
StrutsResultSupportTest.javaAPI DocExample4821Mon Jul 23 13:26:12 BST 2007org.apache.struts2.dispatcher

StrutsResultSupportTest

public class StrutsResultSupportTest extends org.apache.struts2.StrutsTestCase
Test case for StrutsResultSupport.

Fields Summary
Constructors Summary
Methods Summary
public voidtestNoParseAndEncode()

        ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        stack.push(new ActionSupport() {
            public String getMyLocation() {
                return "myLocation.jsp";
            }
        });

        ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class);
        EasyMock.replay(mockActionInvocation);

        InternalStrutsResultSupport result = new InternalStrutsResultSupport();
        result.setParse(false);
        result.setEncode(false); // don't really need this, as encode is only valid when parse is true.
        result.setLocation("/pages/myJsp.jsp?location=${myLocation}");

        result.execute(mockActionInvocation);

        assertNotNull(result.getInternalLocation());
        assertEquals("/pages/myJsp.jsp?location=${myLocation}", result.getInternalLocation());
        EasyMock.verify(mockActionInvocation);
    
public voidtestParse()

        ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        stack.push(new ActionSupport() {
            public String getMyLocation() {
                return "ThisIsMyLocation";
            }
        });

        ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class);
        mockActionInvocation.getStack();
        EasyMock.expectLastCall().andReturn(stack);
        EasyMock.replay(mockActionInvocation);

        InternalStrutsResultSupport result = new InternalStrutsResultSupport();
        result.setParse(true);
        result.setEncode(false);
        result.setLocation("/pages/myJsp.jsp?location=${myLocation}");

        result.execute(mockActionInvocation);

        assertNotNull(result.getInternalLocation());
        assertEquals("/pages/myJsp.jsp?location=ThisIsMyLocation", result.getInternalLocation());
        EasyMock.verify(mockActionInvocation);
    
public voidtestParseAndEncode()

        ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        stack.push(new ActionSupport() {
            public String getMyLocation() {
                return "/myPage?param=value¶m1=value1";
            }
        });

        ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class);
        mockActionInvocation.getStack();
        EasyMock.expectLastCall().andReturn(stack);
        EasyMock.replay(mockActionInvocation);

        InternalStrutsResultSupport result = new InternalStrutsResultSupport();
        result.setParse(true);
        result.setEncode(true);
        result.setLocation("/pages/myJsp.jsp?location=${myLocation}");

        result.execute(mockActionInvocation);

        assertNotNull(result.getInternalLocation());
        assertEquals("/pages/myJsp.jsp?location=%2FmyPage%3Fparam%3Dvalue%26param1%3Dvalue1", result.getInternalLocation());
        EasyMock.verify(mockActionInvocation);