Search in sources :

Example 36 with SimpleAction

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

the class StrutsLocalizedTextProviderTest method testActionGetTextXXX.

public void testActionGetTextXXX() throws Exception {
    localizedTextProvider.addDefaultResourceBundle("com/opensymphony/xwork2/util/FindMe");
    SimpleAction action = new SimpleAction();
    container.inject(action);
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy()).getValueStack().push(action);
    String message = action.getText("bean.name");
    String foundBean2 = action.getText("bean2.name");
    assertEquals("Okay! You found Me!", foundBean2);
    assertEquals("Haha you cant FindMe!", message);
}
Also used : SimpleAction(com.opensymphony.xwork2.SimpleAction) Mock(com.mockobjects.dynamic.Mock)

Example 37 with SimpleAction

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

the class ValidateAction method testNoOrdered.

public void testNoOrdered() throws Exception {
    ParametersInterceptor pi = createParametersInterceptor();
    final Map<String, Object> actual = new LinkedHashMap<>();
    pi.setValueStackFactory(createValueStackFactory(actual));
    ValueStack stack = createStubValueStack(actual);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("user.address.city", "London");
    parameters.put("user.name", "Superman");
    Action action = new SimpleAction();
    pi.setParameters(action, stack, HttpParameters.create(parameters).build());
    assertEquals("ordered should be false by default", false, pi.isOrdered());
    assertEquals(2, actual.size());
    assertEquals("London", actual.get("user.address.city"));
    assertEquals("Superman", actual.get("user.name"));
    // is not ordered
    List<Object> values = new ArrayList<Object>(actual.values());
    assertEquals("London", values.get(0));
    assertEquals("Superman", values.get(1));
}
Also used : SimpleAction(com.opensymphony.xwork2.SimpleAction) ModelDrivenAction(com.opensymphony.xwork2.ModelDrivenAction) Action(com.opensymphony.xwork2.Action) OgnlValueStack(com.opensymphony.xwork2.ognl.OgnlValueStack) ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) SimpleAction(com.opensymphony.xwork2.SimpleAction) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with SimpleAction

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

the class ValidateAction method testParametersWithChineseInTheName.

public void testParametersWithChineseInTheName() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("theProtectedMap['名字']", "test1");
    HashMap<String, Object> extraContext = new HashMap<>();
    extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
    ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
    proxy.execute();
    Map<String, String> existingMap = ((SimpleAction) proxy.getAction()).getTheProtectedMap();
    assertEquals(1, existingMap.size());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 39 with SimpleAction

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

the class ValidateAction method testAccessToOgnlInternals.

public void testAccessToOgnlInternals() throws Exception {
    // given
    Map<String, Object> params = new HashMap<>();
    params.put("blah", "This is blah");
    params.put("('\\u0023_memberAccess[\\'allowStaticMethodAccess\\']')(meh)", "true");
    params.put("('(aaa)(('\\u0023context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\u003d\\u0023foo')(\\u0023foo\\u003dnew java.lang.Boolean(\"false\")))", "");
    params.put("(asdf)(('\\u0023rt.exit(1)')(\\u0023rt\\u003d@java.lang.Runtime@getRuntime()))", "1");
    HashMap<String, Object> extraContext = new HashMap<>();
    extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
    ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
    ValueStack stack = proxy.getInvocation().getStack();
    // when
    proxy.execute();
    proxy.getAction();
    // then
    assertEquals("This is blah", ((SimpleAction) proxy.getAction()).getBlah());
    boolean allowMethodAccess = ((SecurityMemberAccess) ((OgnlContext) stack.getContext()).getMemberAccess()).getAllowStaticMethodAccess();
    assertFalse(allowMethodAccess);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) OgnlValueStack(com.opensymphony.xwork2.ognl.OgnlValueStack) ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SecurityMemberAccess(com.opensymphony.xwork2.ognl.SecurityMemberAccess)

Example 40 with SimpleAction

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

the class ValidateAction method testParametersWithSpacesInTheName.

public void testParametersWithSpacesInTheName() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("theProtectedMap['p0 p1']", "test1");
    params.put("theProtectedMap['p0p1 ']", "test2");
    params.put("theProtectedMap[' p0p1 ']", "test3");
    params.put("theProtectedMap[' p0 p1 ']", "test4");
    HashMap<String, Object> extraContext = new HashMap<>();
    extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
    ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
    proxy.execute();
    Map<String, String> existingMap = ((SimpleAction) proxy.getAction()).getTheProtectedMap();
    assertEquals(0, existingMap.size());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Aggregations

SimpleAction (com.opensymphony.xwork2.SimpleAction)32 ActionProxy (com.opensymphony.xwork2.ActionProxy)24 HashMap (java.util.HashMap)23 LinkedHashMap (java.util.LinkedHashMap)17 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)14 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)8 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)7 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)7 OgnlUtil (com.opensymphony.xwork2.ognl.OgnlUtil)6 Action (com.opensymphony.xwork2.Action)5 TestBean (com.opensymphony.xwork2.TestBean)5 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)5 ValueStack (com.opensymphony.xwork2.util.ValueStack)5 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)4 ModelDrivenAction (com.opensymphony.xwork2.ModelDrivenAction)3 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)3 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)3 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)3 MockConfigurationProvider (com.opensymphony.xwork2.config.providers.MockConfigurationProvider)2 MockResult (com.opensymphony.xwork2.mock.MockResult)2