use of com.opensymphony.xwork2.conversion.impl.FooBarConverter in project struts by apache.
the class ListAction method testStringToCustomTypeUsingCustomConverter.
public void testStringToCustomTypeUsingCustomConverter() {
// the converter needs to be registered as the Bar.class converter
// it won't be detected from the Foo-conversion.properties
// because the Foo-conversion.properties file is only used when converting a property of Foo
converter.registerConverter(Bar.class.getName(), new FooBarConverter());
Bar bar = (Bar) converter.convertValue(null, null, null, null, "blah:123", Bar.class);
assertNotNull("conversion failed", bar);
assertEquals(123, bar.getSomethingElse());
assertEquals("blah", bar.getTitle());
}
use of com.opensymphony.xwork2.conversion.impl.FooBarConverter in project struts by apache.
the class AnnotationXWorkConverterTest method testStringToCustomTypeUsingCustomConverter.
public void testStringToCustomTypeUsingCustomConverter() {
// the converter needs to be registered as the Bar.class converter
// it won't be detected from the Foo-conversion.properties
// because the Foo-conversion.properties file is only used when converting a property of Foo
converter.registerConverter(Bar.class.getName(), new FooBarConverter());
Bar bar = (Bar) converter.convertValue(null, null, null, null, "blah:123", Bar.class);
assertNotNull("conversion failed", bar);
assertEquals(123, bar.getSomethingElse());
assertEquals("blah", bar.getTitle());
}
use of com.opensymphony.xwork2.conversion.impl.FooBarConverter 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.conversion.impl.FooBarConverter 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.conversion.impl.FooBarConverter 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