Add better validation error message and a dedicated test

This commit is contained in:
Simon Willnauer 2016-03-14 14:27:35 +01:00
parent 0ed0fea558
commit 9f382da5d3
2 changed files with 7 additions and 1 deletions

View File

@ -94,7 +94,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
validationException = addValidationError("mapping source is empty", validationException);
}
if (concreteIndex != null && (indices != null && indices.length > 0)) {
validationException = addValidationError("either concreteIndices or unresolved indices can be set", validationException);
validationException = addValidationError("either concreteIndices or unresolved indices can be set concrete: [" + concreteIndex + "] and indices: " + indices , validationException);
}
return validationException;
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.action.admin.indices.mapping.put;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.index.Index;
import org.elasticsearch.test.ESTestCase;
public class PutMappingRequestTests extends ESTestCase {
@ -48,5 +49,10 @@ public class PutMappingRequestTests extends ESTestCase {
r.source("somevalidmapping");
ex = r.validate();
assertNull("validation should succeed", ex);
r.setConcreteIndex(new Index("foo", "bar"));
ex = r.validate();
assertNotNull("source validation should fail", ex);
assertTrue(ex.getMessage().contains("either concreteIndices or unresolved indices can be set"));
}
}