use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testStackValueDevModeChange.
public void testStackValueDevModeChange() {
try {
// Set dev mode false
reloadTestContainerConfiguration(false, false);
} catch (Exception ex) {
fail("Unable to reload container configuration - exception: " + ex);
}
ValueStack stack = ActionContext.getContext().getValueStack();
Map<String, Object> stackContext = stack.getContext();
stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.FALSE);
stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
String[] foo = new String[] { "asdf" };
// With dev mode false, the following set values should not cause failures
stack.setValue("list.1114778947765", foo);
stack.setValue("1114778947765", foo);
stack.setValue("1234", foo);
try {
// Set dev mode true
reloadTestContainerConfiguration(true, false);
} catch (Exception ex) {
fail("Unable to reload container configuration - exception: " + ex);
}
// Repeat stack/context set after retrieving updated stack
stack = ActionContext.getContext().getValueStack();
stackContext = stack.getContext();
stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.FALSE);
stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
try {
stack.setValue("list.1114778947765", foo);
fail("non-valid expression: list.1114778947765");
} catch (RuntimeException ex) {
// Expected with dev mode true
}
try {
stack.setValue("1114778947765", foo);
fail("non-valid expression: 1114778947765");
} catch (RuntimeException ex) {
// Expected with dev mode true
}
try {
stack.setValue("1234", foo);
fail("non-valid expression: 1234");
} catch (RuntimeException ex) {
// Expected with dev mode true
}
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testAvoidCallingMethodsWithBraces.
public void testAvoidCallingMethodsWithBraces() {
Foo foo = new Foo();
Exception expected = null;
try {
ognlUtil.setValue("toString()", ognlUtil.createDefaultContext(foo), foo, true);
fail();
} catch (OgnlException e) {
expected = e;
}
assertNotNull(expected);
assertSame(InappropriateExpressionException.class, expected.getClass());
assertEquals(expected.getMessage(), "Inappropriate OGNL expression: toString()");
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testOgnlHandlesCrapAtTheEndOfANumber.
public void testOgnlHandlesCrapAtTheEndOfANumber() {
Foo foo = new Foo();
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
Map<String, Object> props = new HashMap<>();
props.put("aLong", "123a");
ognlUtil.setProperties(props, foo, context);
assertEquals(0, foo.getALong());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testGetTopTarget.
public void testGetTopTarget() throws Exception {
Foo foo = new Foo();
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
CompoundRoot root = new CompoundRoot();
Object top = ognlUtil.getRealTarget("top", context, root);
// top should be root
assertEquals(root, top);
root.push(foo);
Object val = ognlUtil.getRealTarget("unknown", context, root);
// not found
assertNull(val);
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class OgnlUtilTest method testBlockSequenceOfExpressions.
public void testBlockSequenceOfExpressions() {
Foo foo = new Foo();
Exception expected = null;
try {
ognlUtil.setValue("#booScope=@myclass@DEFAULT_SCOPE,#bootScope.init()", ognlUtil.createDefaultContext(foo), foo, true);
fail();
} catch (OgnlException e) {
expected = e;
}
assertNotNull(expected);
assertSame(OgnlException.class, expected.getClass());
assertEquals(expected.getMessage(), "Eval expressions/chained expressions have been disabled!");
}
Aggregations