Search in sources :

Example 71 with ExpressionParser

use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.

the class SpelDocumentationTests method testLiterals.

// Section 7.5
@Test
public void testLiterals() throws Exception {
    ExpressionParser parser = new SpelExpressionParser();
    // evals to "Hello World"
    String helloWorld = (String) parser.parseExpression("'Hello World'").getValue();
    assertEquals("Hello World", helloWorld);
    double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
    assertEquals(6.0221415E+23, avogadrosNumber, 0);
    // evals to 2147483647
    int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue();
    assertEquals(Integer.MAX_VALUE, maxValue);
    boolean trueValue = (Boolean) parser.parseExpression("true").getValue();
    assertTrue(trueValue);
    Object nullValue = parser.parseExpression("null").getValue();
    assertNull(nullValue);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 72 with ExpressionParser

use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.

the class SpelReproTests method SPR9486_floatGreaterThanDouble.

@Test
public void SPR9486_floatGreaterThanDouble() {
    Boolean expectedResult = -10.21f > -10.2;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("-10.21f > -10.2");
    Boolean result = expression.getValue(context, null, Boolean.class);
    assertEquals(expectedResult, result);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 73 with ExpressionParser

use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.

the class SpelReproTests method SPR9486_floatModulusDouble.

@Test
public void SPR9486_floatModulusDouble() {
    Number expectedResult = 10.21f % 10.2;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("10.21f % 10.2");
    Number result = expression.getValue(context, null, Number.class);
    assertEquals(expectedResult, result);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 74 with ExpressionParser

use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.

the class SpelReproTests method SPR9486_floatEqDouble.

@Test
public void SPR9486_floatEqDouble() {
    Boolean expectedResult = 10.215f == 10.2109;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("10.215f == 10.2109");
    Boolean result = expression.getValue(context, null, Boolean.class);
    assertEquals(expectedResult, result);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 75 with ExpressionParser

use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.

the class SpelReproTests method SPR9486_addFloatWithFloat.

@Test
public void SPR9486_addFloatWithFloat() {
    Number expectedNumber = 10.21f + 10.2f;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("10.21f + 10.2f");
    Number result = expression.getValue(context, null, Number.class);
    assertEquals(expectedNumber, result);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Aggregations

ExpressionParser (org.springframework.expression.ExpressionParser)92 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)89 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)81 Expression (org.springframework.expression.Expression)78 Test (org.junit.Test)76 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)51 EvaluationContext (org.springframework.expression.EvaluationContext)10 BigInteger (java.math.BigInteger)6 Map (java.util.Map)5 BigDecimal (java.math.BigDecimal)4 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 TreeMap (java.util.TreeMap)3 ParseException (org.springframework.expression.ParseException)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 SyslogRuntimeException (org.graylog2.syslog4j.SyslogRuntimeException)2 EvaluationException (org.springframework.expression.EvaluationException)2