Search in sources :

Example 56 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class StaticParametersInterceptorTest method testWithOneParametersParse.

public void testWithOneParametersParse() throws Exception {
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").addParam("top.name", "${top.hero}").build();
    map.setConfig(ac);
    mai.setProxy(map);
    mai.setAction(new SimpleFooAction());
    User user = new User();
    ActionContext.getContext().getValueStack().push(user);
    int before = ActionContext.getContext().getValueStack().size();
    interceptor.setParse("true");
    interceptor.intercept(mai);
    assertEquals(before, ActionContext.getContext().getValueStack().size());
    assertEquals("Superman", user.getName());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) SimpleFooAction(com.opensymphony.xwork2.SimpleFooAction) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 57 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class StaticParametersInterceptorTest method testOverwrite.

public void testOverwrite() throws Exception {
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").addParam("name", "${hero}").build();
    map.setConfig(ac);
    mai.setProxy(map);
    mai.setAction(new SimpleFooAction());
    Map<String, String> existingParams = new HashMap<>();
    existingParams.put("name", "Akash");
    ActionContext.getContext().setParameters(HttpParameters.create(existingParams).build());
    int before = ActionContext.getContext().getValueStack().size();
    interceptor.setOverwrite("true");
    interceptor.intercept(mai);
    assertEquals(before, ActionContext.getContext().getValueStack().size());
    assertEquals("${hero}", ActionContext.getContext().getParameters().get("name").toString());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) HashMap(java.util.HashMap) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) SimpleFooAction(com.opensymphony.xwork2.SimpleFooAction) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 58 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class StaticParametersInterceptorTest method testParameterizable.

public void testParameterizable() throws Exception {
    Mock mock = new Mock(Parameterizable.class);
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    Map params = ac.getParams();
    map.setConfig(ac);
    mai.setProxy(map);
    mai.setAction(mock.proxy());
    mock.expect("setParams", params);
    interceptor.intercept(mai);
    mock.verify();
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) Map(java.util.Map) HashMap(java.util.HashMap) Mock(com.mockobjects.dynamic.Mock) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 59 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class StaticParametersInterceptorTest method testWithOneParameters.

public void testWithOneParameters() throws Exception {
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").addParam("top.name", "Santa").build();
    map.setConfig(ac);
    mai.setProxy(map);
    mai.setAction(new SimpleFooAction());
    User user = new User();
    ActionContext.getContext().getValueStack().push(user);
    int before = ActionContext.getContext().getValueStack().size();
    interceptor.intercept(mai);
    assertEquals(before, ActionContext.getContext().getValueStack().size());
    assertEquals("Santa", user.getName());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) SimpleFooAction(com.opensymphony.xwork2.SimpleFooAction) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 60 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class AliasInterceptorTest method testInvalidAliasExpression.

public void testInvalidAliasExpression() throws Exception {
    Action action = new SimpleFooAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig cfg = new ActionConfig.Builder("", "", "").addParam("aliases", "invalid alias expression").build();
    map.setConfig(cfg);
    mai.setProxy(map);
    mai.setAction(action);
    mai.setInvocationContext(ActionContext.getContext());
    AliasInterceptor ai = new AliasInterceptor();
    ai.init();
    ai.intercept(mai);
    ai.destroy();
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) SimpleFooAction(com.opensymphony.xwork2.SimpleFooAction) SimpleAction(com.opensymphony.xwork2.SimpleAction) Action(com.opensymphony.xwork2.Action) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) SimpleFooAction(com.opensymphony.xwork2.SimpleFooAction) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Aggregations

MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)43 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)34 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)29 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)19 ActionProxy (com.opensymphony.xwork2.ActionProxy)17 HashMap (java.util.HashMap)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)13 ActionContext (com.opensymphony.xwork2.ActionContext)12 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)11 SimpleFooAction (com.opensymphony.xwork2.SimpleFooAction)10 ServletActionContext (org.apache.struts2.ServletActionContext)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 OgnlUtil (com.opensymphony.xwork2.ognl.OgnlUtil)8 ActionMapper (org.apache.struts2.dispatcher.mapper.ActionMapper)7 IMocksControl (org.easymock.IMocksControl)7 ValueStack (com.opensymphony.xwork2.util.ValueStack)6 DefaultUrlHelper (org.apache.struts2.views.util.DefaultUrlHelper)6 Mock (com.mockobjects.dynamic.Mock)5 Action (com.opensymphony.xwork2.Action)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5