Search in sources :

Example 11 with ValueExpression

use of jakarta.el.ValueExpression 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);
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ELException(jakarta.el.ELException) ELException(jakarta.el.ELException) Test(org.junit.Test)

Example 12 with ValueExpression

use of jakarta.el.ValueExpression 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);
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 13 with ValueExpression

use of jakarta.el.ValueExpression 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);
}
Also used : ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 14 with ValueExpression

use of jakarta.el.ValueExpression in project tomcat by apache.

the class TestMethodExpressionImpl method testBug52970.

@Test
public void testBug52970() {
    MethodExpression me = factory.createMethodExpression(context, "${beanEnum.submit('APPLE')}", null, new Class<?>[] { TesterBeanEnum.class });
    me.invoke(context, null);
    ValueExpression ve = factory.createValueExpression(context, "#{beanEnum.lastSubmitted}", TesterEnum.class);
    TesterEnum actual = (TesterEnum) ve.getValue(context);
    Assert.assertEquals(TesterEnum.APPLE, actual);
}
Also used : ValueExpression(jakarta.el.ValueExpression) MethodExpression(jakarta.el.MethodExpression) Test(org.junit.Test)

Example 15 with ValueExpression

use of jakarta.el.ValueExpression in project tomcat by apache.

the class TestMethodExpressionImpl method testBug50790b.

@Test
public void testBug50790b() throws Exception {
    ValueExpression ve = factory.createValueExpression(context, "#{beanA.name.contains(beanAA.name)}", java.lang.Boolean.class);
    Boolean actual = (Boolean) ve.getValue(context);
    Assert.assertEquals(Boolean.FALSE, actual);
}
Also used : ValueExpression(jakarta.el.ValueExpression) Test(org.junit.Test)

Aggregations

ValueExpression (jakarta.el.ValueExpression)42 Test (org.junit.Test)28 ELContext (jakarta.el.ELContext)24 ExpressionFactory (jakarta.el.ExpressionFactory)24 ELContextImpl (org.apache.jasper.el.ELContextImpl)17 VariableMapper (jakarta.el.VariableMapper)8 ELProcessor (jakarta.el.ELProcessor)7 MethodExpression (jakarta.el.MethodExpression)7 ELException (jakarta.el.ELException)6 PropertyNotFoundException (jakarta.el.PropertyNotFoundException)4 ValueReference (jakarta.el.ValueReference)3 ELClass (jakarta.el.ELClass)2 ELManager (jakarta.el.ELManager)1 FunctionMapper (jakarta.el.FunctionMapper)1 LambdaExpression (jakarta.el.LambdaExpression)1 MethodNotFoundException (jakarta.el.MethodNotFoundException)1 TesterELContext (jakarta.el.TesterELContext)1 ELParseException (jakarta.servlet.jsp.el.ELParseException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1