use of com.opensymphony.xwork2.util.Bar 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.Bar in project struts by apache.
the class OgnlUtilTest method testGetBeanMap.
public void testGetBeanMap() throws Exception {
Bar bar = new Bar();
bar.setTitle("I have beer");
Foo foo = new Foo();
foo.setALong(123);
foo.setNumber(44);
foo.setBar(bar);
foo.setTitle("Hello Santa");
foo.setUseful(true);
// just do some of the 15 tests
Map<String, Object> beans = ognlUtil.getBeanMap(foo);
assertNotNull(beans);
assertEquals(22, beans.size());
assertEquals("Hello Santa", beans.get("title"));
assertEquals(new Long("123"), beans.get("ALong"));
assertEquals(new Integer("44"), beans.get("number"));
assertEquals(bar, beans.get("bar"));
assertEquals(Boolean.TRUE, beans.get("useful"));
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class OgnlValueStackTest method testGetBarAsString.
public void testGetBarAsString() {
Foo foo = new Foo();
Bar bar = new Bar();
bar.setTitle("bar");
bar.setSomethingElse(123);
foo.setBar(bar);
OgnlValueStack vs = createValueStack();
vs.push(foo);
String output = (String) vs.findValue("bar", String.class);
assertEquals("bar:123", output);
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class OgnlValueStackTest method testSetBarAsString.
public void testSetBarAsString() {
Foo foo = new Foo();
OgnlValueStack vs = createValueStack();
vs.push(foo);
vs.setValue("bar", "bar:123");
assertEquals("bar", foo.getBar().getTitle());
assertEquals(123, foo.getBar().getSomethingElse());
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class OgnlValueStackTest method testGetComplexBarAsString.
public void testGetComplexBarAsString() {
// children foo->foo->foo
Foo foo = new Foo();
Foo foo2 = new Foo();
foo.setChild(foo2);
Foo foo3 = new Foo();
foo2.setChild(foo3);
// relatives
Foo fooA = new Foo();
foo.setRelatives(new Foo[] { fooA });
Foo fooB = new Foo();
foo2.setRelatives(new Foo[] { fooB });
Foo fooC = new Foo();
foo3.setRelatives(new Foo[] { fooC });
// the bar
Bar bar = new Bar();
bar.setTitle("bar");
bar.setSomethingElse(123);
// now place the bar all over
foo.setBar(bar);
foo2.setBar(bar);
foo3.setBar(bar);
fooA.setBar(bar);
fooB.setBar(bar);
fooC.setBar(bar);
OgnlValueStack vs = createValueStack();
vs.push(foo);
vs.getContext().put("foo", foo);
assertEquals("bar:123", vs.findValue("#foo.bar", String.class));
assertEquals("bar:123", vs.findValue("bar", String.class));
assertEquals("bar:123", vs.findValue("child.bar", String.class));
assertEquals("bar:123", vs.findValue("child.child.bar", String.class));
assertEquals("bar:123", vs.findValue("relatives[0].bar", String.class));
assertEquals("bar:123", vs.findValue("child.relatives[0].bar", String.class));
assertEquals("bar:123", vs.findValue("child.child.relatives[0].bar", String.class));
vs.push(vs.findValue("child"));
assertEquals("bar:123", vs.findValue("bar", String.class));
assertEquals("bar:123", vs.findValue("child.bar", String.class));
assertEquals("bar:123", vs.findValue("relatives[0].bar", String.class));
assertEquals("bar:123", vs.findValue("child.relatives[0].bar", String.class));
}
Aggregations