diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/EtlProcessorApplicationTests.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/EtlProcessorApplicationTests.kt index c5a20bb..62fa13f 100644 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/EtlProcessorApplicationTests.kt +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/EtlProcessorApplicationTests.kt @@ -19,15 +19,27 @@ package dev.dnpm.etl.processor +import com.fasterxml.jackson.databind.ObjectMapper +import de.ukw.ccc.bwhc.dto.* +import dev.dnpm.etl.processor.monitoring.RequestRepository +import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.output.MtbFileSender import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.kotlin.* import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.ApplicationContext +import org.springframework.http.MediaType +import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit.jupiter.SpringExtension +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.post import org.testcontainers.junit.jupiter.Testcontainers @Testcontainers @@ -42,4 +54,85 @@ class EtlProcessorApplicationTests : AbstractTestcontainerTest() { assertThat(context).isNotNull } + @Nested + @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) + @AutoConfigureMockMvc + @TestPropertySource( + properties = [ + "app.transformations[0].path=diagnoses[*].icd10.version", + "app.transformations[0].from=2013", + "app.transformations[0].to=2014", + ] + ) + inner class TransformationTest { + + @MockBean + private lateinit var mtbFileSender: MtbFileSender + + @Autowired + private lateinit var mockMvc: MockMvc + + @Autowired + private lateinit var objectMapper: ObjectMapper + + @BeforeEach + fun setup(@Autowired requestRepository: RequestRepository) { + requestRepository.deleteAll() + } + + @Test + fun mtbFileIsTransformed() { + doAnswer { + MtbFileSender.Response(RequestStatus.SUCCESS) + }.whenever(mtbFileSender).send(any()) + + val mtbFile = MtbFile.builder() + .withPatient( + Patient.builder() + .withId("TEST_12345678") + .withBirthDate("2000-08-08") + .withGender(Patient.Gender.MALE) + .build() + ) + .withConsent( + Consent.builder() + .withId("1") + .withStatus(Consent.Status.ACTIVE) + .withPatient("TEST_12345678") + .build() + ) + .withEpisode( + Episode.builder() + .withId("1") + .withPatient("TEST_12345678") + .withPeriod(PeriodStart("2023-08-08")) + .build() + ) + .withDiagnoses( + listOf( + Diagnosis.builder() + .withId("1234") + .withIcd10(Icd10.builder().withCode("F79.9").withVersion("2013").build()) + .build() + ) + ) + .build() + + mockMvc.post("/mtbfile") { + content = objectMapper.writeValueAsString(mtbFile) + contentType = MediaType.APPLICATION_JSON + }.andExpect { + status { + isAccepted() + } + } + + val captor = argumentCaptor() + verify(mtbFileSender).send(captor.capture()) + assertThat(captor.firstValue.mtbFile.diagnoses).hasSize(1).allMatch { diagnosis -> + diagnosis.icd10.version == "2014" + } + } + } + }