Search in sources :

Example 86 with Expression

use of io.atlasmap.v2.Expression in project shifu by ShifuML.

the class JexlTest method testJavaSubString.

@Test
public void testJavaSubString() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "str.substring(0, 1) == \"a\" ";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("str", "a1");
    Assert.assertEquals(Boolean.TRUE, e.evaluate(jc));
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) Test(org.testng.annotations.Test)

Example 87 with Expression

use of io.atlasmap.v2.Expression in project shifu by ShifuML.

the class JexlTest method testDerived.

@Test
public void testDerived() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "(0.00472217*vbase_t1_model_V2R1 + 0.00341543*vbase_t1_model_V2BM)/0.00813760";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("NumberUtils", new NumberUtils());
    jc.set("vbase_t1_model_V2R1", 238);
    jc.set("vbase_t1_model_V2BM", 289);
    Assert.assertEquals(259.40519686394026, e.evaluate(jc));
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) NumberUtils(org.apache.commons.lang.math.NumberUtils) Test(org.testng.annotations.Test)

Example 88 with Expression

use of io.atlasmap.v2.Expression in project shifu by ShifuML.

the class JexlTest method testJavaCompare.

@Test
public void testJavaCompare() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "time_window == 'DEV' and live_xm_send_amount <= 10000.0";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("time_window", "DEV");
    jc.set("live_xm_send_amount", "50");
    Assert.assertEquals(Boolean.TRUE, e.evaluate(jc));
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) Test(org.testng.annotations.Test)

Example 89 with Expression

use of io.atlasmap.v2.Expression in project shifu by ShifuML.

the class JexlTest method testJavaDouble.

@Test
public void testJavaDouble() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "columnA + columnB";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    // Now evaluate the expression, getting the result
    Integer val = (Integer) e.evaluate(jc);
    Assert.assertEquals(val, Integer.valueOf(0));
    jc.set("columnA", "0.3");
    double value = (Double) e.evaluate(jc);
    Assert.assertEquals(0.3, value);
    jc.set("columnB", "0.7");
    value = (Double) e.evaluate(jc);
    Assert.assertEquals(value, 1.0);
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) Test(org.testng.annotations.Test)

Example 90 with Expression

use of io.atlasmap.v2.Expression in project aries by apache.

the class JexlPropertyEvaluator method evaluate.

public Object evaluate(String expression, Map<String, Object> properties) {
    try {
        JexlEngine engine = new JexlEngine();
        MapContext context = new MapContext(properties);
        Expression exp = engine.createExpression(expression);
        return exp.evaluate(context);
    } catch (Exception e) {
        LOGGER.info("Could not evaluate expression: {}", expression);
        LOGGER.info("Exception:", e);
        return null;
    }
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) MapContext(org.apache.commons.jexl2.MapContext)

Aggregations

Test (org.junit.jupiter.api.Test)34 Expression (org.apache.commons.jexl2.Expression)28 Expression (io.atlasmap.v2.Expression)26 JexlContext (org.apache.commons.jexl2.JexlContext)25 JexlEngine (org.apache.commons.jexl2.JexlEngine)22 Field (io.atlasmap.v2.Field)21 FieldGroup (io.atlasmap.v2.FieldGroup)20 MapContext (org.apache.commons.jexl2.MapContext)20 SimpleField (io.atlasmap.v2.SimpleField)16 Test (org.testng.annotations.Test)13 PropertyField (io.atlasmap.v2.PropertyField)9 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 Expression (org.eclipse.xtext.resource.bug385636.Expression)7 Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)7 Expression (io.atlasmap.expression.Expression)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ParseException (io.atlasmap.expression.parser.ParseException)4 Action (io.atlasmap.v2.Action)4 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)4