Skip to content
Merged
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 @@ -6,6 +6,8 @@
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

import com.github.dockerjava.api.command.InspectContainerResponse;

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

/**
Expand Down Expand Up @@ -59,4 +61,26 @@ public DoclingServeContainer(DoclingServeContainerConfig config) {
public int getPort() {
return getMappedPort(DEFAULT_DOCLING_PORT);
}

/**
* The URL where to access the Docling Serve API.
*/
public String getApiUrl() {
return "http://" + getHost() + ":" + getPort();
}

/**
* The URL where to access the Docling Serve UI, if enabled.
*/
public String getUiUrl() {
return getApiUrl() + "/ui";
}

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
if (config.enableUi()) {
LOG.info(() -> "Docling Serve UI: %s".formatted(getUiUrl()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

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

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

@Testcontainers
class DoclingServeContainerAvailableTests {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final JsonMapper JSON_MAPPER = JsonMapper.builder().build();
private record HealthResponse(String status) {}

@Container
Expand All @@ -33,7 +33,7 @@ private record HealthResponse(String status) {}
@Test
void containerAvailable() throws IOException, InterruptedException {
var healthRequest = HttpRequest.newBuilder(
URI.create("http://localhost:%d/health".formatted(this.doclingContainer.getPort()))
URI.create("%s/health".formatted(this.doclingContainer.getApiUrl()))
)
.header("Accept", "application/json")
.timeout(Duration.ofSeconds(10))
Expand All @@ -48,14 +48,17 @@ void containerAvailable() throws IOException, InterruptedException {
.isNotNull()
.usingRecursiveComparison()
.isEqualTo(new HealthResponse("ok"));

assertThat(this.doclingContainer.getUiUrl())
.isEqualTo(this.doclingContainer.getApiUrl() + "/ui");
}

private static <T> HttpResponse.BodyHandler<T> jsonBodyHandler(Class<T> type) {
return responseInfo -> HttpResponse.BodySubscribers.mapping(
HttpResponse.BodySubscribers.ofByteArray(),
bytes -> {
try {
return OBJECT_MAPPER.readValue(bytes, type);
return JSON_MAPPER.readValue(bytes, type);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down