|
40 | 40 | import org.junit.jupiter.api.AfterEach; |
41 | 41 | import org.junit.jupiter.api.BeforeEach; |
42 | 42 | import org.junit.jupiter.api.Test; |
| 43 | +import org.mockito.ArgumentCaptor; |
43 | 44 |
|
44 | 45 | @SuppressWarnings("unchecked") |
45 | 46 | class CustomObjectServiceImplTest { |
@@ -234,6 +235,55 @@ void fetchCustomObject_WithKeyAndContainer_ShouldFetchCustomObject() { |
234 | 235 | verify(byProjectKeyCustomObjectsByContainerByKeyGet).execute(); |
235 | 236 | } |
236 | 237 |
|
| 238 | + @Test |
| 239 | + void fetchMatchingCustomObjects_WithManyCustomObjects_ShouldChunkAndFetchCustomObjects() { |
| 240 | + final ArgumentCaptor<String> requestArgumentCaptor = ArgumentCaptor.forClass(String.class); |
| 241 | + final Set<CustomObjectCompositeIdentifier> customObjectCompositeIdentifiers = new HashSet<>(); |
| 242 | + for (int i = 0; i < 500; i++) { |
| 243 | + final String key = RandomStringUtils.random(15, true, true); |
| 244 | + final String container = RandomStringUtils.random(15, true, true); |
| 245 | + customObjectCompositeIdentifiers.add(CustomObjectCompositeIdentifier.of(key, container)); |
| 246 | + } |
| 247 | + |
| 248 | + final ByProjectKeyCustomObjectsGet byProjectKeyCustomObjectsGet = |
| 249 | + mock(ByProjectKeyCustomObjectsGet.class); |
| 250 | + |
| 251 | + when(client.customObjects()).thenReturn(mock(ByProjectKeyCustomObjectsRequestBuilder.class)); |
| 252 | + when(client.customObjects().get()).thenReturn(byProjectKeyCustomObjectsGet); |
| 253 | + when(byProjectKeyCustomObjectsGet.withWhere(anyString())) |
| 254 | + .thenReturn(byProjectKeyCustomObjectsGet); |
| 255 | + when(byProjectKeyCustomObjectsGet.withPredicateVar(anyString(), anyString())) |
| 256 | + .thenReturn(byProjectKeyCustomObjectsGet, byProjectKeyCustomObjectsGet); |
| 257 | + when(byProjectKeyCustomObjectsGet.withLimit(anyInt())).thenReturn(byProjectKeyCustomObjectsGet); |
| 258 | + when(byProjectKeyCustomObjectsGet.withWithTotal(anyBoolean())) |
| 259 | + .thenReturn(byProjectKeyCustomObjectsGet); |
| 260 | + when(byProjectKeyCustomObjectsGet.withSort(anyString())) |
| 261 | + .thenReturn(byProjectKeyCustomObjectsGet); |
| 262 | + when(byProjectKeyCustomObjectsGet.withSort(anyString())) |
| 263 | + .thenReturn(byProjectKeyCustomObjectsGet); |
| 264 | + |
| 265 | + final ApiHttpResponse<CustomObjectPagedQueryResponse> apiHttpResponse = |
| 266 | + mock(ApiHttpResponse.class); |
| 267 | + final CustomObjectPagedQueryResponse customObjectPagedQueryResponse = |
| 268 | + mock(CustomObjectPagedQueryResponse.class); |
| 269 | + when(byProjectKeyCustomObjectsGet.execute()) |
| 270 | + .thenReturn(CompletableFuture.completedFuture(apiHttpResponse)); |
| 271 | + when(apiHttpResponse.getBody()).thenReturn(customObjectPagedQueryResponse); |
| 272 | + when(customObjectPagedQueryResponse.getResults()).thenReturn(Collections.emptyList()); |
| 273 | + |
| 274 | + // test |
| 275 | + service |
| 276 | + .fetchMatchingCustomObjects(customObjectCompositeIdentifiers) |
| 277 | + .toCompletableFuture() |
| 278 | + .join(); |
| 279 | + |
| 280 | + // assertions |
| 281 | + verify(byProjectKeyCustomObjectsGet, times(2)).execute(); |
| 282 | + verify(byProjectKeyCustomObjectsGet, times(2)).withWhere(requestArgumentCaptor.capture()); |
| 283 | + assertThat(requestArgumentCaptor.getAllValues().get(0)) |
| 284 | + .isNotEqualTo(requestArgumentCaptor.getAllValues().get(1)); |
| 285 | + } |
| 286 | + |
237 | 287 | @Test |
238 | 288 | void createCustomObject_WithDraft_ShouldCreateCustomObject() { |
239 | 289 | final CustomObject mock = mock(CustomObject.class); |
|
0 commit comments