Search in sources :

Example 51 with ELProcessor

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

the class TestAstAssign method testGetValue01.

@Test
public void testGetValue01() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("bean01", new TesterBeanB());
    Object result = processor.getValue("bean01.text = 'hello'", String.class);
    Assert.assertEquals("hello", result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 52 with ELProcessor

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

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

the class TestAstConcatenation method testConcatenation02.

/**
 * Test coercion to string then concatenation.
 */
@Test
public void testConcatenation02() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("1 += 2", String.class);
    Assert.assertEquals("12", result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 54 with ELProcessor

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

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

the class TestAstConcatenation method testConcatenation04.

/**
 * Test string concatenation with mixed types.
 */
@Test
public void testConcatenation04() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("'a' += 3", String.class);
    Assert.assertEquals("a3", result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Aggregations

ELProcessor (jakarta.el.ELProcessor)138 Test (org.junit.Test)133 ArrayList (java.util.ArrayList)13 ELContext (jakarta.el.ELContext)8 ValueExpression (jakarta.el.ValueExpression)8 ExpressionFactory (jakarta.el.ExpressionFactory)7 TesterBeanA (org.apache.el.TesterBeanA)5 List (java.util.List)1