[CUS-10690] added eisting addon to restapi and salesforce with data generator#335
[CUS-10690] added eisting addon to restapi and salesforce with data generator#335ManojTestsigma wants to merge 1 commit intodevfrom
Conversation
|
|
📝 WalkthroughWalkthroughThis 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
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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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. Comment |
There was a problem hiding this comment.
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.NoSuchElementExceptionis imported but never used in this class (it's only in thethrowsclause, wherejava.util.NoSuchElementExceptionwould 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.printlncalls in favor of the existinglogger.
| @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; | ||
| } |
There was a problem hiding this comment.
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.
| double minVal = Double.parseDouble(min.getValue().toString().replaceAll("[$,@,%,#]", "").trim()); | ||
| double maxVal = Double.parseDouble(max.getValue().toString().replaceAll("[$,@,%,#]", "").trim()); |
There was a problem hiding this comment.
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.
| double number = minVal + (Math.random() * (maxVal - minVal)); | ||
| String formatted = decimals > 0 ? String.format("%." + decimals + "f", number) : String.valueOf((int) number); |
There was a problem hiding this comment.
Truncation instead of rounding, and no min ≤ max validation.
(int) numbertruncates toward zero (e.g., 4.99 → 4). UseMath.round(number)for correct rounding to nearest integer.- 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.
| 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; | ||
|
|
||
| } |
There was a problem hiding this comment.
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.
| 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()); |
There was a problem hiding this comment.
Multiple parsing issues: no exception handling, incorrect regex, and NPE risk.
- No try-catch around
Double.parseDouble/Integer.parseInt: Non-numeric input will throw an unhandledNumberFormatException, crashing the action instead of returning a user-friendly failure. - 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[$@%#,]. - Line 45:
String.valueOf(testData4.getValue().toString())is redundant —.toString()already returns aString. - NPE risk:
getValue()may returnnull; calling.toString()on it will throw NPE. Consider null-checks orObjects.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.
| 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.
| 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; | ||
|
|
||
| } |
There was a problem hiding this comment.
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.
| 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.
| case "division": | ||
| double division=a/b; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
🧩 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 -100Repository: testsigmahq/testsigma-addons
Length of output: 5865
🏁 Script executed:
# Search for ApplicationType.Salesforce specifically
rg "ApplicationType\.Salesforce" --type=javaRepository: 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:
WEBMOBILE_WEBIOSANDROIDWINDOWSMAC[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.
| @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; | ||
| } |
There was a problem hiding this comment.
🛠️ 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.
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