From 18640103831e1dc2d21bc0c3c91263ddf3f8503c Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 6 May 2026 10:12:38 +0200 Subject: test: code cleanup in test classes --- .../etl/processor/config/AppConfigurationTest.kt | 37 +++++++++++----------- .../processor/config/GPasConfigPropertiesTest.kt | 5 +-- .../dnpm/etl/processor/web/ConfigControllerTest.kt | 3 +- .../processor/web/StatisticsRestControllerTest.kt | 3 +- .../processor/monitoring/ConnectionCheckService.kt | 9 +++--- .../dnpm/etl/processor/output/RestMtbFileSender.kt | 3 +- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt index a932ab7..b0fa70f 100644 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt @@ -39,6 +39,7 @@ import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.springframework.beans.factory.NoSuchBeanDefinitionException +import org.springframework.beans.factory.getBean import org.springframework.boot.kafka.autoconfigure.KafkaAutoConfiguration import org.springframework.boot.test.context.SpringBootTest import org.springframework.context.ApplicationContext @@ -76,9 +77,9 @@ class AppConfigurationTest { ) { @Test fun shouldUseRestMtbFileSenderNotKafkaMtbFileSender() { - assertThat(context.getBean(RestMtbFileSender::class.java)).isNotNull + assertThat(context.getBean()).isNotNull assertThrows { - context.getBean(KafkaMtbFileSender::class.java) + context.getBean() } } } @@ -99,8 +100,8 @@ class AppConfigurationTest { ) { @Test fun shouldUseKafkaMtbFileSenderNotRestMtbFileSender() { - assertThrows { context.getBean(RestMtbFileSender::class.java) } - assertThat(context.getBean(KafkaMtbFileSender::class.java)).isNotNull + assertThrows { context.getBean() } + assertThat(context.getBean()).isNotNull } } @@ -120,9 +121,9 @@ class AppConfigurationTest { ) { @Test fun shouldUseRestMtbFileSenderNotKafkaMtbFileSender() { - assertThat(context.getBean(RestMtbFileSender::class.java)).isNotNull + assertThat(context.getBean()).isNotNull assertThrows { - context.getBean(KafkaMtbFileSender::class.java) + context.getBean() } } } @@ -143,7 +144,7 @@ class AppConfigurationTest { @Test fun shouldNotUseKafkaInputListener() { assertThrows { - context.getBean(KafkaInputListener::class.java) + context.getBean() } } } @@ -165,7 +166,7 @@ class AppConfigurationTest { ) { @Test fun shouldUseKafkaInputListener() { - assertThat(context.getBean(KafkaInputListener::class.java)).isNotNull + assertThat(context.getBean()).isNotNull } } @@ -183,7 +184,7 @@ class AppConfigurationTest { ) { @Test fun shouldRecognizeTransformations() { - val appConfigProperties = context.getBean(AppConfigProperties::class.java) + val appConfigProperties = context.getBean() assertThat(appConfigProperties).isNotNull assertThat(appConfigProperties.transformations).hasSize(1) @@ -199,7 +200,7 @@ class AppConfigurationTest { ) { @Test fun shouldUseConfiguredGenerator() { - assertThat(context.getBean(AnonymizingGenerator::class.java)).isNotNull + assertThat(context.getBean()).isNotNull } } @@ -213,7 +214,7 @@ class AppConfigurationTest { ) { @Test fun shouldUseConfiguredGenerator() { - assertThat(context.getBean(GpasPseudonymGenerator::class.java)).isNotNull + assertThat(context.getBean()).isNotNull } } @@ -230,7 +231,7 @@ class AppConfigurationTest { ) { @Test fun shouldUseConfiguredGenerator() { - assertThat(context.getBean(GpasSoapPseudonymGenerator::class.java)).isNotNull + assertThat(context.getBean()).isNotNull } } @@ -244,7 +245,7 @@ class AppConfigurationTest { ) { @Test fun checkTokenService() { - assertThat(context.getBean(TokenService::class.java)).isNotNull + assertThat(context.getBean()).isNotNull } } @@ -257,7 +258,7 @@ class AppConfigurationTest { ) { @Test fun checkTokenService() { - assertThrows { context.getBean(TokenService::class.java) } + assertThrows { context.getBean() } } } } @@ -273,7 +274,7 @@ class AppConfigurationTest { @Test fun shouldUseRetryTemplateWithConfiguredMaxAttempts() { - val retryTemplate = context.getBean(RetryTemplate::class.java) + val retryTemplate = context.getBean() assertThat(retryTemplate).isNotNull assertThrows { @@ -298,7 +299,7 @@ class AppConfigurationTest { ) { @Test fun shouldUseConfiguredGenerator() { - assertThat(context.getBean(GicsConsentService::class.java)).isNotNull + assertThat(context.getBean()).isNotNull } } @@ -315,7 +316,7 @@ class AppConfigurationTest { ) { @Test fun shouldUseConfiguredGenerator() { - assertThat(context.getBean(GicsGetBroadConsentService::class.java)).isNotNull + assertThat(context.getBean()).isNotNull } } @@ -325,7 +326,7 @@ class AppConfigurationTest { ) { @Test fun shouldUseConfiguredGenerator() { - assertThat(context.getBean(MtbFileConsentService::class.java)).isNotNull + assertThat(context.getBean()).isNotNull } } } diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/GPasConfigPropertiesTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/GPasConfigPropertiesTest.kt index bda5b79..7ba171e 100644 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/GPasConfigPropertiesTest.kt +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/GPasConfigPropertiesTest.kt @@ -2,6 +2,7 @@ package dev.dnpm.etl.processor.config import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.springframework.beans.factory.getBean import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.context.runner.ApplicationContextRunner @@ -26,7 +27,7 @@ class GPasConfigPropertiesTest { "app.pseudonymize.gpas.uri=http://localhost/", "app.pseudonymize.gpas.pid-domain=test-pid-domain", ).run { context -> - val properties = context.getBean(GPasConfigProperties::class.java) + val properties = context.getBean() assertThat(properties).isNotNull assertThat(properties.patientDomain).isEqualTo("test-pid-domain") @@ -41,7 +42,7 @@ class GPasConfigPropertiesTest { "app.pseudonymize.gpas.uri=http://localhost/", "app.pseudonymize.gpas.patient-domain=test-patient-domain", ).run { context -> - val properties = context.getBean(GPasConfigProperties::class.java) + val properties = context.getBean() assertThat(properties).isNotNull assertThat(properties.patientDomain).isEqualTo("test-patient-domain") diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/ConfigControllerTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/ConfigControllerTest.kt index 0e24870..b946da8 100644 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/ConfigControllerTest.kt +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/ConfigControllerTest.kt @@ -58,6 +58,7 @@ import org.springframework.test.context.TestPropertySource import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.context.junit.jupiter.SpringExtension import org.springframework.test.web.reactive.server.WebTestClient +import org.springframework.test.web.reactive.server.returnResult import org.springframework.test.web.servlet.* import org.springframework.test.web.servlet.client.MockMvcWebTestClient import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder @@ -351,7 +352,7 @@ class ConfigControllerTest { .isOk() .expectHeader() .contentType(TEXT_EVENT_STREAM) - .returnResult(ConnectionCheckResult.GPasConnectionCheckResult::class.java) + .returnResult() StepVerifier.create(result.responseBody).expectNext(expectedEvent).expectComplete().verify() } diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt index 2568b1b..cb19cf4 100644 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt @@ -49,6 +49,7 @@ import org.springframework.test.context.TestPropertySource import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.context.junit.jupiter.SpringExtension import org.springframework.test.web.reactive.server.WebTestClient +import org.springframework.test.web.reactive.server.returnResult import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.client.MockMvcWebTestClient import org.springframework.test.web.servlet.get @@ -333,7 +334,7 @@ class StatisticsRestControllerTest { .isOk() .expectHeader() .contentType(TEXT_EVENT_STREAM) - .returnResult(String::class.java) + .returnResult() StepVerifier.create(result.responseBody).expectComplete().verify() } diff --git a/src/main/kotlin/dev/dnpm/etl/processor/monitoring/ConnectionCheckService.kt b/src/main/kotlin/dev/dnpm/etl/processor/monitoring/ConnectionCheckService.kt index 085d0a3..a88cf10 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/monitoring/ConnectionCheckService.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/monitoring/ConnectionCheckService.kt @@ -33,6 +33,8 @@ import org.springframework.beans.factory.annotation.Qualifier import org.springframework.http.* import org.springframework.scheduling.annotation.Scheduled import org.springframework.web.client.RestTemplate +import org.springframework.web.client.exchange +import org.springframework.web.client.getForEntity import org.springframework.web.util.UriComponentsBuilder import reactor.core.publisher.Sinks @@ -139,13 +141,12 @@ class RestConnectionCheckService( try { val statusCode = restTemplate - .getForEntity( + .getForEntity( UriComponentsBuilder.fromUriString(restTargetProperties.uri.toString()) .pathSegment("mtb") .pathSegment("kaplan-meier") .pathSegment("config") .toUriString(), - String::class.java, ) .statusCode val available = statusCode == HttpStatus.OK @@ -215,7 +216,7 @@ class GPasConnectionCheckService( val statusCode = restTemplate - .exchange(uri, HttpMethod.GET, HttpEntity(headers), Void::class.java) + .exchange(uri, HttpMethod.GET, HttpEntity(headers)) .statusCode val available = statusCode == HttpStatus.OK @@ -285,7 +286,7 @@ class GIcsConnectionCheckService( val statusCode = restTemplate - .exchange(uri, HttpMethod.GET, HttpEntity(headers), Void::class.java) + .exchange(uri, HttpMethod.GET, HttpEntity(headers)) .statusCode val available = statusCode == HttpStatus.OK diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt index a2a88b6..0d8ed7b 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt @@ -35,6 +35,7 @@ import org.springframework.retry.support.RetryTemplate import org.springframework.web.client.RestClientException import org.springframework.web.client.RestClientResponseException import org.springframework.web.client.RestTemplate +import org.springframework.web.client.exchange abstract class RestMtbFileSender( private val restTemplate: RestTemplate, @@ -54,7 +55,7 @@ abstract class RestMtbFileSender( val headers = getHttpHeaders(request) val entityReq = HttpEntity(request.content, headers) val response = - restTemplate.exchange(sendUrl(), HttpMethod.POST, entityReq, String::class.java) + restTemplate.exchange(sendUrl(), HttpMethod.POST, entityReq) if (!response.statusCode.is2xxSuccessful) { logger.warn("Error sending to remote system: {}", response.body) return@execute MtbFileSender.Response( -- cgit v1.2.3