use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.
the class TestELParser method bug56185.
@Test
public void bug56185() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl(factory);
TesterBeanC beanC = new TesterBeanC();
ValueExpression var = factory.createValueExpression(beanC, TesterBeanC.class);
context.getVariableMapper().setVariable("myBean", var);
ValueExpression ve = factory.createValueExpression(context, "${(myBean.int1 > 1 and myBean.myBool) or " + "((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}", Boolean.class);
Assert.assertEquals(Boolean.FALSE, ve.getValue(context));
beanC.setInt1(2);
beanC.setMyBool1(true);
Assert.assertEquals(Boolean.TRUE, ve.getValue(context));
}
use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.
the class TestELParser method testJavaKeyWordIdentifier.
@Test
public void testJavaKeyWordIdentifier() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl(factory);
TesterBeanA beanA = new TesterBeanA();
beanA.setInt("five");
ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
context.getVariableMapper().setVariable("this", var);
// Should fail
Exception e = null;
try {
factory.createValueExpression(context, "${this}", String.class);
} catch (ELException ele) {
e = ele;
}
Assert.assertNotNull(e);
}
use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.
the class TestELParser method testJavaKeyWordSuffix.
@Test
public void testJavaKeyWordSuffix() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl(factory);
TesterBeanA beanA = new TesterBeanA();
beanA.setInt("five");
ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
context.getVariableMapper().setVariable("beanA", var);
// Should fail
Exception e = null;
try {
factory.createValueExpression(context, "${beanA.int}", String.class);
} catch (ELException ele) {
e = ele;
}
Assert.assertNotNull(e);
}
use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.
the class TestELParser method doTestBug56179.
private void doTestBug56179(int parenthesesCount, String innerExpr) {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl(factory);
ValueExpression var = factory.createValueExpression(Boolean.TRUE, Boolean.class);
context.getVariableMapper().setVariable("test", var);
StringBuilder expr = new StringBuilder();
expr.append("${");
for (int i = 0; i < parenthesesCount; i++) {
expr.append("(");
}
expr.append(innerExpr);
for (int i = 0; i < parenthesesCount; i++) {
expr.append(")");
}
expr.append("}");
ValueExpression ve = factory.createValueExpression(context, expr.toString(), String.class);
String result = (String) ve.getValue(context);
Assert.assertEquals("true", result);
}
use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.
the class TestELEvaluation method evaluateExpression.
// ************************************************************************
private String evaluateExpression(String expression) {
ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
ELContextImpl ctx = new ELContextImpl(exprFactory);
ctx.setFunctionMapper(new TesterFunctions.FMapper());
ValueExpression ve = exprFactory.createValueExpression(ctx, expression, String.class);
return (String) ve.getValue(ctx);
}
Aggregations