From 53fdc8e3f9e010ade931fb86de69d87545fd76e4 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 7 Jun 2026 16:42:20 +0200 Subject: [PATCH] refactor(search): delete orphaned RestClientOllamaClientTest The source class RestClientOllamaClient was removed in 864f44a4 but the corresponding test file was not staged at the time. Removes the leftover file; coverage is provided by RestClientNlpClientTest. Co-Authored-By: Claude Sonnet 4.6 --- .../search/RestClientOllamaClientTest.java | 113 ------------------ 1 file changed, 113 deletions(-) delete mode 100644 backend/src/test/java/org/raddatz/familienarchiv/search/RestClientOllamaClientTest.java diff --git a/backend/src/test/java/org/raddatz/familienarchiv/search/RestClientOllamaClientTest.java b/backend/src/test/java/org/raddatz/familienarchiv/search/RestClientOllamaClientTest.java deleted file mode 100644 index 058ec095..00000000 --- a/backend/src/test/java/org/raddatz/familienarchiv/search/RestClientOllamaClientTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.raddatz.familienarchiv.search; - -import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.core.WireMockConfiguration; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.raddatz.familienarchiv.exception.DomainException; -import org.raddatz.familienarchiv.exception.ErrorCode; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -class RestClientOllamaClientTest { - - private WireMockServer wireMock; - private RestClientOllamaClient client; - - @BeforeEach - void setUp() { - wireMock = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()); - wireMock.start(); - - OllamaProperties props = new OllamaProperties(); - props.setBaseUrl("http://localhost:" + wireMock.port()); - props.setModel("qwen2.5:7b-instruct-q4_K_M"); - props.setTimeoutSeconds(5); - props.setHealthCheckTimeoutSeconds(2); - - client = new RestClientOllamaClient(props); - } - - @AfterEach - void tearDown() { - wireMock.stop(); - } - - // --- Factory helpers --- - - private String makeOllamaResponseJson(String personNamesJson, String personRole, - String dateFrom, String dateTo, String keywordsJson) { - String inner = String.format( - "{\"personNames\":%s,\"personRole\":\"%s\",\"dateFrom\":%s,\"dateTo\":%s,\"keywords\":%s}", - personNamesJson, personRole, - dateFrom == null ? "null" : "\"" + dateFrom + "\"", - dateTo == null ? "null" : "\"" + dateTo + "\"", - keywordsJson - ); - return String.format("{\"model\":\"qwen2.5:7b-instruct-q4_K_M\",\"response\":\"%s\",\"done\":true}", - inner.replace("\"", "\\\"")); - } - - // --- Test cases --- - - @Test - void parse_returnsExtraction_whenOllamaReturnsValidJson() { - String body = makeOllamaResponseJson("[\"Walter\"]", "sender", "1914-01-01", "1914-12-31", "[\"Krieg\"]"); - wireMock.stubFor(post(urlEqualTo("/api/generate")) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(body))); - - OllamaExtraction result = client.parse("Was hat Walter im Krieg geschrieben?"); - - assertThat(result.personNames()).containsExactly("Walter"); - assertThat(result.personRole()).isEqualTo("sender"); - assertThat(result.keywords()).containsExactly("Krieg"); - assertThat(result.dateFrom()).isNotNull(); - assertThat(result.dateTo()).isNotNull(); - } - - @Test - void parse_throwsSmartSearchUnavailable_whenOllamaReturns500() { - wireMock.stubFor(post(urlEqualTo("/api/generate")) - .willReturn(aResponse().withStatus(500))); - - assertThatThrownBy(() -> client.parse("some query")) - .isInstanceOf(DomainException.class) - .extracting(e -> ((DomainException) e).getCode()) - .isEqualTo(ErrorCode.SMART_SEARCH_UNAVAILABLE); - } - - @Test - void parse_throwsSmartSearchUnavailable_whenOllamaExceedsTimeout() { - wireMock.stubFor(post(urlEqualTo("/api/generate")) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withFixedDelay(6000) - .withBody("{\"response\":\"{}\",\"done\":true}"))); - - assertThatThrownBy(() -> client.parse("some query")) - .isInstanceOf(DomainException.class) - .extracting(e -> ((DomainException) e).getCode()) - .isEqualTo(ErrorCode.SMART_SEARCH_UNAVAILABLE); - } - - @Test - void parse_throwsSmartSearchUnavailable_whenOllamaReturnsMalformedJson() { - wireMock.stubFor(post(urlEqualTo("/api/generate")) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody("{\"response\":\"not-json-at-all\",\"done\":true}"))); - - assertThatThrownBy(() -> client.parse("some query")) - .isInstanceOf(DomainException.class) - .extracting(e -> ((DomainException) e).getCode()) - .isEqualTo(ErrorCode.SMART_SEARCH_UNAVAILABLE); - } -}