Search in sources :

Example 6 with ELProcessor

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

the class TestCollectionOperations method testSortedLambdaExpression01.

@Test
public void testSortedLambdaExpression01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("['c', 'd', 'b', 'a'].stream().sorted((x,y)->x.compareTo(y)*-1).toList()", List.class);
    List<String> expected = new ArrayList<>(4);
    expected.add("d");
    expected.add("c");
    expected.add("b");
    expected.add("a");
    Assert.assertEquals(expected, result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with ELProcessor

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

the class TestCollectionOperations method testFilter01.

@Test
public void testFilter01() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("beans", beans);
    Object result = processor.getValue("beans.stream().filter(b->b.valLong > 2).toList()", List.class);
    List<TesterBeanA> expected = new ArrayList<>(1);
    expected.add(bean03);
    Assert.assertEquals(expected, result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) ArrayList(java.util.ArrayList) TesterBeanA(org.apache.el.TesterBeanA) Test(org.junit.Test)

Example 8 with ELProcessor

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

the class TestCollectionOperations method testNoneMatch01.

@Test
public void testNoneMatch01() {
    ELProcessor processor = new ELProcessor();
    Optional result = (Optional) processor.getValue("[1,2,3,4,5].stream().allMatch(x->x>3)", Object.class);
    Assert.assertEquals(Boolean.FALSE, result.get());
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 9 with ELProcessor

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

the class TestCollectionOperations method testMax01.

@Test
public void testMax01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("[1,2,3,4,5].stream().max()", Object.class);
    Assert.assertEquals(Long.valueOf(5), ((Optional) result).get());
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 10 with ELProcessor

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

the class TestCollectionOperations method testSubstreamStart01.

@Test
public void testSubstreamStart01() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("beans", beans);
    Object result = processor.getValue("beans.stream().substream(1).toList()", Object.class);
    List<TesterBeanA> expected = new ArrayList<>(2);
    expected.add(bean02);
    expected.add(bean03);
    Assert.assertEquals(expected, result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) ArrayList(java.util.ArrayList) TesterBeanA(org.apache.el.TesterBeanA) 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