You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2023/04/29 15:52:06 UTC

[jmeter] branch master updated (5d18b2ce1e -> 4846dc4e57)

This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


    from 5d18b2ce1e Revert "fix(deps): update dependency org.apache.commons:commons-jexl3 to v3.3 (#5851)"
     new 1679a714d7 Use correct number format in json assertions with regex
     new 4846dc4e57 Add test for JSONPathAssertion with floating point number

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../jmeter/assertions/JSONPathAssertion.java       |  4 ++-
 .../jmeter/assertions/TestJSONPathAssertion.java   | 29 ++++++++++++++++++++++
 xdocs/changes.xml                                  |  2 ++
 3 files changed, 34 insertions(+), 1 deletion(-)


[jmeter] 02/02: Add test for JSONPathAssertion with floating point number

Posted by fs...@apache.org.
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 <fe...@internetallee.de>
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- &amp; 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>


[jmeter] 01/02: Use correct number format in json assertions with regex

Posted by fs...@apache.org.
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 1679a714d787da0f5eda1e29ac78bf6d5e8b528e
Author: andreaslind01 <an...@gmail.com>
AuthorDate: Fri Aug 5 12:38:41 2022 +0200

    Use correct number format in json assertions with regex
---
 .../src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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 5671e27856..b8e719bb5e 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
@@ -19,6 +19,8 @@ package org.apache.jmeter.assertions;
 
 import java.io.Serializable;
 import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 
@@ -58,7 +60,7 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
             ThreadLocal.withInitial(JSONPathAssertion::createDecimalFormat);
 
     private static DecimalFormat createDecimalFormat() {
-        DecimalFormat decimalFormatter = new DecimalFormat("#.#");
+        DecimalFormat decimalFormatter = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.US));
         decimalFormatter.setMaximumFractionDigits(340); // java.text.DecimalFormat.DOUBLE_FRACTION_DIGITS == 340
         decimalFormatter.setMinimumFractionDigits(1);
         return decimalFormatter;