FileDocCategorySizeDatePackage
ServletActionRedirectResultTest.javaAPI DocExample7062Mon Jul 23 13:26:12 BST 2007org.apache.struts2.dispatcher

ServletActionRedirectResultTest

public class ServletActionRedirectResultTest extends org.apache.struts2.StrutsTestCase
version
$Date: 2007-05-24 23:33:45 -0400 (Thu, 24 May 2007) $ $Id: ServletActionRedirectResultTest.java 541522 2007-05-25 03:33:45Z mrdon $

Fields Summary
Constructors Summary
Methods Summary
public voidtestIncludeParameterInResult()


        ResultConfig resultConfig = new ResultConfig();
        resultConfig.addParam("actionName", "someActionName");
        resultConfig.addParam("namespace", "someNamespace");
        resultConfig.addParam("encode", "true");
        resultConfig.addParam("parse", "true");
        resultConfig.addParam("location", "someLocation");
        resultConfig.addParam("prependServletContext", "true");
        resultConfig.addParam("method", "someMethod");
        resultConfig.addParam("param1", "value 1");
        resultConfig.addParam("param2", "value 2");
        resultConfig.addParam("param3", "value 3");

        ActionContext context = ActionContext.getContext();
        MockHttpServletRequest req = new MockHttpServletRequest();
        MockHttpServletResponse res = new MockHttpServletResponse();
        context.put(ServletActionContext.HTTP_REQUEST, req);
        context.put(ServletActionContext.HTTP_RESPONSE, res);


        Map<String, ResultConfig> results=  new HashMap<String, ResultConfig>();
        results.put("myResult", resultConfig);

        ActionConfig actionConfig = new ActionConfig();
        actionConfig.setResults(results);

        ServletActionRedirectResult result = new ServletActionRedirectResult();
        result.setActionName("myAction");
        result.setNamespace("/myNamespace");
        result.setParse(false);
        result.setEncode(false);
        result.setPrependServletContext(false);

        IMocksControl control = EasyMock.createControl();
        ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
        ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
        mockInvocation.getProxy();
        control.andReturn(mockActionProxy);
        mockInvocation.getResultCode();
        control.andReturn("myResult");
        mockActionProxy.getConfig();
        control.andReturn(actionConfig);
        mockInvocation.getInvocationContext();
        control.andReturn(context);

        control.replay();
        result.setActionMapper(container.getInstance(ActionMapper.class));
        result.execute(mockInvocation);
        assertEquals("/myNamespace/myAction.action?param1=value+1¶m2=value+2¶m3=value+3", res.getRedirectedUrl());

        control.verify();
    
public voidtestIncludeParameterInResultWithConditionParseOn()


        ResultConfig resultConfig = new ResultConfig();
        resultConfig.addParam("actionName", "someActionName");
        resultConfig.addParam("namespace", "someNamespace");
        resultConfig.addParam("encode", "true");
        resultConfig.addParam("parse", "true");
        resultConfig.addParam("location", "someLocation");
        resultConfig.addParam("prependServletContext", "true");
        resultConfig.addParam("method", "someMethod");
        resultConfig.addParam("param1", "${#value1}");
        resultConfig.addParam("param2", "${#value2}");
        resultConfig.addParam("param3", "${#value3}");



        ActionContext context = ActionContext.getContext();
        ValueStack stack = context.getValueStack();
        context.getContextMap().put("value1", "value 1");
        context.getContextMap().put("value2", "value 2");
        context.getContextMap().put("value3", "value 3");
        MockHttpServletRequest req = new MockHttpServletRequest();
        MockHttpServletResponse res = new MockHttpServletResponse();
        context.put(ServletActionContext.HTTP_REQUEST, req);
        context.put(ServletActionContext.HTTP_RESPONSE, res);


        Map<String, ResultConfig> results=  new HashMap<String, ResultConfig>();
        results.put("myResult", resultConfig);

        ActionConfig actionConfig = new ActionConfig();
        actionConfig.setResults(results);

        ServletActionRedirectResult result = new ServletActionRedirectResult();
        result.setActionName("myAction");
        result.setNamespace("/myNamespace");
        result.setParse(true);
        result.setEncode(false);
        result.setPrependServletContext(false);

        IMocksControl control = EasyMock.createControl();
        ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
        ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
        mockInvocation.getProxy();
        control.andReturn(mockActionProxy);
        mockInvocation.getResultCode();
        control.andReturn("myResult");
        mockActionProxy.getConfig();
        control.andReturn(actionConfig);
        mockInvocation.getInvocationContext();
        control.andReturn(context);
        mockInvocation.getStack();
        control.andReturn(stack);
        control.anyTimes();

        control.replay();
        result.setActionMapper(container.getInstance(ActionMapper.class));
        result.execute(mockInvocation);
        assertEquals("/myNamespace/myAction.action?param1=value+1¶m2=value+2¶m3=value+3", res.getRedirectedUrl());

        control.verify();