[CUS-11673] add data generator to get the value from the list string.#369
[CUS-11673] add data generator to get the value from the list string.#369ManojTestsigma wants to merge 1 commit intodevfrom
Conversation
📝 WalkthroughWalkthroughThe pull request increments the module version and introduces three new classes: Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Test Framework
participant Action as WhileLoopStringBySeparator
participant Provider as RuntimeDataProvider
participant Storage as RunTimeData
Caller->>Action: generate() / execute()
Action->>Provider: read current iteration index
alt Index retrieval fails
Provider-->>Action: null or error
Action->>Action: default index to 0
else Index retrieved successfully
Provider-->>Action: current index value
end
Action->>Action: split input by separator
Action->>Action: validate index < length
alt Index out of bounds
Action->>Action: set error message
Action-->>Caller: FAILED / Exception
else Index valid
Action->>Action: get element at index
Action->>Action: trim element value
Action->>Storage: store element in runtime var
Action->>Action: increment index
Action->>Storage: persist next index
Action->>Action: set success message
Action-->>Caller: SUCCESS / TestData result
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (2)
list_data_structure_actions/src/main/java/com/testsigma/addons/restapi/WhileLoopStringBySeparator.java (1)
59-65: Consider handling NumberFormatException explicitly for better diagnostics.If the stored index data is corrupted or non-numeric,
Integer.parseIntwill throw. While the outer catch handles it, a specific error message would aid debugging.♻️ Optional: Add explicit NumberFormatException handling
int currentIterationIndexValue; if (currentIterationIndexData != null) { - currentIterationIndexValue = Integer.parseInt(currentIterationIndexData.toString()); + try { + currentIterationIndexValue = Integer.parseInt(currentIterationIndexData.toString()); + } catch (NumberFormatException nfe) { + logger.warn("Invalid index data, resetting to 0: " + currentIterationIndexData); + currentIterationIndexValue = 0; + } } else { logger.info("Current iteration index is null"); currentIterationIndexValue = 0; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@list_data_structure_actions/src/main/java/com/testsigma/addons/restapi/WhileLoopStringBySeparator.java` around lines 59 - 65, The code in WhileLoopStringBySeparator that parses currentIterationIndexData into currentIterationIndexValue should explicitly catch NumberFormatException to provide a clearer log and fallback when the stored index is non-numeric; wrap Integer.parseInt(currentIterationIndexData.toString()) in a try/catch(NumberFormatException e) inside the currentIterationIndexData != null branch, log a descriptive error via logger.error including the bad value and exception (referencing currentIterationIndexData and currentIterationIndexValue), and set currentIterationIndexValue to 0 as a safe fallback so execution continues predictably.list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/WhileLoopStringBySeparator.java (1)
53-57: Exception from line 56 gets double-wrapped in catch block.The exception thrown at line 56 (
"No more values to iterate...") is caught at line 70 and re-wrapped with"Failed to iterate the while loop due to...", resulting in a nested/confusing error message.♻️ Proposed fix: rethrow directly or use a specific exception type
if (inputValues.length <= currentIterationIndexValue) { logger.info("No more values to iterate the while loop."); setErrorMessage("No more values to iterate the while loop."); - throw new Exception("No more values to iterate. All values have been consumed."); + throw new NoSuchElementException("No more values to iterate. All values have been consumed."); } // ... rest of code ... - } catch (Exception e) { + } catch (NoSuchElementException e) { + throw e; // Don't wrap iteration-complete exceptions + } catch (Exception e) { setErrorMessage("Failed to iterate the while loop due to " + e.getMessage()); logger.warn("Failed to iterate the while loop." + ExceptionUtils.getStackTrace(e)); throw new Exception("Failed to iterate the while loop due to " + e.getMessage()); }Also applies to: 70-74
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/WhileLoopStringBySeparator.java` around lines 53 - 57, The thrown Exception in WhileLoopStringBySeparator (the "No more values to iterate..." at the inputValues bounds check) is being caught later and wrapped again, producing nested/confusing messages; change the catch in the method that calls this check (inside WhileLoopStringBySeparator) to either rethrow the original exception directly or wrap it in a more specific exception type (e.g., NoMoreValuesException) and preserve the original as the cause (pass the caught exception into the new exception's constructor) so the root message is not double-wrapped and callers can distinguish the error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/GetElementCountBySeparator.java`:
- Around line 23-24: The separator string is being passed to String.split which
treats it as a regex; update the split usage in GetElementCountBySeparator so
the separatorValue is quoted for literal matching (use
Pattern.quote(separatorValue)) when splitting inputValue, ensuring you reference
the variables separatorValue and inputValue in the change and adjust any code
that counts the resulting elements accordingly.
- Around line 32-33: The count logic in GetElementCountBySeparator uses
String.split(separatorValue, -1) which preserves trailing empty strings while
WhileLoopStringBySeparator uses String.split(separatorValue) and discards them;
make the behavior consistent by choosing one approach and applying it to both
places—either change GetElementCountBySeparator to use split(separatorValue) to
match WhileLoopStringBySeparator, or update all WhileLoopStringBySeparator
implementations to use split(separatorValue, -1); update the String.split call
in the GetElementCountBySeparator class (and/or the split calls in
WhileLoopStringBySeparator) so both use the same overload and re-run tests to
verify counts/iterations align.
In
`@list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/WhileLoopStringBySeparator.java`:
- Around line 31-33: In WhileLoopStringBySeparator, change how the input string
is split: treat separatorValue as a literal by using
Pattern.quote(separatorValue) and preserve trailing empty tokens by passing a
limit of -1 to split (i.e., use inputValue.split(Pattern.quote(separatorValue),
-1)); update references around separatorValue/inputValue/inputValues to use this
corrected split behavior so it matches GetElementCountBySeparator logic.
- Line 35: The hardcoded index key "WhileLoopStringBySeparator_TSIndex" in
WhileLoopStringBySeparator causes shared state across instances; change the
logic in the class (e.g., in the generate() method) to build the indexKey from
the configured runtime variable name instead of a fixed string (add or use an
existing parameter like runtimeVariableName or variableName), e.g., derive
indexKey = "<prefix>_"+runtimeVariableName to ensure each instance has a unique
key; update any code that reads/writes the index using indexKey to use the new
derived value.
In
`@list_data_structure_actions/src/main/java/com/testsigma/addons/restapi/WhileLoopStringBySeparator.java`:
- Line 85: The log message in WhileLoopStringBySeparator uses
logger.info("Stored next index" + indexedRuntimeVariableName + " = " +
currentIterationIndexValue) which misses a space after "Stored next index";
update the string concatenation in that logger.info call to include a trailing
space (e.g., "Stored next index ") or use formatting so the output reads "Stored
next index <indexedRuntimeVariableName> = <currentIterationIndexValue>" for
clarity.
- Around line 48-50: The split uses String.split with separatorValue which is
treated as a regex and can misbehave for characters like .|*; update the code in
WhileLoopStringBySeparator (the block referencing separatorValue, inputValue,
inputValues) to treat the separator as a literal by quoting/escaping it (e.g.,
use Pattern.quote on separatorValue) before splitting so special characters are
not interpreted as regex metacharacters.
---
Nitpick comments:
In
`@list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/WhileLoopStringBySeparator.java`:
- Around line 53-57: The thrown Exception in WhileLoopStringBySeparator (the "No
more values to iterate..." at the inputValues bounds check) is being caught
later and wrapped again, producing nested/confusing messages; change the catch
in the method that calls this check (inside WhileLoopStringBySeparator) to
either rethrow the original exception directly or wrap it in a more specific
exception type (e.g., NoMoreValuesException) and preserve the original as the
cause (pass the caught exception into the new exception's constructor) so the
root message is not double-wrapped and callers can distinguish the error.
In
`@list_data_structure_actions/src/main/java/com/testsigma/addons/restapi/WhileLoopStringBySeparator.java`:
- Around line 59-65: The code in WhileLoopStringBySeparator that parses
currentIterationIndexData into currentIterationIndexValue should explicitly
catch NumberFormatException to provide a clearer log and fallback when the
stored index is non-numeric; wrap
Integer.parseInt(currentIterationIndexData.toString()) in a
try/catch(NumberFormatException e) inside the currentIterationIndexData != null
branch, log a descriptive error via logger.error including the bad value and
exception (referencing currentIterationIndexData and
currentIterationIndexValue), and set currentIterationIndexValue to 0 as a safe
fallback so execution continues predictably.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d0585eed-7edd-47b4-871b-6b4da1d8fca6
📒 Files selected for processing (4)
list_data_structure_actions/pom.xmllist_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/GetElementCountBySeparator.javalist_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/WhileLoopStringBySeparator.javalist_data_structure_actions/src/main/java/com/testsigma/addons/restapi/WhileLoopStringBySeparator.java
please review this addon and publish as PUBLIC
Addon name : list_data_structure_actions
Addon accont: https://jarvis.testsigma.com/ui/tenants/3072/addons
Jira: https://testsigma.atlassian.net/browse/CUS-11673
fix
Added 2 NLP's in data generator and 1 NLP in rest api step
Summary by CodeRabbit
New Features
Chores