Search in sources :

Example 16 with ExpressionFactory

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

the class TestValueExpressionImpl method testBug51544Direct.

/*
     * Test using list directly as variable.
     */
@Test
public void testBug51544Direct() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    List<?> list = Collections.emptyList();
    ValueExpression var = factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);
    ValueExpression ve = factory.createValueExpression(context, "${list.size()}", Integer.class);
    Integer result = (Integer) ve.getValue(context);
    Assert.assertEquals(Integer.valueOf(0), result);
}
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 17 with ExpressionFactory

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

the class TestValueExpressionImpl method testBug49345.

@Test
public void testBug49345() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanA beanA = new TesterBeanA();
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    beanA.setBean(beanB);
    ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanA.bean.name}", String.class);
    // First check the basics work
    String result = (String) ve.getValue(context);
    Assert.assertEquals("Tomcat", result);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    Assert.assertNotNull(vr);
    Assert.assertEquals(beanB, vr.getBase());
    Assert.assertEquals("name", vr.getProperty());
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(jakarta.el.ValueReference) Test(org.junit.Test)

Example 18 with ExpressionFactory

use of jakarta.el.ExpressionFactory 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 19 with ExpressionFactory

use of jakarta.el.ExpressionFactory 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 20 with ExpressionFactory

use of jakarta.el.ExpressionFactory 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)

Aggregations

ExpressionFactory (jakarta.el.ExpressionFactory)26 ELContext (jakarta.el.ELContext)25 ValueExpression (jakarta.el.ValueExpression)24 Test (org.junit.Test)22 ELContextImpl (org.apache.jasper.el.ELContextImpl)16 ELProcessor (jakarta.el.ELProcessor)7 ELException (jakarta.el.ELException)3 ValueReference (jakarta.el.ValueReference)3 ELManager (jakarta.el.ELManager)1 TesterELContext (jakarta.el.TesterELContext)1 VariableMapper (jakarta.el.VariableMapper)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Nodes (org.apache.jasper.compiler.ELNode.Nodes)1 TextBuilder (org.apache.jasper.compiler.ELParser.TextBuilder)1 ELContextWrapper (org.apache.jasper.runtime.JspContextWrapper.ELContextWrapper)1