Java Code Examples for javax.el.ELProcessor#getValue()

The following examples show how to use javax.el.ELProcessor#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCollectionOperations.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected=ELException.class)
public void testFindFirst02() {
    ELProcessor processor = new ELProcessor();

    Optional result = (Optional) processor.getValue(
            "[].stream().findFirst()",
            Object.class);

    result.get();
}
 
Example 2
Source File: TestCollectionOperations.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testMax02() {
    ELProcessor processor = new ELProcessor();

    Object result = processor.getValue(
            "[5,4,3,2,1].stream().max()",
            Object.class);

    Assert.assertEquals(Long.valueOf(5), ((Optional) result).get());
}
 
Example 3
Source File: TestAstLambdaExpression.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testLambdaAsFunction07() {
    ELProcessor processor = new ELProcessor();
    Object result =
            processor.getValue("v = (()->y->()->()->x->x-y); v()(1)()(3)(2)",
                    Integer.class);
    Assert.assertEquals(Integer.valueOf(1), result);
}
 
Example 4
Source File: TestAstLambdaExpression.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testNested04() {
    ELProcessor processor = new ELProcessor();
    Object result =
            processor.getValue("(()->y->()->x->x-y)()(1)()(2)",
                    Integer.class);
    Assert.assertEquals(Integer.valueOf(1), result);
}
 
Example 5
Source File: TestCollectionOperations.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example 6
Source File: TestCollectionOperations.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testSum01() {
    ELProcessor processor = new ELProcessor();

    Object result = processor.getValue(
            "[1,2,3,4,5].stream().sum()",
            Object.class);

    Assert.assertTrue("Result: " + result.toString(),
            ELSupport.equals(null, Long.valueOf(15), result));
}
 
Example 7
Source File: TestAstConcatenation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Test string concatenation with whitespace.
 */
@Test
public void testConcatenation03() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("' a' += ' b '", String.class);
    Assert.assertEquals(" a b ", result);
}
 
Example 8
Source File: TestAstConcatenation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Test operator precedence (+= before >).
 */
@Test
public void testPrecedence03() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("10 > 2 += 3", String.class);
    Assert.assertEquals("false", result);
}
 
Example 9
Source File: TestAstFunction.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testImport02() {
    ELProcessor processor = new ELProcessor();
    processor.getELManager().getELContext().getImportHandler()
            .importStatic("java.lang.Integer.valueOf");
    Object result = processor.getValue("valueOf(1000)", Integer.class);
    Assert.assertEquals(Integer.valueOf(1000), result);
}
 
Example 10
Source File: TestCollectionOperations.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testToList01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("['a','b','c'].stream().toList()",
            List.class);
    List<String> expected = new ArrayList<>(3);
    expected.add("a");
    expected.add("b");
    expected.add("c");

    Assert.assertEquals(expected, result);
}
 
Example 11
Source File: TestAstMapData.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testSimple01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue(
            "{'a':'1','b':'2','c':'3'}", Map.class);
    Assert.assertEquals(simpleMap, result);
}
 
Example 12
Source File: TestCollectionOperations.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAverage02() {
    ELProcessor processor = new ELProcessor();

    Object result = processor.getValue(
            "[1,2,3,4,5,6].stream().average()",
            Object.class);

    Number average = (Number) ((Optional) result).get();
    Assert.assertTrue("Result: " + average.toString(),
            ELSupport.equals(null, Double.valueOf(3.5), average));
}
 
Example 13
Source File: TestAstIdentifier.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testImport02() {
    ELProcessor processor = new ELProcessor();
    processor.getELManager().getELContext().getImportHandler().importStatic(
            "java.lang.Integer.MAX_VALUE");
    Object result =
            processor.getValue("MAX_VALUE",
                    Integer.class);
    Assert.assertEquals(Integer.valueOf(Integer.MAX_VALUE), result);
}
 
Example 14
Source File: TestCollectionOperations.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testDistinct01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue(
            "['a', 'b', 'b', 'c'].stream().distinct().toList()",
            List.class);
    List<String> expected = new ArrayList<>(3);
    expected.add("a");
    expected.add("b");
    expected.add("c");

    Assert.assertEquals(expected, result);
}
 
Example 15
Source File: TestAstConcatenation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Test operator precedence (+ before +=).
 */
@Test
public void testPrecedence01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("1 + 2 += 3", String.class);
    Assert.assertEquals("33", result);
}
 
Example 16
Source File: TestAstConcatenation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 17
Source File: TestAstLambdaExpression.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test
public void testSpec03() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("(()->64)", Integer.class);
    Assert.assertEquals(Integer.valueOf(64), result);
}
 
Example 18
Source File: TestAstListData.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test
public void testSimple02() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("[]", List.class);
    Assert.assertEquals(Collections.EMPTY_LIST, result);
}
 
Example 19
Source File: TestAstFunction.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test
public void testImport01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("Integer(1000)", Integer.class);
    Assert.assertEquals(Integer.valueOf(1000), result);
}
 
Example 20
Source File: TestAstSetData.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test
public void testSimple01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("{'a','b','c'}", Set.class);
    Assert.assertEquals(simpleSet, result);
}