mirror of https://github.com/apache/jmeter.git
Compare commits
2 Commits
c0a5763e18
...
2cc805fb00
| Author | SHA1 | Date |
|---|---|---|
|
|
2cc805fb00 | |
|
|
77675e0b8e |
|
|
@ -55,7 +55,7 @@ dependencies {
|
||||||
api("com.google.auto.service:auto-service-annotations:1.1.1")
|
api("com.google.auto.service:auto-service-annotations:1.1.1")
|
||||||
api("com.google.auto.service:auto-service:1.1.1")
|
api("com.google.auto.service:auto-service:1.1.1")
|
||||||
api("com.google.errorprone:error_prone_annotations:2.24.0")
|
api("com.google.errorprone:error_prone_annotations:2.24.0")
|
||||||
api("com.helger.commons:ph-commons:11.2.1")
|
api("com.helger.commons:ph-commons:11.2.2")
|
||||||
api("com.helger:ph-css:7.0.4")
|
api("com.helger:ph-css:7.0.4")
|
||||||
api("com.jayway.jsonpath:json-path:2.8.0")
|
api("com.jayway.jsonpath:json-path:2.8.0")
|
||||||
api("com.miglayout:miglayout-core:5.3")
|
api("com.miglayout:miglayout-core:5.3")
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ public class JSONPostProcessor
|
||||||
List<String> jsonResponses = extractJsonResponse(context, vars);
|
List<String> jsonResponses = extractJsonResponse(context, vars);
|
||||||
String[] refNames = getRefNames().split(SEPARATOR);
|
String[] refNames = getRefNames().split(SEPARATOR);
|
||||||
String[] jsonPathExpressions = getJsonPathExpressions().split(SEPARATOR);
|
String[] jsonPathExpressions = getJsonPathExpressions().split(SEPARATOR);
|
||||||
String[] defaultValues = getDefaultValues().split(SEPARATOR);
|
String[] defaultValues = getDefaultValues().split(SEPARATOR, -1);
|
||||||
int[] matchNumbers = getMatchNumbersAsInt(defaultValues.length);
|
int[] matchNumbers = getMatchNumbersAsInt(defaultValues.length);
|
||||||
|
|
||||||
validateSameLengthOfArguments(refNames, jsonPathExpressions, defaultValues);
|
validateSameLengthOfArguments(refNames, jsonPathExpressions, defaultValues);
|
||||||
|
|
|
||||||
|
|
@ -317,6 +317,35 @@ class TestJSONPostProcessor {
|
||||||
assertEquals("3", vars.get(VAR_NAME + "_matchNr"));
|
assertEquals("3", vars.get(VAR_NAME + "_matchNr"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testProcessDefaultsWithAllEmptyStrings() {
|
||||||
|
JMeterContext context = JMeterContextService.getContext();
|
||||||
|
// Use match number 1 for simplicity
|
||||||
|
JSONPostProcessor processor = setupProcessor(context, "1", false);
|
||||||
|
JMeterVariables vars = new JMeterVariables();
|
||||||
|
context.setVariables(vars);
|
||||||
|
|
||||||
|
// Set up sample result that won't match JSON Paths
|
||||||
|
SampleResult sampleResult = createSampleResult("{}"); // Empty JSON
|
||||||
|
context.setPreviousResult(sampleResult);
|
||||||
|
|
||||||
|
// Configure the processor
|
||||||
|
// Three paths and names, corresponding to the three empty defaults
|
||||||
|
processor.setJsonPathExpressions("$.key1;$.key2;$.key3");
|
||||||
|
processor.setRefNames("var1;var2;var3");
|
||||||
|
// *** Default values string containing only separators ***
|
||||||
|
// This should split into ["", "", ""] with the fix
|
||||||
|
processor.setDefaultValues(";;"); // Represents 3 empty default values
|
||||||
|
processor.setScopeAll(); // Ensure it processes the main sample
|
||||||
|
|
||||||
|
// Process the sample
|
||||||
|
processor.process();
|
||||||
|
|
||||||
|
// Assertions: Verify all variables received an empty string default
|
||||||
|
assertEquals("", vars.get("var1"), "Variable var1 should get the first (empty) default value");
|
||||||
|
assertEquals("", vars.get("var2"), "Variable var2 should get the second (empty) default value");
|
||||||
|
assertEquals("", vars.get("var3"), "Variable var3 should get the third (empty) default value");
|
||||||
|
}
|
||||||
|
|
||||||
private static JSONPostProcessor setupProcessor(JMeterContext context, String matchNumbers) {
|
private static JSONPostProcessor setupProcessor(JMeterContext context, String matchNumbers) {
|
||||||
return setupProcessor(context, matchNumbers, true);
|
return setupProcessor(context, matchNumbers, true);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue