use of cn.taketoday.expression.ExpressionParser 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.ExpressionParser in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectFirstItemInMap.
@Test
@SuppressWarnings("unchecked")
void selectFirstItemInMap() {
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("beige");
}
use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.
the class ComparatorTests method customComparatorWorksWithEquality.
@Test
public void customComparatorWorksWithEquality() {
final StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setTypeComparator(customComparator);
ExpressionParser parser = new SpelExpressionParser();
Expression expr = parser.parseExpression("'1' == 1");
assertThat(expr.getValue(ctx, Boolean.class)).isTrue();
}
use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.
the class MapAccessTests method testGetValueFromRootMap.
@Test
public void testGetValueFromRootMap() {
Map<String, String> map = new HashMap<>();
map.put("key", "value");
ExpressionParser spelExpressionParser = new SpelExpressionParser();
Expression expr = spelExpressionParser.parseExpression("#root['key']");
assertThat(expr.getValue(map)).isEqualTo("value");
}
use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.
the class MapAccessTests method testVariableMapAccess.
@Test
public void testVariableMapAccess() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext ctx = TestScenarioCreator.getTestEvaluationContext();
ctx.setVariable("day", "saturday");
Expression expr = parser.parseExpression("testMap[#day]");
Object value = expr.getValue(ctx, String.class);
assertThat(value).isEqualTo("samstag");
}
Aggregations