From 499013f18047621f24216acc1f624c591373235c Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sun, 2 Nov 2025 18:26:47 +0100 Subject: test: use correct expectations in GpasPseudonymGeneratorTest (#178) --- .../pseudonym/GpasPseudonymGeneratorTest.kt | 69 ++++++++++++---------- 1 file changed, 38 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/pseudonym/GpasPseudonymGeneratorTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/pseudonym/GpasPseudonymGeneratorTest.kt index 10f2359..1bf443e 100644 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/pseudonym/GpasPseudonymGeneratorTest.kt +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/pseudonym/GpasPseudonymGeneratorTest.kt @@ -21,6 +21,7 @@ package dev.dnpm.etl.processor.pseudonym import dev.dnpm.etl.processor.config.AppFhirConfig import dev.dnpm.etl.processor.config.GPasConfigProperties +import org.apache.hc.core5.net.URIBuilder import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -37,6 +38,7 @@ import org.springframework.test.web.client.response.MockRestResponseCreators.wit import org.springframework.test.web.client.response.MockRestResponseCreators.withStatus import org.springframework.web.client.RestTemplate import java.io.IOException +import java.net.URI class GpasPseudonymGeneratorTest { @@ -49,7 +51,7 @@ class GpasPseudonymGeneratorTest { fun setup() { val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build() val gPasConfigProperties = GPasConfigProperties( - "https://localhost:9990/ttp-fhir/fhir/gpas", + CONFIGURED_URI, null, "test", "test2", null, @@ -64,54 +66,59 @@ class GpasPseudonymGeneratorTest { @Test fun shouldReturnExpectedPseudonym() { - this.mockRestServiceServer.expect { - method(HttpMethod.POST) - requestTo("https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate") - }.andRespond { - withStatus(HttpStatus.OK).body( - getDummyResponseBody( - "1234", - "test", - "test1234ABCDEF567890" + this.mockRestServiceServer + .expect(method(HttpMethod.POST)) + .andExpect(requestTo(EXPECTED_URI)) + .andRespond { + withStatus(HttpStatus.OK).body( + getDummyResponseBody( + "1234", + "test", + "test1234ABCDEF567890" + ) ) - ) - .createResponse(it) - } + .createResponse(it) + } assertThat(this.generator.generate("ID1234")).isEqualTo("test1234ABCDEF567890") } @Test fun shouldThrowExceptionIfGpasNotAvailable() { - this.mockRestServiceServer.expect { - method(HttpMethod.POST) - requestTo("https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate") - }.andRespond { - withException(IOException("Simulated IO error")).createResponse(it) - } + this.mockRestServiceServer + .expect(method(HttpMethod.POST)) + .andExpect(requestTo(EXPECTED_URI)) + .andRespond { + withException(IOException("Simulated IO error")).createResponse(it) + } assertThrows { this.generator.generate("ID1234") } } @Test fun shouldThrowExceptionIfGpasDoesNotReturn2xxResponse() { - this.mockRestServiceServer.expect { - method(HttpMethod.POST) - requestTo("https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate") - }.andRespond { - withStatus(HttpStatus.FOUND) - .header( - HttpHeaders.LOCATION, - "https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate" - ) - .createResponse(it) - } + this.mockRestServiceServer + .expect(method(HttpMethod.POST)) + .andExpect(requestTo(EXPECTED_URI)) + .andRespond { + withStatus(HttpStatus.FOUND) + .header( + HttpHeaders.LOCATION, + "https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate" + ) + .createResponse(it) + } assertThrows { this.generator.generate("ID1234") } } companion object { + const val CONFIGURED_URI = "https://localhost/ttp-fhir/fhir/gpas" + + val EXPECTED_URI = URIBuilder(URI.create(CONFIGURED_URI)).appendPath($$"$pseudonymizeAllowCreate") + .build()!! + fun getDummyResponseBody(original: String, target: String, pseudonym: String) = """{ "resourceType": "Parameters", "parameter": [ @@ -145,4 +152,4 @@ class GpasPseudonymGeneratorTest { }""".trimIndent() } -} \ No newline at end of file +} -- cgit v1.2.3