Search in sources :

Example 6 with ValueExpression

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

the class TestMethodExpressionImpl method testBug49655.

/*
     * This is also tested implicitly in numerous places elsewhere in this
     * class.
     */
@Test
public void testBug49655() throws Exception {
    // This is the call the failed
    MethodExpression me = factory.createMethodExpression(context, "#{beanA.setName('New value')}", null, null);
    // The rest is to check it worked correctly
    me.invoke(context, null);
    ValueExpression ve = factory.createValueExpression(context, "#{beanA.name}", java.lang.String.class);
    Assert.assertEquals("New value", ve.getValue(context));
}
Also used : ValueExpression(jakarta.el.ValueExpression) MethodExpression(jakarta.el.MethodExpression) Test(org.junit.Test)

Example 7 with ValueExpression

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

the class TestAstSemicolon method testGetType.

@Test
public void testGetType() {
    ELProcessor processor = new ELProcessor();
    ELContext context = processor.getELManager().getELContext();
    ExpressionFactory factory = ELManager.getExpressionFactory();
    ValueExpression ve = factory.createValueExpression(context, "${1+1;2+2}", Integer.class);
    Assert.assertEquals(Number.class, ve.getType(context));
    Assert.assertEquals(Integer.valueOf(4), ve.getValue(context));
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 8 with ValueExpression

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

the class TestELParser method testExpression.

private void testExpression(String expression, String expected) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    ValueExpression ve = factory.createValueExpression(context, expression, String.class);
    String result = (String) ve.getValue(context);
    Assert.assertEquals(expected, result);
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 9 with ValueExpression

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

Example 10 with ValueExpression

use of jakarta.el.ValueExpression 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);
}
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)

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