use of com.opensymphony.xwork2.Result in project struts by apache.
the class ServletActionRedirectResultTest method testExpressionParameterInResultWithConditionParseOn.
public void testExpressionParameterInResultWithConditionParseOn() throws Exception {
ResultConfig resultConfig = new ResultConfig.Builder("", "").addParam("actionName", "someActionName").addParam("namespace", "someNamespace").addParam("encode", "true").addParam("parse", "true").addParam("location", "someLocation").addParam("prependServletContext", "true").addParam("method", "someMethod").addParam("statusCode", "333").addParam("param1", "${#value1}").addParam("param2", "${#value2}").addParam("param3", "${#value3}").addParam("anchor", "${#fragment}").build();
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");
context.getContextMap().put("namespaceName", "${1-1}");
context.getContextMap().put("actionName", "${1-1}");
context.getContextMap().put("methodName", "${1-1}");
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<>();
results.put("myResult", resultConfig);
ActionConfig actionConfig = new ActionConfig.Builder("", "", "").addResultConfigs(results).build();
ServletActionRedirectResult result = new ServletActionRedirectResult();
result.setNamespace("/myNamespace${#namespaceName}");
result.setActionName("myAction${#actionName}");
result.setMethod("myMethod${#methodName}");
result.setParse(true);
result.setEncode(false);
result.setPrependServletContext(false);
result.setAnchor("fragment");
result.setUrlHelper(new DefaultUrlHelper());
IMocksControl control = createControl();
ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
expect(mockInvocation.getProxy()).andReturn(mockActionProxy).anyTimes();
expect(mockInvocation.getResultCode()).andReturn("myResult").anyTimes();
expect(mockActionProxy.getConfig()).andReturn(actionConfig).anyTimes();
expect(mockInvocation.getInvocationContext()).andReturn(context).anyTimes();
expect(mockInvocation.getStack()).andReturn(stack).anyTimes();
control.replay();
result.setActionMapper(container.getInstance(ActionMapper.class));
result.execute(mockInvocation);
assertEquals("/myNamespace${1-1}/myAction${1-1}!myMethod${1-1}.action?param1=value+1¶m2=value+2¶m3=value+3#fragment", res.getRedirectedUrl());
req = new MockHttpServletRequest();
res = new MockHttpServletResponse();
context.put(ServletActionContext.HTTP_REQUEST, req);
context.put(ServletActionContext.HTTP_RESPONSE, res);
result.execute(mockInvocation);
assertEquals("/myNamespace0/myAction0!myMethod0.action?param1=value+1¶m2=value+2¶m3=value+3#fragment", res.getRedirectedUrl());
control.verify();
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class ServletRedirectResultTest method testPassingNullInvocation.
public void testPassingNullInvocation() throws Exception {
Result result = new ServletRedirectResult();
try {
result.execute(null);
fail("Exception should be thrown!");
} catch (IllegalArgumentException e) {
assertEquals("Invocation cannot be null!", e.getMessage());
}
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class StrutsResultSupportTest method testConditionalParseCollection.
public void testConditionalParseCollection() {
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(new ActionSupport() {
public List<String> getList() {
return new ArrayList<String>() {
{
add("val 1");
add("val 2");
}
};
}
});
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);
Collection<String> collection = result.conditionalParseCollection("${list}", mockActionInvocation, true);
assertNotNull(collection);
assertEquals(2, collection.size());
assertTrue(collection.contains("val+1"));
assertTrue(collection.contains("val+2"));
EasyMock.verify(mockActionInvocation);
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class StrutsResultSupportTest method testParse.
public void testParse() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
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);
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class StrutsResultSupportTest method testParseAndEncode.
public void testParseAndEncode() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
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);
}
Aggregations