Search in sources :

Example 1 with Expression

use of cn.taketoday.expression.Expression 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);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) ArrayList(java.util.ArrayList) List(java.util.List) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) EvaluationContext(cn.taketoday.expression.EvaluationContext) Test(org.junit.jupiter.api.Test)

Example 2 with Expression

use of cn.taketoday.expression.Expression 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);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) ArrayList(java.util.ArrayList) List(java.util.List) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) EvaluationContext(cn.taketoday.expression.EvaluationContext) Test(org.junit.jupiter.api.Test)

Example 3 with Expression

use of cn.taketoday.expression.Expression 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);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) EvaluationContext(cn.taketoday.expression.EvaluationContext) Test(org.junit.jupiter.api.Test)

Example 4 with Expression

use of cn.taketoday.expression.Expression 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);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) EvaluationContext(cn.taketoday.expression.EvaluationContext) TypedValue(cn.taketoday.expression.TypedValue) Test(org.junit.jupiter.api.Test)

Example 5 with Expression

use of cn.taketoday.expression.Expression 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);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) EvaluationContext(cn.taketoday.expression.EvaluationContext) Test(org.junit.jupiter.api.Test)

Aggregations

Expression (cn.taketoday.expression.Expression)418 Test (org.junit.jupiter.api.Test)394 SpelExpressionParser (cn.taketoday.expression.spel.standard.SpelExpressionParser)302 StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)268 SpelExpression (cn.taketoday.expression.spel.standard.SpelExpression)206 ExpressionParser (cn.taketoday.expression.ExpressionParser)112 EvaluationContext (cn.taketoday.expression.EvaluationContext)70 ArrayList (java.util.ArrayList)58 HashMap (java.util.HashMap)38 CompoundExpression (cn.taketoday.expression.spel.ast.CompoundExpression)36 EvaluationException (cn.taketoday.expression.EvaluationException)28 List (java.util.List)24 Map (java.util.Map)20 CompositeStringExpression (cn.taketoday.expression.common.CompositeStringExpression)16 LinkedHashMap (java.util.LinkedHashMap)14 TypedValue (cn.taketoday.expression.TypedValue)12 SimpleEvaluationContext (cn.taketoday.expression.spel.support.SimpleEvaluationContext)10 Method (java.lang.reflect.Method)10 AccessException (cn.taketoday.expression.AccessException)8 MethodResolver (cn.taketoday.expression.MethodResolver)8