Address review comments in ES core

Original commit: elastic/x-pack-elasticsearch@925c78d4fe
This commit is contained in:
Daniel Mitterdorfer 2016-12-12 13:30:39 +01:00
parent b7d2ef0160
commit 050a36bb28
2 changed files with 24 additions and 10 deletions

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.xpack.notification.email.attachment; package org.elasticsearch.xpack.notification.email.attachment;
import com.fasterxml.jackson.core.JsonParseException;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
@ -116,6 +115,10 @@ public class EmailAttachmentParsersTests extends ESTestCase {
} }
public void testThatTwoAttachmentsWithTheSameIdThrowError() throws Exception { public void testThatTwoAttachmentsWithTheSameIdThrowError() throws Exception {
if (JsonXContent.isStrictDuplicateDetectionEnabled()) {
logger.info("Skipping test as it uses a custom duplicate check that is obsolete when strict duplicate checks are enabled.");
return;
}
Map<String, EmailAttachmentParser> parsers = new HashMap<>(); Map<String, EmailAttachmentParser> parsers = new HashMap<>();
parsers.put("test", new TestEmailAttachmentParser()); parsers.put("test", new TestEmailAttachmentParser());
EmailAttachmentsParser parser = new EmailAttachmentsParser(parsers); EmailAttachmentsParser parser = new EmailAttachmentsParser(parsers);
@ -144,8 +147,8 @@ public class EmailAttachmentParsersTests extends ESTestCase {
parser.parse(xContentParser); parser.parse(xContentParser);
fail("Expected parser to fail but did not happen"); fail("Expected parser to fail but did not happen");
} catch (JsonParseException e) { } catch (ElasticsearchParseException e) {
assertThat(e.getMessage(), is("Duplicate field 'my-name.json'")); assertThat(e.getMessage(), is("Attachment with id [my-name.json] has already been created, must be renamed"));
} }
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.xpack.watcher.condition; package org.elasticsearch.xpack.watcher.condition;
import com.fasterxml.jackson.core.JsonParseException;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -195,6 +194,10 @@ public class ArrayCompareConditionTests extends ESTestCase {
} }
public void testParseContainsDuplicateOperator() throws IOException { public void testParseContainsDuplicateOperator() throws IOException {
if (JsonXContent.isStrictDuplicateDetectionEnabled()) {
logger.info("Skipping test as it uses a custom duplicate check that is obsolete when strict duplicate checks are enabled.");
return;
}
ArrayCompareCondition.Op op = randomFrom(ArrayCompareCondition.Op.values()); ArrayCompareCondition.Op op = randomFrom(ArrayCompareCondition.Op.values());
ArrayCompareCondition.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values()); ArrayCompareCondition.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values());
Object value = randomFrom("value", 1, null); Object value = randomFrom("value", 1, null);
@ -216,8 +219,8 @@ public class ArrayCompareConditionTests extends ESTestCase {
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
parser.nextToken(); parser.nextToken();
expectedException.expect(JsonParseException.class); expectedException.expect(ElasticsearchParseException.class);
expectedException.expectMessage("Duplicate field '" + op.id() + "'"); expectedException.expectMessage("duplicate comparison operator");
ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser); ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser);
} }
@ -246,6 +249,10 @@ public class ArrayCompareConditionTests extends ESTestCase {
} }
public void testParseContainsDuplicateValue() throws IOException { public void testParseContainsDuplicateValue() throws IOException {
if (JsonXContent.isStrictDuplicateDetectionEnabled()) {
logger.info("Skipping test as it uses a custom duplicate check that is obsolete when strict duplicate checks are enabled.");
return;
}
ArrayCompareCondition.Op op = randomFrom(ArrayCompareCondition.Op.values()); ArrayCompareCondition.Op op = randomFrom(ArrayCompareCondition.Op.values());
ArrayCompareCondition.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values()); ArrayCompareCondition.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values());
Object value = randomFrom("value", 1, null); Object value = randomFrom("value", 1, null);
@ -264,13 +271,17 @@ public class ArrayCompareConditionTests extends ESTestCase {
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
parser.nextToken(); parser.nextToken();
expectedException.expect(JsonParseException.class); expectedException.expect(ElasticsearchParseException.class);
expectedException.expectMessage("Duplicate field 'value'"); expectedException.expectMessage("duplicate field \"value\"");
ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser); ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser);
} }
public void testParseContainsDuplicateQuantifier() throws IOException { public void testParseContainsDuplicateQuantifier() throws IOException {
if (JsonXContent.isStrictDuplicateDetectionEnabled()) {
logger.info("Skipping test as it uses a custom duplicate check that is obsolete when strict duplicate checks are enabled.");
return;
}
ArrayCompareCondition.Op op = randomFrom(ArrayCompareCondition.Op.values()); ArrayCompareCondition.Op op = randomFrom(ArrayCompareCondition.Op.values());
ArrayCompareCondition.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values()); ArrayCompareCondition.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values());
Object value = randomFrom("value", 1, null); Object value = randomFrom("value", 1, null);
@ -289,8 +300,8 @@ public class ArrayCompareConditionTests extends ESTestCase {
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
parser.nextToken(); parser.nextToken();
expectedException.expect(JsonParseException.class); expectedException.expect(ElasticsearchParseException.class);
expectedException.expectMessage("Duplicate field 'quantifier'"); expectedException.expectMessage("duplicate field \"quantifier\"");
ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser); ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser);
} }