|
|
|
@ -34,6 +34,8 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; |
|
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext; |
|
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
import static org.assertj.core.api.InstanceOfAssertFactories.INTEGER; |
|
|
|
|
|
|
|
import static org.assertj.core.api.InstanceOfAssertFactories.LIST; |
|
|
|
import static org.springframework.expression.spel.SpelMessage.INVALID_TYPE_FOR_SELECTION; |
|
|
|
import static org.springframework.expression.spel.SpelMessage.INVALID_TYPE_FOR_SELECTION; |
|
|
|
import static org.springframework.expression.spel.SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE; |
|
|
|
import static org.springframework.expression.spel.SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE; |
|
|
|
import static org.springframework.expression.spel.SpelMessage.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN; |
|
|
|
import static org.springframework.expression.spel.SpelMessage.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN; |
|
|
|
@ -94,28 +96,21 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
void selectionWithList() { |
|
|
|
void selectionWithList() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ListTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ListTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(LIST).containsExactly(0, 1, 2, 3, 4); |
|
|
|
assertThat(value).isInstanceOf(List.class); |
|
|
|
|
|
|
|
List<Integer> list = (List<Integer>) value; |
|
|
|
|
|
|
|
assertThat(list).containsExactly(0, 1, 2, 3, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void selectFirstItemInList() { |
|
|
|
void selectFirstItemInList() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ListTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ListTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(INTEGER).isZero(); |
|
|
|
assertThat(value).isInstanceOf(Integer.class); |
|
|
|
|
|
|
|
assertThat(value).isEqualTo(0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void selectLastItemInList() { |
|
|
|
void selectLastItemInList() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ListTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ListTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(INTEGER).isEqualTo(4); |
|
|
|
assertThat(value).isInstanceOf(Integer.class); |
|
|
|
|
|
|
|
assertThat(value).isEqualTo(4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -130,28 +125,21 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
void selectionWithSet() { |
|
|
|
void selectionWithSet() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new SetTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new SetTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(LIST).containsExactly(0, 1, 2, 3, 4); |
|
|
|
assertThat(value).isInstanceOf(List.class); |
|
|
|
|
|
|
|
List<Integer> list = (List<Integer>) value; |
|
|
|
|
|
|
|
assertThat(list).containsExactly(0, 1, 2, 3, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void selectFirstItemInSet() { |
|
|
|
void selectFirstItemInSet() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new SetTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new SetTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(INTEGER).isZero(); |
|
|
|
assertThat(value).isInstanceOf(Integer.class); |
|
|
|
|
|
|
|
assertThat(value).isEqualTo(0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void selectLastItemInSet() { |
|
|
|
void selectLastItemInSet() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new SetTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new SetTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(INTEGER).isEqualTo(4); |
|
|
|
assertThat(value).isInstanceOf(Integer.class); |
|
|
|
|
|
|
|
assertThat(value).isEqualTo(4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -159,10 +147,7 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
void selectionWithIterable() { |
|
|
|
void selectionWithIterable() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new IterableTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new IterableTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(LIST).containsExactly(0, 1, 2, 3, 4); |
|
|
|
assertThat(value).isInstanceOf(List.class); |
|
|
|
|
|
|
|
List<Integer> list = (List<Integer>) value; |
|
|
|
|
|
|
|
assertThat(list).containsExactly(0, 1, 2, 3, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -173,26 +158,21 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
assertThat(value.getClass().isArray()).isTrue(); |
|
|
|
assertThat(value.getClass().isArray()).isTrue(); |
|
|
|
TypedValue typedValue = new TypedValue(value); |
|
|
|
TypedValue typedValue = new TypedValue(value); |
|
|
|
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Integer.class); |
|
|
|
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Integer.class); |
|
|
|
Integer[] array = (Integer[]) value; |
|
|
|
assertThat((Integer[]) value).containsExactly(0, 1, 2, 3, 4); |
|
|
|
assertThat(array).containsExactly(0, 1, 2, 3, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void selectFirstItemInArray() { |
|
|
|
void selectFirstItemInArray() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(INTEGER).isZero(); |
|
|
|
assertThat(value).isInstanceOf(Integer.class); |
|
|
|
|
|
|
|
assertThat(value).isEqualTo(0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void selectLastItemInArray() { |
|
|
|
void selectLastItemInArray() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(INTEGER).isEqualTo(4); |
|
|
|
assertThat(value).isInstanceOf(Integer.class); |
|
|
|
|
|
|
|
assertThat(value).isEqualTo(4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -203,26 +183,21 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
assertThat(value.getClass().isArray()).isTrue(); |
|
|
|
assertThat(value.getClass().isArray()).isTrue(); |
|
|
|
TypedValue typedValue = new TypedValue(value); |
|
|
|
TypedValue typedValue = new TypedValue(value); |
|
|
|
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Integer.class); |
|
|
|
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Integer.class); |
|
|
|
Integer[] array = (Integer[]) value; |
|
|
|
assertThat((Integer[]) value).containsExactly(0, 1, 2, 3, 4); |
|
|
|
assertThat(array).containsExactly(0, 1, 2, 3, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void selectFirstItemInPrimitiveArray() { |
|
|
|
void selectFirstItemInPrimitiveArray() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("ints.^[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("ints.^[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(INTEGER).isZero(); |
|
|
|
assertThat(value).isInstanceOf(Integer.class); |
|
|
|
|
|
|
|
assertThat(value).isEqualTo(0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void selectLastItemInPrimitiveArray() { |
|
|
|
void selectLastItemInPrimitiveArray() { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("ints.$[#this<5]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("ints.$[#this<5]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean()); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(INTEGER).isEqualTo(4); |
|
|
|
assertThat(value).isInstanceOf(Integer.class); |
|
|
|
|
|
|
|
assertThat(value).isEqualTo(4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -269,10 +244,7 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(); |
|
|
|
context.setVariable("testList", IntegerTestBean.createList()); |
|
|
|
context.setVariable("testList", IntegerTestBean.createList()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(LIST).containsExactly(5, 6, 7); |
|
|
|
assertThat(value).isInstanceOf(List.class); |
|
|
|
|
|
|
|
List<Integer> list = (List<Integer>) value; |
|
|
|
|
|
|
|
assertThat(list).containsExactly(5, 6, 7); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -287,10 +259,7 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(); |
|
|
|
context.setVariable("testList", IntegerTestBean.createSet()); |
|
|
|
context.setVariable("testList", IntegerTestBean.createSet()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(LIST).containsExactly(5, 6, 7); |
|
|
|
assertThat(value).isInstanceOf(List.class); |
|
|
|
|
|
|
|
List<Integer> list = (List<Integer>) value; |
|
|
|
|
|
|
|
assertThat(list).containsExactly(5, 6, 7); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -299,10 +268,7 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]"); |
|
|
|
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]"); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(); |
|
|
|
EvaluationContext context = new StandardEvaluationContext(); |
|
|
|
context.setVariable("testList", IntegerTestBean.createIterable()); |
|
|
|
context.setVariable("testList", IntegerTestBean.createIterable()); |
|
|
|
Object value = expression.getValue(context); |
|
|
|
assertThat(expression.getValue(context)).asInstanceOf(LIST).containsExactly(5, 6, 7); |
|
|
|
assertThat(value).isInstanceOf(List.class); |
|
|
|
|
|
|
|
List<Integer> list = (List<Integer>) value; |
|
|
|
|
|
|
|
assertThat(list).containsExactly(5, 6, 7); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -314,8 +280,7 @@ class SelectionAndProjectionTests extends AbstractExpressionTests { |
|
|
|
assertThat(value.getClass().isArray()).isTrue(); |
|
|
|
assertThat(value.getClass().isArray()).isTrue(); |
|
|
|
TypedValue typedValue = new TypedValue(value); |
|
|
|
TypedValue typedValue = new TypedValue(value); |
|
|
|
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Number.class); |
|
|
|
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Number.class); |
|
|
|
Number[] array = (Number[]) value; |
|
|
|
assertThat((Number[]) value).containsExactly(5, 5.9f, 7); |
|
|
|
assertThat(array).containsExactly(5, 5.9f, 7); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|