Skip to content

[CUS-11673] add data generator to get the value from the list string.#369

Open
ManojTestsigma wants to merge 1 commit intodevfrom
CUS-11673
Open

[CUS-11673] add data generator to get the value from the list string.#369
ManojTestsigma wants to merge 1 commit intodevfrom
CUS-11673

Conversation

@ManojTestsigma
Copy link
Copy Markdown
Contributor

@ManojTestsigma ManojTestsigma commented Mar 31, 2026

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

  1. gets the size of array.
  2. gets the current index value from array.

Summary by CodeRabbit

  • New Features

    • Added support for counting elements within delimiter-separated strings
    • Added support for iterating through delimiter-separated string values for sequential processing
  • Chores

    • Module version incremented to 1.0.2

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

The pull request increments the module version and introduces three new classes: GetElementCountBySeparator for counting delimiter-separated elements, and two WhileLoopStringBySeparator implementations (one as a TestDataFunction and one as a REST API action) for iterating through separated values while managing iteration state via runtime data.

Changes

Cohort / File(s) Summary
Module versioning
list_data_structure_actions/pom.xml
Project version incremented from 1.0.0 to 1.0.2.
Element counting functionality
list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/GetElementCountBySeparator.java
New TestDataFunction that counts elements in a delimiter-separated string, returning "0" for empty input or the element count otherwise. Includes exception handling with error messages.
Stateful iteration logic
list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/WhileLoopStringBySeparator.java, list_data_structure_actions/src/main/java/com/testsigma/addons/restapi/WhileLoopStringBySeparator.java
Two complementary implementations of a while-loop iterator for separator-delimited strings. Both read/persist the current iteration index via RuntimeDataProvider and RunTimeData, validate bounds, return the current element, and increment the index for the next iteration. The datagenerator version uses TestDataFunction pattern; the restapi version uses RestApiAction pattern.

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
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

Suggested Reviewers

  • vigneshtestsigma
  • Ganesh-Testsigma

Poem

🐰 A rabbit hops through strings so fine,
Counting clover, element by line,
The index stored with careful grace,
While loops leap through data's space,
New functions make our tests divine! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding data generators to extract values from list strings, which aligns with the new classes GetElementCountBySeparator and WhileLoopStringBySeparator.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch CUS-11673

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.parseInt will 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

📥 Commits

Reviewing files that changed from the base of the PR and between 21e0da1 and 0634a80.

📒 Files selected for processing (4)
  • list_data_structure_actions/pom.xml
  • list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/GetElementCountBySeparator.java
  • list_data_structure_actions/src/main/java/com/testsigma/addons/datagenerator/WhileLoopStringBySeparator.java
  • list_data_structure_actions/src/main/java/com/testsigma/addons/restapi/WhileLoopStringBySeparator.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants