use of org.apache.commons.jexl2.JexlContext in project shifu by ShifuML.
the class JexlTest method testJavaExpressionString.
@Test
public void testJavaExpressionString() {
JexlEngine jexl = new JexlEngine();
String jexlExp = "name == \"user_a\"";
Expression e = jexl.createExpression(jexlExp);
JexlContext jc = new MapContext();
jc.set("name", "user_a");
// Now evaluate the expression, getting the result
Boolean isEqual = (Boolean) e.evaluate(jc);
Assert.assertTrue(isEqual);
jc.set("name", "user_b");
isEqual = (Boolean) e.evaluate(jc);
Assert.assertFalse(isEqual);
}
use of org.apache.commons.jexl2.JexlContext 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));
}
use of org.apache.commons.jexl2.JexlContext 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));
}
use of org.apache.commons.jexl2.JexlContext 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));
}
use of org.apache.commons.jexl2.JexlContext 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);
}
Aggregations