You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by vl...@apache.org on 2022/12/14 08:51:36 UTC
[jmeter] branch master updated: added jsonpath string to assertion error message so it is easier to understand the error
This is an automated email from the ASF dual-hosted git repository.
vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new 74d9040362 added jsonpath string to assertion error message so it is easier to understand the error
74d9040362 is described below
commit 74d9040362a78c07a2afd6c9068c2ec97b4a59c8
Author: Kai Lehmann <kl...@aservo.com>
AuthorDate: Wed Oct 19 12:27:21 2022 +0200
added jsonpath string to assertion error message so it is easier to understand the error
fixes #5717
---
.../java/org/apache/jmeter/assertions/JSONPathAssertion.java | 12 ++++++------
.../org/apache/jmeter/assertions/TestJSONPathAssertion.java | 12 +++++++-----
xdocs/changes.xml | 2 ++
3 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java b/src/components/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
index 446ff6f72e..5671e27856 100644
--- a/src/components/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
+++ b/src/components/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
@@ -118,8 +118,8 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
if (value instanceof JSONArray) {
JSONArray arrayValue = (JSONArray) value;
if (arrayValue.isEmpty() && !JsonPath.isPathDefinite(getJsonPath())) {
- throw new IllegalStateException("JSONPath is indefinite and the extracted Value is an empty Array." +
- " Please use an assertion value, to be sure to get a correct result. " + getExpectedValue());
+ throw new IllegalStateException(String.format("JSONPath '%s' is indefinite and the extracted Value is an empty Array." +
+ " Please use an assertion value, to be sure to get a correct result. Expected value was '%s'", getJsonPath(), getExpectedValue()));
}
}
return;
@@ -137,15 +137,15 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
}
if (isExpectNull()) {
- throw new IllegalStateException(String.format("Value expected to be null, but found '%s'", value));
+ throw new IllegalStateException(String.format("Value in json path '%s' expected to be null, but found '%s'", getJsonPath(), value));
} else {
String msg;
if (isUseRegex()) {
- msg = "Value expected to match regexp '%s', but it did not match: '%s'";
+ msg = "Value in json path '%s' expected to match regexp '%s', but it did not match: '%s'";
} else {
- msg = "Value expected to be '%s', but found '%s'";
+ msg = "Value in json path '%s' expected to be '%s', but found '%s'";
}
- throw new IllegalStateException(String.format(msg, getExpectedValue(), objectToString(value)));
+ throw new IllegalStateException(String.format(msg, getJsonPath(), getExpectedValue(), objectToString(value)));
}
}
diff --git a/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java b/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
index e9349efb1e..c01f5c5e87 100644
--- a/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
+++ b/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
@@ -311,18 +311,20 @@ class TestJSONPathAssertion {
samplerResult.setResponseData(str.getBytes(Charset.defaultCharset()));
JSONPathAssertion instance = new JSONPathAssertion();
- instance.setJsonPath("$.execution[0].scenario.requests[0].headers");
+ String jsonPath = "$.execution[0].scenario.requests[0].headers";
+ String expectedValue = "\\{headerkey=header value\\}";
+ instance.setJsonPath(jsonPath);
instance.setJsonValidationBool(true);
instance.setExpectNull(false);
- instance.setExpectedValue("\\{headerkey=header value\\}");
+ instance.setExpectedValue(expectedValue);
instance.setInvert(false);
AssertionResult expResult = new AssertionResult("");
AssertionResult result = instance.getResult(samplerResult);
assertEquals(expResult.getName(), result.getName());
assertTrue(result.isFailure());
- assertEquals(
- "Value expected to match regexp '\\{headerkey=header value\\}', but it did not match: '{\"headerkey\":\"header value\"}'",
- result.getFailureMessage());
+ assertEquals(String.format(
+ "Value in json path '%s' expected to match regexp '%s', but it did not match: '{\"headerkey\":\"header value\"}'",
+ jsonPath, expectedValue), result.getFailureMessage());
}
@Test
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 048343e00a..e05d77416e 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -132,6 +132,7 @@ Summary
<h3>Timers, Assertions, Config, Pre- & Post-Processors</h3>
<ul>
+ <li><pr>5717</pr>Add jsonpath string to jsonpath assertion error message so the error is easier to understand</li>
</ul>
<h3>Functions</h3>
@@ -163,6 +164,7 @@ Summary
<p>We thank all contributors mentioned in bug and improvement sections above:
</p>
<ul>
+ <li>Kai Lehmann (klehmann at aservo.com)</li>
</ul>
<p>We also thank bug reporters who helped us improve JMeter.</p>
<ul>