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());
}
}
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()));
}
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()));
}
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"));
}
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()));
}
Aggregations