Skip to content

Add cucumber tests for API Product context length validation - #14271

Open
manodyaSenevirathne wants to merge 3 commits into
wso2:masterfrom
manodyaSenevirathne:feature-17921-apiproduct-context-length-tests
Open

Add cucumber tests for API Product context length validation#14271
manodyaSenevirathne wants to merge 3 commits into
wso2:masterfrom
manodyaSenevirathne:feature-17921-apiproduct-context-length-tests

Conversation

@manodyaSenevirathne

@manodyaSenevirathne manodyaSenevirathne commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Purpose

Adds two new Cucumber scenarios to publisher/api_products.feature validating the maximum allowed length for API Product contexts:

  • Within the limit (150 chars) — expects 201.
  • Exceeding the limit (233 chars) — expects 400, with the response mentioning the limit.

Introduces a ${LENGTH:n} payload placeholder (Utils.resolvePayloadPlaceholders / Names.ofLength) for generating a context of an exact character count that also stays unique across reruns — neither a literal string nor the existing ${UNIQUE:base} pattern could satisfy both requirements at once.

Note: these two scenarios currently fail against this repo's present carbon-apimgt dependency, which still enforces the old 60-char limit rather than 232 (confirmed via context: size must be between 1 and 60 in the actual response). They are correctly detecting that the underlying fix has not yet been forward-ported here — that is a separate, follow-up piece of work.

Related Issue

Merge after

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 70f5851a-1929-4f17-b9ec-2b5dec95258e

📥 Commits

Reviewing files that changed from the base of the PR and between 1b48d50 and 9adb74f.

📒 Files selected for processing (1)
  • all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java

📝 Walkthrough

Walkthrough

Changes

API product context length handling

Layer / File(s) Summary
Exact-length placeholder resolution
all-in-one-apim/.../utils/Names.java, all-in-one-apim/.../utils/Utils.java
Names.ofLength generates exact-length strings. Payload resolution now supports ${LENGTH:<n>} and ${UNIQUE:<base>} placeholders.
Context length boundary scenarios
all-in-one-apim/.../features/publisher/api_products.feature
Publisher scenarios validate acceptance at 150 characters and rejection at 233 characters. The rejection check verifies the 232 limit.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CucumberScenario
  participant Utils
  participant Names
  CucumberScenario->>Utils: resolvePayloadPlaceholders(payload)
  Utils->>Names: ofLength(length)
  Names-->>Utils: exact-length value
  Utils-->>CucumberScenario: resolved payload
Loading

Suggested reviewers: anugayan, tharindu1st, chamilaadhi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the new API Product context length scenarios and the supporting placeholder implementation.
Title check ✅ Passed The title clearly identifies the primary change: adding Cucumber tests for API Product context length validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Names.java`:
- Around line 66-73: Update Names.ofLength(int length) to validate negative
inputs before building or truncating the value. When length is less than zero,
throw IllegalArgumentException with a clear message; preserve the existing
generation behavior for zero and positive lengths.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b6646cff-b83a-42e5-8c18-8105856bf453

📥 Commits

Reviewing files that changed from the base of the PR and between d56b231 and 0639831.

📒 Files selected for processing (3)
  • all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Names.java
  • all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java
  • all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/resources/features/publisher/api_products.feature

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 24, 2026
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.87%. Comparing base (0028d8b) to head (b7128da).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@              Coverage Diff              @@
##             master   #14271       +/-   ##
=============================================
+ Coverage     19.94%   63.87%   +43.92%     
+ Complexity     1523      166     -1357     
=============================================
  Files           365       25      -340     
  Lines         17875      454    -17421     
  Branches       1913       11     -1902     
=============================================
- Hits           3566      290     -3276     
+ Misses        14266      158    -14108     
+ Partials         43        6       -37     
Flag Coverage Δ
integration-v2_tests 63.87% <ø> (ø)
integration_tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 27, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java (3)

346-355: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exclude the URL fragment from query parsing.

For a URL such as ...?code=abc#fragment, this method returns abc#fragment for code. The fragment is not part of the query value and can corrupt redirect or authorization-code handling.

Stop the query substring at the first raw # before splitting it into parameters.

Suggested fix
-        for (String pair : url.substring(q + 1).split("&")) {
+        String query = url.substring(q + 1);
+        int fragment = query.indexOf('#');
+        if (fragment >= 0) {
+            query = query.substring(0, fragment);
+        }
+        for (String pair : query.split("&")) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java`
around lines 346 - 355, Update the query parsing logic in the URL parameter
helper around the visible q and substring handling to locate the first raw '#'
after the query marker and exclude it from the query substring before splitting
parameters. Preserve existing parameter decoding and handling for URLs without
fragments.

1042-1070: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Keep lookup failures distinct from “resource not found.”

This helper returns null for failed reads and malformed bodies, but its documented callers treat every null as absent and retry the create path. A 4xx/5xx response, bad JSON, or missing list can therefore cause duplicate resource creation.

Return null only for a valid successful body where no matching entry exists. Propagate lookup failures or return an explicit error result.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java`
around lines 1042 - 1070, Update findIdByNameInListResponse so null is returned
only after a valid 200 response with a parseable body and list containing no
matching name. Treat non-2xx responses, missing or malformed list data, and
HTTP/JSON failures as lookup errors by propagating them or using an explicit
error result, and update the method contract/callers as needed so failures are
not interpreted as “not found.”

Sources: Coding guidelines, Learnings


111-117: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Cap the inter-poll sleep at the deadline.

pollWithin sleeps after an unsuccessful attempt only via pollPause, so System.currentTimeMillis() < deadline does not limit that sleep. When an attempt finishes near deadline, this sleeps for the full tiered interval before returning null and overruns the documented retry window.

Use a deadline-aware pause helper and pass the remaining time to pollPausePauseUntil(...) as Math.min(interval, remaining). Also update external callers that pass their own deadlines, such as GatewayRestArtifactsSteps.iRetrieveGatewayArtifactUntilAvailable and the stepdefs with direct pollPause waits.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java`
around lines 111 - 117, The pollPause retry sleep can exceed the caller’s
deadline. Update pollPause and its callers to use a deadline-aware pause helper,
passing the remaining duration and capping each tiered interval with
Math.min(interval, remaining); update pollWithin,
GatewayRestArtifactsSteps.iRetrieveGatewayArtifactUntilAvailable, and step
definitions with direct pollPause waits while preserving existing polling
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java`:
- Around line 346-355: Update the query parsing logic in the URL parameter
helper around the visible q and substring handling to locate the first raw '#'
after the query marker and exclude it from the query substring before splitting
parameters. Preserve existing parameter decoding and handling for URLs without
fragments.
- Around line 1042-1070: Update findIdByNameInListResponse so null is returned
only after a valid 200 response with a parseable body and list containing no
matching name. Treat non-2xx responses, missing or malformed list data, and
HTTP/JSON failures as lookup errors by propagating them or using an explicit
error result, and update the method contract/callers as needed so failures are
not interpreted as “not found.”
- Around line 111-117: The pollPause retry sleep can exceed the caller’s
deadline. Update pollPause and its callers to use a deadline-aware pause helper,
passing the remaining duration and capping each tiered interval with
Math.min(interval, remaining); update pollWithin,
GatewayRestArtifactsSteps.iRetrieveGatewayArtifactUntilAvailable, and step
definitions with direct pollPause waits while preserving existing polling
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a7e91d3e-9e35-4f4c-974d-305ce9c3fd73

📥 Commits

Reviewing files that changed from the base of the PR and between d67c13d and 1b48d50.

📒 Files selected for processing (1)
  • all-in-one-apim/modules/integration-v2/tests-integration/cucumber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Utils.java

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 6, 2026
@manodyaSenevirathne
manodyaSenevirathne force-pushed the feature-17921-apiproduct-context-length-tests branch from 5ac8c9d to 99c11d2 Compare August 11, 2026 10:03
@manodyaSenevirathne
manodyaSenevirathne force-pushed the feature-17921-apiproduct-context-length-tests branch from b6f9324 to ca06b32 Compare September 1, 2026 09:50
@manodyaSenevirathne
manodyaSenevirathne force-pushed the feature-17921-apiproduct-context-length-tests branch 2 times, most recently from ec0b6cd to 5024c00 Compare September 2, 2026 04:45
manodyaSenevirathne and others added 3 commits September 2, 2026 12:23
Adds two scenarios to publisher/api_products.feature validating the
maximum allowed length for API Product contexts: one within the limit
(150 chars, expects 201) and one exceeding it (233 chars, expects 400
mentioning the limit). Introduces a ${LENGTH:n} payload placeholder
(Utils.resolvePayloadPlaceholders / Names.ofLength) for generating a
context of an exact character count that stays unique across reruns,
since neither a literal string nor the existing ${UNIQUE:base} pattern
could satisfy both an exact length and rerun-safety at once.

Note: these two new scenarios currently fail against this repo's
present carbon-apimgt dependency, which still enforces the old 60-char
limit rather than 232. They are correctly detecting that the
underlying fix has not yet been forward-ported here.

Related Issue
- wso2-enterprise/wso2-apim-internal#17921
…ber-tests/src/test/java/org/wso2/am/integration/cucumbertests/utils/Names.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…cenarios

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@manodyaSenevirathne
manodyaSenevirathne force-pushed the feature-17921-apiproduct-context-length-tests branch from 5024c00 to b7128da Compare September 2, 2026 06:53
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.

1 participant