Compare commits

...

2 Commits

Author SHA1 Message Date
Mend Renovate 2cc805fb00
fix(deps): update com.helger 2025-05-13 17:00:08 +00:00
Raul Almeida 77675e0b8e
fix: support trailing empty default values in JSON Extractor(#6448)
See https://errorprone.info/bugpattern/StringSplitter
2025-04-23 16:00:46 +03:00
3 changed files with 32 additions and 3 deletions

View File

@ -55,8 +55,8 @@ dependencies {
api("com.google.auto.service:auto-service-annotations: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.helger.commons:ph-commons:10.2.5")
api("com.helger:ph-css:6.5.0")
api("com.helger.commons:ph-commons:11.2.2")
api("com.helger:ph-css:7.0.4")
api("com.jayway.jsonpath:json-path:2.8.0")
api("com.miglayout:miglayout-core:5.3")
api("com.miglayout:miglayout-swing:5.3")

View File

@ -70,7 +70,7 @@ public class JSONPostProcessor
List<String> jsonResponses = extractJsonResponse(context, vars);
String[] refNames = getRefNames().split(SEPARATOR);
String[] jsonPathExpressions = getJsonPathExpressions().split(SEPARATOR);
String[] defaultValues = getDefaultValues().split(SEPARATOR);
String[] defaultValues = getDefaultValues().split(SEPARATOR, -1);
int[] matchNumbers = getMatchNumbersAsInt(defaultValues.length);
validateSameLengthOfArguments(refNames, jsonPathExpressions, defaultValues);

View File

@ -317,6 +317,35 @@ class TestJSONPostProcessor {
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) {
return setupProcessor(context, matchNumbers, true);