Skip to content

Commit

Permalink
[TEST] Added index templates tests for broken mapping and invalid set…
Browse files Browse the repository at this point in the history
…tings scenarios
  • Loading branch information
javanna committed Feb 19, 2014
1 parent 32d85c2 commit 3224c25
Showing 1 changed file with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
package org.elasticsearch.indices.template;

import com.google.common.collect.Lists;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.indices.IndexTemplateAlreadyExistsException;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
Expand All @@ -41,7 +44,6 @@
*/
public class SimpleIndexTemplateTests extends ElasticsearchIntegrationTest {


@Test
public void simpleIndexTemplateTests() throws Exception {
// clean all templates setup by the framework.
Expand Down Expand Up @@ -268,4 +270,56 @@ private void testExpectActionRequestValidationException(String... names) {
"get template with " + Arrays.toString(names));
}

@Test
public void testBrokenMapping() throws Exception {
// clean all templates setup by the framework.
client().admin().indices().prepareDeleteTemplate("*").get();

// check get all templates on an empty index.
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());

client().admin().indices().preparePutTemplate("template_1")
.setTemplate("te*")
.addMapping("type1", "abcde")
.get();

response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), hasSize(1));
assertThat(response.getIndexTemplates().get(0).getMappings().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getMappings().get("type1").string(), equalTo("abcde"));

try {
createIndex("test");
fail("create index should have failed due to broken index templates mapping");
} catch(ElasticsearchParseException e) {
//everything fine
}
}

@Test
public void testInvalidSettings() throws Exception {
// clean all templates setup by the framework.
client().admin().indices().prepareDeleteTemplate("*").get();

// check get all templates on an empty index.
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());

client().admin().indices().preparePutTemplate("template_1")
.setTemplate("te*")
.setSettings(ImmutableSettings.builder().put("does_not_exist", "test"))
.get();

response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), hasSize(1));
assertThat(response.getIndexTemplates().get(0).getSettings().getAsMap().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getSettings().get("index.does_not_exist"), equalTo("test"));

createIndex("test");

//the wrong setting has no effect but does get stored among the index settings
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getIndexToSettings().get("test").getAsMap().get("index.does_not_exist"), equalTo("test"));
}
}

0 comments on commit 3224c25

Please sign in to comment.