more fixes for tests

This commit is contained in:
Colin Goodheart-Smithe 2015-10-06 14:50:24 +01:00
parent 86be9db7b9
commit 10a559348b
2 changed files with 38 additions and 26 deletions

View File

@ -88,4 +88,34 @@ public class TemplateQueryBuilderTests extends AbstractQueryTestCase<TemplateQue
content.string()); content.string());
} }
@Test
public void testRawEscapedTemplate() throws IOException {
String expectedTemplateString = "{\"match_{{template}}\": {}}\"";
String query = "{\"template\": {\"query\": \"{\\\"match_{{template}}\\\": {}}\\\"\",\"params\" : {\"template\" : \"all\"}}}";
Map<String, Object> 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<String, Object> params = new HashMap<>();
params.put("template", "all");
QueryBuilder<?> expectedBuilder = new TemplateQueryBuilder(new Template(expectedTemplateString, ScriptType.INLINE, null, null,
params));
assertParsedQuery(query, expectedBuilder);
}
} }

View File

@ -136,32 +136,14 @@ public class TemplateQueryIT extends ESIntegTestCase {
assertHitCount(sr, 2); assertHitCount(sr, 2);
} }
// NORELEASE These need to be tested in TemplateQueryBuilderTests @Test
// @Test public void testRawFSTemplate() throws IOException {
// public void testRawEscapedTemplate() throws IOException { Map<String, Object> params = new HashMap<>();
// String query = params.put("template", "all");
// "{\"template\": {\"query\": \"{\\\"match_{{template}}\\\": {}}\\\"\",\"params\" : {\"template\" : \"all\"}}}"; TemplateQueryBuilder builder = new TemplateQueryBuilder(new Template("storedTemplate", ScriptType.FILE, null, null, params));
// SearchResponse sr = client().prepareSearch().setQuery(builder).get();
// SearchResponse sr = client().prepareSearch().setQuery(query).get(); assertHitCount(sr, 2);
// 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 @Test
public void testSearchRequestTemplateSource() throws Exception { public void testSearchRequestTemplateSource() throws Exception {