summaryrefslogtreecommitdiff
path: root/src/integrationTest/kotlin/dev/dnpm/etl/processor
diff options
context:
space:
mode:
authorPaul-Christian Volkmer2023-11-25 14:33:02 +0100
committerPaul-Christian Volkmer2023-11-25 14:33:02 +0100
commitcf2d338e1327aa305d33bf2f20628aa0081bca5d (patch)
tree66c54d50ac183ce115a776f5a8b971261a493a90 /src/integrationTest/kotlin/dev/dnpm/etl/processor
parentd5552b3ca4e1fbd423b365dcbeb08e53a7e19633 (diff)
test: add integration test for mtb file transformation
Diffstat (limited to 'src/integrationTest/kotlin/dev/dnpm/etl/processor')
-rw-r--r--src/integrationTest/kotlin/dev/dnpm/etl/processor/EtlProcessorApplicationTests.kt93
1 files changed, 93 insertions, 0 deletions
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<MtbFileSender.MtbFileRequest>())
+
+ 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<MtbFileSender.MtbFileRequest>()
+ verify(mtbFileSender).send(captor.capture())
+ assertThat(captor.firstValue.mtbFile.diagnoses).hasSize(1).allMatch { diagnosis ->
+ diagnosis.icd10.version == "2014"
+ }
+ }
+ }
+
}