use of cn.taketoday.expression.EvaluationContext in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectLastItemInMap.
@Test
@SuppressWarnings("unchecked")
void selectLastItemInMap() {
EvaluationContext context = new StandardEvaluationContext(new MapTestBean());
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("colors.$[key.startsWith('b')]");
Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
assertThat(colorsMap.size()).isEqualTo(1);
assertThat(colorsMap.keySet().iterator().next()).isEqualTo("brown");
}
use of cn.taketoday.expression.EvaluationContext in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectFirstItemInArray.
@Test
void selectFirstItemInArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertThat(value).isInstanceOf(Integer.class);
assertThat(value).isEqualTo(0);
}
use of cn.taketoday.expression.EvaluationContext in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method projectionWithSet.
@Test
@SuppressWarnings("unchecked")
void projectionWithSet() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("testList", IntegerTestBean.createSet());
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 projectionWithList.
@Test
@SuppressWarnings("unchecked")
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);
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 selectionWithArray.
@Test
void selectionWithArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#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);
}
Aggregations