From 100b5b922c454dcd41b8a24670bf9a5c50de02b8 Mon Sep 17 00:00:00 2001 From: Brian Murphy Date: Thu, 19 Mar 2015 15:56:19 -0400 Subject: [PATCH] Fix SearchInput tests. SearchInput tests were failing locally for me in DEBUG because they weren't setting a valid alert on the ExecutionContext which was causing the debug log messages in the SearchInput.execute method to NPE. I've added a dummy Alert to the context to fix things. ` Original commit: elastic/x-pack-elasticsearch@2d744fdb7bcce0d1c729e3a8a38314b03154be8e --- .../alerts/input/search/SearchInputTests.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/elasticsearch/alerts/input/search/SearchInputTests.java b/src/test/java/org/elasticsearch/alerts/input/search/SearchInputTests.java index 9cf9afe7f32..914cb102c63 100644 --- a/src/test/java/org/elasticsearch/alerts/input/search/SearchInputTests.java +++ b/src/test/java/org/elasticsearch/alerts/input/search/SearchInputTests.java @@ -7,11 +7,19 @@ package org.elasticsearch.alerts.input.search; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.alerts.Alert; import org.elasticsearch.alerts.ExecutionContext; +import org.elasticsearch.alerts.Payload; +import org.elasticsearch.alerts.actions.Action; +import org.elasticsearch.alerts.actions.Actions; +import org.elasticsearch.alerts.condition.simple.AlwaysTrueCondition; import org.elasticsearch.alerts.input.Input; import org.elasticsearch.alerts.input.InputException; +import org.elasticsearch.alerts.input.simple.SimpleInput; +import org.elasticsearch.alerts.scheduler.schedule.IntervalSchedule; import org.elasticsearch.alerts.support.AlertUtils; import org.elasticsearch.alerts.support.Variables; +import org.elasticsearch.alerts.support.clock.ClockMock; import org.elasticsearch.alerts.support.init.proxy.ClientProxy; import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy; import org.elasticsearch.common.joda.time.DateTime; @@ -59,7 +67,17 @@ public class SearchInputTests extends ElasticsearchIntegrationTest { SearchInput searchInput = new SearchInput(logger, ScriptServiceProxy.of(internalCluster().getInstance(ScriptService.class)), ClientProxy.of(client()), request); - ExecutionContext ctx = new ExecutionContext("test-alert", null, + ExecutionContext ctx = new ExecutionContext("test-alert", + new Alert("test-alert", + new ClockMock(), + new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES)), + new SimpleInput(logger, new Payload.Simple()), + new AlwaysTrueCondition(logger), + null, + new Actions(new ArrayList()), + null, + null, + new Alert.Status()), new DateTime(0, DateTimeZone.UTC), new DateTime(0, DateTimeZone.UTC), new DateTime(0, DateTimeZone.UTC)); SearchInput.Result result = searchInput.execute(ctx); @@ -85,7 +103,17 @@ public class SearchInputTests extends ElasticsearchIntegrationTest { SearchInput searchInput = new SearchInput(logger, ScriptServiceProxy.of(internalCluster().getInstance(ScriptService.class)), ClientProxy.of(client()), request); - ExecutionContext ctx = new ExecutionContext("test-alert", null, + ExecutionContext ctx = new ExecutionContext("test-alert", + new Alert("test-alert", + new ClockMock(), + new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES)), + new SimpleInput(logger, new Payload.Simple()), + new AlwaysTrueCondition(logger), + null, + new Actions(new ArrayList()), + null, + null, + new Alert.Status()), new DateTime(0, DateTimeZone.UTC), new DateTime(0, DateTimeZone.UTC), new DateTime(0, DateTimeZone.UTC)); SearchInput.Result result = searchInput.execute(ctx);