-
Notifications
You must be signed in to change notification settings - Fork 23
test(version-tests): add tests for client, domain, and service layers #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
margi212
wants to merge
5
commits into
docling-project:main
Choose a base branch
from
margi212:test--add-test-cases
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a878782
test(docling-version-tests): add unit tests for client, domain, and s…
margi212 479c3af
Merge branch 'main' into test--add-test-cases
margi212 604a5ed
test(work-parallelizer): refactor transform tests to parameterized cases
margi212 55d2b47
test: rewrite shouldRunItemsInParallel to use AtomicInteger counter p…
margi212 fb3c532
Merge branch 'main' into test--add-test-cases
margi212 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...rsion-tests/src/test/java/ai/docling/client/tester/client/RegistryClientFactoryTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package ai.docling.client.tester.client; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| import ai.docling.client.tester.client.ghcr.GHCRClient; | ||
|
|
||
| class RegistryClientFactoryTests { | ||
|
|
||
| private GHCRClient ghcrClient; | ||
| private RegistryClientFactory factory; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| ghcrClient = mock(GHCRClient.class); | ||
| factory = new RegistryClientFactory(ghcrClient); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldReturnGHCRClientForGhcrRegistry() { | ||
| assertThat(factory.getRegistryClient("ghcr.io")) | ||
| .isNotNull() | ||
| .isSameAs(ghcrClient); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @NullAndEmptySource | ||
| @ValueSource(strings = { "docker.io", "quay.io", "GHCR.IO", " ghcr.io " }) | ||
| void shouldThrowExceptionForUnsupportedRegistry(String registry) { | ||
| assertThatThrownBy(() -> factory.getRegistryClient(registry)) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessage("Unsupported registry: " + registry); | ||
| } | ||
| } | ||
176 changes: 176 additions & 0 deletions
176
...rsion-tests/src/test/java/ai/docling/client/tester/client/ghcr/GHCRClientLoggerTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| package ai.docling.client.tester.client.ghcr; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import jakarta.ws.rs.core.HttpHeaders; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.mockito.ArgumentCaptor; | ||
|
|
||
| import ai.docling.client.tester.config.Config; | ||
|
|
||
| import io.vertx.core.Handler; | ||
| import io.vertx.core.MultiMap; | ||
| import io.vertx.core.buffer.Buffer; | ||
| import io.vertx.core.http.HttpClientRequest; | ||
| import io.vertx.core.http.HttpClientResponse; | ||
| import io.vertx.core.http.HttpMethod; | ||
|
|
||
| class GHCRClientLoggerTests { | ||
|
margi212 marked this conversation as resolved.
|
||
|
|
||
| private Config config; | ||
| private GHCRClientLogger logger; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| config = mock(Config.class); | ||
| logger = new GHCRClientLogger(config); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotLogResponseWhenDisabled() { | ||
| when(config.logResponses()).thenReturn(false); | ||
| HttpClientResponse response = mock(HttpClientResponse.class); | ||
|
|
||
| logger.logResponse(response, false); | ||
|
|
||
| verify(response, never()).bodyHandler(any()); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { | ||
| "{\"token\":\"secret123\"}", | ||
| "{\"token\":\"very-secret-token-value\"}", | ||
| "[{\"token\":\"secret1\"}, {\"token\":\"secret2\"}]", | ||
| "Plain text response", | ||
| "" | ||
| }) | ||
| void shouldLogResponseBody(String rawBody) { | ||
| when(config.logResponses()).thenReturn(true); | ||
| MockedResponse mr = mockedResponse(200, MultiMap.caseInsensitiveMultiMap()); | ||
|
|
||
| logger.logResponse(mr.response, false); | ||
| mr.triggerBody(Buffer.buffer(rawBody)); | ||
|
|
||
| verify(mr.response).statusCode(); | ||
| verify(mr.response).headers(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldHandleNullBodyInResponse() { | ||
| when(config.logResponses()).thenReturn(true); | ||
| MockedResponse mr = mockedResponse(204, MultiMap.caseInsensitiveMultiMap()); | ||
|
|
||
| logger.logResponse(mr.response, false); | ||
| mr.triggerBody(null); | ||
|
|
||
| verify(mr.response).statusCode(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldMaskSetCookieHeaderInResponse() { | ||
| when(config.logResponses()).thenReturn(true); | ||
|
|
||
| MultiMap headers = MultiMap.caseInsensitiveMultiMap(); | ||
| headers.add(HttpHeaders.SET_COOKIE, "session=very-long-session-id"); | ||
| MockedResponse mr = mockedResponse(200, headers); | ||
|
|
||
| logger.logResponse(mr.response, false); | ||
| mr.triggerBody(Buffer.buffer("{}")); | ||
|
|
||
| verify(mr.response).headers(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotLogRequestWhenDisabled() { | ||
| when(config.logRequests()).thenReturn(false); | ||
| HttpClientRequest request = mock(HttpClientRequest.class); | ||
|
|
||
| logger.logRequest(request, Buffer.buffer("{\"test\":\"data\"}"), false); | ||
|
|
||
| verify(request, never()).getMethod(); | ||
| verify(request, never()).absoluteURI(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldLogRequestWhenEnabled() { | ||
| when(config.logRequests()).thenReturn(true); | ||
|
|
||
| MultiMap headers = MultiMap.caseInsensitiveMultiMap(); | ||
| headers.add("Content-Type", "application/json"); | ||
| HttpClientRequest request = mockedRequest(HttpMethod.GET, "https://ghcr.io/v2/test/tags/list", headers); | ||
|
|
||
| logger.logRequest(request, Buffer.buffer("{\"test\":\"data\"}"), false); | ||
|
|
||
| verify(request).getMethod(); | ||
| verify(request).absoluteURI(); | ||
| verify(request).headers(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldLogRequestWithNullBody() { | ||
| when(config.logRequests()).thenReturn(true); | ||
| HttpClientRequest request = mockedRequest( | ||
| HttpMethod.GET, "https://ghcr.io/token", MultiMap.caseInsensitiveMultiMap()); | ||
|
|
||
| logger.logRequest(request, null, false); | ||
|
|
||
| verify(request).getMethod(); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { "Bearer very-long-secret-token", "abc" }) | ||
| void shouldMaskAuthorizationHeader(String authValue) { | ||
| when(config.logRequests()).thenReturn(true); | ||
|
|
||
| MultiMap headers = MultiMap.caseInsensitiveMultiMap(); | ||
| headers.add(HttpHeaders.AUTHORIZATION, authValue); | ||
| HttpClientRequest request = mockedRequest( | ||
| HttpMethod.GET, "https://ghcr.io/v2/test/tags/list", headers); | ||
|
|
||
| logger.logRequest(request, null, false); | ||
|
|
||
| verify(request).headers(); | ||
| } | ||
|
|
||
| private static class MockedResponse { | ||
| final HttpClientResponse response; | ||
| private final ArgumentCaptor<Handler<Buffer>> captor; | ||
|
|
||
| MockedResponse(HttpClientResponse response, ArgumentCaptor<Handler<Buffer>> captor) { | ||
| this.response = response; | ||
| this.captor = captor; | ||
| } | ||
|
|
||
| void triggerBody(Buffer body) { | ||
| captor.getValue().handle(body); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private MockedResponse mockedResponse(int statusCode, MultiMap headers) { | ||
| HttpClientResponse response = mock(HttpClientResponse.class); | ||
| when(response.statusCode()).thenReturn(statusCode); | ||
| when(response.headers()).thenReturn(headers); | ||
|
|
||
| ArgumentCaptor<Handler<Buffer>> captor = ArgumentCaptor.forClass(Handler.class); | ||
| when(response.bodyHandler(captor.capture())).thenReturn(response); | ||
|
|
||
| return new MockedResponse(response, captor); | ||
| } | ||
|
|
||
| private HttpClientRequest mockedRequest(HttpMethod method, String uri, MultiMap headers) { | ||
| HttpClientRequest request = mock(HttpClientRequest.class); | ||
| when(request.getMethod()).thenReturn(method); | ||
| when(request.absoluteURI()).thenReturn(uri); | ||
| when(request.headers()).thenReturn(headers); | ||
| return request; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.