Skip to content

Commit

Permalink
[TEST] Unknown scripting annotations raise error (#50343)
Browse files Browse the repository at this point in the history
Ensure that unknown annotations, such as typo'd `@nondeterministic`, 
will raise an exception.
  • Loading branch information
stu-elastic authored Dec 18, 2019
1 parent 5adbf67 commit b92b91a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@
import java.util.Map;

public class WhitelistLoaderTests extends ScriptTestCase {
public void testUnknownAnnotations() {
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);

RuntimeException expected = expectThrows(RuntimeException.class, () -> {
WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.elasticsearch.painless.annotation.unknown");
});
assertEquals(
"invalid annotation: parser not found for [unknownAnnotation] [@unknownAnnotation]", expected.getCause().getMessage()
);
assertEquals(IllegalArgumentException.class, expected.getCause().getClass());

expected = expectThrows(RuntimeException.class, () -> {
WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.elasticsearch.painless.annotation.unknown_with_options");
});
assertEquals(
"invalid annotation: parser not found for [unknownAnootationWithMessage] [@unknownAnootationWithMessage[arg=\"arg value\"]]",
expected.getCause().getMessage()
);
assertEquals(IllegalArgumentException.class, expected.getCause().getClass());
}

public void testAnnotations() {
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# whitelist for annotation tests with unknown annotation

class org.elasticsearch.painless.AnnotationTestObject @no_import {
void unknownAnnotationMethod() @unknownAnnotation
void unknownAnnotationMethod() @unknownAnootationWithMessage[message="use another method"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# whitelist for annotation tests with unknown annotation containing options

class org.elasticsearch.painless.AnnotationTestObject @no_import {
void unknownAnnotationMethod() @unknownAnootationWithMessage[arg="arg value"]
}

0 comments on commit b92b91a

Please sign in to comment.