Skip to content

Add test cases for API Product behaviour#14120

Merged
PasanT9 merged 1 commit intowso2:masterfrom
tharikaGitHub:new-master-after-460
Apr 12, 2026
Merged

Add test cases for API Product behaviour#14120
PasanT9 merged 1 commit intowso2:masterfrom
tharikaGitHub:new-master-after-460

Conversation

@tharikaGitHub
Copy link
Copy Markdown
Member

@tharikaGitHub tharikaGitHub commented Apr 10, 2026

This PR adds test cases for [1].

[1] wso2/api-manager#4801

Summary by CodeRabbit

  • Tests
    • Added integration tests for API revision restoration, validating behavior when resources are modified.
    • Added integration test for API product updates to ensure underlying API changes are properly reflected in product configurations.

@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
Contributor

coderabbitai bot commented Apr 10, 2026

Walkthrough

Two new integration test cases were added to verify API product functionality: one tests restoring API revisions in products when operations differ between revisions, and another tests updating the underlying API of an API product with validation of API and operation mappings.

Changes

Cohort / File(s) Summary
API Product Integration Tests
all-in-one-apim/modules/integration/.../api/revision/APIProductRevisionTestCase.java, all-in-one-apim/modules/integration/.../apiproduct/APIProductCreationTestCase.java
Added two test methods: one verifying HTTP 400 response when restoring an older API revision lacking operations in a product, and another validating successful product updates preserve underlying API details and operation counts. Introduced HTTP_RESPONSE_CODE_BAD_REQUEST constant for assertion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A pair of tests hops into the code,
Revisions and products down the road,
When APIs shift, the tests ensure,
That updates and restores stay pure!
Carrots of logic, vegetables of test,
We verify that products work their best! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add test cases for API Product behaviour' accurately describes the main change: two new test cases were added to verify API Product behavior in specific scenarios.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Contributor

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

🧹 Nitpick comments (1)
all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/APIProductCreationTestCase.java (1)

898-899: Strengthen operation validation beyond count comparison.

At Line [898]-Line [899], count equality can still pass with incorrect operation mappings. Consider asserting verb+target membership too.

🔧 Suggested assertion hardening
         Assert.assertEquals(matchingApi.getOperations().size(), apiOne.getOperations().size(),
                 "Number of operations in the API Product should match the underlying API");
+        Assert.assertTrue(
+                matchingApi.getOperations().stream().allMatch(productOp ->
+                        apiOne.getOperations().stream().anyMatch(apiOp ->
+                                apiOp.getVerb().equals(productOp.getVerb())
+                                        && apiOp.getTarget().equals(productOp.getTarget()))),
+                "API Product operations should match underlying API verb/target mappings");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/APIProductCreationTestCase.java`
around lines 898 - 899, Current assertion only compares counts between
matchingApi.getOperations() and apiOne.getOperations(), which can hide incorrect
mappings; update the test in APIProductCreationTestCase to iterate over
apiOne.getOperations() and assert that each operation's verb and target (e.g.,
operation.getVerb(), operation.getTarget()) exist in matchingApi.getOperations()
(compare by verb+target string or a composite key) and also assert any
response/permission attributes if relevant; keep the existing count assertion
but add these membership checks so matchingApi truly contains the same
operations as apiOne.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/revision/APIProductRevisionTestCase.java`:
- Around line 214-216: The local declaration of apisToBeUsed in the test is
shadowing the class-level field used by destroy(), causing created APIs to be
skipped in teardown; remove the local "List<APIDTO> apisToBeUsed = new
ArrayList<>();" and instead use the class field apisToBeUsed (e.g.,
apisToBeUsed.add(apiOne);) so the API created via
apiProductTestHelper.createAPIProductInPublisher(...) is tracked and cleaned up
by destroy().

---

Nitpick comments:
In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/APIProductCreationTestCase.java`:
- Around line 898-899: Current assertion only compares counts between
matchingApi.getOperations() and apiOne.getOperations(), which can hide incorrect
mappings; update the test in APIProductCreationTestCase to iterate over
apiOne.getOperations() and assert that each operation's verb and target (e.g.,
operation.getVerb(), operation.getTarget()) exist in matchingApi.getOperations()
(compare by verb+target string or a composite key) and also assert any
response/permission attributes if relevant; keep the existing count assertion
but add these membership checks so matchingApi truly contains the same
operations as apiOne.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: def78ceb-9c9c-422c-80e4-215cd0e85e3f

📥 Commits

Reviewing files that changed from the base of the PR and between 45c5859 and b0779eb.

📒 Files selected for processing (2)
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/revision/APIProductRevisionTestCase.java
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/APIProductCreationTestCase.java

Comment on lines +214 to +216
List<APIDTO> apisToBeUsed = new ArrayList<>();
apisToBeUsed.add(apiOne);
APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid shadowing apisToBeUsed; it skips teardown tracking.

At Line [214]-Line [216], the local apisToBeUsed shadows the class field used in destroy(). The API created in this test will not be cleaned up, which can pollute the test environment.

🧹 Suggested fix
-        List<APIDTO> apisToBeUsed = new ArrayList<>();
-        apisToBeUsed.add(apiOne);
+        List<APIDTO> productApisToBeUsed = new ArrayList<>();
+        productApisToBeUsed.add(apiOne);
+        this.apisToBeUsed.add(apiOne);
         APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version,
-                apisToBeUsed, policies);
+                productApisToBeUsed, policies);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/revision/APIProductRevisionTestCase.java`
around lines 214 - 216, The local declaration of apisToBeUsed in the test is
shadowing the class-level field used by destroy(), causing created APIs to be
skipped in teardown; remove the local "List<APIDTO> apisToBeUsed = new
ArrayList<>();" and instead use the class field apisToBeUsed (e.g.,
apisToBeUsed.add(apiOne);) so the API created via
apiProductTestHelper.createAPIProductInPublisher(...) is tracked and cleaned up
by destroy().

@PasanT9 PasanT9 merged commit c19afcb into wso2:master Apr 12, 2026
7 of 8 checks passed
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