Search in sources :

Example 66 with ExpressionParser

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

the class SpelReproTests method SPR12035.

@Test
public void SPR12035() {
    ExpressionParser parser = new SpelExpressionParser();
    Expression expression1 = parser.parseExpression("list.?[ value>2 ].size()!=0");
    assertTrue(expression1.getValue(new BeanClass(new ListOf(1.1), new ListOf(2.2)), Boolean.class));
    Expression expression2 = parser.parseExpression("list.?[ T(java.lang.Math).abs(value) > 2 ].size()!=0");
    assertTrue(expression2.getValue(new BeanClass(new ListOf(1.1), new ListOf(-2.2)), Boolean.class));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) 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 67 with ExpressionParser

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

the class SpelReproTests method SPR9486_floatPowerDouble.

@Test
public void SPR9486_floatPowerDouble() {
    Number expectedResult = Math.pow(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 68 with ExpressionParser

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

the class SpelReproTests method SPR10091_primitiveTestValue.

@Test
public void SPR10091_primitiveTestValue() {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
    Object value = parser.parseExpression("primitiveProperty").getValue(evaluationContext);
    assertNotNull(value);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 69 with ExpressionParser

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

the class SpelReproTests method SPR9486_floatLessThanOrEqualDouble.

@Test
public void SPR9486_floatLessThanOrEqualDouble() {
    Boolean expectedNumber = -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(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)

Example 70 with ExpressionParser

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

the class SpelDocumentationTests method testPropertyNavigation.

@Test
public void testPropertyNavigation() throws Exception {
    ExpressionParser parser = new SpelExpressionParser();
    // Inventions Array
    StandardEvaluationContext teslaContext = TestScenarioCreator.getTestEvaluationContext();
    //		teslaContext.setRootObject(tesla);
    // evaluates to "Induction motor"
    String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
    assertEquals("Induction motor", invention);
    // Members List
    StandardEvaluationContext societyContext = new StandardEvaluationContext();
    IEEE ieee = new IEEE();
    ieee.Members[0] = tesla;
    societyContext.setRootObject(ieee);
    // evaluates to "Nikola Tesla"
    String name = parser.parseExpression("Members[0].Name").getValue(societyContext, String.class);
    assertEquals("Nikola Tesla", name);
    // List and Array navigation
    // evaluates to "Wireless communication"
    invention = parser.parseExpression("Members[0].Inventions[6]").getValue(societyContext, String.class);
    assertEquals("Wireless communication", invention);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) 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