Search in sources :

Example 1 with SimpleAction

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

the class ValidateAction method doTestParameterNameLengthRestriction.

private void doTestParameterNameLengthRestriction(ParametersInterceptor parametersInterceptor, int paramNameMaxLength) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < paramNameMaxLength + 1; i++) {
        sb.append("x");
    }
    Map<String, Object> actual = new LinkedHashMap<>();
    parametersInterceptor.setValueStackFactory(createValueStackFactory(actual));
    ValueStack stack = createStubValueStack(actual);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put(sb.toString(), "");
    parameters.put("huuhaa", "");
    Action action = new SimpleAction();
    parametersInterceptor.setParameters(action, stack, HttpParameters.create(parameters).build());
    assertEquals(1, actual.size());
}
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) SimpleAction(com.opensymphony.xwork2.SimpleAction) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with SimpleAction

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

the class ValidateAction method testParametersDoesNotAffectSession.

public void testParametersDoesNotAffectSession() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("blah", "This is blah");
    params.put("#session.foo", "Foo");
    params.put("\u0023session['user']", "0wn3d");
    params.put("\\u0023session['user']", "0wn3d");
    params.put("\u0023session.user2", "0wn3d");
    params.put("\\u0023session.user2", "0wn3d");
    params.put("('\u0023'%20%2b%20'session['user3']')(unused)", "0wn3d");
    params.put("('\\u0023' + 'session[\\'user4\\']')(unused)", "0wn3d");
    params.put("('\u0023'%2b'session['user5']')(unused)", "0wn3d");
    params.put("('\\u0023'%2b'session['user5']')(unused)", "0wn3d");
    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();
    HashMap<String, Object> session = new HashMap<>();
    stack.getContext().put("session", session);
    proxy.execute();
    assertEquals("This is blah", ((SimpleAction) proxy.getAction()).getBlah());
    assertNull(session.get("foo"));
    assertNull(session.get("user"));
    assertNull(session.get("user2"));
    assertNull(session.get("user3"));
    assertNull(session.get("user4"));
    assertNull(session.get("user5"));
}
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)

Example 3 with SimpleAction

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

the class ValidateAction method testNonexistentParametersGetLoggedInDevMode.

public void testNonexistentParametersGetLoggedInDevMode() throws Exception {
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-test-beans.xml");
    container.inject(provider);
    loadConfigurationProviders(provider, new MockConfigurationProvider(Collections.singletonMap("struts.devMode", "true")));
    Map<String, Object> params = new HashMap<>();
    params.put("not_a_property", "There is no action property named like this");
    HashMap<String, Object> extraContext = new HashMap<>();
    extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
    ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
    container.inject(config.getInterceptors().get(0).getInterceptor());
    ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
    proxy.execute();
    final String actionMessage = "" + ((SimpleAction) proxy.getAction()).getActionMessages().toArray()[0];
    assertTrue(actionMessage.contains("Error setting expression 'not_a_property' with value 'There is no action property named like this'"));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) ActionProxy(com.opensymphony.xwork2.ActionProxy) MockConfigurationProvider(com.opensymphony.xwork2.config.providers.MockConfigurationProvider) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with SimpleAction

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

the class ValidateAction method testParameters.

public void testParameters() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("blah", "This is blah");
    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();
    assertEquals("This is blah", ((SimpleAction) proxy.getAction()).getBlah());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with SimpleAction

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

the class ValidateAction method testOrdered.

public void testOrdered() throws Exception {
    ParametersInterceptor pi = new ParametersInterceptor();
    pi.setOrdered(true);
    container.inject(pi);
    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.address['postal']", "QJR387");
    parameters.put("user.name", "Superman");
    Action action = new SimpleAction();
    pi.setParameters(action, stack, HttpParameters.create(parameters).build());
    assertEquals(true, pi.isOrdered());
    assertEquals(3, actual.size());
    assertEquals("London", actual.get("user.address.city"));
    assertEquals("QJR387", actual.get("user.address['postal']"));
    assertEquals("Superman", actual.get("user.name"));
    // should be ordered so user.name should be first
    List<Object> values = new ArrayList<Object>(actual.values());
    assertEquals("Superman", values.get(0));
    assertEquals("London", values.get(1));
    assertEquals("QJR387", values.get(2));
}
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)

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