diff --git a/plugin/src/test/java/org/elasticsearch/script/LatchScriptEngine.java b/plugin/src/test/java/org/elasticsearch/script/LatchScriptEngine.java index 0df10996ac3..a47e3366f44 100644 --- a/plugin/src/test/java/org/elasticsearch/script/LatchScriptEngine.java +++ b/plugin/src/test/java/org/elasticsearch/script/LatchScriptEngine.java @@ -93,11 +93,6 @@ public class LatchScriptEngine implements ScriptEngine { return new Script(ScriptType.INLINE, NAME, "", Collections.emptyMap()); } - @Override - public boolean isInlineScriptEnabled() { - return true; - } - public static class LatchScriptPlugin extends Plugin implements ScriptPlugin { @Override diff --git a/plugin/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java b/plugin/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java index 5a8c5073147..57df1936053 100644 --- a/plugin/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java +++ b/plugin/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java @@ -46,9 +46,4 @@ public class MockMustacheScriptEngine extends MockScriptEngine { // We always return the script's source as it is return new MockCompiledScript(name, params, script, null); } - - @Override - public boolean isInlineScriptEnabled() { - return true; - } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/test/MockPainlessScriptEngine.java b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/test/MockPainlessScriptEngine.java index bd69312d46b..5bbc5e16c4e 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/test/MockPainlessScriptEngine.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/test/MockPainlessScriptEngine.java @@ -43,9 +43,4 @@ public class MockPainlessScriptEngine extends MockScriptEngine { // We always return the script's source as it is return new MockCompiledScript(name, params, script, null); } - - @Override - public boolean isInlineScriptEnabled() { - return true; - } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java b/plugin/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java index e99cb79152e..e9ec36135b2 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java @@ -18,14 +18,12 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.env.Environment; import org.elasticsearch.script.GeneralScriptException; import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContextRegistry; import org.elasticsearch.script.ScriptEngine; -import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptException; import org.elasticsearch.script.ScriptMetaData; import org.elasticsearch.script.ScriptService; @@ -40,6 +38,7 @@ import org.joda.time.DateTimeZone; import org.junit.Before; import java.io.IOException; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -86,10 +85,8 @@ public class ScriptConditionTests extends ESTestCase { }); ScriptEngine engine = new MockScriptEngine(MockScriptEngine.NAME, scripts); - - ScriptEngineRegistry registry = new ScriptEngineRegistry(singleton(engine)); ScriptContextRegistry contextRegistry = new ScriptContextRegistry(singleton(new ScriptContext.Plugin("xpack", "watch"))); - scriptService = new ScriptService(Settings.EMPTY, registry, contextRegistry); + scriptService = new ScriptService(Settings.EMPTY, Collections.singletonMap(engine.getType(), engine), contextRegistry); ClusterState.Builder clusterState = new ClusterState.Builder(new ClusterName("_name")); clusterState.metaData(MetaData.builder().putCustom(ScriptMetaData.TYPE, new ScriptMetaData.Builder(null).build())); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java b/plugin/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java index 406fc0a6e41..442840a9450 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java @@ -16,15 +16,12 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.env.Environment; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContextRegistry; -import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.xpack.common.http.HttpClient; import org.elasticsearch.xpack.common.http.HttpMethod; import org.elasticsearch.xpack.common.http.HttpRequestTemplate; @@ -241,11 +238,7 @@ public final class WatcherTestUtils { .build(); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.singletonList(new ScriptContext.Plugin("xpack", "watch"))); - - ScriptEngineRegistry scriptEngineRegistry = - new ScriptEngineRegistry(Collections.emptyList()); - - return new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry); + return new ScriptService(settings, Collections.emptyMap(), scriptContextRegistry); } public static SearchType getRandomSupportedSearchType() { diff --git a/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateIT.java b/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateIT.java index 090124f0713..2908339d287 100644 --- a/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateIT.java +++ b/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateIT.java @@ -10,18 +10,15 @@ import com.fasterxml.jackson.core.io.JsonStringEncoder; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.env.Environment; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContextRegistry; -import org.elasticsearch.script.ScriptEngineRegistry; +import org.elasticsearch.script.ScriptEngine; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.mustache.MustacheScriptEngine; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.xpack.common.text.TextTemplate; import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.junit.Before; -import org.mockito.Mockito; import java.io.IOException; import java.io.StringWriter; @@ -36,17 +33,16 @@ import static org.hamcrest.Matchers.notNullValue; public class WatcherTemplateIT extends ESTestCase { - private TextTemplateEngine engine; + private TextTemplateEngine textTemplateEngine; @Before public void init() throws Exception { ScriptContextRegistry registry = new ScriptContextRegistry(Collections.singletonList(new ScriptContext.Plugin("xpack", "watch"))); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry( - Collections.singleton(new MustacheScriptEngine()) - ); - ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, registry); - engine = new TextTemplateEngine(Settings.EMPTY, scriptService); + MustacheScriptEngine engine = new MustacheScriptEngine(); + Map engines = Collections.singletonMap(engine.getType(), engine); + ScriptService scriptService = new ScriptService(Settings.EMPTY, engines, registry); + textTemplateEngine = new TextTemplateEngine(Settings.EMPTY, scriptService); } public void testEscaping() throws Exception { @@ -91,7 +87,7 @@ public class WatcherTemplateIT extends ESTestCase { Map dataMap = new HashMap<>(); dataMap.put("data", unescaped.toString()); - String renderedTemplate = engine.render(new TextTemplate(template), dataMap); + String renderedTemplate = textTemplateEngine.render(new TextTemplate(template), dataMap); assertThat(renderedTemplate, notNullValue()); if (contentType == XContentType.JSON) { @@ -116,7 +112,7 @@ public class WatcherTemplateIT extends ESTestCase { + "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}" + "}}, \"negative_boost\": {{boost_val}} } }}"; Map vars = new HashMap<>(); vars.put("boost_val", "0.3"); - String result = engine.render(new TextTemplate(template), vars); + String result = textTemplateEngine.render(new TextTemplate(template), vars); assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}}," + "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}}}, \"negative_boost\": 0.3 } }}", result); @@ -127,7 +123,7 @@ public class WatcherTemplateIT extends ESTestCase { Map vars = new HashMap<>(); vars.put("boost_val", "0.3"); vars.put("body_val", "\"quick brown\""); - String result = engine.render(new TextTemplate(template), vars); + String result = textTemplateEngine.render(new TextTemplate(template), vars); assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}}," + "\"negative\": {\"term\": {\"body\": {\"value\": \"\\\"quick brown\\\"\"}}}, \"negative_boost\": 0.3 } }}", result); @@ -151,7 +147,7 @@ public class WatcherTemplateIT extends ESTestCase { vars.put("test_var1", var1Writer.toString()); vars.put("test_var2", var2Writer.toString()); - String s1 = engine.render(new TextTemplate(template), vars); + String s1 = textTemplateEngine.render(new TextTemplate(template), vars); String s2 = prefix + " " + var1Writer.toString() + " " + var2Writer.toString(); assertThat(s1, equalTo(s2)); }