Search in sources :

Example 26 with OgnlValueStack

use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.

the class OgnlValueStackTest method testFailOnErrorOnInheritedProperties.

public void testFailOnErrorOnInheritedProperties() {
    // this shuld not fail as the property is defined on a parent class
    OgnlValueStack vs = createValueStack();
    Foo foo = new Foo();
    BarJunior barjr = new BarJunior();
    foo.setBarJunior(barjr);
    vs.push(foo);
    assertNull(barjr.getTitle());
    vs.findValue("barJunior.title", true);
}
Also used : Foo(com.opensymphony.xwork2.util.Foo)

Example 27 with OgnlValueStack

use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.

the class OgnlValueStackTest method testMapEntriesAvailableByKey.

public void testMapEntriesAvailableByKey() {
    Foo foo = new Foo();
    String title = "a title";
    foo.setTitle(title);
    OgnlValueStack vs = createValueStack();
    vs.push(foo);
    Map map = new HashMap();
    String a_key = "a";
    String a_value = "A";
    map.put(a_key, a_value);
    String b_key = "b";
    String b_value = "B";
    map.put(b_key, b_value);
    vs.push(map);
    assertEquals(title, vs.findValue("title"));
    assertEquals(a_value, vs.findValue(a_key));
    assertEquals(b_value, vs.findValue(b_key));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Foo(com.opensymphony.xwork2.util.Foo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 28 with OgnlValueStack

use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.

the class OgnlUtilTest method testSetBigIndexedValue.

/**
 * XW-281
 */
public void testSetBigIndexedValue() {
    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);
    User user = new User();
    stack.push(user);
    // indexed string w/ existing array
    user.setList(new ArrayList<>());
    String[] foo = new String[] { "asdf" };
    ((OgnlValueStack) stack).setDevMode("true");
    try {
        stack.setValue("list.1114778947765", foo);
        fail("non-valid expression: list.1114778947765");
    } catch (RuntimeException ex) {
    // it's oke
    }
    try {
        stack.setValue("1114778947765", foo);
        fail("non-valid expression: 1114778947765");
    } catch (RuntimeException ignore) {
    }
    try {
        stack.setValue("1234", foo);
        fail("non-valid expression: 1234");
    } catch (RuntimeException ignore) {
    }
    ((OgnlValueStack) stack).setDevMode("false");
    try {
        // Set dev mode false (above set now refused)
        reloadTestContainerConfiguration(false, 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);
    stack.setValue("list.1114778947765", foo);
    stack.setValue("1114778947765", foo);
    stack.setValue("1234", foo);
}
Also used : User(com.opensymphony.xwork2.test.User) 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)

Aggregations

Foo (com.opensymphony.xwork2.util.Foo)14 ValueStack (com.opensymphony.xwork2.util.ValueStack)6 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)5 OgnlException (ognl.OgnlException)5 StrutsException (org.apache.struts2.StrutsException)5 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 ParseException (ognl.ParseException)4 TextProvider (com.opensymphony.xwork2.TextProvider)2 XWorkConverter (com.opensymphony.xwork2.conversion.impl.XWorkConverter)2 WrapperTemplateModel (freemarker.ext.util.WrapperTemplateModel)2 AdapterTemplateModel (freemarker.template.AdapterTemplateModel)2 TemplateBooleanModel (freemarker.template.TemplateBooleanModel)2 TemplateCollectionModel (freemarker.template.TemplateCollectionModel)2 TemplateHashModel (freemarker.template.TemplateHashModel)2 TemplateModel (freemarker.template.TemplateModel)2 TemplateModelException (freemarker.template.TemplateModelException)2 TemplateModelIterator (freemarker.template.TemplateModelIterator)2 TemplateNumberModel (freemarker.template.TemplateNumberModel)2