|
16 | 16 | import static org.junit.jupiter.api.Assertions.*;
|
17 | 17 | import static org.mockito.Mockito.*;
|
18 | 18 |
|
| 19 | +import org.mockito.ArgumentMatchers; |
| 20 | + |
19 | 21 | import com.fasterxml.jackson.databind.ObjectMapper;
|
20 | 22 | import com.pgssoft.httpclient.HttpClientMock;
|
21 | 23 | import dev.openfga.sdk.api.client.*;
|
@@ -74,6 +76,8 @@ public void beforeEachTest() throws Exception {
|
74 | 76 | when(mockConfiguration.getMaxRetries()).thenReturn(DEFAULT_MAX_RETRIES);
|
75 | 77 | when(mockConfiguration.getMinimumRetryDelay()).thenReturn(DEFAULT_RETRY_DELAY);
|
76 | 78 | when(mockConfiguration.getTelemetryConfiguration()).thenReturn(DEFAULT_TELEMETRY_CONFIG);
|
| 79 | + when(mockConfiguration.override(ArgumentMatchers.any(ConfigurationOverride.class))).thenReturn(mockConfiguration); |
| 80 | + doNothing().when(mockConfiguration).assertValid(); |
77 | 81 |
|
78 | 82 | mockApiClient = mock(ApiClient.class);
|
79 | 83 | when(mockApiClient.getObjectMapper()).thenReturn(mapper);
|
@@ -175,6 +179,77 @@ public void listStores_500() throws Exception {
|
175 | 179 | "{\"code\":\"internal_error\",\"message\":\"Internal Server Error\"}", exception.getResponseData());
|
176 | 180 | }
|
177 | 181 |
|
| 182 | + @Test |
| 183 | + public void listStoresTest_withNameFilter() throws Exception { |
| 184 | + // Given |
| 185 | + String responseBody = |
| 186 | + String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME); |
| 187 | + String storeName = "test-store"; |
| 188 | + String getUrl = String.format("https://api.fga.example/stores?name=%s", storeName); |
| 189 | + mockHttpClient.onGet(getUrl).doReturn(200, responseBody); |
| 190 | + Integer pageSize = null; // Input is optional |
| 191 | + String continuationToken = null; // Input is optional |
| 192 | + |
| 193 | + // When |
| 194 | + var response = fga.listStores(pageSize, continuationToken, storeName).get(); |
| 195 | + |
| 196 | + // Then |
| 197 | + mockHttpClient.verify().get(getUrl).called(1); |
| 198 | + assertNotNull(response.getData()); |
| 199 | + assertNotNull(response.getData().getStores()); |
| 200 | + var stores = response.getData().getStores(); |
| 201 | + assertEquals(1, stores.size()); |
| 202 | + assertEquals(DEFAULT_STORE_ID, stores.get(0).getId()); |
| 203 | + assertEquals(DEFAULT_STORE_NAME, stores.get(0).getName()); |
| 204 | + } |
| 205 | + |
| 206 | + @Test |
| 207 | + public void listStoresTest_withNameOnly() throws Exception { |
| 208 | + // Given |
| 209 | + String responseBody = |
| 210 | + String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME); |
| 211 | + String storeName = "test-store"; |
| 212 | + String getUrl = String.format("https://api.fga.example/stores?name=%s", storeName); |
| 213 | + mockHttpClient.onGet(getUrl).doReturn(200, responseBody); |
| 214 | + Integer pageSize = null; // Input is optional |
| 215 | + String continuationToken = null; // Input is optional |
| 216 | + |
| 217 | + // When - This covers the specific line: return listStores(pageSize, continuationToken, name, this.configuration); |
| 218 | + var response = fga.listStores(pageSize, continuationToken, storeName).get(); |
| 219 | + |
| 220 | + // Then |
| 221 | + mockHttpClient.verify().get(getUrl).called(1); |
| 222 | + assertNotNull(response.getData()); |
| 223 | + assertNotNull(response.getData().getStores()); |
| 224 | + var stores = response.getData().getStores(); |
| 225 | + assertEquals(1, stores.size()); |
| 226 | + assertEquals(DEFAULT_STORE_ID, stores.get(0).getId()); |
| 227 | + assertEquals(DEFAULT_STORE_NAME, stores.get(0).getName()); |
| 228 | + } |
| 229 | + |
| 230 | + @Test |
| 231 | + public void listStoresTest_withConfigurationOverride() throws Exception { |
| 232 | + // Given |
| 233 | + String responseBody = |
| 234 | + String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME); |
| 235 | + mockHttpClient.onGet("https://api.fga.example/stores").doReturn(200, responseBody); |
| 236 | + Integer pageSize = null; // Input is optional |
| 237 | + String continuationToken = null; // Input is optional |
| 238 | + ConfigurationOverride configOverride = new ConfigurationOverride(); |
| 239 | + |
| 240 | + // When - This covers the specific line: return listStores(pageSize, continuationToken, null, this.configuration.override(configurationOverride)); |
| 241 | + var response = fga.listStores(pageSize, continuationToken, configOverride).get(); |
| 242 | + |
| 243 | + // Then |
| 244 | + mockHttpClient.verify().get("https://api.fga.example/stores").called(1); |
| 245 | + assertNotNull(response.getData()); |
| 246 | + assertNotNull(response.getData().getStores()); |
| 247 | + var stores = response.getData().getStores(); |
| 248 | + assertEquals(1, stores.size()); |
| 249 | + assertEquals(DEFAULT_STORE_ID, stores.get(0).getId()); |
| 250 | + assertEquals(DEFAULT_STORE_NAME, stores.get(0).getName()); |
| 251 | + } |
| 252 | + |
178 | 253 | /**
|
179 | 254 | * Create a store.
|
180 | 255 | */
|
|
0 commit comments