use of cn.taketoday.expression.EvaluationContext in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectionWithList.
@Test
@SuppressWarnings("unchecked")
void selectionWithList() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
Object value = expression.getValue(context);
assertThat(value).isInstanceOf(List.class);
List<Integer> list = (List<Integer>) value;
assertThat(list).containsExactly(0, 1, 2, 3, 4);
}
use of cn.taketoday.expression.EvaluationContext in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method projectionWithIterable.
@Test
@SuppressWarnings("unchecked")
void projectionWithIterable() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("testList", IntegerTestBean.createIterable());
Object value = expression.getValue(context);
assertThat(value).isInstanceOf(List.class);
List<Integer> list = (List<Integer>) value;
assertThat(list).containsExactly(5, 6, 7);
}
use of cn.taketoday.expression.EvaluationContext in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectLastItemInList.
@Test
void selectLastItemInList() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
Object value = expression.getValue(context);
assertThat(value).isInstanceOf(Integer.class);
assertThat(value).isEqualTo(4);
}
use of cn.taketoday.expression.EvaluationContext in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectionWithPrimitiveArray.
@Test
void selectionWithPrimitiveArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("ints.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertThat(value.getClass().isArray()).isTrue();
TypedValue typedValue = new TypedValue(value);
assertThat(typedValue.getTypeDescriptor().getElementDescriptor().getType()).isEqualTo(Integer.class);
Integer[] array = (Integer[]) value;
assertThat(array).containsExactly(0, 1, 2, 3, 4);
}
use of cn.taketoday.expression.EvaluationContext in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectLastItemInSet.
@Test
void selectLastItemInSet() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
Object value = expression.getValue(context);
assertThat(value).isInstanceOf(Integer.class);
assertThat(value).isEqualTo(4);
}
Aggregations