Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package {{apiPackage}};

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.
import static org.mockito.Mockito.*;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 com.fasterxml.jackson.databind.ObjectMapper;
import com.pgssoft.httpclient.HttpClientMock;
import {{clientPackage}}.model.*;
Expand Down Expand Up @@ -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.
*/
Expand Down
Loading