use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR9735.
@Test
public void SPR9735() {
Item item = new Item();
item.setName("parent");
Item item1 = new Item();
item1.setName("child1");
Item item2 = new Item();
item2.setName("child2");
item.add(item1);
item.add(item2);
ExpressionParser parser = new SpelExpressionParser();
EvaluationContext context = new StandardEvaluationContext();
Expression exp = parser.parseExpression("#item[0].name");
context.setVariable("item", item);
assertEquals("child1", exp.getValue(context));
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR9486_floatLessThanFloat.
@Test
public void SPR9486_floatLessThanFloat() {
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_subtractFloatWithFloat.
@Test
public void SPR9486_subtractFloatWithFloat() {
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);
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR9486_floatModulusFloat.
@Test
public void SPR9486_floatModulusFloat() {
Number expectedResult = 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(expectedResult, result);
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method customStaticFunctions_SPR9038.
/**
* Test the ability to subclass the ReflectiveMethodResolver and change how it
* determines the set of methods for a type.
*/
@Test
public void customStaticFunctions_SPR9038() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
List<MethodResolver> methodResolvers = new ArrayList<>();
methodResolvers.add(new ReflectiveMethodResolver() {
@Override
protected Method[] getMethods(Class<?> type) {
try {
return new Method[] { Integer.class.getDeclaredMethod("parseInt", new Class<?>[] { String.class, Integer.TYPE }) };
} catch (NoSuchMethodException ex) {
return new Method[0];
}
}
});
context.setMethodResolvers(methodResolvers);
Expression expression = parser.parseExpression("parseInt('-FF', 16)");
Integer result = expression.getValue(context, "", Integer.class);
assertEquals(-255, result.intValue());
}
Aggregations