Skip to content

Conversation

@akhil-testsigma
Copy link
Contributor

@akhil-testsigma akhil-testsigma commented Oct 22, 2025

Addon Name: Rest API Utils
Jarvis Link: https://jarvis.testsigma.com/ui/tenants/3072/addons
Jira : https://testsigma.atlassian.net/browse/CUS-8113
Migrated the class to rest api application

Summary by CodeRabbit

  • New Features
    • Added numeric value comparison and conditional evaluation capabilities for REST API testing scenarios
  • Chores
    • Version updated to 1.0.1

@coderabbitai
Copy link

coderabbitai bot commented Oct 22, 2025

Walkthrough

The pull request adds a minor version bump to the project and introduces two new REST API action classes for numeric comparison operations. Both classes evaluate conditional expressions between test data values using comparison operators.

Changes

Cohort / File(s) Summary
Version Update
rest_api_utils/pom.xml
Version bumped from 1.0.0 to 1.0.1
Conditional Action Classes
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java, rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperatorsIf.java
New action classes extending RestApiAction. Each accepts three TestData inputs (testData1, operator, testData2) with operators restricted to >, <, >=, <=, ==. Parse numeric inputs as doubles, evaluate comparison, and return Result with corresponding success/error messages.

Sequence Diagram

sequenceDiagram
    participant Executor
    participant Action as ConditionalOperators/<br/>ConditionalOperatorsIf
    participant Parser as Double.parseDouble()
    participant Logger
    
    Executor->>Action: execute()
    Action->>Parser: Parse testData1 to double
    Action->>Parser: Parse testData2 to double
    Note over Action: Switch on operator<br/>(>, <, >=, <=, ==)
    alt Comparison True
        Action->>Logger: Log success
        Action->>Action: setSuccessMessage()
        Action-->>Executor: Result.SUCCESS
    else Comparison False
        Action->>Logger: Log failure
        Action->>Action: setErrorMessage()
        Action-->>Executor: Result.FAILED
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The version bump is trivial, but the two new action classes require careful review of the comparison logic implementation, operator handling, error cases, and consistency between the two similar implementations.

Suggested reviewers

  • Ganesh-Testsigma
  • vigneshtestsigma

Poem

🐰 Two operators hop and compare,
Numeric values floating through the air,
Greater than, less than, they carefully weigh,
Success or failure—they'll have their say!
Version bumped with Easter care. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The title "feat/CUS-8113-Migrated the class to rest api application" is related to the changeset's primary activity—adding new classes to the REST API addon—but it lacks specificity and clarity. The changeset introduces two new action classes (ConditionalOperators and ConditionalOperatorsIf) for numeric comparison operations, along with a version bump. However, the title uses generic language ("the class" is singular when two classes are added) and doesn't convey what functionality is being added or why these classes matter, making it too vague for someone scanning git history to understand the actual changes made. Consider updating the title to be more specific about the changes, such as "Add ConditionalOperators and ConditionalOperatorsIf action classes for numeric comparisons" or "Add REST API action classes for conditional numeric comparisons." This would clearly convey the primary functional changes to developers reviewing the history without requiring them to examine the full changeset details.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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 feat/CUS-8113-Migrated-the-class-to-rest-api-application

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.

@akhil-testsigma akhil-testsigma merged commit a7e0bdf into dev Oct 22, 2025
1 of 2 checks passed
Copy link

@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: 8

🧹 Nitpick comments (4)
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperatorsIf.java (2)

23-24: Add error handling for invalid numeric inputs.

Double.valueOf() will throw NumberFormatException if the test data values cannot be parsed as valid numbers. Consider wrapping these calls in a try-catch block to provide a more user-friendly error message.

 @Override
 public Result execute() throws NoSuchElementException {
+	try {
 		String operatorString = operator.getValue().toString();
 		double a = Double.valueOf(testData1.getValue().toString());
 		double b = Double.valueOf(testData2.getValue().toString());
 		Result result = Result.SUCCESS;
 		switch (operatorString) {
 		// ... rest of switch cases
 		}
 		return result;
+	} catch (NumberFormatException e) {
+		logger.error("Invalid numeric input: " + e.getMessage());
+		setErrorMessage("Invalid numeric input. Please ensure test data contains valid numbers.");
+		return Result.FAILED;
+	}
 }

26-92: Add a default case to handle unexpected operators.

Although the allowedValues constraint limits valid operators, defensive coding suggests adding a default case to handle unexpected scenarios gracefully.

 		break;
 	}
+	default:
+		logger.error("Unsupported operator: " + operatorString);
+		setErrorMessage("Unsupported operator: " + operatorString);
+		return Result.FAILED;
+	}
 
 	return result;
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java (2)

26-27: Add error handling for invalid numeric inputs.

Same issue as in ConditionalOperatorsIf: Double.valueOf() can throw NumberFormatException. Consider adding try-catch block for better error handling.

See the suggested fix in the ConditionalOperatorsIf.java review comments.


29-95: Add a default case to the switch statement.

Same as in ConditionalOperatorsIf: add a default case to handle unexpected operators defensively.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51d1ade and 6fd4819.

📒 Files selected for processing (3)
  • rest_api_utils/pom.xml (1 hunks)
  • rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java (1 hunks)
  • rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperatorsIf.java (1 hunks)
🔇 Additional comments (3)
rest_api_utils/pom.xml (1)

9-9: LGTM!

The version bump from 1.0.0 to 1.0.1 is appropriate for this minor release that adds new REST API action classes.

rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java (1)

13-13: Clarify the purpose of "[Latest]" prefix and relationship with ConditionalOperatorsIf.

The [Latest] prefix in the actionText and the absence of actionType differentiate this class from ConditionalOperatorsIf. Please clarify:

  • Is this intended to supersede ConditionalOperatorsIf?
  • Should ConditionalOperatorsIf be deprecated?
  • What is the intended use case difference between these two nearly identical classes?
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperatorsIf.java (1)

7-7: Verify if NoSuchElementException is necessary.

The execute method declares throws NoSuchElementException, but this exception is never thrown by the method logic. If this exception is not required by the RestApiAction contract, consider removing it from the throws clause.

import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.RestApiAction;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.WebAction;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove unused import.

WebAction is imported but never used in this class. The class extends RestApiAction, not WebAction.

-import com.testsigma.sdk.WebAction;
📝 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
import com.testsigma.sdk.WebAction;
🤖 Prompt for AI Agents
In
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java
around line 6, remove the unused import "import com.testsigma.sdk.WebAction;"
since the class extends RestApiAction and never references WebAction; simply
delete that import line to eliminate the unused import warning and keep imports
minimal.

Comment on lines +24 to +98
public Result execute() throws NoSuchElementException {
String operatorString = operator.getValue().toString();
double a = Double.valueOf(testData1.getValue().toString());
double b = Double.valueOf(testData2.getValue().toString());
Result result = Result.SUCCESS;
switch (operatorString) {
case ">":
if (a > b) {
logger.info("Passed " + a + " is > " + b);
setSuccessMessage("Passed " + a + " is > " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is not > " + b);
setErrorMessage("Validation failed: " + a + " is not > " + b);
System.out.println("failure");
}

break;
case "<":
if (a < b) {
logger.info("Passed " + a + " is < " + b);
setSuccessMessage("Passed " + a + " is < " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is not < " + b);
setErrorMessage("Validation failed: " + a + " is not < " + b);
System.out.println("failure");
}

break;
case ">=":
if (a >= b) {
logger.info("Passed " + a + " is >= " + b);
setSuccessMessage("Passed " + a + " is >= " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is not >= " + b);
setErrorMessage("Validation failed:" + a + " is not >= " + b);
System.out.println("failure");
}

break;
case "<=":
if (a <= b) {
logger.info("Passed " + a + " is <= " + b);
setSuccessMessage("Passed " + a + " is <= " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is not <= " + b);
setErrorMessage("Validation failed: " + a + " is not <= " + b);
System.out.println("failure");
}

break;
case "==":
if (a == b) {
logger.info("Passed " + a + " is == " + b);
setSuccessMessage("Passed " + a + " is == " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is != " + b);
setErrorMessage("Validation failed: " + a + " is != " + b);
System.out.println("failure");
}

break;
}

return result;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Significant code duplication with ConditionalOperatorsIf.

The execute() method is nearly identical to ConditionalOperatorsIf.execute(). This violates the DRY (Don't Repeat Yourself) principle and creates maintenance burden.

Consider extracting the common comparison logic into a shared protected method in the RestApiAction base class or a utility class. Both classes could then call this shared method.

Example refactoring approach:

Create a shared utility method:

protected Result performNumericComparison(double a, double b, String operator) {
    // Common logic here
}

Then both classes can use:

@Override
public Result execute() throws NoSuchElementException {
    String operatorString = operator.getValue().toString();
    double a = Double.valueOf(testData1.getValue().toString());
    double b = Double.valueOf(testData2.getValue().toString());
    return performNumericComparison(a, b, operatorString);
}
🤖 Prompt for AI Agents
In
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java
around lines 24-98, the execute() method duplicates nearly identical comparison
logic found in ConditionalOperatorsIf; extract that logic into a single shared
protected method (e.g., in RestApiAction or a new utility class) with signature
like performNumericComparison(double a, double b, String operator) that
evaluates the operator, sets success/error messages, logs appropriately, and
returns Result; then simplify execute() to parse operator and operands and
delegate to this shared method, removing duplicated prints and ensuring
consistent log/error messages.

if (a > b) {
logger.info("Passed " + a + " is > " + b);
setSuccessMessage("Passed " + a + " is > " + b);
System.out.print("Success");
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove System.out statements.

Same as in ConditionalOperatorsIf: remove all System.out.print/println statements. Logging is already handled by the logger.

Also applies to: 39-39, 47-47, 52-52, 60-60, 65-65, 73-73, 78-78, 86-86, 91-91

🤖 Prompt for AI Agents
In
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java
around lines 34, 39, 47, 52, 60, 65, 73, 78, 86 and 91, remove all
System.out.print/System.out.println calls; replace them with appropriate logger
calls or delete them entirely since logging is already handled by the existing
logger, ensuring no System.out usage remains in the file.

} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is not >= " + b);
setErrorMessage("Validation failed:" + a + " is not >= " + b);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix formatting inconsistency in error message.

Same issue as in ConditionalOperatorsIf (line 61): missing space after colon in "Validation failed:".

-			setErrorMessage("Validation failed:" + a + " is not >= " + b);
+			setErrorMessage("Validation failed: " + a + " is not >= " + b);
📝 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
setErrorMessage("Validation failed:" + a + " is not >= " + b);
setErrorMessage("Validation failed: " + a + " is not >= " + b);
🤖 Prompt for AI Agents
In
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java
around line 64, the error message string lacks a space after the colon
("Validation failed:"), causing inconsistent formatting; update the
setErrorMessage call to insert a space after the colon so it reads "Validation
failed: " before concatenating variables (match formatting used in
ConditionalOperatorsIf).

Comment on lines +83 to +92
if (a == b) {
logger.info("Passed " + a + " is == " + b);
setSuccessMessage("Passed " + a + " is == " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is != " + b);
setErrorMessage("Validation failed: " + a + " is != " + b);
System.out.println("failure");
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Avoid using == for double comparison.

Same critical issue as in ConditionalOperatorsIf: using == for double comparison is problematic due to floating-point precision.

Use tolerance-based comparison: Math.abs(a - b) < 0.0000001 instead of a == b.

🤖 Prompt for AI Agents
In
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperators.java
around lines 83 to 92, the code uses the == operator to compare double values (a
== b) which is unsafe for floating‑point; replace this with a tolerance-based
check such as Math.abs(a - b) < 1e-7 (or a defined EPSILON constant) to
determine equality, update the if/else to use that condition, and keep the
logging and success/error messages unchanged (or adjust wording to indicate
approximate equality) to reflect the new comparison.

if (a > b) {
logger.info("Passed " + a + " is > " + b);
setSuccessMessage("Passed " + a + " is > " + b);
System.out.print("Success");
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove System.out statements in favor of logger.

Using System.out.print/println in production code is not a best practice. The class already has a logger that should be used instead. Additionally, there's inconsistency between print (no newline) and println, as well as capitalization ("Success" vs "failure").

-			System.out.print("Success");
-			System.out.println("failure");

Remove all System.out statements throughout the method, as logging is already handled by the logger.

Also applies to: 34-34, 36-36, 44-44, 47-47, 49-49, 57-57, 60-60, 62-62, 70-70, 73-73, 75-75, 83-83, 86-86, 88-88

🤖 Prompt for AI Agents
In
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperatorsIf.java
around lines 31-88, several System.out.print/println calls (lines
31,34,36,44,47,49,57,60,62,70,73,75,83,86,88) should be removed and replaced
with the class logger; update each occurrence to use
logger.debug/info/warn/error as appropriate, standardize message formatting and
capitalization (e.g., "Success" -> "success" or follow project convention) and
ensure messages include context rather than relying on newlines, removing any
direct System.out usage entirely.

} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is not >= " + b);
setErrorMessage("Validation failed:" + a + " is not >= " + b);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix formatting inconsistency in error message.

Missing space after colon. Should be "Validation failed: " (note the space after colon) to match other error messages in the method.

-			setErrorMessage("Validation failed:" + a + " is not >= " + b);
+			setErrorMessage("Validation failed: " + a + " is not >= " + b);
📝 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
setErrorMessage("Validation failed:" + a + " is not >= " + b);
setErrorMessage("Validation failed: " + a + " is not >= " + b);
🤖 Prompt for AI Agents
In
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperatorsIf.java
around line 61, the error message concatenation lacks a space after the colon;
change the string from "Validation failed:" + a + " is not >= " + b to include a
space after the colon so it reads "Validation failed: " + a + " is not >= " + b
to match the other messages' formatting.

Comment on lines +80 to +89
if (a == b) {
logger.info("Passed " + a + " is == " + b);
setSuccessMessage("Passed " + a + " is == " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is != " + b);
setErrorMessage("Validation failed: " + a + " is != " + b);
System.out.println("failure");
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Avoid using == for double comparison.

Using == to compare doubles is problematic due to floating-point precision issues. Use a tolerance-based comparison instead.

 	case "==":
-		if (a == b) {
+		if (Math.abs(a - b) < 0.0000001) {
 			logger.info("Passed " + a + " is == " + b);
 			setSuccessMessage("Passed " + a + " is == " + b);
 			System.out.print("Success");
📝 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
if (a == b) {
logger.info("Passed " + a + " is == " + b);
setSuccessMessage("Passed " + a + " is == " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is != " + b);
setErrorMessage("Validation failed: " + a + " is != " + b);
System.out.println("failure");
}
if (Math.abs(a - b) < 0.0000001) {
logger.info("Passed " + a + " is == " + b);
setSuccessMessage("Passed " + a + " is == " + b);
System.out.print("Success");
} else {
result = Result.FAILED;
logger.warn("Validation failed: " + a + " is != " + b);
setErrorMessage("Validation failed: " + a + " is != " + b);
System.out.println("failure");
}
🤖 Prompt for AI Agents
In
rest_api_utils/src/main/java/com/testsigma/addons/restapi/ConditionalOperatorsIf.java
around lines 80 to 89, the code uses `==` to compare doubles which is
unreliable; replace the direct equality check with a tolerance-based comparison
(e.g., use Math.abs(a - b) <= EPSILON) where EPSILON is a small constant (like
1e-9) or a configurable threshold; also handle special cases (NaN/infinite) if
relevant by checking Double.isNaN/Double.isInfinite before comparison, and
update the log and message text to reflect "approximately equal" when the
tolerance check succeeds.

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.

3 participants