enable SpEL syntax validation for anntation hierarchies and fixed additional test cases

This commit is contained in:
Martin Lippert
2020-07-13 16:26:18 +02:00
parent 11df688a3d
commit f5a5599686
4 changed files with 42 additions and 10 deletions

View File

@@ -233,7 +233,7 @@ public class ValueSpelExpressionValidationTest {
@Test
public void testIncorrectSpelExpressionFoundOnSpelParamOfCachableAnnotation() throws Exception {
TextDocument doc = prepareDocument("@Value(\"onField\")", "@Cacheable(condition=\"#{new String('hello world).toUpperCase()}\")");
TextDocument doc = prepareDocument("@Value(\"onField\")", "@Cacheable(condition=\"new String('hello world).toUpperCase()\")");
assertNotNull(doc);
reconcileEngine.reconcile(doc, problemCollector);
@@ -244,7 +244,7 @@ public class ValueSpelExpressionValidationTest {
@Test
public void testIncorrectSpelExpressionNotFoundOnNonSpelParamOfCachableAnnotation() throws Exception {
TextDocument doc = prepareDocument("@Value(\"onField\")", "@Cacheable(keyGenerator=\"#{new String('hello world).toUpperCase()}\")");
TextDocument doc = prepareDocument("@Value(\"onField\")", "@Cacheable(keyGenerator=\"new String('hello world).toUpperCase()\")");
assertNotNull(doc);
reconcileEngine.reconcile(doc, problemCollector);
@@ -255,7 +255,7 @@ public class ValueSpelExpressionValidationTest {
@Test
public void testIncorrectSpelExpressionFoundOnSpelParamOfCachableAnnotationAmongOtherParams() throws Exception {
TextDocument doc = prepareDocument("@Value(\"onField\")", "@Cacheable(keyGenerator=\"somekey\", condition=\"#{new String('hello world).toUpperCase()}\")");
TextDocument doc = prepareDocument("@Value(\"onField\")", "@Cacheable(keyGenerator=\"somekey\", condition=\"new String('hello world).toUpperCase()\")");
assertNotNull(doc);
reconcileEngine.reconcile(doc, problemCollector);
@@ -266,7 +266,7 @@ public class ValueSpelExpressionValidationTest {
@Test
public void testIncorrectSpelExpressionFoundOnMultipleSpelParamsOfCachableAnnotation() throws Exception {
TextDocument doc = prepareDocument("@Value(\"onField\")", "@Cacheable(unless=\"#{new String('hello world).toUpperCase()}\", condition=\"#{new String('hello world).toUpperCase()}\")");
TextDocument doc = prepareDocument("@Value(\"onField\")", "@Cacheable(unless=\"new String('hello world).toUpperCase()\", condition=\"new String('hello world).toUpperCase()\")");
assertNotNull(doc);
reconcileEngine.reconcile(doc, problemCollector);
@@ -275,6 +275,30 @@ public class ValueSpelExpressionValidationTest {
assertEquals(2, problems.size());
}
@Test
public void testCorrectSpelExpressionFoundOnCustomAnnotation() throws Exception {
TextDocument doc = prepareDocument("@Value(\"onMethod\")", "@CustomEventListener(condition=\"new String('hello world').toUpperCase()\")");
assertNotNull(doc);
reconcileEngine.reconcile(doc, problemCollector);
List<ReconcileProblem> problems = problemCollector.getCollectedProblems();
assertEquals(0, problems.size());
}
@Test
public void testIncorrectSpelExpressionFoundOnCustomAnnotation() throws Exception {
TextDocument doc = prepareDocument("@Value(\"onMethod\")", "@CustomEventListener(condition=\"new String('hello world).toUpperCase()\")");
assertNotNull(doc);
reconcileEngine.reconcile(doc, problemCollector);
List<ReconcileProblem> problems = problemCollector.getCollectedProblems();
assertEquals(1, problems.size());
}
private TextDocument prepareDocument(String selectedAnnotation, String annotationStatementBeforeTest) throws Exception {
String content = IOUtils.toString(new URI(docUri));

View File

@@ -0,0 +1,7 @@
package org.test;
import org.springframework.context.event.EventListener;
@EventListener
public @interface CustomEventListener {
}