use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class ConversionErrorInterceptorTest method testFieldErrorWithMapKeyAdded.
public void testFieldErrorWithMapKeyAdded() throws Exception {
String fieldName = "foo['1'].intValue";
conversionErrors.put(fieldName, new ConversionData("bar", int.class));
ActionSupport action = new ActionSupport();
mockInvocation.expectAndReturn("getAction", action);
stack.push(action);
mockInvocation.matchAndReturn("getAction", action);
assertNull(action.getFieldErrors().get(fieldName));
interceptor.doIntercept(invocation);
// This fails!
assertTrue(action.hasFieldErrors());
assertNotNull(action.getFieldErrors().get(fieldName));
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testAvoidCallingMethodsOnObjectClass.
public void testAvoidCallingMethodsOnObjectClass() {
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 testCopyEditable.
public void testCopyEditable() {
Foo foo1 = new Foo();
Foo foo2 = new Foo();
Map<String, Object> context = ognlUtil.createDefaultContext(foo1);
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(Calendar.MONTH, Calendar.MAY);
cal.set(Calendar.DAY_OF_MONTH, 29);
cal.set(Calendar.YEAR, 2017);
foo1.setTitle("blah");
foo1.setNumber(1);
foo1.setPoints(new long[] { 1, 2, 3 });
foo1.setBirthday(cal.getTime());
foo1.setUseful(false);
ognlUtil.copy(foo1, foo2, context, null, null, Bar.class);
assertEquals(foo1.getTitle(), foo2.getTitle());
assertEquals(0, foo2.getNumber());
assertNull(foo2.getPoints());
assertNull(foo2.getBirthday());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testExpressionIsCachedIrrespectiveOfItsExecutionStatus.
public void testExpressionIsCachedIrrespectiveOfItsExecutionStatus() throws OgnlException {
Foo foo = new Foo();
OgnlContext context = (OgnlContext) ognlUtil.createDefaultContext(foo);
// Expression which executes with success
try {
ognlUtil.getValue("@com.opensymphony.xwork2.ognl.OgnlUtilTest@STATIC_FINAL_PUBLIC_ATTRIBUTE", context, foo);
assertEquals("Successfully executed expression must have been cached", ognlUtil.expressionCacheSize(), 1);
} catch (Exception ex) {
fail("Expression execution should have succeeded here. Exception: " + ex);
}
// Expression which executes with failure
try {
ognlUtil.getValue("@com.opensymphony.xwork2.ognl.OgnlUtilTest@STATIC_PRIVATE_ATTRIBUTE", context, foo);
fail("Expression execution should have failed here");
} catch (Exception ex) {
assertEquals("Expression with failed execution must have been cached nevertheless", ognlUtil.expressionCacheSize(), 2);
}
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testSetPropertiesString.
public void testSetPropertiesString() {
Foo foo = new Foo();
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
Map<String, Object> props = new HashMap<>();
props.put("title", "this is a title");
ognlUtil.setProperties(props, foo, context);
assertEquals(foo.getTitle(), "this is a title");
}
Aggregations