Search in sources :

Example 16 with Expression

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

the class JexlTest method testJavaExpressionNum.

@Test
public void testJavaExpressionNum() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "bad_num == 2";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("bad_num", 2);
    // Now evaluate the expression, getting the result
    Boolean isEqual = (Boolean) e.evaluate(jc);
    Assert.assertTrue(isEqual);
    jc.set("bad_num", null);
    isEqual = (Boolean) e.evaluate(jc);
    Assert.assertFalse(isEqual);
    jc.set("bad_num", "2");
    isEqual = (Boolean) e.evaluate(jc);
    Assert.assertTrue(isEqual);
}
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 17 with Expression

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

the class JexlTest method testJavaStrEmpty.

@Test
public void testJavaStrEmpty() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "ARM17_score != null and !ARM17_score.isEmpty()";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("ARM17_score", null);
    Assert.assertEquals(Boolean.FALSE, 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 18 with Expression

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

the class JexlTest method testJavaEqual.

@Test
public void testJavaEqual() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "arm14_seg==1 and time_window=='DEV'";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("arm14_seg", "1");
    jc.set("time_window", "DEV");
    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 19 with Expression

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

the class JexlTest method testEvaluator.

@Test
public void testEvaluator() {
    String weightColumnName = "cg_dol_wgt";
    JexlEngine jexl = new JexlEngine();
    Expression e = jexl.createExpression(weightColumnName);
    JexlContext jc = new MapContext();
    jc.set("cg_dol_wgt", "1083.22500000");
    Object result = e.evaluate(jc);
    System.out.println((result instanceof Integer));
    System.out.println((result instanceof Double));
    System.out.println(result.toString());
}
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 20 with Expression

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

the class JexlTest method testJavaMode.

@Test
public void testJavaMode() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "txn_id % 2 == 0 ";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("txn_id", "1");
    Assert.assertEquals(Boolean.FALSE, e.evaluate(jc));
    jc.set("txn_id", "2");
    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)

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