Search in sources :

Example 16 with ELProcessor

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

the class TestCollectionOperations method testLimit01.

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

Example 17 with ELProcessor

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

the class TestCollectionOperations method testFlatMap01.

@Test
public void testFlatMap01() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("beans", beans);
    Object result = processor.getValue("beans.stream().flatMap(b->b.name.toCharArray().stream()).toList()", List.class);
    List<Character> expected = new ArrayList<>(18);
    expected.add(Character.valueOf('b'));
    expected.add(Character.valueOf('e'));
    expected.add(Character.valueOf('a'));
    expected.add(Character.valueOf('n'));
    expected.add(Character.valueOf('0'));
    expected.add(Character.valueOf('1'));
    expected.add(Character.valueOf('b'));
    expected.add(Character.valueOf('e'));
    expected.add(Character.valueOf('a'));
    expected.add(Character.valueOf('n'));
    expected.add(Character.valueOf('0'));
    expected.add(Character.valueOf('2'));
    expected.add(Character.valueOf('b'));
    expected.add(Character.valueOf('e'));
    expected.add(Character.valueOf('a'));
    expected.add(Character.valueOf('n'));
    expected.add(Character.valueOf('0'));
    expected.add(Character.valueOf('3'));
    Assert.assertEquals(expected, result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with ELProcessor

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

the class TestCollectionOperations method testMaxLambda02.

@Test
public void testMaxLambda02() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("beans", beans);
    processor.setVariable("comparison", "v->(x,y)->v(x).compareTo(v(y))");
    Object result = processor.getValue("beans.stream().max(comparison(x->x.name))", Object.class);
    Assert.assertEquals(bean03, ((Optional) result).get());
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 19 with ELProcessor

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

the class TestCollectionOperations method testMap02.

@Test
public void testMap02() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("beans", beans);
    Object result = processor.getValue("beans.stream().filter(b->b.valLong > 1).map(b->[b.name, b.valLong]).toList()", List.class);
    @SuppressWarnings("unchecked") List<List<Object>> list = (List<List<Object>>) result;
    Assert.assertEquals(2, list.size());
    Assert.assertEquals("bean02", list.get(0).get(0));
    Assert.assertEquals(Long.valueOf(2), list.get(0).get(1));
    Assert.assertEquals("bean03", list.get(1).get(0));
    Assert.assertEquals(Long.valueOf(3), list.get(1).get(1));
}
Also used : ELProcessor(jakarta.el.ELProcessor) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 20 with ELProcessor

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

the class TestCollectionOperations method testAllMatch03.

@Test
public void testAllMatch03() {
    ELProcessor processor = new ELProcessor();
    Optional result = (Optional) processor.getValue("[1,2,3,4,5].stream().allMatch(x->x>10)", Object.class);
    Assert.assertEquals(Boolean.FALSE, result.get());
}
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