public class PutMappingRequestTests extends ElasticsearchTestCase {
public void testValidation() {
PutMappingRequest r = new PutMappingRequest("myindex");
ActionRequestValidationException ex = r.validate();
assertNotNull("type validation should fail", ex);
assertTrue(ex.getMessage().contains("type is missing"));
r.type("");
ex = r.validate();
assertNotNull("type validation should fail", ex);
assertTrue(ex.getMessage().contains("type is empty"));
r.type("mytype");
ex = r.validate();
assertNotNull("source validation should fail", ex);
assertTrue(ex.getMessage().contains("source is missing"));
r.source("");
ex = r.validate();
assertNotNull("source validation should fail", ex);
assertTrue(ex.getMessage().contains("source is empty"));
r.source("somevalidmapping");
ex = r.validate();
assertNull("validation should succeed", ex);
}