use of org.apache.commons.jexl3.JexlOptions in project commons-jexl by apache.
the class Issues100Test method test106.
@Test
public void test106() throws Exception {
final JexlEvalContext context = new JexlEvalContext();
final JexlOptions options = context.getEngineOptions();
options.setStrict(true);
options.setStrictArithmetic(true);
context.set("a", new BigDecimal(1));
context.set("b", new BigDecimal(3));
final JexlEngine jexl = new Engine();
try {
final Object value = jexl.createExpression("a / b").evaluate(context);
Assert.assertNotNull(value);
} catch (final JexlException xjexl) {
Assert.fail("should not occur");
}
options.setMathContext(MathContext.UNLIMITED);
options.setMathScale(2);
try {
jexl.createExpression("a / b").evaluate(context);
Assert.fail("should fail");
} catch (final JexlException xjexl) {
// ok to fail
}
}
use of org.apache.commons.jexl3.JexlOptions in project commons-jexl by apache.
the class Issues100Test method testScaleIssue.
@Test
public void testScaleIssue() throws Exception {
final JexlEngine jexlX = new Engine();
final String expStr1 = "result == salary/month * work.percent/100.00";
final JexlExpression exp1 = jexlX.createExpression(expStr1);
final JexlEvalContext ctx = new JexlEvalContext();
final JexlOptions options = ctx.getEngineOptions();
ctx.set("result", new BigDecimal("9958.33"));
ctx.set("salary", new BigDecimal("119500.00"));
ctx.set("month", new BigDecimal("12.00"));
ctx.set("work.percent", new BigDecimal("100.00"));
// will fail because default scale is 5
Assert.assertFalse((Boolean) exp1.evaluate(ctx));
// will succeed with scale = 2
options.setMathScale(2);
Assert.assertTrue((Boolean) exp1.evaluate(ctx));
}
Aggregations