use of com.opensymphony.xwork2.interceptor.ParametersInterceptor 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());
}
use of com.opensymphony.xwork2.interceptor.ParametersInterceptor 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));
}
use of com.opensymphony.xwork2.interceptor.ParametersInterceptor in project struts by apache.
the class ValidateAction method testAcceptedTrickyParameters.
public void testAcceptedTrickyParameters() throws Exception {
Map<String, Object> params = new HashMap<String, Object>() {
{
put("blah", "This is blah");
put("baz", "123");
put("name", "try_1");
put("(name)", "try_2");
put("['name']", "try_3");
put("['na' + 'me']", "try_4");
put("{name}[0]", "try_5");
put("(new string{'name'})[0]", "try_6");
put("#{key: 'name'}.key", "try_7");
}
};
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);
ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
ParametersInterceptor pi = (ParametersInterceptor) config.getInterceptors().get(0).getInterceptor();
pi.setAcceptParamNames("blah, baz");
proxy.execute();
SimpleAction action = (SimpleAction) proxy.getAction();
assertNull("try_1", action.getName());
assertEquals("This is blah", (action).getBlah());
assertEquals(123, action.getBaz());
}
use of com.opensymphony.xwork2.interceptor.ParametersInterceptor in project struts by apache.
the class ValidateAction method testExcludedParametersAreIgnored.
public void testExcludedParametersAreIgnored() throws Exception {
ParametersInterceptor pi = createParametersInterceptor();
pi.setExcludeParams("dojo\\..*");
final Map<String, Object> actual = injectValueStackFactory(pi);
ValueStack stack = injectValueStack(actual);
final Map<String, Object> expected = new HashMap<String, Object>() {
{
put("fooKey", "fooValue");
}
};
Map<String, Object> parameters = new HashMap<String, Object>() {
{
put("dojo.test", "dojoValue");
put("fooKey", "fooValue");
}
};
pi.setParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build());
assertEquals(expected, actual);
}
use of com.opensymphony.xwork2.interceptor.ParametersInterceptor in project struts by apache.
the class ValidateAction method testNoParametersAction.
public void testNoParametersAction() throws Exception {
ParametersInterceptor interceptor = new ParametersInterceptor();
interceptor.init();
MockActionInvocation mai = new MockActionInvocation();
Action action = new NoParametersAction();
mai.setAction(action);
interceptor.doIntercept(mai);
interceptor.destroy();
}
Aggregations