Search in sources :

Example 46 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class IndexingTests method emptyList.

@Test
public void emptyList() {
    listOfScalarNotGeneric = new ArrayList();
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("listOfScalarNotGeneric");
    assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
    assertEquals("", expression.getValue(this, String.class));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 47 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class IndexingTests method resolveCollectionElementTypeNull.

@Test
public void resolveCollectionElementTypeNull() {
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("listNotGeneric");
    assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.List<?>", expression.getValueTypeDescriptor(this).toString());
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 48 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class IndexingTests method indexIntoGenericPropertyContainingGrowingList2.

@Test
public void indexIntoGenericPropertyContainingGrowingList2() {
    List<String> property2 = new ArrayList<>();
    this.property2 = property2;
    SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
    SpelExpressionParser parser = new SpelExpressionParser(configuration);
    Expression expression = parser.parseExpression("property2");
    assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
    assertEquals(property2, expression.getValue(this));
    expression = parser.parseExpression("property2[0]");
    try {
        assertEquals("bar", expression.getValue(this));
    } catch (EvaluationException ex) {
        assertTrue(ex.getMessage().startsWith("EL1053E"));
    }
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) EvaluationException(org.springframework.expression.EvaluationException) Test(org.junit.Test)

Example 49 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class IndexingTests method indexIntoGenericPropertyContainingList.

@Test
public void indexIntoGenericPropertyContainingList() {
    List<String> property = new ArrayList<>();
    property.add("bar");
    this.property = property;
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("property");
    assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
    assertEquals(property, expression.getValue(this));
    expression = parser.parseExpression("property[0]");
    assertEquals("bar", expression.getValue(this));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 50 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class IndexingTests method indexIntoGenericPropertyContainingArray.

@Test
public void indexIntoGenericPropertyContainingArray() {
    String[] property = new String[] { "bar" };
    this.property = property;
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("property");
    assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.lang.String[]", expression.getValueTypeDescriptor(this).toString());
    assertEquals(property, expression.getValue(this));
    expression = parser.parseExpression("property[0]");
    assertEquals("bar", expression.getValue(this));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Aggregations

SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)218 Test (org.junit.Test)190 Expression (org.springframework.expression.Expression)179 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)155 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)101 ExpressionParser (org.springframework.expression.ExpressionParser)89 EvaluationContext (org.springframework.expression.EvaluationContext)32 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)16 List (java.util.List)14 EvaluationException (org.springframework.expression.EvaluationException)13 Map (java.util.Map)11 LinkedHashMap (java.util.LinkedHashMap)8 BigInteger (java.math.BigInteger)6 AccessException (org.springframework.expression.AccessException)6 CompositeStringExpression (org.springframework.expression.common.CompositeStringExpression)6 ParseException (org.springframework.expression.ParseException)5 BigDecimal (java.math.BigDecimal)4 TypedValue (org.springframework.expression.TypedValue)4 TreeMap (java.util.TreeMap)3