[TEST] replaced assert with actual assertions in TemplateQueryTest

This commit is contained in:
javanna 2014-09-03 14:44:49 +02:00 committed by Luca Cavanna
parent 59ecfd67e8
commit 5ac77f79c2
1 changed files with 10 additions and 26 deletions

View File

@ -113,7 +113,6 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
.execute().actionGet(); .execute().actionGet();
assertNoFailures(sr); assertNoFailures(sr);
assertThat(sr.getHits().hits().length, equalTo(0)); assertThat(sr.getHits().hits().length, equalTo(0));
} }
@Test @Test
@ -137,7 +136,6 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
SearchResponse sr = client().prepareSearch().setQuery(builder) SearchResponse sr = client().prepareSearch().setQuery(builder)
.execute().actionGet(); .execute().actionGet();
assertHitCount(sr, 2); assertHitCount(sr, 2);
} }
@Test @Test
@ -222,7 +220,7 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
@Test @Test(expected = SearchPhaseExecutionException.class)
public void testIndexedTemplateClient() throws Exception { public void testIndexedTemplateClient() throws Exception {
createIndex(ScriptService.SCRIPT_INDEX); createIndex(ScriptService.SCRIPT_INDEX);
ensureGreen(ScriptService.SCRIPT_INDEX); ensureGreen(ScriptService.SCRIPT_INDEX);
@ -262,7 +260,6 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
indexRandom(true,builders); indexRandom(true,builders);
Map<String, String> templateParams = Maps.newHashMap(); Map<String, String> templateParams = Maps.newHashMap();
templateParams.put("fieldParam", "foo"); templateParams.put("fieldParam", "foo");
@ -270,30 +267,21 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
setTemplateName("testTemplate").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get(); setTemplateName("testTemplate").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get();
assertHitCount(searchResponse, 4); assertHitCount(searchResponse, 4);
DeleteIndexedScriptResponse deleteResponse = client().prepareDeleteIndexedScript("mustache","testTemplate").get(); DeleteIndexedScriptResponse deleteResponse = client().prepareDeleteIndexedScript("mustache","testTemplate").get();
assertTrue(deleteResponse.isFound() == true); assertTrue(deleteResponse.isFound());
getResponse = client().prepareGetIndexedScript("mustache", "testTemplate").get(); getResponse = client().prepareGetIndexedScript("mustache", "testTemplate").get();
assertFalse(getResponse.isExists()); assertFalse(getResponse.isExists());
Exception e = null;
try {
client().prepareSearch("test").setTypes("type"). client().prepareSearch("test").setTypes("type").
setTemplateName("/template_index/mustache/1000").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get(); setTemplateName("/template_index/mustache/1000").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get();
} catch (SearchPhaseExecutionException spee) {
e = spee;
}
assert e != null;
e = null;
} }
@Test @Test
public void testIndexedTemplate() throws Exception { public void testIndexedTemplate() throws Exception {
createIndex(ScriptService.SCRIPT_INDEX); createIndex(ScriptService.SCRIPT_INDEX);
ensureGreen(ScriptService.SCRIPT_INDEX); ensureGreen(ScriptService.SCRIPT_INDEX);
List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>(); List<IndexRequestBuilder> builders = new ArrayList<>();
builders.add(client().prepareIndex(ScriptService.SCRIPT_INDEX, "mustache", "1a").setSource("{" + builders.add(client().prepareIndex(ScriptService.SCRIPT_INDEX, "mustache", "1a").setSource("{" +
"\"template\":{"+ "\"template\":{"+
" \"query\":{" + " \"query\":{" +
@ -338,24 +326,21 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
setTemplateName("/mustache/1a").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get(); setTemplateName("/mustache/1a").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get();
assertHitCount(searchResponse, 4); assertHitCount(searchResponse, 4);
Exception e = null;
try { try {
searchResponse = client().prepareSearch("test").setTypes("type"). client().prepareSearch("test").setTypes("type").
setTemplateName("/template_index/mustache/1000").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get(); setTemplateName("/template_index/mustache/1000").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get();
fail("shouldn't get here");
} catch (SearchPhaseExecutionException spee) { } catch (SearchPhaseExecutionException spee) {
e = spee; //all good
} }
assert e != null;
e = null;
try { try {
searchResponse = client().prepareSearch("test").setTypes("type"). searchResponse = client().prepareSearch("test").setTypes("type").
setTemplateName("/myindex/mustache/1").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get(); setTemplateName("/myindex/mustache/1").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get();
assertFailures(searchResponse); assertFailures(searchResponse);
} catch (SearchPhaseExecutionException spee) { } catch (SearchPhaseExecutionException spee) {
e = spee; //all good
} }
assert e != null;
searchResponse = client().prepareSearch("test").setTypes("type"). searchResponse = client().prepareSearch("test").setTypes("type").
setTemplateName("1a").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get(); setTemplateName("1a").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get();
@ -383,5 +368,4 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
sr = client().prepareSearch().setQuery(query).get(); sr = client().prepareSearch().setQuery(query).get();
assertHitCount(sr, 4); assertHitCount(sr, 4);
} }
} }