diff --git a/plugin/src/main/java/org/elasticsearch/xpack/watcher/input/http/ExecutableHttpInput.java b/plugin/src/main/java/org/elasticsearch/xpack/watcher/input/http/ExecutableHttpInput.java index eba6e4bcc41..93c8b991740 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/watcher/input/http/ExecutableHttpInput.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/watcher/input/http/ExecutableHttpInput.java @@ -83,7 +83,13 @@ public class ExecutableHttpInput extends ExecutableInput headers = Collections.singletonMap("Content-Type", new String[]{"application/json"}); + HttpResponse response = new HttpResponse(200, "[ { \"foo\": \"first\" }, { \"foo\": \"second\"}]", headers); + when(httpClient.execute(any(HttpRequest.class))).thenReturn(response); + + HttpRequestTemplate.Builder request = HttpRequestTemplate.builder("localhost", 8080); + HttpInput httpInput = InputBuilders.httpInput(request.build()).build(); + ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine); + + WatchExecutionContext ctx = createWatchExecutionContext(); + HttpInput.Result result = input.execute(ctx, new Payload.Simple()); + assertThat(result.statusCode, is(200)); + assertThat(result.payload().data(), not(hasKey("_value"))); + assertThat(result.payload().data(), hasKey("data")); + assertThat(result.payload().data().get("data"), instanceOf(List.class)); + List> data = (List>) result.payload().data().get("data"); + assertThat(data, hasSize(2)); + assertThat(data.get(0).get("foo"), is("first")); + assertThat(data.get(1).get("foo"), is("second")); + } + + private WatchExecutionContext createWatchExecutionContext() { Watch watch = new Watch("test-watch", new ScheduleTrigger(new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES))),