Search in sources :

Example 31 with ValueExpression

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

the class TestMethodExpressionImpl method testBug50790a.

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

Example 32 with ValueExpression

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

the class TesterVariableMapperImpl method testSetVariable01.

@Test
public void testSetVariable01() {
    ExpressionFactory factory = ELManager.getExpressionFactory();
    ELContext context = new TesterELContext();
    ValueExpression ve1 = factory.createValueExpression(context, "${1}", int.class);
    ValueExpression ve2 = factory.createValueExpression(context, "${2}", int.class);
    ValueExpression ve3 = factory.createValueExpression(context, "${3}", int.class);
    VariableMapper mapper = new VariableMapperImpl();
    mapper.setVariable("var1", ve1);
    mapper.setVariable("var2", ve2);
    mapper.setVariable("var3", ve3);
    mapper.setVariable("var2", null);
    Assert.assertEquals(ve1, mapper.resolveVariable("var1"));
    Assert.assertNull(mapper.resolveVariable("var2"));
    Assert.assertEquals(ve3, mapper.resolveVariable("var3"));
}
Also used : ELContext(jakarta.el.ELContext) TesterELContext(jakarta.el.TesterELContext) ExpressionFactory(jakarta.el.ExpressionFactory) VariableMapper(jakarta.el.VariableMapper) ValueExpression(jakarta.el.ValueExpression) TesterELContext(jakarta.el.TesterELContext) Test(org.junit.Test)

Example 33 with ValueExpression

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

the class TestAstAssign method testGetType01.

@Test
public void testGetType01() {
    ELProcessor processor = new ELProcessor();
    ELContext context = processor.getELManager().getELContext();
    ExpressionFactory factory = ELManager.getExpressionFactory();
    processor.defineBean("bean01", new TesterBeanB());
    ValueExpression ve = factory.createValueExpression(context, "${bean01.text = 'hello'}", String.class);
    Assert.assertEquals(String.class, ve.getType(context));
    Assert.assertEquals("hello", 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 34 with ValueExpression

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

the class TestAstSetData method testGetType.

@Test
public void testGetType() {
    ELProcessor processor = new ELProcessor();
    ELContext context = processor.getELManager().getELContext();
    ExpressionFactory factory = ELManager.getExpressionFactory();
    ValueExpression ve = factory.createValueExpression(context, "${{'a','b','c'}}", Set.class);
    Assert.assertEquals(Set.class, ve.getType(context));
    Assert.assertEquals(simpleSet, 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 35 with ValueExpression

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

the class TestValueExpressionImpl method testBug56522SetNullValue.

@Test
public void testBug56522SetNullValue() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanB.name}", String.class);
    // First check the basics work
    String result = (String) ve.getValue(context);
    Assert.assertEquals("Tomcat", result);
    // Now set the value to null
    ve.setValue(context, null);
    Assert.assertEquals("", beanB.getName());
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) 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