Skip to content

Conversation

@ewanharris
Copy link
Member

@ewanharris ewanharris commented Oct 15, 2025

Description

Copies across some extra tests for the list stores by name in Java

References

openfga/java-sdk#195 / openfga/java-sdk#237

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Tests
    • Added integration tests confirming store listing supports exact name filtering and returns only the matching store.
    • Expanded unit tests to cover listing with name-only filters, all parameters (page size, continuation token, name), and configuration overrides.
    • Verified correct request construction, URL formation, and response parsing across scenarios.
    • Strengthens confidence in filtering, pagination, and configuration behaviors without changing user-facing functionality.

@ewanharris ewanharris requested a review from a team as a code owner October 15, 2025 16:49
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds new Java test methods to validate ListStores filtering by name across API and client layers, including integration and unit tests. Updates OpenFgaApiTest with Mockito stubs for configuration override and validation.

Changes

Cohort / File(s) Summary of changes
Integration tests: name filter
config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache, config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache
Add listStoresWithNameFilter tests that create multiple stores, apply exact-name filter, and assert a single matching result.
API unit tests: name filter + override
config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache
Add Mockito stubs for Configuration.override(...) and assertValid(); add tests listStoresTest_withNameOnly and listStoresTest_withConfigurationOverride validating URL, parsing, and override invocation.
Client unit tests: all params
config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache
Add listStoresTest_withAllParameters validating pageSize, continuationToken, and name handling; add import for anyInt.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant T as Test
  participant C as Client
  participant API as OpenFGA API

  Note over T,C: ListStores with optional name filter
  T->>C: listStores(options{name, pageSize, token})
  C->>API: GET /stores?name={name}&page_size={n}&continuation_token={t}
  API-->>C: 200 OK + stores[]
  C-->>T: stores[]

  rect rgba(230,245,255,0.5)
  Note right of C: If ConfigurationOverride provided
  T->>C: listStores(options, override)
  C->>C: apply override
  C->>API: GET with override-config
  API-->>C: 200 OK
  C-->>T: stores[]
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • rhamzeh

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly states that the pull request improves the Java SDK tests for listing stores, matching the added and enhanced test cases described in the changeset, and follows conventional commit syntax with scope and type.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

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

🧹 Nitpick comments (6)
config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache (1)

309-335: Good coverage; watch out for brittle URL ordering and encoding

Exact URL matching can flake if query param order changes or values need encoding. Consider making the verification order‑agnostic (if the mock supports it) or encoding values in getUrl to match production.

config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache (5)

7-7: Redundant Mockito imports

You import both static any and ArgumentMatchers class. Prefer one style for consistency (use static any everywhere or qualify with ArgumentMatchers.any).


25-25: Avoid mixed usage of ArgumentMatchers

Since you already statically import any, you can drop the direct ArgumentMatchers import and call any(ConfigurationOverride.class) directly.

- import org.mockito.ArgumentMatchers;
+ // use static any(...) already imported

69-72: Good stubs; consider verifying interactions

You stub override(...) and assertValid(). In the test that uses a ConfigurationOverride, add verifies to assert these are called, guarding against regressions.

 // in listStoresTest_withConfigurationOverride THEN block
+ verify(mockConfiguration).override(configOverride);
+ verify(mockConfiguration).assertValid();

129-153: Strengthen assertion to match filtered name

You filter by storeName but assert DEFAULT_STORE_NAME from the stubbed body. Align the stub and expectation with storeName to validate end‑to‑end.

- String responseBody =
-         String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME);
+ String responseBody =
+         String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, storeName);
...
- assertEquals(DEFAULT_STORE_NAME, response.getData().getStores().get(0).getName());
+ assertEquals(storeName, response.getData().getStores().get(0).getName());

154-179: Verify override path and consider URL brittleness

Test looks good. Add verify(mockConfiguration).override(configOverride) (and assertValid) to ensure the override path executes. Also, exact URL matching can break if query param order changes; keep values URL‑safe or adjust matcher if possible.

 // Then
 mockHttpClient.verify().get("https://api.fga.example/stores").called(1);
+ verify(mockConfiguration).override(configOverride);
+ verify(mockConfiguration).assertValid();
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad10a02 and b5d7d26.

📒 Files selected for processing (4)
  • config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache (1 hunks)
  • config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache (1 hunks)
  • config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache (4 hunks)
  • config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
config/**/*.mustache

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Validate mustache syntax and variable references across all template files, including CHANGELOG.md.mustache

Files:

  • config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache
  • config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache
  • config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache
  • config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache
config/**/*.{json,mustache}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Never hardcode API keys or credentials in configuration or template files

Files:

  • config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache
  • config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache
  • config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache
  • config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build-and-test-go-sdk
  • GitHub Check: build-and-test-java-sdk
  • GitHub Check: build-and-test-dotnet-sdk
🔇 Additional comments (3)
config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache (1)

11-11: Import is correct and used

anyInt is needed for mocking Executors; good addition.

config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache (1)

118-141: Nice integration coverage for name filter

Creates multiple stores and validates exact‑name filtering returns a single match; looks good.

config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache (1)

134-159: Solid client-level test for name filter

Mirrors API integ path; assertions are correct and concise.

@ewanharris ewanharris force-pushed the test/list-store-tests branch from b5d7d26 to 052b8a8 Compare October 16, 2025 11:22
Copilot AI review requested due to automatic review settings October 22, 2025 13:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances test coverage for the listStores functionality in the Java SDK by adding tests for name-based filtering and pagination parameters. The changes validate that store listing correctly supports exact name matching, returns only matching stores, and properly handles various parameter combinations.

Key Changes:

  • Added integration tests confirming name-based filtering returns only the target store
  • Extended unit tests to cover all parameter combinations (pageSize, continuationToken, name)
  • Added tests verifying configuration override behavior

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
OpenFgaClientTest.java.mustache Added unit test for listStores with all parameters (pageSize, continuationToken, name)
OpenFgaApiTest.java.mustache Added unit tests for name-only filtering and configuration override scenarios
OpenFgaClientIntegrationTest.java.mustache Added integration test verifying exact name filtering returns single matching store
OpenFgaApiIntegrationTest.java.mustache Added integration test validating name-based filtering at API layer

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.anyInt;
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

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

The import anyInt is added but never used in this file. Consider removing unused imports to keep the code clean.

Suggested change
import static org.mockito.ArgumentMatchers.anyInt;

Copilot uses AI. Check for mistakes.

import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

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

The static import for any is added but appears unused in the test methods. The code uses ArgumentMatchers.any() with the full qualifier instead. Either use the static import or remove it.

Suggested change
import static org.mockito.ArgumentMatchers.any;

Copilot uses AI. Check for mistakes.
Copy link
Member

@SoulPancake SoulPancake left a comment

Choose a reason for hiding this comment

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

LG

@ewanharris
Copy link
Member Author

Closing because #638 makes this unnecessary 🎉

@ewanharris ewanharris closed this Nov 5, 2025
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