Search in sources :

Example 16 with ELContext

use of jakarta.el.ELContext 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 17 with ELContext

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

the class TestScopedAttributeELResolverPerformance method testGetValuePerformance.

/*
     * With the caching of NotFound responses this test takes ~20ms. Without the
     * caching it takes ~6s.
     */
@Test
public void testGetValuePerformance() throws Exception {
    ELContext context = new StandardELContext(ELManager.getExpressionFactory());
    context.putContext(JspContext.class, new TesterPageContext());
    ELResolver resolver = new ScopedAttributeELResolver();
    for (int i = 0; i < 100000; i++) {
        resolver.getValue(context, null, "unknown");
    }
}
Also used : TesterPageContext(jakarta.servlet.jsp.TesterPageContext) ELContext(jakarta.el.ELContext) StandardELContext(jakarta.el.StandardELContext) ELResolver(jakarta.el.ELResolver) StandardELContext(jakarta.el.StandardELContext) Test(org.junit.Test)

Example 18 with ELContext

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

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

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

ELContext (jakarta.el.ELContext)26 ExpressionFactory (jakarta.el.ExpressionFactory)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 ELResolver (jakarta.el.ELResolver)1 StandardELContext (jakarta.el.StandardELContext)1 TesterELContext (jakarta.el.TesterELContext)1 VariableMapper (jakarta.el.VariableMapper)1 TesterPageContext (jakarta.servlet.jsp.TesterPageContext)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