Search in sources :

Example 91 with Result

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&param2=value+2&param3=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&param2=value+2&param3=value+3#fragment", res.getRedirectedUrl());
    control.verify();
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ActionProxy(com.opensymphony.xwork2.ActionProxy) ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) IMocksControl(org.easymock.IMocksControl) ActionMapper(org.apache.struts2.dispatcher.mapper.ActionMapper) DefaultUrlHelper(org.apache.struts2.views.util.DefaultUrlHelper) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 92 with Result

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());
    }
}
Also used : Result(com.opensymphony.xwork2.Result)

Example 93 with Result

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);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionSupport(com.opensymphony.xwork2.ActionSupport) List(java.util.List) ArrayList(java.util.ArrayList)

Example 94 with Result

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);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionSupport(com.opensymphony.xwork2.ActionSupport)

Example 95 with Result

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&param1=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);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionSupport(com.opensymphony.xwork2.ActionSupport)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)63 Test (org.junit.Test)52 ActionProxy (com.opensymphony.xwork2.ActionProxy)51 List (java.util.List)49 ValueStack (com.opensymphony.xwork2.util.ValueStack)38 Result (edu.stanford.CVC4.Result)35 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)34 ActionContext (com.opensymphony.xwork2.ActionContext)33 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 ArrayList (java.util.ArrayList)31 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)30 HashMap (java.util.HashMap)29 Rational (edu.stanford.CVC4.Rational)25 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)22 Map (java.util.Map)21 ServletActionContext (org.apache.struts2.ServletActionContext)21 Result (com.opensymphony.xwork2.Result)18 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)18