use of com.opensymphony.xwork2.util.Foo 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.Foo 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.Foo 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.Foo in project struts by apache.
the class OgnlValueStackTest method testSetNullMap.
public void testSetNullMap() {
Foo foo = new Foo();
OgnlValueStack vs = createValueStack();
vs.getContext().put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
vs.push(foo);
vs.setValue("catMap['One'].name", "Cat One");
vs.setValue("catMap['Two'].name", "Cat Two");
assertNotNull(foo.getCatMap());
assertEquals(2, foo.getCatMap().size());
assertEquals("Cat One", ((Cat) foo.getCatMap().get("One")).getName());
assertEquals("Cat Two", ((Cat) foo.getCatMap().get("Two")).getName());
vs.setValue("catMap['One'].foo.catMap['Two'].name", "Deep null cat");
assertNotNull(((Cat) foo.getCatMap().get("One")).getFoo());
assertNotNull(((Cat) foo.getCatMap().get("One")).getFoo().getCatMap());
assertNotNull(((Cat) foo.getCatMap().get("One")).getFoo().getCatMap().get("Two"));
assertEquals("Deep null cat", ((Cat) ((Cat) foo.getCatMap().get("One")).getFoo().getCatMap().get("Two")).getName());
}
use of com.opensymphony.xwork2.util.Foo 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