diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java index 5f3a6bc69d4..59357eeafa2 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java @@ -30,6 +30,7 @@ import java.util.Map; import static java.util.Collections.singletonMap; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.script.ScriptService.ScriptType; import static org.elasticsearch.xpack.watcher.input.search.ExecutableSearchInput.DEFAULT_SEARCH_TYPE; import static org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils.formatDate; import static org.elasticsearch.xpack.watcher.support.WatcherUtils.flattenModel; @@ -85,7 +86,6 @@ public class WatcherUtilsTests extends ESTestCase { assertThat(result, equalTo(expected)); } - @AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/3134") public void testSerializeSearchRequest() throws Exception { String[] expectedIndices = generateRandomStringArray(5, 5, true); String[] expectedTypes = generateRandomStringArray(2, 5, true); @@ -105,8 +105,10 @@ public class WatcherUtilsTests extends ESTestCase { } } String text = randomAsciiOfLengthBetween(1, 5); - expectedTemplate = randomFrom(WatcherScript.inline(text), WatcherScript.file(text), - WatcherScript.indexed(text)).params(params).build(); + expectedTemplate = randomFrom(WatcherScript.inline(text), WatcherScript.file(text), WatcherScript.indexed(text)) + .lang(randomBoolean() ? null : "mustache") + .params(params) + .build(); request = new WatcherSearchTemplateRequest(expectedIndices, expectedTypes, expectedSearchType, expectedIndicesOptions, expectedTemplate); } else { @@ -128,15 +130,19 @@ public class WatcherUtilsTests extends ESTestCase { assertThat(result.getTypes(), arrayContainingInAnyOrder(expectedTypes != null ? expectedTypes : new String[0])); assertThat(result.getIndicesOptions(), equalTo(expectedIndicesOptions)); assertThat(result.getSearchType(), equalTo(expectedSearchType)); + + assertNotNull(result.getTemplate()); + assertThat(result.getTemplate().lang(), equalTo("mustache")); if (expectedSource == null) { - assertThat(result.getTemplate(), equalTo(expectedTemplate)); + assertThat(result.getTemplate().script(), equalTo(expectedTemplate.script())); + assertThat(result.getTemplate().type(), equalTo(expectedTemplate.type())); + assertThat(result.getTemplate().params(), equalTo(expectedTemplate.params())); } else { assertThat(result.getTemplate().script(), equalTo(expectedSource.utf8ToString())); + assertThat(result.getTemplate().type(), equalTo(ScriptType.INLINE)); } - } - @AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/3136") public void testDeserializeSearchRequest() throws Exception { XContentBuilder builder = jsonBuilder().startObject(); @@ -200,7 +206,9 @@ public class WatcherUtilsTests extends ESTestCase { } String text = randomAsciiOfLengthBetween(1, 5); template = randomFrom(WatcherScript.inline(text), WatcherScript.file(text), WatcherScript.indexed(text)) - .params(params).build(); + .lang(randomBoolean() ? null : "mustache") + .params(params) + .build(); builder.field("template", template); } builder.endObject(); @@ -218,7 +226,14 @@ public class WatcherUtilsTests extends ESTestCase { } else { assertThat(result.getSearchSource().utf8ToString(), equalTo(source.utf8ToString())); } - assertThat(result.getTemplate(), equalTo(template)); + if (template == null) { + assertThat(result.getTemplate(), nullValue()); + } else { + assertThat(result.getTemplate().script(), equalTo(template.script())); + assertThat(result.getTemplate().type(), equalTo(template.type())); + assertThat(result.getTemplate().params(), equalTo(template.params())); + assertThat(result.getTemplate().lang(), equalTo("mustache")); + } } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java index 6b90415ae02..b84667429f4 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java @@ -16,16 +16,13 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.script.MockMustacheScriptEngine; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.SearchRequestParsers; -import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.xpack.common.text.TextTemplate; @@ -183,7 +180,6 @@ public class SearchTransformTests extends ESIntegTestCase { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/3135") public void testParser() throws Exception { String[] indices = rarely() ? null : randomBoolean() ? new String[] { "idx" } : new String[] { "idx1", "idx2" }; SearchType searchType = getRandomSupportedSearchType(); @@ -234,7 +230,7 @@ public class SearchTransformTests extends ESIntegTestCase { } if (templateName != null) { assertThat(executable.transform().getRequest().getTemplate(), - equalTo(WatcherScript.file("template1").build())); + equalTo(WatcherScript.file("template1").lang("mustache").build())); } assertThat(executable.transform().getRequest().getSearchSource().utf8ToString(), equalTo("{\"query\":{\"match_all\":{}}}")); assertThat(executable.transform().getTimeout(), equalTo(readTimeout));