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);
}
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));
}
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());
}
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);
}
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());
}
Aggregations