From e0741997d058f96623257962ef5852db3c7c1b3e Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 12 Nov 2014 21:27:48 +0100 Subject: [PATCH] Test: Extended malformed test to also check if the strict alert mapping in the template is active. Original commit: elastic/x-pack-elasticsearch@dfcad46f94f6745d4d4945fe5438a1ffc0d9ac6d --- .../alerts/BasicAlertingTest.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java index 036d61f1060..a3dbd251edf 100644 --- a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java +++ b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java @@ -86,7 +86,7 @@ public class BasicAlertingTest extends AbstractAlertingTests { assertFalse(deleteAlertResponse.deleteResponse().isFound()); } - @Test(expected = ElasticsearchIllegalArgumentException.class) + @Test public void testMalformedAlert() throws Exception { AlertsClientInterface alertsClient = alertClient(); createIndex("my-index"); @@ -98,8 +98,21 @@ public class BasicAlertingTest extends AbstractAlertingTests { .field("enable", true) .field("malformed_field", "x") .endObject().bytes(); - alertsClient.prepareIndexAlert("my-first-alert") - .setAlertSource(alertSource) - .get(); + try { + alertsClient.prepareIndexAlert("my-first-alert") + .setAlertSource(alertSource) + .get(); + fail(); + } catch (ElasticsearchIllegalArgumentException e) { + // In AlertStore we fail parsing if an alert contains undefined fields. + } + try { + client().prepareIndex(AlertsStore.ALERT_INDEX, AlertsStore.ALERT_TYPE, "my-first-alert") + .setSource(alertSource) + .get(); + fail(); + } catch (Exception e) { + // The alert index template the mapping is defined as strict + } } }