View | Details | Raw Unified | Return to bug 60295
Collapse All | Expand All

(-)a/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java (-1 / +2 lines)
Lines 161-167 public class JSONPostProcessor extends AbstractScopedTestElement implements Seri Link Here
161
                            }
161
                            }
162
                        } else {
162
                        } else {
163
                            // else just one value extracted
163
                            // else just one value extracted
164
                            placeObjectIntoVars(vars, currentRefName, extractedValues, 0);
164
                            String suffix = (matchNumber < 0) ? "_1" : "";
165
                            placeObjectIntoVars(vars, currentRefName + suffix, extractedValues, 0);
165
                            if (matchNumber < 0 && getComputeConcatenation()) {
166
                            if (matchNumber < 0 && getComputeConcatenation()) {
166
                                vars.put(currentRefName + ALL_SUFFIX, vars.get(currentRefName));
167
                                vars.put(currentRefName + ALL_SUFFIX, vars.get(currentRefName));
167
                            }
168
                            }
(-)a/test/src/org/apache/jmeter/extractor/TestJSONPostProcessor.java (+37 lines)
Lines 18-23 Link Here
18
18
19
package org.apache.jmeter.extractor;
19
package org.apache.jmeter.extractor;
20
20
21
import static org.junit.Assert.assertThat;
22
21
import java.nio.charset.StandardCharsets;
23
import java.nio.charset.StandardCharsets;
22
24
23
import net.minidev.json.parser.JSONParser;
25
import net.minidev.json.parser.JSONParser;
Lines 28-33 import org.apache.jmeter.samplers.SampleResult; Link Here
28
import org.apache.jmeter.threads.JMeterContext;
30
import org.apache.jmeter.threads.JMeterContext;
29
import org.apache.jmeter.threads.JMeterContextService;
31
import org.apache.jmeter.threads.JMeterContextService;
30
import org.apache.jmeter.threads.JMeterVariables;
32
import org.apache.jmeter.threads.JMeterVariables;
33
import org.hamcrest.CoreMatchers;
31
import org.junit.Assert;
34
import org.junit.Assert;
32
import org.junit.Test;
35
import org.junit.Test;
33
36
Lines 36-41 public class TestJSONPostProcessor { Link Here
36
    private static final String VAR_NAME = "varName";
39
    private static final String VAR_NAME = "varName";
37
40
38
    @Test
41
    @Test
42
    public void testProcessAllElementsOneMatch() {
43
        JMeterContext context = JMeterContextService.getContext();
44
        JSONPostProcessor processor = setupProcessor(context, "-1", true);
45
        JMeterVariables vars = new JMeterVariables();
46
        processor.setDefaultValues("NONE");
47
        processor.setJsonPathExpressions("$[*]");
48
        processor.setRefNames("varname");
49
        processor.setScopeVariable("contentvar");
50
        context.setVariables(vars);
51
        vars.put("contentvar", "[\"one\"]");
52
        processor.process();
53
        assertThat(vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
54
        assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
55
        assertThat(vars.get("varname_matchNr"), CoreMatchers.is("1"));
56
    }
57
58
    @Test
59
    public void testProcessAllElementsMultipleMatches() {
60
        JMeterContext context = JMeterContextService.getContext();
61
        JSONPostProcessor processor = setupProcessor(context, "-1", true);
62
        JMeterVariables vars = new JMeterVariables();
63
        processor.setDefaultValues("NONE");
64
        processor.setJsonPathExpressions("$[*]");
65
        processor.setRefNames("varname");
66
        processor.setScopeVariable("contentvar");
67
        context.setVariables(vars);
68
        vars.put("contentvar", "[\"one\", \"two\"]");
69
        processor.process();
70
        assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
71
        assertThat(vars.get("varname_2"), CoreMatchers.is("two"));
72
        assertThat(vars.get("varname_matchNr"), CoreMatchers.is("2"));
73
    }
74
75
    @Test
39
    public void testBug59609() throws ParseException {
76
    public void testBug59609() throws ParseException {
40
        JMeterContext context = JMeterContextService.getContext();
77
        JMeterContext context = JMeterContextService.getContext();
41
        JSONPostProcessor processor = setupProcessor(context, "0", false);
78
        JSONPostProcessor processor = setupProcessor(context, "0", false);
(-)a/test/src/org/apache/jmeter/extractor/TestRegexExtractor.java (-1 / +32 lines)
Lines 23-35 import static org.junit.Assert.assertEquals; Link Here
23
import static org.junit.Assert.assertFalse;
23
import static org.junit.Assert.assertFalse;
24
import static org.junit.Assert.assertNotNull;
24
import static org.junit.Assert.assertNotNull;
25
import static org.junit.Assert.assertNull;
25
import static org.junit.Assert.assertNull;
26
import static org.junit.Assert.assertThat;
26
import static org.junit.Assert.assertTrue;
27
import static org.junit.Assert.assertTrue;
27
28
28
import java.net.URL;
29
import java.net.URL;
30
29
import org.apache.jmeter.samplers.SampleResult;
31
import org.apache.jmeter.samplers.SampleResult;
30
import org.apache.jmeter.threads.JMeterContext;
32
import org.apache.jmeter.threads.JMeterContext;
31
import org.apache.jmeter.threads.JMeterContextService;
33
import org.apache.jmeter.threads.JMeterContextService;
32
import org.apache.jmeter.threads.JMeterVariables;
34
import org.apache.jmeter.threads.JMeterVariables;
35
import org.hamcrest.CoreMatchers;
33
import org.junit.Before;
36
import org.junit.Before;
34
import org.junit.Test;
37
import org.junit.Test;
35
38
Lines 68-73 public class TestRegexExtractor { Link Here
68
        }
71
        }
69
72
70
        @Test
73
        @Test
74
        public void testProcessAllElementsSingleMatch() {
75
            vars.put("content", "one");
76
            extractor.setMatchNumber(-1);
77
            extractor.setRefName("varname");
78
            extractor.setRegex("(\\w+)");
79
            extractor.setScopeVariable("content");
80
            extractor.setThreadContext(jmctx);
81
            extractor.setTemplate("$1$");
82
            extractor.process();
83
            assertThat(vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
84
            assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
85
        }
86
87
        @Test
88
        public void testProcessAllElementsMultipleMatches() {
89
            vars.put("content", "one, two");
90
            extractor.setMatchNumber(-1);
91
            extractor.setRefName("varname");
92
            extractor.setRegex("(\\w+)");
93
            extractor.setScopeVariable("content");
94
            extractor.setThreadContext(jmctx);
95
            extractor.setTemplate("$1$");
96
            extractor.process();
97
            assertThat(vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
98
            assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
99
            assertThat(vars.get("varname_2"), CoreMatchers.is("two"));
100
        }
101
102
        @Test
71
        public void testEmptyDefaultVariable() throws Exception {
103
        public void testEmptyDefaultVariable() throws Exception {
72
            extractor.setRegex("<value name=\"positioncount\">(.+?)</value>");
104
            extractor.setRegex("<value name=\"positioncount\">(.+?)</value>");
73
            extractor.setTemplate("$1$");
105
            extractor.setTemplate("$1$");
74
- 

Return to bug 60295