use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR9486_floatGreaterThanOrEqualFloat.
@Test
public void SPR9486_floatGreaterThanOrEqualFloat() {
Boolean expectedNumber = -10.21f >= -10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression expression = parser.parseExpression("-10.21f >= -10.2f");
Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals(expectedNumber, result);
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR9486_floatEqFloatUnaryMinus.
@Test
public void SPR9486_floatEqFloatUnaryMinus() {
Boolean expectedResult = -10.21f == -10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression expression = parser.parseExpression("-10.21f == -10.2f");
Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals(expectedResult, result);
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelDocumentationTests method testSpecialVariables.
@SuppressWarnings("unchecked")
@Test
public void testSpecialVariables() throws Exception {
// create an array of integers
List<Integer> primes = new ArrayList<>();
primes.addAll(Arrays.asList(2, 3, 5, 7, 11, 13, 17));
// create parser and set variable 'primes' as the array of integers
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("primes", primes);
// all prime numbers > 10 from the list (using selection ?{...})
List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExpression("#primes.?[#this>10]").getValue(context);
assertEquals("[11, 13, 17]", primesGreaterThanTen.toString());
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelDocumentationTests method testFunctions.
// 7.5.9
@Test
public void testFunctions() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.registerFunction("reverseString", StringUtils.class.getDeclaredMethod("reverseString", new Class[] { String.class }));
String helloWorldReversed = parser.parseExpression("#reverseString('hello world')").getValue(context, String.class);
assertEquals("dlrow olleh", helloWorldReversed);
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelDocumentationTests method testRootObject.
@Test
public void testRootObject() throws Exception {
GregorianCalendar c = new GregorianCalendar();
c.set(1856, 7, 9);
// The constructor arguments are name, birthday, and nationaltiy.
Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("name");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(tesla);
String name = (String) exp.getValue(context);
assertEquals("Nikola Tesla", name);
}
Aggregations