diff --git a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java index 8bb1b9361c2..0c8151b0e3b 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java @@ -88,4 +88,34 @@ public class TemplateQueryBuilderTests extends AbstractQueryTestCase params = new HashMap<>(); + params.put("template", "all"); + QueryBuilder expectedBuilder = new TemplateQueryBuilder(new Template(expectedTemplateString, ScriptType.INLINE, null, null, + params)); + assertParsedQuery(query, expectedBuilder); + } + + // NORELEASE Can we actually test raw templates in either unit or + // integration tests now? + @Test + @AwaitsFix(bugUrl = "Can we actually test raw templates in either unit or integration tests now?") + public void testRawTemplate() throws IOException { + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + builder.startObject("match_{{template}}"); + builder.endObject(); + builder.endObject(); + String expectedTemplateString = "{\"match_{{template}}\": {}}"; + String query = "{\"template\": {\"query\": {\"match_{{template}}\": {}},\"params\" : {\"template\" : \"all\"}}}"; + Map params = new HashMap<>(); + params.put("template", "all"); + QueryBuilder expectedBuilder = new TemplateQueryBuilder(new Template(expectedTemplateString, ScriptType.INLINE, null, null, + params)); + assertParsedQuery(query, expectedBuilder); + } + } diff --git a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryIT.java b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryIT.java index adebb7f5ed3..71dd323f1ff 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryIT.java +++ b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryIT.java @@ -136,32 +136,14 @@ public class TemplateQueryIT extends ESIntegTestCase { assertHitCount(sr, 2); } - // NORELEASE These need to be tested in TemplateQueryBuilderTests - // @Test - // public void testRawEscapedTemplate() throws IOException { - // String query = - // "{\"template\": {\"query\": \"{\\\"match_{{template}}\\\": {}}\\\"\",\"params\" : {\"template\" : \"all\"}}}"; - // - // SearchResponse sr = client().prepareSearch().setQuery(query).get(); - // assertHitCount(sr, 2); - // } - // - // @Test - // public void testRawTemplate() throws IOException { - // String query = - // "{\"template\": {\"query\": {\"match_{{template}}\": {}},\"params\" : {\"template\" : \"all\"}}}"; - // SearchResponse sr = client().prepareSearch().setQuery(query).get(); - // assertHitCount(sr, 2); - // } - // - // @Test - // public void testRawFSTemplate() throws IOException { - // String query = - // "{\"template\": {\"file\": \"storedTemplate\",\"params\" : {\"template\" : \"all\"}}}"; - // - // SearchResponse sr = client().prepareSearch().setQuery(query).get(); - // assertHitCount(sr, 2); - // } + @Test + public void testRawFSTemplate() throws IOException { + Map params = new HashMap<>(); + params.put("template", "all"); + TemplateQueryBuilder builder = new TemplateQueryBuilder(new Template("storedTemplate", ScriptType.FILE, null, null, params)); + SearchResponse sr = client().prepareSearch().setQuery(builder).get(); + assertHitCount(sr, 2); + } @Test public void testSearchRequestTemplateSource() throws Exception {