Search in sources :

Example 6 with SimpleFooAction

use of com.opensymphony.xwork2.SimpleFooAction in project struts by apache.

the class StaticParametersInterceptorTest method testNoMerge.

public void testNoMerge() 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);
    ActionContext.getContext().setParameters(HttpParameters.create().build());
    int before = ActionContext.getContext().getValueStack().size();
    interceptor.setMerge("false");
    interceptor.intercept(mai);
    assertEquals(before, ActionContext.getContext().getValueStack().size());
    assertEquals("${top.hero}", user.getName());
    assertEquals(0, ActionContext.getContext().getParameters().keySet().size());
}
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 7 with SimpleFooAction

use of com.opensymphony.xwork2.SimpleFooAction in project struts by apache.

the class AliasInterceptorTest method testSetAliasKeys.

public void testSetAliasKeys() throws Exception {
    Action action = new SimpleFooAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig cfg = new ActionConfig.Builder("", "", "").addParam("hello", "invalid alias expression").build();
    map.setConfig(cfg);
    mai.setProxy(map);
    mai.setAction(action);
    mai.setInvocationContext(ActionContext.getContext());
    AliasInterceptor ai = new AliasInterceptor();
    ai.init();
    ai.setAliasesKey("hello");
    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)

Example 8 with SimpleFooAction

use of com.opensymphony.xwork2.SimpleFooAction in project struts by apache.

the class AliasInterceptorTest method testSetInvalidAliasKeys.

public void testSetInvalidAliasKeys() throws Exception {
    Action action = new SimpleFooAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig cfg = new ActionConfig.Builder("", "", "").addParam("hello", "invalid alias expression").build();
    map.setConfig(cfg);
    mai.setProxy(map);
    mai.setAction(action);
    mai.setInvocationContext(ActionContext.getContext());
    AliasInterceptor ai = new AliasInterceptor();
    ai.init();
    ai.setAliasesKey("iamnotinconfig");
    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)

Example 9 with SimpleFooAction

use of com.opensymphony.xwork2.SimpleFooAction 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 10 with SimpleFooAction

use of com.opensymphony.xwork2.SimpleFooAction 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)

Aggregations

SimpleFooAction (com.opensymphony.xwork2.SimpleFooAction)12 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)11 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)10 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)10 Action (com.opensymphony.xwork2.Action)3 SimpleAction (com.opensymphony.xwork2.SimpleAction)3 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2