Search in sources :

Example 16 with Foo

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
    }
}
Also used : StubValueStack(com.opensymphony.xwork2.StubValueStack) ValueStack(com.opensymphony.xwork2.util.ValueStack) NoSuchPropertyException(ognl.NoSuchPropertyException) MethodFailedException(ognl.MethodFailedException) InappropriateExpressionException(ognl.InappropriateExpressionException) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) IntrospectionException(java.beans.IntrospectionException) StrutsException(org.apache.struts2.StrutsException) OgnlException(ognl.OgnlException)

Example 17 with Foo

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()");
}
Also used : OgnlException(ognl.OgnlException) Foo(com.opensymphony.xwork2.util.Foo) NoSuchPropertyException(ognl.NoSuchPropertyException) MethodFailedException(ognl.MethodFailedException) InappropriateExpressionException(ognl.InappropriateExpressionException) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) IntrospectionException(java.beans.IntrospectionException) StrutsException(org.apache.struts2.StrutsException) OgnlException(ognl.OgnlException)

Example 18 with Foo

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());
}
Also used : HashMap(java.util.HashMap) Foo(com.opensymphony.xwork2.util.Foo)

Example 19 with Foo

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);
}
Also used : Foo(com.opensymphony.xwork2.util.Foo) CompoundRoot(com.opensymphony.xwork2.util.CompoundRoot)

Example 20 with Foo

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!");
}
Also used : OgnlException(ognl.OgnlException) Foo(com.opensymphony.xwork2.util.Foo) NoSuchPropertyException(ognl.NoSuchPropertyException) MethodFailedException(ognl.MethodFailedException) InappropriateExpressionException(ognl.InappropriateExpressionException) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) IntrospectionException(java.beans.IntrospectionException) StrutsException(org.apache.struts2.StrutsException) OgnlException(ognl.OgnlException)

Aggregations

Foo (com.opensymphony.xwork2.util.Foo)53 HashMap (java.util.HashMap)32 ValueStack (com.opensymphony.xwork2.util.ValueStack)23 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)20 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)19 StrutsException (org.apache.struts2.StrutsException)19 OgnlException (ognl.OgnlException)18 IntrospectionException (java.beans.IntrospectionException)17 InappropriateExpressionException (ognl.InappropriateExpressionException)17 MethodFailedException (ognl.MethodFailedException)17 NoSuchPropertyException (ognl.NoSuchPropertyException)17 ActionProxy (com.opensymphony.xwork2.ActionProxy)16 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)8 Bar (com.opensymphony.xwork2.util.Bar)8 Map (java.util.Map)8 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)7 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)7 StubValueStack (com.opensymphony.xwork2.StubValueStack)6