Skip to content

[CUS-10690] added eisting addon to restapi and salesforce with data generator#335

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

[CUS-10690] added eisting addon to restapi and salesforce with data generator#335
ManojTestsigma wants to merge 1 commit intodevfrom
CUS-10690

Conversation

@ManojTestsigma
Copy link
Copy Markdown
Contributor

@ManojTestsigma ManojTestsigma commented Feb 16, 2026

please review this addon and publish as PUBLIC

Addon name : mathematical operations
Addon accont: https://jarvis.testsigma.com/ui/tenants/30397/addons
Jira: https://testsigma.atlassian.net/browse/CUS-10690

fix

Summary by CodeRabbit

  • New Features
    • Added REST API addon supporting mathematical operations (addition, subtraction, multiplication, division) with customizable decimal precision.
    • Added Salesforce addon supporting mathematical operations (addition, subtraction, multiplication, division) with customizable decimal precision.
    • Added random number generator utility with configurable range and decimal places.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

This pull request introduces three new addon and utility classes for the Testsigma framework: two mathematical operation action classes (REST API and Salesforce-specific implementations) that perform arithmetic operations with input validation and result formatting, and a random number generator utility for test data creation.

Changes

Cohort / File(s) Summary
Mathematical Operations Actions
mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java, mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsSalesforce.java
New action classes for performing addition, subtraction, multiplication, and division operations. Both validate non-empty inputs, parse numeric values, execute the selected operation, format results to specified decimal places, and store results in runtime variables. Nearly identical implementations tailored for REST API and Salesforce platforms respectively.
Test Data Generator
mathematical_operations/src/main/java/com/testsigma/addons/web/generators/RandomNumberGenerator.java
New TestDataFunction that generates random numbers within a configurable range [min, max] with optional decimal place formatting. Parses input parameters, generates the random value, applies formatting, and wraps the result in a TestData object.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Addon as MathematicalOperationsRestApi/<br/>Salesforce
    participant Parser as Input Parser
    participant Op as Operation Engine
    participant Formatter as Result Formatter
    participant Runtime as RuntimeData Storage

    User->>Addon: Execute with inputs (testData1, operator, testData2, testData4)
    Addon->>Addon: Validate non-empty inputs
    alt Validation Failed
        Addon-->>User: FAILED (empty input error)
    else Validation Passed
        Addon->>Parser: Parse numeric values (strip symbols)
        Parser-->>Addon: Parsed numbers
        Addon->>Op: Execute operation (+, -, *, /)
        Op-->>Addon: Numeric result
        Addon->>Formatter: Format to decimal places
        Formatter-->>Addon: Formatted string
        Addon->>Runtime: Store result in runtime variable
        Runtime-->>Addon: Confirmation
        Addon-->>User: SUCCESS with result location
    end
Loading
sequenceDiagram
    actor User
    participant Gen as RandomNumberGenerator
    participant Parser as Input Parser
    participant RNG as Random Engine
    participant Formatter as Result Formatter
    participant TestData as TestData Wrapper

    User->>Gen: Generate with min, max, decimal_places
    Gen->>Parser: Parse min, max values (strip symbols)
    Parser-->>Gen: Parsed range boundaries
    Gen->>RNG: Generate random in [min, max]
    RNG-->>Gen: Random number
    Gen->>Formatter: Format to decimal places
    Formatter-->>Gen: Formatted string
    Gen->>TestData: Wrap in TestData object
    TestData-->>Gen: TestData instance
    Gen-->>User: Return TestData object
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested reviewers

  • Ganesh-Testsigma
  • vigneshtestsigma

Poem

🐰 Math hops and random bounds align,
Operations dance in perfect line,
From REST to Salesforce, numbers flow,
Formatted results steal the show! ✨
A generator's gift, both swift and bright,
These addons make testing feel just right! 🎯

🚥 Pre-merge checks | ✅ 1 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

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.
Merge Conflict Detection ⚠️ Warning ⚠️ Unable to check for merge conflicts: Failed to fetch base branch: fatal: refusing to fetch into branch 'refs/heads/dev' checked out at '/home/jailuser/git'
Title check ❓ Inconclusive The title contains a typo ('eisting' instead of 'existing') and is somewhat vague about the main changes, though it does reference the key components (REST API, Salesforce, data generator). Correct the typo and consider clarifying the title to better convey the primary change, such as: 'Add mathematical operations addon for REST API and Salesforce with random number generator'
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch CUS-10690
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch CUS-10690
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

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.

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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: 9

🤖 Fix all issues with AI agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/generators/RandomNumberGenerator.java`:
- Around line 24-25: The regex in RandomNumberGenerator that strips symbols
before parsing (used when computing minVal and maxVal) incorrectly includes
commas in the character class ("[$,@,%,#]") so commas are removed; update the
replaceAll pattern to the intended character set (e.g., "[$@%#]" to not strip
commas or "[$@%#,]" to strip commas) in both places where min.getValue() and
max.getValue() are parsed (variables minVal and maxVal) so parsing behaves
correctly.
- Around line 21-35: The generate() method in RandomNumberGenerator lacks
handling for NumberFormatException from Double.parseDouble and Integer.parseInt;
wrap the parsing and number-generation logic in a try-catch that catches
NumberFormatException (and optionally other Exceptions), validate that min, max,
and decimalPlaces values are non-null and numeric before parsing, and when a
parse fails throw or rethrow an Exception with a clear message identifying which
field (min, max, or decimalPlaces) was invalid and include the offending input
value; ensure the logger (logger.info / logger.error) records the error message
before propagating the exception so callers can diagnose bad inputs.
- Around line 30-31: The RandomNumberGenerator computes a double "number" and
then truncates to int with (int) number and doesn't validate minVal/maxVal;
change the logic in the generator (e.g., where "number", "minVal", "maxVal", and
"decimals" are used) to first ensure minVal <= maxVal (either validate and throw
IllegalArgumentException or swap them), compute number as minVal + Math.random()
* (maxVal - minVal), then when decimals == 0 use Math.round(number) to correctly
round to the nearest integer instead of truncating, and for decimals > 0 keep
the formatted String.format approach using decimals.

In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`:
- Around line 34-41: In execute(), after the empty-input validation that sets
result = Result.FAILED and calls setErrorMessage/logger, add an immediate return
of that result to prevent further execution; specifically update the execute()
method (where testData1, testData2, testData4 are checked) to return result
right after setting FAILED so the subsequent Double.parseDouble(...) calls
cannot run on empty strings.
- Around line 77-78: In the "division" case inside MathematicalOperationsRestApi
(the switch handling a and b), add a guard that checks if b == 0 before
computing double division = a / b; and handle it by returning or throwing a
meaningful error (e.g., HTTP 400 / IllegalArgumentException or setting the
runtime variable to an error state) instead of storing Infinity/NaN; ensure the
error message references the division-by-zero condition and avoid performing the
division when b is zero so the operation is reported as failed rather than
successful.
- Around line 49-87: Normalize operatorString before the switch (e.g.,
operatorString = operatorString.trim().toLowerCase()) to handle
whitespace/capitalization, and add a default case to the switch that logs the
unsupported operator (using logger.error("Unsupported operator:
"+operatorString)), clears or does not set runTimeData, and prevents silent
success by throwing an IllegalArgumentException with a descriptive message (so
the method does not fall through returning success); update any callers if they
rely on exceptions for failure handling instead of setSuccessMessage.
- Around line 42-45: The parsing code for operatorString and numeric inputs
(operatorString, Double.parseDouble calls for testData1 and testData2, and the
testData4 handling) is unsafe: calling getValue().toString() can NPE, the regex
"[$,@,%,#]" incorrectly includes commas, and there is no NumberFormatException
handling. Fix by null-checking getValue() (or use Objects.toString(value, "") )
before toString(), replace the regex with a correct character class like
"[$@%#]" (or include comma if desired), and wrap parsing (Double.parseDouble /
Integer.parseInt) in try-catch to handle NumberFormatException and return a
controlled failure result; also simplify testData4 by removing redundant
String.valueOf(...) and using the null-safe string.

In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsSalesforce.java`:
- Around line 32-89: The execute() implementation in
MathematicalOperationsSalesforce is a duplicate of MathematicalOperationsRestApi
and must be consolidated into the base class (MathematicalOperationsWeb): move
the execute() method into MathematicalOperationsWeb and have subclasses only
keep their `@Action` annotations; while doing so fix the logic in execute():
validate empty inputs and return immediately on failure (use setErrorMessage and
return Result.FAILED), wrap parsing of testData1/testData2/testData4 in a
try/catch for NumberFormatException and set an error on catch, guard division by
zero before computing division, add a default case in the operator switch to set
failure if operator is unknown, replace the incorrect regex
replaceAll("[$,@,%,#]","") with a correct character-class like
replaceAll("[\\\\$@%#]", "") and remove System.out.println calls (use logger).
Ensure you reference and use the existing fields/methods (execute(),
testData1/testData2/testData4, operator, runTimeData, setErrorMessage,
setSuccessMessage, logger) so subclasses inherit the fixed behavior.
- Line 14: The code sets applicationType = ApplicationType.Salesforce, but
ApplicationType.Salesforce is not a valid enum member; change that assignment in
MathematicalOperationsSalesforce (the applicationType field/initializer) to one
of the supported enum constants (e.g., ApplicationType.WEB or
ApplicationType.MOBILE_WEB) that best matches the addon’s target environment,
ensuring you update any related metadata or comments to reflect the chosen
ApplicationType.
🧹 Nitpick comments (2)
mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java (2)

10-10: Unused import.

org.openqa.selenium.NoSuchElementException is imported but never used in this class (it's only in the throws clause, where java.util.NoSuchElementException would be more appropriate, or it could be removed entirely if the base class signature requires it).


49-87: Extract duplicated switch-case logic into a helper method.

All four cases follow the same pattern: compute result → format → set runtime data → log → set success message. This can be a single helper that takes the operation name and computed value, eliminating ~30 lines of duplication. Also, remove System.out.println calls in favor of the existing logger.

Comment on lines +21 to +35
@Override
public TestData generate() throws Exception {
logger.info("Initiating random number generation");
double minVal = Double.parseDouble(min.getValue().toString().replaceAll("[$,@,%,#]", "").trim());
double maxVal = Double.parseDouble(max.getValue().toString().replaceAll("[$,@,%,#]", "").trim());
int decimals = 0;
if (decimalPlaces != null && decimalPlaces.getValue() != null && !decimalPlaces.getValue().toString().trim().isEmpty()) {
decimals = Integer.parseInt(decimalPlaces.getValue().toString().trim());
}
double number = minVal + (Math.random() * (maxVal - minVal));
String formatted = decimals > 0 ? String.format("%." + decimals + "f", number) : String.valueOf((int) number);
TestData testData = new TestData(formatted);
logger.info("Generated random number: " + formatted);
return testData;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

No error handling for invalid inputs.

Double.parseDouble and Integer.parseInt can throw NumberFormatException if the input strings are non-numeric after stripping. Wrapping in a try-catch with a meaningful error message would improve robustness.

🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/generators/RandomNumberGenerator.java`
around lines 21 - 35, The generate() method in RandomNumberGenerator lacks
handling for NumberFormatException from Double.parseDouble and Integer.parseInt;
wrap the parsing and number-generation logic in a try-catch that catches
NumberFormatException (and optionally other Exceptions), validate that min, max,
and decimalPlaces values are non-null and numeric before parsing, and when a
parse fails throw or rethrow an Exception with a clear message identifying which
field (min, max, or decimalPlaces) was invalid and include the offending input
value; ensure the logger (logger.info / logger.error) records the error message
before propagating the exception so callers can diagnose bad inputs.

Comment on lines +24 to +25
double minVal = Double.parseDouble(min.getValue().toString().replaceAll("[$,@,%,#]", "").trim());
double maxVal = Double.parseDouble(max.getValue().toString().replaceAll("[$,@,%,#]", "").trim());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Same regex issue: commas are matched literally in character class.

"[$,@,%,#]" matches literal commas in addition to $, @, %, #. Use "[$@%#]" if commas should not be stripped, or "[$@%#,]" if they should.

🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/generators/RandomNumberGenerator.java`
around lines 24 - 25, The regex in RandomNumberGenerator that strips symbols
before parsing (used when computing minVal and maxVal) incorrectly includes
commas in the character class ("[$,@,%,#]") so commas are removed; update the
replaceAll pattern to the intended character set (e.g., "[$@%#]" to not strip
commas or "[$@%#,]" to strip commas) in both places where min.getValue() and
max.getValue() are parsed (variables minVal and maxVal) so parsing behaves
correctly.

Comment on lines +30 to +31
double number = minVal + (Math.random() * (maxVal - minVal));
String formatted = decimals > 0 ? String.format("%." + decimals + "f", number) : String.valueOf((int) number);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Truncation instead of rounding, and no min ≤ max validation.

  1. (int) number truncates toward zero (e.g., 4.99 → 4). Use Math.round(number) for correct rounding to nearest integer.
  2. If minVal > maxVal, Math.random() * (maxVal - minVal) produces a negative offset, resulting in values outside the intended range. Validate or swap the values.
🐛 Proposed fix
+        if (minVal > maxVal) {
+            double temp = minVal;
+            minVal = maxVal;
+            maxVal = temp;
+        }
         double number = minVal + (Math.random() * (maxVal - minVal));
-        String formatted = decimals > 0 ? String.format("%." + decimals + "f", number) : String.valueOf((int) number);
+        String formatted = decimals > 0 ? String.format("%." + decimals + "f", number) : String.valueOf(Math.round(number));
🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/generators/RandomNumberGenerator.java`
around lines 30 - 31, The RandomNumberGenerator computes a double "number" and
then truncates to int with (int) number and doesn't validate minVal/maxVal;
change the logic in the generator (e.g., where "number", "minVal", "maxVal", and
"decimals" are used) to first ensure minVal <= maxVal (either validate and throw
IllegalArgumentException or swap them), compute number as minVal + Math.random()
* (maxVal - minVal), then when decimals == 0 use Math.round(number) to correctly
round to the nearest integer instead of truncating, and for decimals > 0 keep
the formatted String.format approach using decimals.

Comment on lines +34 to +41
public Result execute() throws NoSuchElementException {
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
if(testData1.getValue().toString().isEmpty()|| testData2.getValue().toString().isEmpty()||testData4.getValue().toString().isEmpty()) {
logger.info("Some data is empty check the source for details");
setErrorMessage("Operation failed. Please check if some datas are empty");
result = Result.FAILED;

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Execution continues after validation failure — no early return.

When any input is empty, result is set to FAILED but execution proceeds to Double.parseDouble on lines 43-44, which will throw NumberFormatException on empty strings. Add return result; after setting FAILED.

🐛 Proposed fix
  	  if(testData1.getValue().toString().isEmpty()|| testData2.getValue().toString().isEmpty()||testData4.getValue().toString().isEmpty()) {
      	  logger.info("Some data is empty check the source for details");
      	  setErrorMessage("Operation failed. Please check if some datas are empty");
      	  result = Result.FAILED;
-     	  
+     	  return result;
        }
🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`
around lines 34 - 41, In execute(), after the empty-input validation that sets
result = Result.FAILED and calls setErrorMessage/logger, add an immediate return
of that result to prevent further execution; specifically update the execute()
method (where testData1, testData2, testData4 are checked) to return result
right after setting FAILED so the subsequent Double.parseDouble(...) calls
cannot run on empty strings.

Comment on lines +42 to +45
String operatorString = operator.getValue().toString();
double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$,@,%,#]",""));
double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$,@,%,#]",""));
String num=String.valueOf(testData4.getValue().toString());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Multiple parsing issues: no exception handling, incorrect regex, and NPE risk.

  1. No try-catch around Double.parseDouble/Integer.parseInt: Non-numeric input will throw an unhandled NumberFormatException, crashing the action instead of returning a user-friendly failure.
  2. Regex [$,@,%,#]: The commas inside the character class are matched literally. If the intent is to strip $, @, %, # only, use [$@%#]. If commas should also be stripped, use [$@%#,].
  3. Line 45: String.valueOf(testData4.getValue().toString()) is redundant — .toString() already returns a String.
  4. NPE risk: getValue() may return null; calling .toString() on it will throw NPE. Consider null-checks or Objects.toString().
🐛 Proposed fix (parsing with error handling)
+    try {
       String operatorString = operator.getValue().toString();
-      double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$,@,%,#]",""));
-      double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$,@,%,#]",""));
-      String num=String.valueOf(testData4.getValue().toString());
+      double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$@%#,]","").trim());
+      double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$@%#,]","").trim());
+      String num = testData4.getValue().toString().trim();
       // ... switch block ...
+    } catch (NumberFormatException e) {
+        logger.warn("Failed to parse numeric input: " + e.getMessage());
+        setErrorMessage("Invalid numeric input provided. Please check testdata1, testdata2, and decimal places.");
+        return Result.FAILED;
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
String operatorString = operator.getValue().toString();
double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$,@,%,#]",""));
double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$,@,%,#]",""));
String num=String.valueOf(testData4.getValue().toString());
try {
String operatorString = operator.getValue().toString();
double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$@%#,]","").trim());
double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$@%#,]","").trim());
String num = testData4.getValue().toString().trim();
// ... switch block ...
} catch (NumberFormatException e) {
logger.warn("Failed to parse numeric input: " + e.getMessage());
setErrorMessage("Invalid numeric input provided. Please check testdata1, testdata2, and decimal places.");
return Result.FAILED;
}
🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`
around lines 42 - 45, The parsing code for operatorString and numeric inputs
(operatorString, Double.parseDouble calls for testData1 and testData2, and the
testData4 handling) is unsafe: calling getValue().toString() can NPE, the regex
"[$,@,%,#]" incorrectly includes commas, and there is no NumberFormatException
handling. Fix by null-checking getValue() (or use Objects.toString(value, "") )
before toString(), replace the regex with a correct character class like
"[$@%#]" (or include comma if desired), and wrap parsing (Double.parseDouble /
Integer.parseInt) in try-catch to handle NumberFormatException and return a
controlled failure result; also simplify testData4 by removing redundant
String.valueOf(...) and using the null-safe string.

Comment on lines +49 to +87
switch (operatorString) {
case "addition":
double sum=a+b;
String formattedvaluesum=String.format("%."+num+"f", sum);
runTimeData.setValue(String.valueOf(formattedvaluesum));
runTimeData.setKey(testData3.getValue().toString());
logger.info("sum is "+formattedvaluesum);
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed addition. The sum is "+formattedvaluesum+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "subtraction":
double difference=a-b;
String formattedvaluediff=String.format("%."+num+"f", difference);
runTimeData.setValue(String.valueOf(formattedvaluediff));
runTimeData.setKey(testData3.getValue().toString());
logger.info("difference is "+formattedvaluediff);
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed Subtraction. The output is "+formattedvaluediff+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "multiplication":
double multiplication=a*b;
String formattedvaluemulti=String.format("%."+num+"f",multiplication);
logger.info("multiplication is "+ formattedvaluemulti);
runTimeData.setValue(String.valueOf(formattedvaluemulti));
runTimeData.setKey(testData3.getValue().toString());
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed Multiplication. The output is "+ formattedvaluemulti+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "division":
double division=a/b;
String formattedvaluediv=String.format("%."+num+"f",division);
logger.info("division is "+ formattedvaluediv);
runTimeData.setValue(String.valueOf( formattedvaluediv));
runTimeData.setKey(testData3.getValue().toString());
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed division. The output is "+ formattedvaluediv+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

No default case in switch; silent success on invalid operator.

If operatorString doesn't match any case (e.g., due to extra whitespace or capitalization), the method returns SUCCESS without performing any operation or setting a runtime value. Add a default case that fails with a descriptive message. Also consider normalizing input with .trim().toLowerCase().

🐛 Proposed fix
+          default:
+              setErrorMessage("Unsupported operation: " + operatorString);
+              return Result.FAILED;
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
switch (operatorString) {
case "addition":
double sum=a+b;
String formattedvaluesum=String.format("%."+num+"f", sum);
runTimeData.setValue(String.valueOf(formattedvaluesum));
runTimeData.setKey(testData3.getValue().toString());
logger.info("sum is "+formattedvaluesum);
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed addition. The sum is "+formattedvaluesum+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "subtraction":
double difference=a-b;
String formattedvaluediff=String.format("%."+num+"f", difference);
runTimeData.setValue(String.valueOf(formattedvaluediff));
runTimeData.setKey(testData3.getValue().toString());
logger.info("difference is "+formattedvaluediff);
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed Subtraction. The output is "+formattedvaluediff+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "multiplication":
double multiplication=a*b;
String formattedvaluemulti=String.format("%."+num+"f",multiplication);
logger.info("multiplication is "+ formattedvaluemulti);
runTimeData.setValue(String.valueOf(formattedvaluemulti));
runTimeData.setKey(testData3.getValue().toString());
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed Multiplication. The output is "+ formattedvaluemulti+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "division":
double division=a/b;
String formattedvaluediv=String.format("%."+num+"f",division);
logger.info("division is "+ formattedvaluediv);
runTimeData.setValue(String.valueOf( formattedvaluediv));
runTimeData.setKey(testData3.getValue().toString());
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed division. The output is "+ formattedvaluediv+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
}
switch (operatorString) {
case "addition":
double sum=a+b;
String formattedvaluesum=String.format("%."+num+"f", sum);
runTimeData.setValue(String.valueOf(formattedvaluesum));
runTimeData.setKey(testData3.getValue().toString());
logger.info("sum is "+formattedvaluesum);
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed addition. The sum is "+formattedvaluesum+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "subtraction":
double difference=a-b;
String formattedvaluediff=String.format("%."+num+"f", difference);
runTimeData.setValue(String.valueOf(formattedvaluediff));
runTimeData.setKey(testData3.getValue().toString());
logger.info("difference is "+formattedvaluediff);
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed Subtraction. The output is "+formattedvaluediff+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "multiplication":
double multiplication=a*b;
String formattedvaluemulti=String.format("%."+num+"f",multiplication);
logger.info("multiplication is "+ formattedvaluemulti);
runTimeData.setValue(String.valueOf(formattedvaluemulti));
runTimeData.setKey(testData3.getValue().toString());
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed Multiplication. The output is "+ formattedvaluemulti+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "division":
double division=a/b;
String formattedvaluediv=String.format("%."+num+"f",division);
logger.info("division is "+ formattedvaluediv);
runTimeData.setValue(String.valueOf( formattedvaluediv));
runTimeData.setKey(testData3.getValue().toString());
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed division. The output is "+ formattedvaluediv+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
default:
setErrorMessage("Unsupported operation: " + operatorString);
return Result.FAILED;
}
🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`
around lines 49 - 87, Normalize operatorString before the switch (e.g.,
operatorString = operatorString.trim().toLowerCase()) to handle
whitespace/capitalization, and add a default case to the switch that logs the
unsupported operator (using logger.error("Unsupported operator:
"+operatorString)), clears or does not set runTimeData, and prevents silent
success by throwing an IllegalArgumentException with a descriptive message (so
the method does not fall through returning success); update any callers if they
rely on exceptions for failure handling instead of setSuccessMessage.

Comment on lines +77 to +78
case "division":
double division=a/b;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Division by zero is not handled.

When b is 0, a / b produces Infinity or NaN (IEEE 754 doubles). This will be stored as the runtime variable value and reported as a "successful" division, which is incorrect. Check for b == 0 and return a meaningful error.

🐛 Proposed fix
          case "division":
+          	if (b == 0) {
+          	    setErrorMessage("Division by zero is not allowed.");
+          	    return Result.FAILED;
+          	}
          	double division=a/b;
🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`
around lines 77 - 78, In the "division" case inside
MathematicalOperationsRestApi (the switch handling a and b), add a guard that
checks if b == 0 before computing double division = a / b; and handle it by
returning or throwing a meaningful error (e.g., HTTP 400 /
IllegalArgumentException or setting the runtime variable to an error state)
instead of storing Infinity/NaN; ensure the error message references the
division-by-zero condition and avoid performing the division when b is zero so
the operation is reported as failed rather than successful.

@Data
@Action(actionText = "Perform mathematical_operations on testdata1 and testdata2 and store the result inside a runtimevariable considering number decimal places",
description = "Perform math operations and shows the result based on number of decimal places as per users requirement",
applicationType = ApplicationType.Salesforce)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, find the ApplicationType enum definition
find . -type f -name "*.java" | xargs grep -l "enum ApplicationType"

Repository: testsigmahq/testsigma-addons

Length of output: 5865


🏁 Script executed:

# Also search for where ApplicationType is imported/used
rg "ApplicationType" --type=java -B2 -A2 | head -100

Repository: testsigmahq/testsigma-addons

Length of output: 5865


🏁 Script executed:

# Search for ApplicationType.Salesforce specifically
rg "ApplicationType\.Salesforce" --type=java

Repository: testsigmahq/testsigma-addons

Length of output: 5865


🌐 Web query:

Testsigma ApplicationType enum Salesforce constant

💡 Result:

In Testsigma, Salesforce is treated as an application type, so the ApplicationType enum’s Salesforce value is SALESFORCE (i.e., the “Salesforce” application type). [1]

Source: Testsigma docs list supported application types including Salesforce. [1]

References
[1] Testsigma guide: “Application Types Supported: Salesforce, SAP, Web, Mobile, Desktop, Mobile Web, and API apps” https://testsigma.com/guides/salesforce-testing/


🌐 Web query:

Testsigma SDK ApplicationType supported values documentation

💡 Result:

In the Testsigma Java SDK, com.testsigma.sdk.ApplicationType is an enum with these supported values:

  • WEB
  • MOBILE_WEB
  • IOS
  • ANDROID
  • WINDOWS
  • MAC [1]

You typically use it in add-ons via the @Action(..., applicationType = ApplicationType.<VALUE>) annotation (example shown with ApplicationType.WEB). [2]

Sources: [1], [2]


ApplicationType.Salesforce is not a valid enum constant.

The Testsigma Java SDK's ApplicationType enum only supports: WEB, MOBILE_WEB, IOS, ANDROID, WINDOWS, and MAC. Replace ApplicationType.Salesforce with an appropriate constant from this list.

🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsSalesforce.java`
at line 14, The code sets applicationType = ApplicationType.Salesforce, but
ApplicationType.Salesforce is not a valid enum member; change that assignment in
MathematicalOperationsSalesforce (the applicationType field/initializer) to one
of the supported enum constants (e.g., ApplicationType.WEB or
ApplicationType.MOBILE_WEB) that best matches the addon’s target environment,
ensuring you update any related metadata or comments to reflect the chosen
ApplicationType.

Comment on lines +32 to +89
@Override
public Result execute() throws NoSuchElementException {
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
if(testData1.getValue().toString().isEmpty()|| testData2.getValue().toString().isEmpty()||testData4.getValue().toString().isEmpty()) {
logger.info("Some data is empty check the source for details");
setErrorMessage("Operation failed. Please check if some datas are empty");
result = Result.FAILED;

}
String operatorString = operator.getValue().toString();
double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$,@,%,#]",""));
double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$,@,%,#]",""));
String num=String.valueOf(testData4.getValue().toString());



switch (operatorString) {
case "addition":
double sum=a+b;
String formattedvaluesum=String.format("%."+num+"f", sum);
runTimeData.setValue(String.valueOf(formattedvaluesum));
runTimeData.setKey(testData3.getValue().toString());
logger.info("sum is "+formattedvaluesum);
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed addition. The sum is "+formattedvaluesum+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "subtraction":
double difference=a-b;
String formattedvaluediff=String.format("%."+num+"f", difference);
runTimeData.setValue(String.valueOf(formattedvaluediff));
runTimeData.setKey(testData3.getValue().toString());
logger.info("difference is "+formattedvaluediff);
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed Subtraction. The output is "+formattedvaluediff+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "multiplication":
double multiplication=a*b;
String formattedvaluemulti=String.format("%."+num+"f",multiplication);
logger.info("multiplication is "+ formattedvaluemulti);
runTimeData.setValue(String.valueOf(formattedvaluemulti));
runTimeData.setKey(testData3.getValue().toString());
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed Multiplication. The output is "+ formattedvaluemulti+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;
case "division":
double division=a/b;
String formattedvaluediv=String.format("%."+num+"f",division);
logger.info("division is "+ formattedvaluediv);
runTimeData.setValue(String.valueOf( formattedvaluediv));
runTimeData.setKey(testData3.getValue().toString());
System.out.println(runTimeData);
setSuccessMessage("Successfully Performed division. The output is "+ formattedvaluediv+" .:: and has been stored into a runtime variable "+runTimeData.getKey());
break;

}

return result;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

This execute() method is a verbatim copy of MathematicalOperationsRestApi.execute().

All issues raised in the RestApi review (no early return after validation, unhandled NumberFormatException, division by zero, missing default case, incorrect regex, System.out.println) apply identically here. Since both classes extend MathematicalOperationsWeb, the shared execute() logic and field declarations should be pulled up into the base class. The subclasses would then only differ by their @Action annotation.

🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsSalesforce.java`
around lines 32 - 89, The execute() implementation in
MathematicalOperationsSalesforce is a duplicate of MathematicalOperationsRestApi
and must be consolidated into the base class (MathematicalOperationsWeb): move
the execute() method into MathematicalOperationsWeb and have subclasses only
keep their `@Action` annotations; while doing so fix the logic in execute():
validate empty inputs and return immediately on failure (use setErrorMessage and
return Result.FAILED), wrap parsing of testData1/testData2/testData4 in a
try/catch for NumberFormatException and set an error on catch, guard division by
zero before computing division, add a default case in the operator switch to set
failure if operator is unknown, replace the incorrect regex
replaceAll("[$,@,%,#]","") with a correct character-class like
replaceAll("[\\\\$@%#]", "") and remove System.out.println calls (use logger).
Ensure you reference and use the existing fields/methods (execute(),
testData1/testData2/testData4, operator, runTimeData, setErrorMessage,
setSuccessMessage, logger) so subclasses inherit the fixed behavior.

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.

4 participants