Search in sources :

Example 1 with StandardEvaluationContext

use of cn.taketoday.expression.spel.support.StandardEvaluationContext 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 StandardEvaluationContext

use of cn.taketoday.expression.spel.support.StandardEvaluationContext 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 StandardEvaluationContext

use of cn.taketoday.expression.spel.support.StandardEvaluationContext 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 StandardEvaluationContext

use of cn.taketoday.expression.spel.support.StandardEvaluationContext 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 StandardEvaluationContext

use of cn.taketoday.expression.spel.support.StandardEvaluationContext 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

StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)398 Test (org.junit.jupiter.api.Test)390 Expression (cn.taketoday.expression.Expression)258 SpelExpressionParser (cn.taketoday.expression.spel.standard.SpelExpressionParser)256 SpelExpression (cn.taketoday.expression.spel.standard.SpelExpression)178 ExpressionParser (cn.taketoday.expression.ExpressionParser)114 EvaluationContext (cn.taketoday.expression.EvaluationContext)80 ArrayList (java.util.ArrayList)56 List (java.util.List)30 TypedValue (cn.taketoday.expression.TypedValue)28 HashMap (java.util.HashMap)28 Map (java.util.Map)24 TypeDescriptor (cn.taketoday.core.TypeDescriptor)20 EvaluationException (cn.taketoday.expression.EvaluationException)18 LinkedHashMap (java.util.LinkedHashMap)16 ReflectiveMethodResolver (cn.taketoday.expression.spel.support.ReflectiveMethodResolver)14 MethodExecutor (cn.taketoday.expression.MethodExecutor)12 ExpressionState (cn.taketoday.expression.spel.ExpressionState)12 Method (java.lang.reflect.Method)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12