use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class XmlConfigurationProviderActionsTest method testDefaultActionClass.
public void testDefaultActionClass() throws Exception {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
final String testDefaultClassName = "com.opensymphony.xwork2.ActionSupport";
ConfigurationProvider provider = buildConfigurationProvider(filename);
// setup expectations
params.put("foo", "17");
params.put("bar", "23");
ActionConfig barWithoutClassNameConfig = new ActionConfig.Builder("", "BarWithoutClassName", "").addParams(params).build();
// execute the configuration
provider.init(configuration);
PackageConfig pkg = configuration.getPackageConfig("default");
Map actionConfigs = pkg.getActionConfigs();
// assertions
assertEquals(7, actionConfigs.size());
assertEquals(barWithoutClassNameConfig, actionConfigs.get("BarWithoutClassName"));
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class XmlConfigurationProviderActionsTest method testActions.
public void testActions() throws Exception {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
// setup expectations
// bar action is very simple, just two params
params.put("foo", "17");
params.put("bar", "23");
params.put("testXW412", "foo.jspa?fooID=${fooID}&something=bar");
params.put("testXW412Again", "something");
ActionConfig barAction = new ActionConfig.Builder("", "Bar", SimpleAction.class.getName()).addParams(params).build();
// foo action is a little more complex, two params, a result and an interceptor stack
results = new HashMap<>();
params = new HashMap<>();
params.put("foo", "18");
params.put("bar", "24");
results.put("success", new ResultConfig.Builder("success", MockResult.class.getName()).build());
InterceptorConfig noopInterceptorConfig = new InterceptorConfig.Builder("noop", NoOpInterceptor.class.getName()).build();
interceptors.add(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptorConfig, new HashMap<String, String>())));
ActionConfig fooAction = new ActionConfig.Builder("", "Foo", SimpleAction.class.getName()).addParams(params).addResultConfigs(results).addInterceptors(interceptors).build();
// wildcard action is simple wildcard example
results = new HashMap<>();
results.put("*", new ResultConfig.Builder("*", MockResult.class.getName()).build());
ActionConfig wildcardAction = new ActionConfig.Builder("", "WildCard", SimpleAction.class.getName()).addResultConfigs(results).addInterceptors(interceptors).build();
// fooBar action is a little more complex, two params, a result and an interceptor stack
params = new HashMap<String, String>();
params.put("foo", "18");
params.put("bar", "24");
results = new HashMap<>();
results.put("success", new ResultConfig.Builder("success", MockResult.class.getName()).build());
ExceptionMappingConfig exceptionConfig = new ExceptionMappingConfig.Builder("runtime", "java.lang.RuntimeException", "exception").build();
exceptionMappings.add(exceptionConfig);
ActionConfig fooBarAction = new ActionConfig.Builder("", "FooBar", SimpleAction.class.getName()).addParams(params).addResultConfigs(results).addInterceptors(interceptors).addExceptionMappings(exceptionMappings).build();
// TestInterceptorParam action tests that an interceptor worked
HashMap<String, String> interceptorParams = new HashMap<>();
interceptorParams.put("expectedFoo", "expectedFooValue");
interceptorParams.put("foo", MockInterceptor.DEFAULT_FOO_VALUE);
InterceptorConfig mockInterceptorConfig = new InterceptorConfig.Builder("test", MockInterceptor.class.getName()).build();
interceptors = new ArrayList<>();
interceptors.add(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptorConfig, interceptorParams)));
ActionConfig intAction = new ActionConfig.Builder("", "TestInterceptorParam", SimpleAction.class.getName()).addInterceptors(interceptors).build();
// TestInterceptorParamOverride action tests that an interceptor with a param override worked
interceptorParams = new HashMap<>();
interceptorParams.put("expectedFoo", "expectedFooValue");
interceptorParams.put("foo", "foo123");
interceptors = new ArrayList<>();
interceptors.add(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptorConfig, interceptorParams)));
ActionConfig intOverAction = new ActionConfig.Builder("", "TestInterceptorParamOverride", SimpleAction.class.getName()).addInterceptors(interceptors).build();
// execute the configuration
provider.init(configuration);
provider.loadPackages();
PackageConfig pkg = configuration.getPackageConfig("default");
Map actionConfigs = pkg.getActionConfigs();
// assertions
assertEquals(7, actionConfigs.size());
assertEquals(barAction, actionConfigs.get("Bar"));
assertEquals(fooAction, actionConfigs.get("Foo"));
assertEquals(wildcardAction, actionConfigs.get("WildCard"));
assertEquals(fooBarAction, actionConfigs.get("FooBar"));
assertEquals(intAction, actionConfigs.get("TestInterceptorParam"));
assertEquals(intOverAction, actionConfigs.get("TestInterceptorParamOverride"));
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testSetIndexedValue.
/**
* Test that type conversion is performed on indexed collection properties.
*/
public void testSetIndexedValue() {
ValueStack stack = ActionContext.getContext().getValueStack();
Map<String, Object> stackContext = stack.getContext();
stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
User user = new User();
stack.push(user);
// indexed string w/ existing array
user.setList(new ArrayList<>());
user.getList().add("");
String[] foo = new String[] { "asdf" };
stack.setValue("list[0]", foo);
assertNotNull(user.getList());
assertEquals(1, user.getList().size());
assertEquals(String.class, user.getList().get(0).getClass());
assertEquals("asdf", user.getList().get(0));
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testAllowCallingMethodsOnObjectClassInDevModeTrue.
public void testAllowCallingMethodsOnObjectClassInDevModeTrue() {
Exception expected = null;
try {
ognlUtil.setExcludedClasses(Foo.class.getName());
ognlUtil.setDevModeExcludedClasses("");
ognlUtil.setDevMode(Boolean.TRUE.toString());
Foo foo = new Foo();
String result = (String) ognlUtil.getValue("toString", ognlUtil.createDefaultContext(foo), foo, String.class);
assertEquals("Foo", result);
} catch (OgnlException e) {
expected = e;
}
assertNull(expected);
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testSetPropertiesBoolean.
public void testSetPropertiesBoolean() {
Foo foo = new Foo();
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
Map<String, Object> props = new HashMap<>();
props.put("useful", "true");
ognlUtil.setProperties(props, foo, context);
assertTrue(foo.isUseful());
props = new HashMap<>();
props.put("useful", "false");
ognlUtil.setProperties(props, foo, context);
assertFalse(foo.isUseful());
}
Aggregations