This is an automated email from the ASF dual-hosted git repository. fschumacher pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jmeter.git
commit 4846dc4e57d51e6af67b225be559d4627d519860 Author: Felix Schumacher <[email protected]> AuthorDate: Fri Apr 28 16:15:50 2023 +0200 Add test for JSONPathAssertion with floating point number Closes PR #723 --- .../jmeter/assertions/TestJSONPathAssertion.java | 29 ++++++++++++++++++++++ xdocs/changes.xml | 2 ++ 2 files changed, 31 insertions(+) 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 c01f5c5e87..a2a9c6b3ca 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 @@ -99,6 +99,35 @@ class TestJSONPathAssertion { assertFalse(result.isFailure()); } + @Test + void testGetResult_positive_regexp_for_floating_point() { + SampleResult samplerResult = new SampleResult(); + samplerResult.setResponseData("{\"myval\": 123.45}".getBytes(Charset.defaultCharset())); + + JSONPathAssertion instance = new JSONPathAssertion(); + instance.setJsonPath("$.myval"); + instance.setJsonValidationBool(true); + instance.setExpectedValue("^\\d+\\.\\d+$"); + AssertionResult expResult = new AssertionResult(""); + AssertionResult result = instance.getResult(samplerResult); + assertEquals(expResult.getName(), result.getName()); + assertFalse(result.isFailure()); + } + + @Test + void testGetResult_positive_wrong_regexp_for_floating_point() { + SampleResult samplerResult = new SampleResult(); + samplerResult.setResponseData("{\"myval\": 123.45}".getBytes(Charset.defaultCharset())); + + JSONPathAssertion instance = new JSONPathAssertion(); + instance.setJsonPath("$.myval"); + instance.setJsonValidationBool(true); + instance.setExpectedValue("^\\d+,\\d+$"); + AssertionResult expResult = new AssertionResult(""); + AssertionResult result = instance.getResult(samplerResult); + assertEquals(expResult.getName(), result.getName()); + assertTrue(result.isFailure()); + } @Test void testGetResult_positive_regexp() { SampleResult samplerResult = new SampleResult(); diff --git a/xdocs/changes.xml b/xdocs/changes.xml index c2769d1058..fef507cfb9 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -147,6 +147,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> + <li><pr>723</pr>Use correct number format on JSON Path Assertion. Contributed by andreaslind01 (andreaslind01 at gmail.com)</li> </ul> <h3>Functions</h3> @@ -184,6 +185,7 @@ Summary <li>Kai Lehmann (klehmann at aservo.com)</li> <li>Ori Marko (orimarko at gmail.com)</li> <li>Stefan Seide (stefan at trilobyte-se.de)</li> + <li>andreaslind01 Lind (andreaslind01 at gmail.com)</li> </ul> <p>We also thank bug reporters who helped us improve JMeter.</p> <ul>
