From ef2e3a8c39dde33d7df2a19729df716eb233f2b8 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 9 May 2016 09:50:35 -0400 Subject: [PATCH] Rest tests: More defense around stashing body Integration tests failed: https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+master+multijob-intake/483/console We'll see if the rest tests were hiding some other failure. --- .../src/main/java/org/elasticsearch/test/rest/Stash.java | 3 +++ .../org/elasticsearch/test/rest/client/RestResponse.java | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java b/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java index 9eae902c3e3..52b531e5cd1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java @@ -88,6 +88,9 @@ public class Stash implements ToXContent { */ public Object unstashValue(String value) throws IOException { if (value.startsWith("$body.")) { + if (response == null) { + return null; + } return response.evaluate(value.substring("$body".length()), this); } Object stashedValue = stash.get(value.substring(1)); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestResponse.java b/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestResponse.java index cdcd6a21a52..e0b2f3ab729 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestResponse.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestResponse.java @@ -51,7 +51,11 @@ public class RestResponse { */ public Object getBody() throws IOException { if (isJson()) { - return parsedResponse().evaluate(""); + JsonPath parsedResponse = parsedResponse(); + if (parsedResponse == null) { + return null; + } + return parsedResponse.evaluate(""); } return response.getBody(); }