Search in sources :

Example 1 with JSONPostProcessor

use of org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor in project jmeter by apache.

the class JSONPostProcessorGui method modifyTestElement.

/**
     * Modifies a given TestElement to mirror the data in the gui components.
     *
     * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
     */
@Override
public void modifyTestElement(TestElement c) {
    super.configureTestElement(c);
    if (c instanceof JSONPostProcessor) {
        JSONPostProcessor config = (JSONPostProcessor) c;
        saveScopeSettings(config);
        config.setRefNames(refNamesField.getText());
        config.setJsonPathExpressions(jsonPathExpressionsField.getText());
        config.setDefaultValues(defaultValuesField.getText());
        config.setMatchNumbers(matchNumbersField.getText());
        config.setComputeConcatenation(computeConcatenationField.isSelected());
    }
}
Also used : JSONPostProcessor(org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)

Example 2 with JSONPostProcessor

use of org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor in project jmeter by apache.

the class TestJSONPostProcessor method testBug59609.

@Test
public void testBug59609() throws ParseException {
    JMeterContext context = JMeterContextService.getContext();
    JSONPostProcessor processor = setupProcessor(context, "0", false);
    String innerValue = "{\"a\":\"one\",\"b\":\"two\"}";
    String data = "{\"context\":" + innerValue + "}";
    SampleResult result = new SampleResult();
    result.setResponseData(data.getBytes(StandardCharsets.UTF_8));
    JMeterVariables vars = new JMeterVariables();
    context.setVariables(vars);
    context.setPreviousResult(result);
    processor.setJsonPathExpressions("$.context");
    processor.process();
    JSONParser parser = new JSONParser(0);
    Object expectedValue = parser.parse(innerValue);
    assertThat(parser.parse(vars.get(VAR_NAME)), CoreMatchers.is(expectedValue));
    assertThat(vars.get(VAR_NAME + "_matchNr"), CoreMatchers.is(CoreMatchers.nullValue()));
    assertThat(vars.get(VAR_NAME + "_1"), CoreMatchers.is(CoreMatchers.nullValue()));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) JSONPostProcessor(org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor) SampleResult(org.apache.jmeter.samplers.SampleResult) JSONParser(net.minidev.json.parser.JSONParser) Test(org.junit.Test)

Example 3 with JSONPostProcessor

use of org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor in project jmeter by apache.

the class TestJSONPostProcessor method testPR235CaseEmptyResponse.

@Test
public void testPR235CaseEmptyResponse() {
    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"));
    vars.put("contentvar", "");
    processor.process();
    assertThat(vars.get("varname_matchNr"), CoreMatchers.is(CoreMatchers.nullValue()));
    assertThat(vars.get("varname_1"), CoreMatchers.is(CoreMatchers.nullValue()));
    assertThat(vars.get("varname_2"), CoreMatchers.is(CoreMatchers.nullValue()));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) JSONPostProcessor(org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor) Test(org.junit.Test)

Example 4 with JSONPostProcessor

use of org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor in project jmeter by apache.

the class TestJSONPostProcessor method testProcessAllElementsMultipleMatches.

@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"));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) JSONPostProcessor(org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor) Test(org.junit.Test)

Example 5 with JSONPostProcessor

use of org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor in project jmeter by apache.

the class TestJSONPostProcessor method testProcessRandomElementMultipleMatches.

@Test
public void testProcessRandomElementMultipleMatches() {
    JMeterContext context = JMeterContextService.getContext();
    JSONPostProcessor processor = setupProcessor(context, "0", 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"), CoreMatchers.is(CoreMatchers.anyOf(CoreMatchers.is("one"), CoreMatchers.is("two"))));
    assertThat(vars.get("varname_1"), CoreMatchers.is(CoreMatchers.nullValue()));
    assertThat(vars.get("varname_2"), CoreMatchers.is(CoreMatchers.nullValue()));
    assertThat(vars.get("varname_matchNr"), CoreMatchers.is(CoreMatchers.nullValue()));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) JSONPostProcessor(org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor) Test(org.junit.Test)

Aggregations

JSONPostProcessor (org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)12 JMeterContext (org.apache.jmeter.threads.JMeterContext)8 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)8 Test (org.junit.Test)8 SampleResult (org.apache.jmeter.samplers.SampleResult)3 JSONParser (net.minidev.json.parser.JSONParser)1