use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class SetPropertiesTest method doTestAddingToMapsWithObjects.
public void doTestAddingToMapsWithObjects(boolean allowAdditions) throws Exception {
loadButAdd(ObjectTypeDeterminer.class, new MockObjectTypeDeterminer(Long.class, Cat.class, null, allowAdditions));
Foo foo = new Foo();
foo.setAnotherCatMap(new HashMap());
String spielname = "Spielen";
ValueStack vs = ActionContext.getContext().getValueStack();
vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
vs.getContext().put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
vs.push(foo);
vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
vs.setValue("anotherCatMap[\"3\"].name", spielname);
Object setCat = foo.getAnotherCatMap().get(new Long(3));
if (allowAdditions) {
assertNotNull(setCat);
assertTrue(setCat instanceof Cat);
assertTrue(((Cat) setCat).getName().equals(spielname));
} else {
assertNull(setCat);
}
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class SetPropertiesTest method testSetCollectionByConverterFromArray.
public void testSetCollectionByConverterFromArray() {
Foo foo = new Foo();
ValueStack vs = ActionContext.getContext().getValueStack();
vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
XWorkConverter c = (XWorkConverter) ((OgnlTypeConverterWrapper) Ognl.getTypeConverter(vs.getContext())).getTarget();
c.registerConverter(Cat.class.getName(), new FooBarConverter());
vs.push(foo);
vs.setValue("cats", new String[] { "1", "2" });
assertNotNull(foo.getCats());
assertEquals(2, foo.getCats().size());
assertEquals(Cat.class, foo.getCats().get(0).getClass());
assertEquals(Cat.class, foo.getCats().get(1).getClass());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class SetPropertiesTest method testSetCollectionByConverterFromCollection.
public void testSetCollectionByConverterFromCollection() {
Foo foo = new Foo();
ValueStack vs = ActionContext.getContext().getValueStack();
vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
XWorkConverter c = (XWorkConverter) ((OgnlTypeConverterWrapper) Ognl.getTypeConverter(vs.getContext())).getTarget();
c.registerConverter(Cat.class.getName(), new FooBarConverter());
vs.push(foo);
HashSet s = new HashSet();
s.add("1");
s.add("2");
vs.setValue("cats", s);
assertNotNull(foo.getCats());
assertEquals(2, foo.getCats().size());
assertEquals(Cat.class, foo.getCats().get(0).getClass());
assertEquals(Cat.class, foo.getCats().get(1).getClass());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class PropertyTest method testTopValueShouldReturnTopOfValueStack.
public void testTopValueShouldReturnTopOfValueStack() {
final ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(new FooBar("foo-value", "bar-value"));
final Property property = new Property(stack);
property.setDefault("default");
property.setValue("top");
assertPropertyOutput("foo-value/bar-value", property);
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class PropertyTest method testTypeConverterShouldBeUsed.
public void testTypeConverterShouldBeUsed() {
final ValueStack stack = ActionContext.getContext().getValueStack();
converter.registerConverter("org.apache.struts2.components.PropertyTest$FooBar", new FooBarConverter());
stack.push(new FooBar("foo-value", "bar-value"));
final Property property = new Property(stack);
property.setDefault("default");
property.setValue("top");
assertPropertyOutput("*foo-value + bar-value*", property);
}
Aggregations