From 9f382da5d3fc5ad3b44819dfdb0d712965919e49 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 14 Mar 2016 14:27:35 +0100 Subject: [PATCH] Add better validation error message and a dedicated test --- .../action/admin/indices/mapping/put/PutMappingRequest.java | 2 +- .../admin/indices/mapping/put/PutMappingRequestTests.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index 9444e322a68..9e33103b371 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -94,7 +94,7 @@ public class PutMappingRequest extends AcknowledgedRequest 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; } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java index 967a9026469..65b9ff0dd22 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java @@ -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")); } }