use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method selectionWithIterable.
@Test
public void selectionWithIterable() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new IterableTestBean());
Object value = expression.getValue(context);
assertTrue(value instanceof List);
List<?> list = (List<?>) value;
assertEquals(5, list.size());
assertEquals(0, list.get(0));
assertEquals(1, list.get(1));
assertEquals(2, list.get(2));
assertEquals(3, list.get(3));
assertEquals(4, list.get(4));
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method selectLastItemInPrimitiveArray.
@Test
public void selectLastItemInPrimitiveArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("ints.$[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertTrue(value instanceof Integer);
assertEquals(4, value);
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method selectLastItemInArray.
@Test
public void selectLastItemInArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertTrue(value instanceof Integer);
assertEquals(4, value);
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method selectionWithArray.
@Test
public void selectionWithArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertTrue(value.getClass().isArray());
TypedValue typedValue = new TypedValue(value);
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
Integer[] array = (Integer[]) value;
assertEquals(5, array.length);
assertEquals(new Integer(0), array[0]);
assertEquals(new Integer(1), array[1]);
assertEquals(new Integer(2), array[2]);
assertEquals(new Integer(3), array[3]);
assertEquals(new Integer(4), array[4]);
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method projectionWithList.
@Test
public void projectionWithList() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("testList", IntegerTestBean.createList());
Object value = expression.getValue(context);
assertTrue(value instanceof List);
List<?> list = (List<?>) value;
assertEquals(3, list.size());
assertEquals(5, list.get(0));
assertEquals(6, list.get(1));
assertEquals(7, list.get(2));
}
Aggregations