use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testNullProperties.
public void testNullProperties() {
Foo foo = new Foo();
foo.setALong(88);
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
ognlUtil.setProperties(null, foo, context);
assertEquals(88, foo.getALong());
Map<String, Object> props = new HashMap<>();
props.put("ALong", "99");
ognlUtil.setProperties(props, foo, context);
assertEquals(99, foo.getALong());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testAvoidCallingMethodsOnObjectClassAsMapWithQuotes.
public void testAvoidCallingMethodsOnObjectClassAsMapWithQuotes() {
Foo foo = new Foo();
Exception expected = null;
try {
ognlUtil.setExcludedClasses(Object.class.getName());
ognlUtil.setValue("class[\"classLoader\"]['defaultAssertionStatus']", ognlUtil.createDefaultContext(foo), foo, true);
fail();
} catch (OgnlException e) {
expected = e;
}
assertNotNull(expected);
assertSame(NoSuchPropertyException.class, expected.getClass());
assertEquals("com.opensymphony.xwork2.util.Foo.class", expected.getMessage());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testSetPropertiesDate.
public void testSetPropertiesDate() {
Foo foo = new Foo();
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
ValueStack stack = new StubValueStack();
stack.push(new StubTextProvider(new HashMap<>()));
Map<String, Object> props = new HashMap<>();
props.put("birthday", "02/12/1982");
// US style test
context = ActionContext.of(context).withLocale(Locale.US).withValueStack(stack).getContextMap();
ognlUtil.setProperties(props, foo, context);
Calendar cal = Calendar.getInstance(Locale.US);
cal.clear();
cal.set(Calendar.MONTH, Calendar.FEBRUARY);
cal.set(Calendar.DAY_OF_MONTH, 12);
cal.set(Calendar.YEAR, 1982);
assertEquals(cal.getTime(), foo.getBirthday());
// UK style test
cal = Calendar.getInstance(Locale.UK);
cal.clear();
cal.set(Calendar.MONTH, Calendar.OCTOBER);
cal.set(Calendar.DAY_OF_MONTH, 18);
cal.set(Calendar.YEAR, 2006);
cal.set(Calendar.HOUR_OF_DAY, 14);
cal.set(Calendar.MINUTE, 23);
cal.set(Calendar.SECOND, 45);
Date eventTime = cal.getTime();
String formatted = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.UK).format(eventTime);
props.put("event", formatted);
cal = Calendar.getInstance(Locale.UK);
cal.clear();
cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
cal.set(Calendar.DAY_OF_MONTH, 9);
cal.set(Calendar.YEAR, 2006);
cal.set(Calendar.HOUR_OF_DAY, 14);
cal.set(Calendar.MINUTE, 30);
Date meetingTime = cal.getTime();
formatted = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.UK).format(meetingTime);
props.put("meeting", formatted);
context = ActionContext.of(context).withLocale(Locale.UK).getContextMap();
ognlUtil.setProperties(props, foo, context);
assertEquals(eventTime, foo.getEvent());
assertEquals(meetingTime, foo.getMeeting());
// test RFC 3339 date format for JSON
props.put("event", "1996-12-19T16:39:57Z");
context = ActionContext.of(context).withLocale(Locale.US).getContextMap();
ognlUtil.setProperties(props, foo, context);
cal = Calendar.getInstance(Locale.US);
cal.clear();
cal.set(Calendar.MONTH, Calendar.DECEMBER);
cal.set(Calendar.DAY_OF_MONTH, 19);
cal.set(Calendar.YEAR, 1996);
cal.set(Calendar.HOUR_OF_DAY, 16);
cal.set(Calendar.MINUTE, 39);
cal.set(Calendar.SECOND, 57);
assertEquals(cal.getTime(), foo.getEvent());
// test setting a calendar property
props.put("calendar", "1996-12-19T16:39:57Z");
context = ActionContext.of(context).withLocale(Locale.US).getContextMap();
ognlUtil.setProperties(props, foo, context);
assertEquals(cal, foo.getCalendar());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testCallMethod.
public void testCallMethod() {
Foo foo = new Foo();
Exception expected = null;
try {
ognlUtil.callMethod("#booScope=@myclass@DEFAULT_SCOPE,#bootScope.init()", ognlUtil.createDefaultContext(foo), foo);
fail();
} catch (OgnlException e) {
expected = e;
}
assertNotNull(expected);
assertSame(OgnlException.class, expected.getClass());
assertEquals(expected.getMessage(), "It isn't a simple method which can be called!");
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testAllowCallingMethodsOnObjectClassInDevModeFalse.
public void testAllowCallingMethodsOnObjectClassInDevModeFalse() {
Exception expected = null;
try {
ognlUtil.setExcludedClasses(Foo.class.getName());
ognlUtil.setDevModeExcludedClasses("");
ognlUtil.setDevMode(Boolean.FALSE.toString());
Foo foo = new Foo();
String result = (String) ognlUtil.getValue("toString", ognlUtil.createDefaultContext(foo), foo, String.class);
assertEquals("Foo", result);
} catch (OgnlException e) {
expected = e;
}
assertNotNull(expected);
assertSame(NoSuchPropertyException.class, expected.getClass());
assertEquals("com.opensymphony.xwork2.util.Foo.toString", expected.getMessage());
}
Aggregations