use of org.apache.commons.jexl2.JexlContext 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);
}
use of org.apache.commons.jexl2.JexlContext 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));
}
use of org.apache.commons.jexl2.JexlContext 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));
}
use of org.apache.commons.jexl2.JexlContext 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());
}
use of org.apache.commons.jexl2.JexlContext 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));
}
Aggregations