Remove obsolete InProgressTests
Since SpEL is no longer "in progress", this commit removes the obsolete InProgressTests class and moves all non-duplicated test cases to other test classes.
This commit is contained in:
parent
e1c22c5385
commit
1ff84671f8
|
@ -46,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
import static org.assertj.core.api.Assertions.within;
|
import static org.assertj.core.api.Assertions.within;
|
||||||
|
import static org.springframework.expression.spel.SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the evaluation of real expressions in a real context.
|
* Tests the evaluation of real expressions in a real context.
|
||||||
|
@ -546,6 +547,18 @@ class EvaluationTests extends AbstractExpressionTests {
|
||||||
evaluateAndCheckError("'X' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED);
|
evaluateAndCheckError("'X' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void betweenOperator() {
|
||||||
|
evaluate("1 between listOneFive", "true", Boolean.class);
|
||||||
|
evaluate("1 between {1, 5}", "true", Boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void betweenOperatorErrors() {
|
||||||
|
evaluateAndCheckError("1 between T(String)", BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST, 10);
|
||||||
|
evaluateAndCheckError("1 between listOfNumbersUpToTen", BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST, 10);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|
|
@ -1,146 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-2024 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.expression.spel;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.expression.spel.standard.SpelExpression;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.springframework.expression.spel.SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* These are tests for language features that are not yet considered 'live':
|
|
||||||
* either missing implementation or documentation.
|
|
||||||
*
|
|
||||||
* @author Andy Clement
|
|
||||||
*/
|
|
||||||
class InProgressTests extends AbstractExpressionTests {
|
|
||||||
|
|
||||||
// BETWEEN
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void betweenOperator() {
|
|
||||||
evaluate("1 between listOneFive", "true", Boolean.class);
|
|
||||||
evaluate("1 between {1, 5}", "true", Boolean.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void betweenOperatorErrors() {
|
|
||||||
evaluateAndCheckError("1 between T(String)", BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST, 10);
|
|
||||||
evaluateAndCheckError("1 between listOfNumbersUpToTen", BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROJECTION
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void projectionOnList() {
|
|
||||||
evaluate("listOfNumbersUpToTen.![#this<5?'y':'n']", "[y, y, y, y, n, n, n, n, n, n]", ArrayList.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void projectionOnInlineList() {
|
|
||||||
evaluate("{1,2,3,4,5,6,7,8,9,10}.![#this<5?'y':'n']", "[y, y, y, y, n, n, n, n, n, n]", ArrayList.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void projectionOnMap() {
|
|
||||||
evaluate("mapOfNumbersUpToTen.![key > 5 ? value : null]",
|
|
||||||
"[null, null, null, null, null, six, seven, eight, nine, ten]", ArrayList.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void projectionOnUnsupportedType() {
|
|
||||||
evaluateAndCheckError("'abc'.![true]", PROJECTION_NOT_SUPPORTED_ON_TYPE);
|
|
||||||
evaluateAndCheckError("null.![true]", PROJECTION_NOT_SUPPORTED_ON_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void projectionOnNullWithSafeNavigation() {
|
|
||||||
evaluate("null?.![true]", null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SELECTION
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void selectionWithNonBooleanSelectionCriteria() {
|
|
||||||
evaluateAndCheckError("listOfNumbersUpToTen.?['nonboolean']", RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);
|
|
||||||
evaluateAndCheckError("mapOfNumbersUpToTen.?['hello'].size()", RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void selectionOnSet() {
|
|
||||||
evaluate("testMap.keySet().?[#this matches '.*o.*']", "[monday]", ArrayList.class);
|
|
||||||
evaluate("testMap.keySet().?[#this matches '.*r.*'].contains('saturday')", "true", Boolean.class);
|
|
||||||
evaluate("testMap.keySet().?[#this matches '.*r.*'].size()", "3", Integer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void selectionOnMap() {
|
|
||||||
evaluate("mapOfNumbersUpToTen.?[key>5].size()", "5", Integer.class);
|
|
||||||
evaluate("mapOfNumbersUpToTen.?[key>11].size()", "0", Integer.class);
|
|
||||||
evaluate("mapOfNumbersUpToTen.^[key>11]", null, null);
|
|
||||||
evaluate("mapOfNumbersUpToTen.$[key>11]", null, null);
|
|
||||||
evaluate("null?.$[key>11]", null, null);
|
|
||||||
evaluateAndCheckError("null.?[key>11]", SpelMessage.INVALID_TYPE_FOR_SELECTION);
|
|
||||||
evaluateAndCheckError("'abc'.?[key>11]", SpelMessage.INVALID_TYPE_FOR_SELECTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void selectFirstOnList() {
|
|
||||||
evaluate("listOfNumbersUpToTen.^[#isEven(#this) == 'y']", "2", Integer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void selectFirstOnMap() {
|
|
||||||
evaluate("mapOfNumbersUpToTen.^[key>5].size()", "1", Integer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void selectLastOnList() {
|
|
||||||
evaluate("listOfNumbersUpToTen.$[#isEven(#this) == 'y']", "10", Integer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void selectLastOnMap() {
|
|
||||||
evaluate("mapOfNumbersUpToTen.$[key>5]", "{10=ten}", HashMap.class);
|
|
||||||
evaluate("mapOfNumbersUpToTen.$[key>5].size()", "1", Integer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void selectionAST() {
|
|
||||||
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.^[true]");
|
|
||||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.^[true]");
|
|
||||||
expr = (SpelExpression) parser.parseExpression("'abc'.?[true]");
|
|
||||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.?[true]");
|
|
||||||
expr = (SpelExpression) parser.parseExpression("'abc'.$[true]");
|
|
||||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.$[true]");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructor invocation
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void constructorInvocationMethodInvocationAndInlineList() {
|
|
||||||
evaluate("new java.util.HashSet().addAll({'a','b','c'})", "true", Boolean.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -27,6 +27,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
import static org.springframework.expression.spel.SpelMessage.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test usage of inline lists.
|
* Test usage of inline lists.
|
||||||
|
@ -89,14 +90,39 @@ class ListTests extends AbstractExpressionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInlineListAndProjectionSelection() {
|
void projectionOnList() {
|
||||||
|
evaluate("listOfNumbersUpToTen.![#this<5?'y':'n']", "[y, y, y, y, n, n, n, n, n, n]", ArrayList.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void projectionOnInlineList() {
|
||||||
evaluate("{1,2,3,4,5,6}.![#this>3]", "[false, false, false, true, true, true]", ArrayList.class);
|
evaluate("{1,2,3,4,5,6}.![#this>3]", "[false, false, false, true, true, true]", ArrayList.class);
|
||||||
|
evaluate("{1,2,3,4,5,6,7,8,9,10}.![#this<5?'y':'n']", "[y, y, y, y, n, n, n, n, n, n]", ArrayList.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectionOnInlineList() {
|
||||||
evaluate("{1,2,3,4,5,6}.?[#this>3]", "[4, 5, 6]", ArrayList.class);
|
evaluate("{1,2,3,4,5,6}.?[#this>3]", "[4, 5, 6]", ArrayList.class);
|
||||||
evaluate("{1,2,3,4,5,6,7,8,9,10}.?[#isEven(#this) == 'y']", "[2, 4, 6, 8, 10]", ArrayList.class);
|
evaluate("{1,2,3,4,5,6,7,8,9,10}.?[#isEven(#this) == 'y']", "[2, 4, 6, 8, 10]", ArrayList.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSetConstruction01() {
|
void selectionOnListWithNonBooleanSelectionCriteria() {
|
||||||
|
evaluateAndCheckError("listOfNumbersUpToTen.?['nonboolean']", RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectFirstOnList() {
|
||||||
|
evaluate("listOfNumbersUpToTen.^[#isEven(#this) == 'y']", "2", Integer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectLastOnList() {
|
||||||
|
evaluate("listOfNumbersUpToTen.$[#isEven(#this) == 'y']", "10", Integer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void setConstructionWithInlineList() {
|
||||||
evaluate("new java.util.HashSet().addAll({'a','b','c'})", "true", Boolean.class);
|
evaluate("new java.util.HashSet().addAll({'a','b','c'})", "true", Boolean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,17 +29,65 @@ import org.springframework.expression.EvaluationContext;
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
import org.springframework.expression.TypedValue;
|
import org.springframework.expression.TypedValue;
|
||||||
|
import org.springframework.expression.spel.standard.SpelExpression;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
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.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.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
class SelectionAndProjectionTests {
|
class SelectionAndProjectionTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectionOnUnsupportedType() {
|
||||||
|
evaluateAndCheckError("'abc'.?[#this<5]", INVALID_TYPE_FOR_SELECTION);
|
||||||
|
evaluateAndCheckError("null.?[#this<5]", INVALID_TYPE_FOR_SELECTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void projectionOnUnsupportedType() {
|
||||||
|
evaluateAndCheckError("'abc'.![true]", PROJECTION_NOT_SUPPORTED_ON_TYPE);
|
||||||
|
evaluateAndCheckError("null.![true]", PROJECTION_NOT_SUPPORTED_ON_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectionOnNullWithSafeNavigation() {
|
||||||
|
evaluate("null?.?[#this<5]", null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void projectionOnNullWithSafeNavigation() {
|
||||||
|
evaluate("null?.![true]", null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectionWithNonBooleanSelectionCriteria() {
|
||||||
|
evaluateAndCheckError("mapOfNumbersUpToTen.?['hello']", RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);
|
||||||
|
evaluateAndCheckError("mapOfNumbersUpToTen.keySet().?['hello']", RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectionAST() {
|
||||||
|
// select first
|
||||||
|
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.^[true]");
|
||||||
|
assertThat(expr.toStringAST()).isEqualTo("'abc'.^[true]");
|
||||||
|
|
||||||
|
// select all
|
||||||
|
expr = (SpelExpression) parser.parseExpression("'abc'.?[true]");
|
||||||
|
assertThat(expr.toStringAST()).isEqualTo("'abc'.?[true]");
|
||||||
|
|
||||||
|
// select last
|
||||||
|
expr = (SpelExpression) parser.parseExpression("'abc'.$[true]");
|
||||||
|
assertThat(expr.toStringAST()).isEqualTo("'abc'.$[true]");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -70,6 +118,13 @@ class SelectionAndProjectionTests {
|
||||||
assertThat(value).isEqualTo(4);
|
assertThat(value).isEqualTo(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectionWithSetAndRegex() {
|
||||||
|
evaluate("testMap.keySet().?[#this matches '.*o.*']", "[monday]", ArrayList.class);
|
||||||
|
evaluate("testMap.keySet().?[#this matches '.*r.*'].contains('saturday')", "true", Boolean.class);
|
||||||
|
evaluate("testMap.keySet().?[#this matches '.*r.*'].size()", "3", Integer.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void selectionWithSet() {
|
void selectionWithSet() {
|
||||||
|
@ -175,10 +230,15 @@ class SelectionAndProjectionTests {
|
||||||
void selectionWithMap() {
|
void selectionWithMap() {
|
||||||
EvaluationContext context = new StandardEvaluationContext(new MapTestBean());
|
EvaluationContext context = new StandardEvaluationContext(new MapTestBean());
|
||||||
ExpressionParser parser = new SpelExpressionParser();
|
ExpressionParser parser = new SpelExpressionParser();
|
||||||
Expression exp = parser.parseExpression("colors.?[key.startsWith('b')]");
|
|
||||||
|
|
||||||
|
Expression exp = parser.parseExpression("colors.?[key.startsWith('b')]");
|
||||||
Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
|
Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
|
||||||
assertThat(colorsMap).containsOnlyKeys("beige", "blue", "brown");
|
assertThat(colorsMap).containsOnlyKeys("beige", "blue", "brown");
|
||||||
|
|
||||||
|
exp = parser.parseExpression("colors.?[key.startsWith('X')]");
|
||||||
|
|
||||||
|
colorsMap = (Map<String, String>) exp.getValue(context);
|
||||||
|
assertThat(colorsMap).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -215,6 +275,12 @@ class SelectionAndProjectionTests {
|
||||||
assertThat(list).containsExactly(5, 6, 7);
|
assertThat(list).containsExactly(5, 6, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void projectionWithMap() {
|
||||||
|
evaluate("mapOfNumbersUpToTen.![key > 5 ? value : null]",
|
||||||
|
"[null, null, null, null, null, six, seven, eight, nine, ten]", ArrayList.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void projectionWithSet() {
|
void projectionWithSet() {
|
||||||
|
|
Loading…
Reference in New Issue