Skip to content

Commit 82d3c4b

Browse files
authored
feat(testcontainers): Show Docling Serve UI (#90)
When starting a Docling Server Testcontainer and the UI is enabled, the URL for the UI will be logged in the console. Furthermore, the DoclingServeContainer now provides two additional convenient methods: getApiUrl() and getUiUrl(). Signed-off-by: Thomas Vitale <[email protected]>
1 parent 5fe5b8f commit 82d3c4b

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

docling-testcontainers/src/main/java/ai/docling/testcontainers/serve/DoclingServeContainer.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.testcontainers.containers.wait.strategy.Wait;
77
import org.testcontainers.utility.DockerImageName;
88

9+
import com.github.dockerjava.api.command.InspectContainerResponse;
10+
911
import ai.docling.testcontainers.serve.config.DoclingServeContainerConfig;
1012

1113
/**
@@ -59,4 +61,26 @@ public DoclingServeContainer(DoclingServeContainerConfig config) {
5961
public int getPort() {
6062
return getMappedPort(DEFAULT_DOCLING_PORT);
6163
}
64+
65+
/**
66+
* The URL where to access the Docling Serve API.
67+
*/
68+
public String getApiUrl() {
69+
return "http://" + getHost() + ":" + getPort();
70+
}
71+
72+
/**
73+
* The URL where to access the Docling Serve UI, if enabled.
74+
*/
75+
public String getUiUrl() {
76+
return getApiUrl() + "/ui";
77+
}
78+
79+
@Override
80+
protected void containerIsStarted(InspectContainerResponse containerInfo) {
81+
if (config.enableUi()) {
82+
LOG.info(() -> "Docling Serve UI: %s".formatted(getUiUrl()));
83+
}
84+
}
85+
6286
}

docling-testcontainers/src/test/java/ai/docling/testcontainers/serve/DoclingServeContainerAvailableTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
import ai.docling.testcontainers.serve.config.DoclingServeContainerConfig;
1717

18-
import tools.jackson.databind.ObjectMapper;
18+
import tools.jackson.databind.json.JsonMapper;
1919

2020
@Testcontainers
2121
class DoclingServeContainerAvailableTests {
22-
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
22+
private static final JsonMapper JSON_MAPPER = JsonMapper.builder().build();
2323
private record HealthResponse(String status) {}
2424

2525
@Container
@@ -33,7 +33,7 @@ private record HealthResponse(String status) {}
3333
@Test
3434
void containerAvailable() throws IOException, InterruptedException {
3535
var healthRequest = HttpRequest.newBuilder(
36-
URI.create("http://localhost:%d/health".formatted(this.doclingContainer.getPort()))
36+
URI.create("%s/health".formatted(this.doclingContainer.getApiUrl()))
3737
)
3838
.header("Accept", "application/json")
3939
.timeout(Duration.ofSeconds(10))
@@ -48,14 +48,17 @@ void containerAvailable() throws IOException, InterruptedException {
4848
.isNotNull()
4949
.usingRecursiveComparison()
5050
.isEqualTo(new HealthResponse("ok"));
51+
52+
assertThat(this.doclingContainer.getUiUrl())
53+
.isEqualTo(this.doclingContainer.getApiUrl() + "/ui");
5154
}
5255

5356
private static <T> HttpResponse.BodyHandler<T> jsonBodyHandler(Class<T> type) {
5457
return responseInfo -> HttpResponse.BodySubscribers.mapping(
5558
HttpResponse.BodySubscribers.ofByteArray(),
5659
bytes -> {
5760
try {
58-
return OBJECT_MAPPER.readValue(bytes, type);
61+
return JSON_MAPPER.readValue(bytes, type);
5962
} catch (Exception e) {
6063
throw new RuntimeException(e);
6164
}

0 commit comments

Comments
 (0)