|
|
|
|
@@ -108,8 +108,8 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
assertThat(o).isEqualTo("");
|
|
|
|
|
assertThat(testClass.list).hasSize(4);
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
|
|
|
|
parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass)));
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass)));
|
|
|
|
|
|
|
|
|
|
o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass));
|
|
|
|
|
assertThat(o).isEqualTo("");
|
|
|
|
|
@@ -127,8 +127,8 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
o = parser.parseExpression("map").getValue(ctx);
|
|
|
|
|
assertThat(o).isNotNull();
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
parser.parseExpression("map2['a']").getValue(ctx));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> parser.parseExpression("map2['a']").getValue(ctx));
|
|
|
|
|
// map2 should be null, there is no setter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -144,8 +144,8 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
o = parser.parseExpression("wibble").getValue(ctx);
|
|
|
|
|
assertThat(o).isNotNull();
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
parser.parseExpression("wibble2.bar").getValue(ctx));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> parser.parseExpression("wibble2.bar").getValue(ctx));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -270,8 +270,8 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
@Test
|
|
|
|
|
void resolvingList() {
|
|
|
|
|
StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
|
|
|
|
parser.parseExpression("T(List)!=null").getValue(context, Boolean.class));
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> parser.parseExpression("T(List)!=null").getValue(context, Boolean.class));
|
|
|
|
|
((StandardTypeLocator) context.getTypeLocator()).registerImport("java.util");
|
|
|
|
|
assertThat(parser.parseExpression("T(List)!=null").getValue(context, Boolean.class)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
@@ -343,8 +343,8 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
// Register a custom MethodFilter...
|
|
|
|
|
MethodFilter methodFilter = methods -> null;
|
|
|
|
|
assertThatIllegalStateException()
|
|
|
|
|
.isThrownBy(() -> context.registerMethodFilter(String.class, methodFilter))
|
|
|
|
|
.withMessage("Method filter cannot be set as the reflective method resolver is not in use");
|
|
|
|
|
.isThrownBy(() -> context.registerMethodFilter(String.class, methodFilter))
|
|
|
|
|
.withMessage("Method filter cannot be set as the reflective method resolver is not in use");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -380,9 +380,9 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
StandardEvaluationContext failCtx = new StandardEvaluationContext(instance);
|
|
|
|
|
parser = new SpelExpressionParser(new SpelParserConfiguration(false, false));
|
|
|
|
|
Expression failExp = parser.parseExpression("listOfStrings[3]");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
failExp.getValue(failCtx, String.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> failExp.getValue(failCtx, String.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -567,12 +567,12 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void rogueTrailingDotCausesNPE_SPR6866() {
|
|
|
|
|
assertThatExceptionOfType(SpelParseException.class).isThrownBy(() ->
|
|
|
|
|
new SpelExpressionParser().parseExpression("placeOfBirth.foo."))
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OOD);
|
|
|
|
|
assertThat(ex.getPosition()).isEqualTo(16);
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(SpelParseException.class)
|
|
|
|
|
.isThrownBy(() -> new SpelExpressionParser().parseExpression("placeOfBirth.foo."))
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OOD);
|
|
|
|
|
assertThat(ex.getPosition()).isEqualTo(16);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Nested
|
|
|
|
|
@@ -591,12 +591,12 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void propertiesNested03() throws ParseException {
|
|
|
|
|
assertThatExceptionOfType(SpelParseException.class).isThrownBy(() ->
|
|
|
|
|
new SpelExpressionParser().parseRaw("placeOfBirth.23"))
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.UNEXPECTED_DATA_AFTER_DOT);
|
|
|
|
|
assertThat(ex.getInserts()[0]).isEqualTo("23");
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(SpelParseException.class)
|
|
|
|
|
.isThrownBy(() -> new SpelExpressionParser().parseRaw("placeOfBirth.23"))
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.UNEXPECTED_DATA_AFTER_DOT);
|
|
|
|
|
assertThat(ex.getInserts()[0]).isEqualTo("23");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -680,26 +680,26 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void andWithNullValueOnLeft() {
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(
|
|
|
|
|
parser.parseExpression("null and true")::getValue);
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class)
|
|
|
|
|
.isThrownBy(parser.parseExpression("null and true")::getValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void andWithNullValueOnRight() {
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(
|
|
|
|
|
parser.parseExpression("true and null")::getValue);
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class)
|
|
|
|
|
.isThrownBy(parser.parseExpression("true and null")::getValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void orWithNullValueOnLeft() {
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(
|
|
|
|
|
parser.parseExpression("null or false")::getValue);
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class)
|
|
|
|
|
.isThrownBy(parser.parseExpression("null or false")::getValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void orWithNullValueOnRight() {
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(
|
|
|
|
|
parser.parseExpression("false or null")::getValue);
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class)
|
|
|
|
|
.isThrownBy(parser.parseExpression("false or null")::getValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -757,8 +757,8 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void ternaryOperatorWithNullValue() {
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(
|
|
|
|
|
parser.parseExpression("null ? 0 : 1")::getValue);
|
|
|
|
|
assertThatExceptionOfType(EvaluationException.class)
|
|
|
|
|
.isThrownBy(parser.parseExpression("null ? 0 : 1")::getValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -859,9 +859,9 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
|
|
|
|
Expression e = parser.parseExpression("#this++");
|
|
|
|
|
assertThat(i).isEqualTo(42);
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e.getValue(ctx, Integer.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e.getValue(ctx, Integer.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -977,14 +977,14 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
|
|
|
|
|
|
|
|
|
Expression e1 = parser.parseExpression("m()++");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e1.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OPERAND_NOT_INCREMENTABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e1.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OPERAND_NOT_INCREMENTABLE));
|
|
|
|
|
|
|
|
|
|
Expression e2 = parser.parseExpression("++m()");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e2.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OPERAND_NOT_INCREMENTABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e2.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OPERAND_NOT_INCREMENTABLE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -993,13 +993,13 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
StandardEvaluationContext ctx = new StandardEvaluationContext(i);
|
|
|
|
|
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
|
|
|
|
Expression e1 = parser.parseExpression("++1");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e1.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e1.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
Expression e2 = parser.parseExpression("1++");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e2.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e2.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -1009,9 +1009,9 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
|
|
|
|
Expression e = parser.parseExpression("#this--");
|
|
|
|
|
assertThat(i).isEqualTo(42);
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e.getValue(ctx, Integer.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e.getValue(ctx, Integer.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -1127,14 +1127,14 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
|
|
|
|
|
|
|
|
|
Expression e1 = parser.parseExpression("m()--");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e1.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OPERAND_NOT_DECREMENTABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e1.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OPERAND_NOT_DECREMENTABLE));
|
|
|
|
|
|
|
|
|
|
Expression e2 = parser.parseExpression("--m()");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e2.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OPERAND_NOT_DECREMENTABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e2.getValue(ctx, Double.TYPE))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.OPERAND_NOT_DECREMENTABLE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -1143,14 +1143,14 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
StandardEvaluationContext ctx = new StandardEvaluationContext(i);
|
|
|
|
|
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
|
|
|
|
Expression e1 = parser.parseExpression("--1");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e1.getValue(ctx, Integer.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e1.getValue(ctx, Integer.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
|
|
|
|
|
Expression e2 = parser.parseExpression("1--");
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
|
|
|
|
e2.getValue(ctx, Integer.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> e2.getValue(ctx, Integer.class))
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -1508,13 +1508,15 @@ class EvaluationTests extends AbstractExpressionTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void expectFail(ExpressionParser parser, EvaluationContext eContext, String expressionString, SpelMessage messageCode) {
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() -> {
|
|
|
|
|
Expression e = parser.parseExpression(expressionString);
|
|
|
|
|
if (DEBUG) {
|
|
|
|
|
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
|
|
|
|
}
|
|
|
|
|
e.getValue(eContext);
|
|
|
|
|
}).satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(messageCode));
|
|
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
|
|
|
|
.isThrownBy(() -> {
|
|
|
|
|
Expression e = parser.parseExpression(expressionString);
|
|
|
|
|
if (DEBUG) {
|
|
|
|
|
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
|
|
|
|
}
|
|
|
|
|
e.getValue(eContext);
|
|
|
|
|
})
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(messageCode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|