Search in sources :

Example 6 with ExpressionFactory

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

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

the class TestAstMapData 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':'1','b':'2','c':'3'}}", Map.class);
    Assert.assertEquals(Map.class, ve.getType(context));
    Assert.assertEquals(simpleMap, 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 ExpressionFactory

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

the class TestAstAssign method testGetType02.

@Test
public void testGetType02() {
    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'; bean01.text}", 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 9 with ExpressionFactory

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

the class TestAstConcatenation 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' += 3}", String.class);
    Assert.assertEquals(String.class, ve.getType(context));
    Assert.assertEquals("a3", 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 10 with ExpressionFactory

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

the class TestAstListData 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','b','c']}", List.class);
    Assert.assertEquals(List.class, ve.getType(context));
    Assert.assertEquals(simpleList, 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