Search in sources :

Example 26 with ELProcessor

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

the class TestCollectionOperations method testForEach01.

@Test
public void testForEach01() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("beans", beans);
    processor.getValue("beans.stream().forEach(b->b.setValLong(b.valLong + 1))", Object.class);
    Assert.assertEquals(2, bean01.getValLong());
    Assert.assertEquals(3, bean02.getValLong());
    Assert.assertEquals(4, bean03.getValLong());
    // Restore the beans to their default state
    processor.getValue("beans.stream().forEach(b->b.setValLong(b.valLong - 1))", Object.class);
    Assert.assertEquals(1, bean01.getValLong());
    Assert.assertEquals(2, bean02.getValLong());
    Assert.assertEquals(3, bean03.getValLong());
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 27 with ELProcessor

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

the class TestCollectionOperations method testAverage01.

@Test
public void testAverage01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("[1,2,3,4,5].stream().average()", Object.class);
    Number average = (Number) ((Optional) result).get();
    Assert.assertTrue("Result: " + average.toString(), ELSupport.equals(null, Long.valueOf(3), average));
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 28 with ELProcessor

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

the class TestCollectionOperations method testFindFirst01.

@Test
public void testFindFirst01() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("beans", beans);
    Optional result = (Optional) processor.getValue("beans.stream().findFirst()", Object.class);
    Assert.assertEquals(bean01, result.get());
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 29 with ELProcessor

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

the class TestCollectionOperations method testReduceLambdaSeed01.

@Test
public void testReduceLambdaSeed01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("[1,2,3,4,5].stream().reduce(10, (x,y)->x+y)", Object.class);
    Assert.assertEquals(Long.valueOf(25), result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 30 with ELProcessor

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

the class TestCollectionOperations method testAverage04.

@Test
public void testAverage04() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("[].stream().average().orElseGet(()->10)", Object.class);
    Assert.assertEquals(Long.valueOf(10), 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