From 050a36bb287f0b4eb35607fc8bddeaf9eb79d97a Mon Sep 17 00:00:00 2001 From: Daniel Mitterdorfer Date: Mon, 12 Dec 2016 13:30:39 +0100 Subject: [PATCH] Address review comments in ES core Original commit: elastic/x-pack-elasticsearch@925c78d4fefa6e8d4da5f310242b5f986b79a9a0 --- .../EmailAttachmentParsersTests.java | 9 ++++--- .../condition/ArrayCompareConditionTests.java | 25 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java index 8b36e7671fe..3b480bf166f 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.notification.email.attachment; -import com.fasterxml.jackson.core.JsonParseException; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.ToXContent; @@ -116,6 +115,10 @@ public class EmailAttachmentParsersTests extends ESTestCase { } 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 parsers = new HashMap<>(); parsers.put("test", new TestEmailAttachmentParser()); EmailAttachmentsParser parser = new EmailAttachmentsParser(parsers); @@ -144,8 +147,8 @@ public class EmailAttachmentParsersTests extends ESTestCase { parser.parse(xContentParser); fail("Expected parser to fail but did not happen"); - } catch (JsonParseException e) { - assertThat(e.getMessage(), is("Duplicate field 'my-name.json'")); + } catch (ElasticsearchParseException e) { + assertThat(e.getMessage(), is("Attachment with id [my-name.json] has already been created, must be renamed")); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionTests.java index 5105ed25d8d..8bbbb689823 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.condition; -import com.fasterxml.jackson.core.JsonParseException; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -195,6 +194,10 @@ public class ArrayCompareConditionTests extends ESTestCase { } 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.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values()); Object value = randomFrom("value", 1, null); @@ -216,8 +219,8 @@ public class ArrayCompareConditionTests extends ESTestCase { XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); - expectedException.expect(JsonParseException.class); - expectedException.expectMessage("Duplicate field '" + op.id() + "'"); + expectedException.expect(ElasticsearchParseException.class); + expectedException.expectMessage("duplicate comparison operator"); ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser); } @@ -246,6 +249,10 @@ public class ArrayCompareConditionTests extends ESTestCase { } 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.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values()); Object value = randomFrom("value", 1, null); @@ -264,13 +271,17 @@ public class ArrayCompareConditionTests extends ESTestCase { XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); - expectedException.expect(JsonParseException.class); - expectedException.expectMessage("Duplicate field 'value'"); + expectedException.expect(ElasticsearchParseException.class); + expectedException.expectMessage("duplicate field \"value\""); ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser); } 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.Quantifier quantifier = randomFrom(ArrayCompareCondition.Quantifier.values()); Object value = randomFrom("value", 1, null); @@ -289,8 +300,8 @@ public class ArrayCompareConditionTests extends ESTestCase { XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); - expectedException.expect(JsonParseException.class); - expectedException.expectMessage("Duplicate field 'quantifier'"); + expectedException.expect(ElasticsearchParseException.class); + expectedException.expectMessage("duplicate field \"quantifier\""); ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser); }