From 956123157b586e0ab4719b2b98910d3321772a50 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Tue, 7 Jul 2015 19:19:58 +0200 Subject: [PATCH] Added rest tests for language plugins --- plugins/lang-javascript/pom.xml | 2 + .../test/lang_javascript/10_basic.yaml | 26 ++++++++++++ .../javascript/LangJavaScriptRestIT.java | 41 +++++++++++++++++++ plugins/lang-python/pom.xml | 2 + .../test/lang_python/10_basic.yaml | 26 ++++++++++++ .../script/python/LangPythonScriptRestIT.java | 41 +++++++++++++++++++ plugins/pom.xml | 1 + 7 files changed, 139 insertions(+) create mode 100644 plugins/lang-javascript/rest-api-spec/test/lang_javascript/10_basic.yaml create mode 100644 plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavaScriptRestIT.java create mode 100644 plugins/lang-python/rest-api-spec/test/lang_python/10_basic.yaml create mode 100644 plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonScriptRestIT.java diff --git a/plugins/lang-javascript/pom.xml b/plugins/lang-javascript/pom.xml index 97ebd3e3ac4..d72585b604c 100644 --- a/plugins/lang-javascript/pom.xml +++ b/plugins/lang-javascript/pom.xml @@ -16,6 +16,8 @@ + lang_javascript + false diff --git a/plugins/lang-javascript/rest-api-spec/test/lang_javascript/10_basic.yaml b/plugins/lang-javascript/rest-api-spec/test/lang_javascript/10_basic.yaml new file mode 100644 index 00000000000..ee77a848c44 --- /dev/null +++ b/plugins/lang-javascript/rest-api-spec/test/lang_javascript/10_basic.yaml @@ -0,0 +1,26 @@ +# Integration tests for Lang JavaScript components +# +setup: + - do: + index: + index: test + type: test + id: 1 + body: { "foo": "aaa" } + - do: + indices.refresh: {} + +--- + +"Lang JavaScript": + - do: + search: + body: + script_fields: + bar: + lang: javascript + script: "doc['foo'].value + x" + params: + x: "bbb" + + - match: { hits.hits.0.fields.bar.0: "aaabbb"} diff --git a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavaScriptRestIT.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavaScriptRestIT.java new file mode 100644 index 00000000000..3bc18af4c77 --- /dev/null +++ b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavaScriptRestIT.java @@ -0,0 +1,41 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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 + * + * http://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.elasticsearch.script.javascript; + +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.elasticsearch.test.rest.ElasticsearchRestTestCase; +import org.elasticsearch.test.rest.RestTestCandidate; +import org.elasticsearch.test.rest.parser.RestTestParseException; + +import java.io.IOException; + +public class LangJavaScriptRestIT extends ElasticsearchRestTestCase { + + public LangJavaScriptRestIT(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return ElasticsearchRestTestCase.createParameters(0, 1); + } +} + diff --git a/plugins/lang-python/pom.xml b/plugins/lang-python/pom.xml index a8c98d5eeaf..86458279318 100644 --- a/plugins/lang-python/pom.xml +++ b/plugins/lang-python/pom.xml @@ -16,6 +16,8 @@ + lang_python + false diff --git a/plugins/lang-python/rest-api-spec/test/lang_python/10_basic.yaml b/plugins/lang-python/rest-api-spec/test/lang_python/10_basic.yaml new file mode 100644 index 00000000000..ba7b733e806 --- /dev/null +++ b/plugins/lang-python/rest-api-spec/test/lang_python/10_basic.yaml @@ -0,0 +1,26 @@ +# Integration tests for Lang Python components +# +setup: + - do: + index: + index: test + type: test + id: 1 + body: { "foo": "aaa" } + - do: + indices.refresh: {} + +--- + +"Lang Python": + - do: + search: + body: + script_fields: + bar: + lang: python + script: "doc['foo'].value + x" + params: + x: "bbb" + + - match: { hits.hits.0.fields.bar.0: "aaabbb"} diff --git a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonScriptRestIT.java b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonScriptRestIT.java new file mode 100644 index 00000000000..d9a0bdd8abb --- /dev/null +++ b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonScriptRestIT.java @@ -0,0 +1,41 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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 + * + * http://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.elasticsearch.script.python; + +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.elasticsearch.test.rest.ElasticsearchRestTestCase; +import org.elasticsearch.test.rest.RestTestCandidate; +import org.elasticsearch.test.rest.parser.RestTestParseException; + +import java.io.IOException; + +public class LangPythonScriptRestIT extends ElasticsearchRestTestCase { + + public LangPythonScriptRestIT(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return ElasticsearchRestTestCase.createParameters(0, 1); + } +} + diff --git a/plugins/pom.xml b/plugins/pom.xml index 6d2dfda5906..262c035e648 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -284,6 +284,7 @@ api/indices.refresh.json api/nodes.info.json api/count.json + api/search.json