use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class PropertiesConversionSpelTests method mapWithNonStringValue.
@Test
public void mapWithNonStringValue() {
Map<String, Object> map = new HashMap<>();
map.put("x", "1");
map.put("y", 2);
map.put("z", "3");
map.put("a", new UUID(1, 1));
Expression expression = parser.parseExpression("foo(#props)");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("props", map);
String result = expression.getValue(context, new TestBean(), String.class);
assertEquals("1null3", result);
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class PropertiesConversionSpelTests method mapWithAllStringValues.
@Test
public void mapWithAllStringValues() {
Map<String, Object> map = new HashMap<>();
map.put("x", "1");
map.put("y", "2");
map.put("z", "3");
Expression expression = parser.parseExpression("foo(#props)");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("props", map);
String result = expression.getValue(context, new TestBean(), String.class);
assertEquals("123", result);
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class PropertiesConversionSpelTests method customMapWithNonStringValue.
@Test
public void customMapWithNonStringValue() {
CustomMap map = new CustomMap();
map.put("x", "1");
map.put("y", 2);
map.put("z", "3");
Expression expression = parser.parseExpression("foo(#props)");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("props", map);
String result = expression.getValue(context, new TestBean(), String.class);
assertEquals("1null3", result);
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class PropertiesConversionSpelTests method props.
@Test
public void props() {
Properties props = new Properties();
props.setProperty("x", "1");
props.setProperty("y", "2");
props.setProperty("z", "3");
Expression expression = parser.parseExpression("foo(#props)");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("props", props);
String result = expression.getValue(context, new TestBean(), String.class);
assertEquals("123", result);
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelParserTests method valueType.
@Test
public void valueType() {
SpelExpressionParser parser = new SpelExpressionParser();
EvaluationContext ctx = new StandardEvaluationContext();
Class<?> c = parser.parseRaw("2").getValueType();
assertEquals(Integer.class, c);
c = parser.parseRaw("12").getValueType(ctx);
assertEquals(Integer.class, c);
c = parser.parseRaw("null").getValueType();
assertNull(c);
c = parser.parseRaw("null").getValueType(ctx);
assertNull(c);
Object o = parser.parseRaw("null").getValue(ctx, Integer.class);
assertNull(o);
}
Aggregations