ServletActionRedirectResultTestpublic class ServletActionRedirectResultTest extends org.apache.struts2.StrutsTestCase
Methods Summary |
---|
public void | testIncludeParameterInResult()
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 void | testIncludeParameterInResultWithConditionParseOn()
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();
|
|