Search in sources :

Example 56 with SpelExpression

use of org.springframework.expression.spel.standard.SpelExpression in project spring-framework by spring-projects.

the class ReflectionHelperTests method testUtilities.

@Test
public void testUtilities() throws ParseException {
    SpelExpression expr = (SpelExpression) parser.parseExpression("3+4+5+6+7-2");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    SpelUtilities.printAbstractSyntaxTree(ps, expr);
    ps.flush();
    String s = baos.toString();
    // ===> Expression '3+4+5+6+7-2' - AST start
    // OperatorMinus  value:(((((3 + 4) + 5) + 6) + 7) - 2)  #children:2
    // OperatorPlus  value:((((3 + 4) + 5) + 6) + 7)  #children:2
    // OperatorPlus  value:(((3 + 4) + 5) + 6)  #children:2
    // OperatorPlus  value:((3 + 4) + 5)  #children:2
    // OperatorPlus  value:(3 + 4)  #children:2
    // CompoundExpression  value:3
    // IntLiteral  value:3
    // CompoundExpression  value:4
    // IntLiteral  value:4
    // CompoundExpression  value:5
    // IntLiteral  value:5
    // CompoundExpression  value:6
    // IntLiteral  value:6
    // CompoundExpression  value:7
    // IntLiteral  value:7
    // CompoundExpression  value:2
    // IntLiteral  value:2
    // ===> Expression '3+4+5+6+7-2' - AST end
    assertThat(s.contains("===> Expression '3+4+5+6+7-2' - AST start")).isTrue();
    assertThat(s.contains(" OpPlus  value:((((3 + 4) + 5) + 6) + 7)  #children:2")).isTrue();
}
Also used : PrintStream(java.io.PrintStream) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

SpelExpression (org.springframework.expression.spel.standard.SpelExpression)56 Test (org.junit.jupiter.api.Test)30 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)27 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)18 Test (org.junit.Test)15 Expression (org.springframework.expression.Expression)8 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 EvaluationContext (org.springframework.expression.EvaluationContext)4 HashMap (java.util.HashMap)3 List (java.util.List)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)3 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)3 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)3 HttpRequestExecutingMessageHandler (org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler)3 Method (java.lang.reflect.Method)2 BigDecimal (java.math.BigDecimal)2 LinkedHashMap (java.util.LinkedHashMap)2