use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testSetPropertiesLongArray.
public void testSetPropertiesLongArray() {
Foo foo = new Foo();
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
Map<String, Object> props = new HashMap<>();
props.put("points", new String[] { "1", "2" });
ognlUtil.setProperties(props, foo, context);
assertNotNull(foo.getPoints());
assertEquals(2, foo.getPoints().length);
assertEquals(1, foo.getPoints()[0]);
assertEquals(2, foo.getPoints()[1]);
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testAccessContext.
public void testAccessContext() throws Exception {
Map<String, Object> context = ognlUtil.createDefaultContext(null);
Foo foo = new Foo();
Object result = ognlUtil.getValue("#context", context, null);
Object root = ognlUtil.getValue("#root", context, foo);
Object that = ognlUtil.getValue("#this", context, foo);
assertNotSame(context, result);
assertNull(result);
assertNotNull(root);
assertSame(root.getClass(), Foo.class);
assertNotNull(that);
assertSame(that.getClass(), Foo.class);
assertSame(that, root);
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testIncudeExcludes.
public void testIncudeExcludes() {
Foo foo1 = new Foo();
Foo foo2 = new Foo();
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(Calendar.MONTH, Calendar.FEBRUARY);
cal.set(Calendar.DAY_OF_MONTH, 12);
cal.set(Calendar.YEAR, 1982);
foo1.setPoints(new long[] { 1, 2, 3 });
foo1.setBirthday(cal.getTime());
foo1.setUseful(false);
foo1.setTitle("foo1 title");
foo1.setNumber(1);
foo2.setTitle("foo2 title");
foo2.setNumber(2);
Map<String, Object> context = ognlUtil.createDefaultContext(foo1);
List<String> excludes = new ArrayList<>();
excludes.add("title");
excludes.add("number");
ognlUtil.copy(foo1, foo2, context, excludes, null);
// these values should remain unchanged in foo2
assertEquals(foo2.getTitle(), "foo2 title");
assertEquals(foo2.getNumber(), 2);
// these values should be changed/copied
assertEquals(foo1.getPoints(), foo2.getPoints());
assertEquals(foo1.getBirthday(), foo2.getBirthday());
assertEquals(foo1.isUseful(), foo2.isUseful());
Bar b1 = new Bar();
Bar b2 = new Bar();
b1.setTitle("bar1 title");
b1.setSomethingElse(10);
b1.setId(1L);
b2.setTitle("");
b2.setId(2L);
context = ognlUtil.createDefaultContext(b1);
List<String> includes = new ArrayList<>();
includes.add("title");
includes.add("somethingElse");
ognlUtil.copy(b1, b2, context, null, includes);
// includes properties got copied
assertEquals(b1.getTitle(), b2.getTitle());
assertEquals(b1.getSomethingElse(), b2.getSomethingElse());
// id properties did not
assertEquals(b2.getId(), new Long(2));
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class DomHelperTest method testGetLocationObject.
public void testGetLocationObject() throws Exception {
InputSource in = new InputSource(new StringReader(xml));
in.setSystemId("foo://bar");
Document doc = DomHelper.parse(in);
NodeList nl = doc.getElementsByTagName("bar");
Location loc = DomHelper.getLocationObject((Element) nl.item(0));
assertNotNull(loc);
assertTrue("Should be line 6, was " + loc.getLineNumber(), 6 == loc.getLineNumber());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class AnnotationXWorkConverterTest method testFindConversionErrorMessage.
public void testFindConversionErrorMessage() {
ModelDrivenAnnotationAction action = new ModelDrivenAnnotationAction();
container.inject(action);
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(action);
stack.push(action.getModel());
String message = XWorkConverter.getConversionErrorMessage("birth", Integer.class, stack);
assertNotNull(message);
assertEquals("Invalid date for birth.", message);
message = XWorkConverter.getConversionErrorMessage("foo", Integer.class, stack);
assertNotNull(message);
assertEquals("Invalid field value for field \"foo\".", message);
}
Aggregations