jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1854276 - in /jmeter/trunk: src/components/org/apache/jmeter/extractor/json/render/ src/components/org/apache/jmeter/visualizers/ test/src/org/apache/jmeter/extractor/json/render/ xdocs/
Date Sun, 24 Feb 2019 19:21:14 GMT
Author: pmouawad
Date: Sun Feb 24 19:21:14 2019
New Revision: 1854276

URL: http://svn.apache.org/viewvc?rev=1854276&view=rev
Log:
Bug 63204 - RenderAsJSON#prettyJSON : JSONParser#parse cannot return JSONValue

Also increase coverage
Bugzilla Id: 63204

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java
    jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java?rev=1854276&r1=1854275&r2=1854276&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java
(original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java
Sun Feb 24 19:21:14 2019
@@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
 public class RenderAsJsonRenderer implements ResultRenderer, ActionListener {
 
     private static final Logger log = LoggerFactory.getLogger(RenderAsJsonRenderer.class);
-
+    private static final String NO_MATCH = "NO MATCH"; //$NON-NLS-1$
     private static final String TAB_SEPARATOR = "    "; //$NON-NLS-1$
     
     private static final String JSONPATH_TESTER_COMMAND = "jsonpath_tester"; // $NON-NLS-1$
@@ -121,7 +121,7 @@ public class RenderAsJsonRenderer implem
         try {
             List<Object> matchStrings = extractWithJSonPath(textToParse, jsonPathExpressionField.getText());
             if (matchStrings.isEmpty()) {
-                return "NO MATCH"; //$NON-NLS-1$
+                return NO_MATCH; //$NON-NLS-1$
             } else {
                 StringBuilder builder = new StringBuilder();
                 int i = 0;
@@ -149,14 +149,8 @@ public class RenderAsJsonRenderer implem
     @Override
     public void renderResult(SampleResult sampleResult) {
         String response = ViewResultsFullVisualizer.getResponseAsString(sampleResult);
-        try {
-            jsonDataField.setText(response == null ? "" : RenderAsJSON.prettyJSON(response,
TAB_SEPARATOR));  //$NON-NLS-1$
-            jsonDataField.setCaretPosition(0);
-        } catch (Exception e) {
-            log.error("Exception converting to XML: {}, message: {}", response, e.getMessage(),
e); //$NON-NLS-1$ $NON-NLS-2$
-            jsonDataField.setText("Exception converting to XML: "+response+ ", message: "+e.getMessage());
//$NON-NLS-1$ $NON-NLS-2$
-            jsonDataField.setCaretPosition(0);
-        }
+        jsonDataField.setText(response == null ? "" : RenderAsJSON.prettyJSON(response, TAB_SEPARATOR));
 //$NON-NLS-1$
+        jsonDataField.setCaretPosition(0);
     }
 
 

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java?rev=1854276&r1=1854275&r2=1854276&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java Sun Feb 24
19:21:14 2019
@@ -28,7 +28,6 @@ import org.apache.jmeter.util.JMeterUtil
 import net.minidev.json.JSONArray;
 import net.minidev.json.JSONObject;
 import net.minidev.json.JSONStyle;
-import net.minidev.json.JSONValue;
 import net.minidev.json.parser.JSONParser;
 import net.minidev.json.parser.ParseException;
 
@@ -76,9 +75,6 @@ public class RenderAsJSON extends Sample
             } else if (o instanceof JSONArray) {
                 return ((JSONArray) o)
                         .toJSONString(new PrettyJSONStyle(tabSeparator));
-            } else if (o instanceof JSONValue) {
-                return ((JSONValue) o)
-                        .toJSONString(new PrettyJSONStyle(tabSeparator));
             }
         } catch (ParseException e) {
             return json;

Modified: jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy?rev=1854276&r1=1854275&r2=1854276&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy
(original)
+++ jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy
Sun Feb 24 19:21:14 2019
@@ -57,21 +57,41 @@ class RenderAsJsonRendererSpec extends J
             sut.jsonDataField.getText() == ""
     }
     
-    def "render JSON Response"() {
+    def "render '#input' as JSON Response to '#output'"() {
         given:
             sut.init();
             def sampleResult = new SampleResult();
-            sampleResult.setResponseData("{name:\"Ludwig\",age: 23,city: \"Bonn\"}");
         when:
+            sampleResult.setResponseData(input);
             sut.renderResult(sampleResult)
         then:
-            sut.jsonDataField.getText() == '''{
+            output == sut.jsonDataField.getText()
+        where:
+            input               |   output
+            "This is not json"  |   "This is not json" 
+            "{name:\"Ludwig\",age: 23,city: \"Bonn\"}" | '''{
     "city": "Bonn",
     "name": "Ludwig",
     "age": 23
 }'''
     }
     
+    def "execute '#expression' on '#input' results into '#output'"() {
+        given:
+            sut.init();
+            sut.jsonPathExpressionField.setText(expression);
+            def sampleResult = new SampleResult();
+        when:
+            sut.executeAndJSonPathTester(input);
+        then:
+            output == sut.jsonPathResultField.getText()
+        where:
+            input               | expression          | output
+            "{name:\"Ludwig\",age: 23,city: \"Bonn\"}"   | "\$..name"           | "Result[0]=Ludwig\n"
+            "This is not json"  | "\$..name" | "NO MATCH" 
+            "{name:\"Ludwig\",age: 23,city: \"Bonn\"}" | "\$.." | "Exception: Path must not
end with a '.' or '..'"
+    }
+    
     def "clearData clears expected fields"() {
         given:
             sut.init()

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1854276&r1=1854275&r2=1854276&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sun Feb 24 19:21:14 2019
@@ -136,6 +136,7 @@ Summary
 
 <h3>Listeners</h3>
 <ul>
+    <li><bug>63204</bug>RenderAsJSON#prettyJSON : JSONParser#parse cannot
return JSONValue</li>
 </ul>
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>



Mime
View raw message