jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1766100 - in /jmeter/trunk: src/components/org/apache/jmeter/extractor/json/jsonpath/ test/src/org/apache/jmeter/extractor/ xdocs/
Date Fri, 21 Oct 2016 18:39:22 GMT
Author: fschumacher
Date: Fri Oct 21 18:39:22 2016
New Revision: 1766100

URL: http://svn.apache.org/viewvc?rev=1766100&view=rev
Log:
JSON Extractor doesn't index array elements when only one element is found.
Based on patch by Roberto Braga (roberto.braga at sociale.it).

Bugzilla Id: 60295

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java
    jmeter/trunk/test/src/org/apache/jmeter/extractor/TestJSONPostProcessor.java
    jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java?rev=1766100&r1=1766099&r2=1766100&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java
(original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java
Fri Oct 21 18:39:22 2016
@@ -161,7 +161,8 @@ public class JSONPostProcessor extends A
                             }
                         } else {
                             // else just one value extracted
-                            placeObjectIntoVars(vars, currentRefName, extractedValues, 0);
+                            String suffix = (matchNumber < 0) ? "_1" : "";
+                            placeObjectIntoVars(vars, currentRefName + suffix, extractedValues,
0);
                             if (matchNumber < 0 && getComputeConcatenation())
{
                                 vars.put(currentRefName + ALL_SUFFIX, vars.get(currentRefName));
                             }

Modified: jmeter/trunk/test/src/org/apache/jmeter/extractor/TestJSONPostProcessor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestJSONPostProcessor.java?rev=1766100&r1=1766099&r2=1766100&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/extractor/TestJSONPostProcessor.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/extractor/TestJSONPostProcessor.java Fri Oct 21
18:39:22 2016
@@ -18,6 +18,8 @@
 
 package org.apache.jmeter.extractor;
 
+import static org.junit.Assert.assertThat;
+
 import java.nio.charset.StandardCharsets;
 
 import net.minidev.json.parser.JSONParser;
@@ -28,6 +30,7 @@ import org.apache.jmeter.samplers.Sample
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.hamcrest.CoreMatchers;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -36,6 +39,40 @@ public class TestJSONPostProcessor {
     private static final String VAR_NAME = "varName";
 
     @Test
+    public void testProcessAllElementsOneMatch() {
+        JMeterContext context = JMeterContextService.getContext();
+        JSONPostProcessor processor = setupProcessor(context, "-1", true);
+        JMeterVariables vars = new JMeterVariables();
+        processor.setDefaultValues("NONE");
+        processor.setJsonPathExpressions("$[*]");
+        processor.setRefNames("varname");
+        processor.setScopeVariable("contentvar");
+        context.setVariables(vars);
+        vars.put("contentvar", "[\"one\"]");
+        processor.process();
+        assertThat(vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
+        assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
+        assertThat(vars.get("varname_matchNr"), CoreMatchers.is("1"));
+    }
+
+    @Test
+    public void testProcessAllElementsMultipleMatches() {
+        JMeterContext context = JMeterContextService.getContext();
+        JSONPostProcessor processor = setupProcessor(context, "-1", true);
+        JMeterVariables vars = new JMeterVariables();
+        processor.setDefaultValues("NONE");
+        processor.setJsonPathExpressions("$[*]");
+        processor.setRefNames("varname");
+        processor.setScopeVariable("contentvar");
+        context.setVariables(vars);
+        vars.put("contentvar", "[\"one\", \"two\"]");
+        processor.process();
+        assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
+        assertThat(vars.get("varname_2"), CoreMatchers.is("two"));
+        assertThat(vars.get("varname_matchNr"), CoreMatchers.is("2"));
+    }
+
+    @Test
     public void testBug59609() throws ParseException {
         JMeterContext context = JMeterContextService.getContext();
         JSONPostProcessor processor = setupProcessor(context, "0", false);

Modified: jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java?rev=1766100&r1=1766099&r2=1766100&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java Fri Oct 21 18:39:22
2016
@@ -23,13 +23,16 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.net.URL;
+
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.hamcrest.CoreMatchers;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -68,6 +71,37 @@ public class TestRegexExtractor {
         }
 
         @Test
+        public void testProcessAllElementsSingleMatch() {
+            vars.put("content", "one");
+            extractor.setMatchNumber(-1);
+            extractor.setRefName("varname");
+            extractor.setRegex("(\\w+)");
+            extractor.setScopeVariable("content");
+            extractor.setThreadContext(jmctx);
+            extractor.setTemplate("$1$");
+            extractor.process();
+            assertThat(vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
+            assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
+            assertThat(vars.get("varname_matchNr"), CoreMatchers.is("1"));
+        }
+
+        @Test
+        public void testProcessAllElementsMultipleMatches() {
+            vars.put("content", "one, two");
+            extractor.setMatchNumber(-1);
+            extractor.setRefName("varname");
+            extractor.setRegex("(\\w+)");
+            extractor.setScopeVariable("content");
+            extractor.setThreadContext(jmctx);
+            extractor.setTemplate("$1$");
+            extractor.process();
+            assertThat(vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
+            assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
+            assertThat(vars.get("varname_2"), CoreMatchers.is("two"));
+            assertThat(vars.get("varname_matchNr"), CoreMatchers.is("2"));
+        }
+
+        @Test
         public void testEmptyDefaultVariable() throws Exception {
             extractor.setRegex("<value name=\"positioncount\">(.+?)</value>");
             extractor.setTemplate("$1$");

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1766100&r1=1766099&r2=1766100&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Fri Oct 21 18:39:22 2016
@@ -277,6 +277,7 @@ Summary
     <li><bug>60125</bug>Report / Dashboard : Dashboard cannot be generated
if the default delimiter is <code>\t</code>. Based on a report from Tamas Szabadi
(tamas.szabadi at rightside.co)</li>
     <li><bug>59439</bug>Report / Dashboard : AbstractOverTimeGraphConsumer.createGroupInfos()
should be abstract</li>
     <li><bug>59918</bug>Ant generated HTML report is broken (extras folder)</li>
+    <li><bug>60295</bug>JSON Extractor doesn't index array elements when
only one element is found. Based on a patch by Roberto Braga (roberto.braga at sociale.it)</li>
 </ul>
 
  <!--  =================== Thanks =================== -->
@@ -295,6 +296,7 @@ Summary
 <li>Maxime Chassagneux (maxime.chassagneux at gmail.com)</li>
 <li><a href="http://ubikloadpack.com">Ubik Load Pack</a></li>
 <li>Tamas Szabadi (tamas.szabadi at rightside.co)</li>
+<li>Roberto Braga (roberto.braga at soziale.it)</li>
 </ul>
 <p>We also thank bug reporters who helped us improve JMeter. <br/>
 For this release we want to give special thanks to the following reporters for the clear
reports and tests made after our fixes:</p>



Mime
View raw message