Search in sources :

Example 1 with TestClass

use of org.mvel2.tests.core.res.TestClass in project mvel by mvel.

the class CoreConfidenceTests method testSetterViaMapNotation.

public void testSetterViaMapNotation() {
    TestClass tc = new TestClass();
    tc.getExtra().put("test", "value");
    ParserContext ctx = new ParserContext();
    ctx.withInput("this", TestClass.class);
    ctx.setStrongTyping(true);
    String expression = "extra[\"test\"]";
    Serializable compiled = MVEL.compileSetExpression(expression, tc.getClass(), ctx);
    MVEL.executeSetExpression(compiled, tc, "value3");
    assertEquals("value3", tc.getExtra().get("test"));
}
Also used : Serializable(java.io.Serializable) TestClass(org.mvel2.tests.core.res.TestClass) ParserContext(org.mvel2.ParserContext)

Example 2 with TestClass

use of org.mvel2.tests.core.res.TestClass in project mvel by mvel.

the class CoreConfidenceTests method testSetterViaDotNotation.

public void testSetterViaDotNotation() {
    TestClass tc = new TestClass();
    tc.getExtra().put("test", "value");
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    String expression = "extra.test";
    Serializable compiled = MVEL.compileSetExpression(expression, ctx);
    MVEL.executeSetExpression(compiled, tc, "value2");
    assertEquals("value2", tc.getExtra().get("test"));
}
Also used : Serializable(java.io.Serializable) TestClass(org.mvel2.tests.core.res.TestClass) ParserContext(org.mvel2.ParserContext)

Example 3 with TestClass

use of org.mvel2.tests.core.res.TestClass in project mvel by mvel.

the class CoreConfidenceTests method testGetterViaMapNotation.

public void testGetterViaMapNotation() {
    TestClass tc = new TestClass();
    tc.getExtra().put("test", "value");
    Map vars = new HashMap();
    vars.put("tc", tc);
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("tc", tc.getClass());
    String expression = "tc.extra[\"test\"]";
    Serializable compiled = MVEL.compileExpression(expression, ctx);
    String val = (String) executeExpression(compiled, vars);
    assertEquals("value", val);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestClass(org.mvel2.tests.core.res.TestClass) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with TestClass

use of org.mvel2.tests.core.res.TestClass in project mvel by mvel.

the class CoreConfidenceTests method testGetterViaDotNotation.

public void testGetterViaDotNotation() {
    TestClass tc = new TestClass();
    tc.getExtra().put("test", "value");
    Map vars = new HashMap();
    vars.put("tc", tc);
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("tc", tc.getClass());
    String expression = "tc.extra.test";
    Serializable compiled = MVEL.compileExpression(expression, ctx);
    String val = (String) executeExpression(compiled, vars);
    assertEquals("value", val);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestClass(org.mvel2.tests.core.res.TestClass) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with TestClass

use of org.mvel2.tests.core.res.TestClass in project mvel by mvel.

the class CoreConfidenceTests method testGetterViaMapGetter.

public void testGetterViaMapGetter() {
    TestClass tc = new TestClass();
    tc.getExtra().put("test", "value");
    Map vars = new HashMap();
    vars.put("tc", tc);
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("tc", tc.getClass());
    String expression = "tc.extra.get(\"test\")";
    Serializable compiled = MVEL.compileExpression(expression, ctx);
    String val = (String) executeExpression(compiled, vars);
    assertEquals("value", val);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestClass(org.mvel2.tests.core.res.TestClass) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Serializable (java.io.Serializable)5 ParserContext (org.mvel2.ParserContext)5 TestClass (org.mvel2.tests.core.res.TestClass)5 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3