Search in sources :

Example 1 with SimpleFooAction

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

the class NumberConverterTest method testStringToNumberConversionPL.

public void testStringToNumberConversionPL() throws Exception {
    // given
    NumberConverter converter = new NumberConverter();
    Map<String, Object> context = createContextWithLocale(new Locale("pl", "PL"));
    SimpleFooAction foo = new SimpleFooAction();
    // when
    Object value = converter.convertValue(context, foo, null, "id", "1234", Integer.class);
    // then
    assertEquals(1234, value);
}
Also used : Locale(java.util.Locale) SimpleFooAction(com.opensymphony.xwork2.SimpleFooAction)

Example 2 with SimpleFooAction

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

the class PrepareInterceptorTest method testNoPrepareCalled.

public void testNoPrepareCalled() throws Exception {
    MockActionInvocation mai = new MockActionInvocation();
    mai.setAction(new SimpleFooAction());
    interceptor.doIntercept(mai);
}
Also used : MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation)

Example 3 with SimpleFooAction

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

the class StaticParametersInterceptorTest method testWithOneParametersNoParse.

public void testWithOneParametersNoParse() 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("false");
    interceptor.intercept(mai);
    assertEquals(before, ActionContext.getContext().getValueStack().size());
    assertEquals("${top.hero}", 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 4 with SimpleFooAction

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

the class StaticParametersInterceptorTest method testFewParametersParse.

public void testFewParametersParse() throws Exception {
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").addParam("top.age", "${top.myAge}").addParam("top.email", "${top.myEmail}").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(user.getMyAge(), user.age);
    assertEquals(user.getMyEmail(), user.email);
}
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 5 with SimpleFooAction

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

the class StaticParametersInterceptorTest method testNoOverwrite.

public void testNoOverwrite() 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());
    mai.setInvocationContext(ActionContext.getContext());
    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("false");
    interceptor.intercept(mai);
    assertEquals(before, ActionContext.getContext().getValueStack().size());
    assertEquals("Akash", 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