diff --git a/config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache b/config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache index 9f7b0af7a..6a373e2e6 100644 --- a/config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache +++ b/config/clients/java/template/src/test-integration/api/OpenFgaApiIntegrationTest.java.mustache @@ -115,6 +115,30 @@ public class OpenFgaApiIntegrationTest { } } + @Test + public void listStoresWithNameFilter() throws Exception { + // Given + String testName = thisTestName(); + String targetStore = testName + "-target-store"; + String otherStore1 = testName + "-other-store-1"; + String otherStore2 = testName + "-other-store-2"; + + // Create multiple stores + createStore(targetStore); + createStore(otherStore1); + createStore(otherStore2); + + // When - Filter by name + ListStoresResponse response = + api.listStores(100, null, targetStore).get().getData(); + + // Then - Should only return the target store + List storeNames = + response.getStores().stream().map(Store::getName).collect(java.util.stream.Collectors.toList()); + assertTrue(storeNames.contains(targetStore), "Target store should be in the filtered response"); + assertEquals(1, storeNames.size(), "Should return only one store when filtering by exact name"); + } + @Test public void readAuthModel() throws Exception { // Given diff --git a/config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache b/config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache index 7f2eb3d4f..b21ea77d8 100644 --- a/config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache +++ b/config/clients/java/template/src/test-integration/api/client/OpenFgaClientIntegrationTest.java.mustache @@ -131,6 +131,32 @@ public class OpenFgaClientIntegrationTest { } } + @Test + public void listStoresWithNameFilter() throws Exception { + // Given + String testName = thisTestName(); + String targetStore = testName + "-target"; + String otherStore1 = testName + "-other-1"; + String otherStore2 = testName + "-other-2"; + + // Create multiple stores + createStore(targetStore); + createStore(otherStore1); + createStore(otherStore2); + + ClientListStoresOptions options = new ClientListStoresOptions().name(targetStore); + + // When - Filter by name using client options + ClientListStoresResponse response = fga.listStores(options).get(); + + // Then - Should only return the target store + assertNotNull(response.getStores()); + List storeNames = + response.getStores().stream().map(Store::getName).collect(java.util.stream.Collectors.toList()); + assertTrue(storeNames.contains(targetStore), "Target store should be in the filtered response"); + assertEquals(1, storeNames.size(), "Should return only one store when filtering by exact name"); + } + @Test public void readAuthModel() throws Exception { // Given diff --git a/config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache b/config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache index 33eb565f7..fa1a3ea2f 100644 --- a/config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache +++ b/config/clients/java/template/src/test/api/OpenFgaApiTest.java.mustache @@ -4,6 +4,7 @@ package {{apiPackage}}; import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import com.fasterxml.jackson.databind.ObjectMapper; @@ -21,6 +22,7 @@ import java.util.concurrent.ExecutionException; import java.time.OffsetDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentMatchers; /** * API tests for OpenFgaApi. @@ -64,6 +66,9 @@ public class OpenFgaApiTest { when(mockConfiguration.getMaxRetries()).thenReturn(DEFAULT_MAX_RETRIES); when(mockConfiguration.getMinimumRetryDelay()).thenReturn(DEFAULT_RETRY_DELAY); when(mockConfiguration.getTelemetryConfiguration()).thenReturn(DEFAULT_TELEMETRY_CONFIG); + when(mockConfiguration.override(ArgumentMatchers.any(ConfigurationOverride.class))) + .thenReturn(mockConfiguration); + doNothing().when(mockConfiguration).assertValid(); mockApiClient = mock(ApiClient.class); when(mockApiClient.getObjectMapper()).thenReturn(mapper); @@ -121,6 +126,57 @@ public class OpenFgaApiTest { assertEquals(storeName, stores.get(0).getName()); } + @Test + public void listStoresTest_withNameOnly() throws Exception { + // Given + String responseBody = + String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME); + String storeName = "test-store"; + String getUrl = String.format("https://api.fga.example/stores?name=%s", storeName); + mockHttpClient.onGet(getUrl).doReturn(200, responseBody); + Integer pageSize = null; // Input is optional + String continuationToken = null; // Input is optional + + // When - This covers the specific line: return listStores(pageSize, continuationToken, name, + // this.configuration); + var response = fga.listStores(pageSize, continuationToken, storeName).get(); + + // Then + mockHttpClient.verify().get(getUrl).called(1); + assertNotNull(response.getData()); + assertNotNull(response.getData().getStores()); + var stores = response.getData().getStores(); + assertEquals(1, stores.size()); + assertEquals(DEFAULT_STORE_ID, stores.get(0).getId()); + assertEquals(DEFAULT_STORE_NAME, stores.get(0).getName()); + } + + @Test + public void listStoresTest_withConfigurationOverride() throws Exception { + // Given + String responseBody = + String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME); + mockHttpClient.onGet("https://api.fga.example/stores").doReturn(200, responseBody); + Integer pageSize = null; // Input is optional + String continuationToken = null; // Input is optional + String name = null; + ConfigurationOverride configOverride = new ConfigurationOverride(); + + // When - This covers the specific line: return listStores(pageSize, continuationToken, null, + // this.configuration.override(configurationOverride)); + var response = fga.listStores(pageSize, continuationToken, name, configOverride) + .get(); + + // Then + mockHttpClient.verify().get("https://api.fga.example/stores").called(1); + assertNotNull(response.getData()); + assertNotNull(response.getData().getStores()); + var stores = response.getData().getStores(); + assertEquals(1, stores.size()); + assertEquals(DEFAULT_STORE_ID, stores.get(0).getId()); + assertEquals(DEFAULT_STORE_NAME, stores.get(0).getName()); + } + @Test public void listStores_400() { // Given diff --git a/config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache b/config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache index e4247650d..6bc3bf79f 100644 --- a/config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache +++ b/config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache @@ -8,6 +8,7 @@ import static org.hamcrest.core.StringContains.containsString; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.anyInt; import com.fasterxml.jackson.databind.ObjectMapper; import com.pgssoft.httpclient.HttpClientMock; import {{clientPackage}}.model.*; @@ -305,6 +306,34 @@ public class OpenFgaClientTest { assertEquals(storeName, response.getStores().get(0).getName()); } + @Test + public void listStoresTest_withAllParameters() throws Exception { + // Given + String responseBody = + String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME); + int pageSize = 10; + String continuationToken = "continuationToken"; + String storeName = "test-store"; + String getUrl = String.format( + "https://api.fga.example/stores?page_size=%d&continuation_token=%s&name=%s", + pageSize, continuationToken, storeName); + mockHttpClient.onGet(getUrl).doReturn(200, responseBody); + ClientListStoresOptions options = new ClientListStoresOptions() + .pageSize(pageSize) + .continuationToken(continuationToken) + .name(storeName); + + // When + ClientListStoresResponse response = fga.listStores(options).get(); + + // Then + mockHttpClient.verify().get(getUrl).called(1); + assertNotNull(response.getStores()); + assertEquals(1, response.getStores().size()); + assertEquals(DEFAULT_STORE_ID, response.getStores().get(0).getId()); + assertEquals(DEFAULT_STORE_NAME, response.getStores().get(0).getName()); + } + /** * Create a store. */