Fix watrcher script parsing tests
closes elastic/elasticsearch#3135, elastic/elasticsearch#3134, elastic/elasticsearch#3136 Original commit: elastic/x-pack-elasticsearch@a1b0402be4
This commit is contained in:
parent
572869087d
commit
5b2c7dd503
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue