Search in sources :

Example 81 with StandardEvaluationContext

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);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) HashMap(java.util.HashMap) Expression(org.springframework.expression.Expression) UUID(java.util.UUID) Test(org.junit.Test)

Example 82 with StandardEvaluationContext

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);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) HashMap(java.util.HashMap) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 83 with StandardEvaluationContext

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);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 84 with StandardEvaluationContext

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);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) Properties(java.util.Properties) Test(org.junit.Test)

Example 85 with StandardEvaluationContext

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);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) EvaluationContext(org.springframework.expression.EvaluationContext) Test(org.junit.Test)

Aggregations

StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)251 Test (org.junit.Test)211 Expression (org.springframework.expression.Expression)157 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)155 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)104 ExpressionParser (org.springframework.expression.ExpressionParser)81 EvaluationContext (org.springframework.expression.EvaluationContext)43 ArrayList (java.util.ArrayList)27 List (java.util.List)14 HashMap (java.util.HashMap)12 EvaluationException (org.springframework.expression.EvaluationException)12 TypedValue (org.springframework.expression.TypedValue)12 Map (java.util.Map)11 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)8 BigInteger (java.math.BigInteger)7 LinkedHashMap (java.util.LinkedHashMap)7 ExpressionState (org.springframework.expression.spel.ExpressionState)7 AccessException (org.springframework.expression.AccessException)6 Inventor (org.springframework.expression.spel.testresources.Inventor)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5