use of org.springframework.expression.Expression 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));
}
use of org.springframework.expression.Expression in project spring-framework by spring-projects.
the class IndexingTests method indexIntoPropertyContainingList.
@Test
public void indexIntoPropertyContainingList() {
List<Integer> property = new ArrayList<>();
property.add(3);
this.parameterizedList = property;
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("parameterizedList");
assertEquals("java.util.ArrayList<java.lang.Integer>", expression.getValueTypeDescriptor(this).toString());
assertEquals(property, expression.getValue(this));
expression = parser.parseExpression("parameterizedList[0]");
assertEquals(3, expression.getValue(this));
}
use of org.springframework.expression.Expression in project spring-framework by spring-projects.
the class IndexingTests method resolveCollectionElementType.
@SuppressWarnings("unchecked")
@Test
public void resolveCollectionElementType() {
listNotGeneric = new ArrayList(2);
listNotGeneric.add(5);
listNotGeneric.add(6);
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("listNotGeneric");
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
assertEquals("5,6", expression.getValue(this, String.class));
}
use of org.springframework.expression.Expression in project spring-framework by spring-projects.
the class SpelDocumentationTests method testEqualityCheck.
@Test
public void testEqualityCheck() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(tesla);
Expression exp = parser.parseExpression("name == 'Nikola Tesla'");
// evaluates to true
boolean isEqual = exp.getValue(context, Boolean.class);
assertTrue(isEqual);
}
use of org.springframework.expression.Expression in project spring-framework by spring-projects.
the class SpelReproTests method SPR10486.
@Test
public void SPR10486() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Spr10486 rootObject = new Spr10486();
Expression classNameExpression = parser.parseExpression("class.name");
Expression nameExpression = parser.parseExpression("name");
assertThat(classNameExpression.getValue(context, rootObject), equalTo((Object) Spr10486.class.getName()));
assertThat(nameExpression.getValue(context, rootObject), equalTo((Object) "name"));
}
Aggregations