From 59d8744c8448223e2ecea958bbe045f198766549 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sat, 17 Feb 2024 14:58:24 +0100 Subject: refactor: move mtb file controller into package input --- .../processor/input/MtbFileRestControllerTest.kt | 157 +++++++++++++++++++++ .../etl/processor/web/MtbFileRestControllerTest.kt | 157 --------------------- .../etl/processor/input/MtbFileRestController.kt | 61 ++++++++ .../etl/processor/web/MtbFileRestController.kt | 61 -------- .../processor/input/MtbFileRestControllerTest.kt | 150 ++++++++++++++++++++ .../etl/processor/web/MtbFileRestControllerTest.kt | 150 -------------------- 6 files changed, 368 insertions(+), 368 deletions(-) create mode 100644 src/integrationTest/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt delete mode 100644 src/integrationTest/kotlin/dev/dnpm/etl/processor/web/MtbFileRestControllerTest.kt create mode 100644 src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt delete mode 100644 src/main/kotlin/dev/dnpm/etl/processor/web/MtbFileRestController.kt create mode 100644 src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt delete mode 100644 src/test/kotlin/dev/dnpm/etl/processor/web/MtbFileRestControllerTest.kt diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt new file mode 100644 index 0000000..f1586d0 --- /dev/null +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt @@ -0,0 +1,157 @@ +/* + * This file is part of ETL-Processor + * + * Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package dev.dnpm.etl.processor.input + +import com.fasterxml.jackson.databind.ObjectMapper +import de.ukw.ccc.bwhc.dto.* +import dev.dnpm.etl.processor.config.AppSecurityConfiguration +import dev.dnpm.etl.processor.services.RequestProcessor +import dev.dnpm.etl.processor.services.TokenRepository +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.ArgumentMatchers.anyString +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.any +import org.mockito.kotlin.never +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.http.MediaType +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.anonymous +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user +import org.springframework.test.context.ContextConfiguration +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.delete +import org.springframework.test.web.servlet.post + +@WebMvcTest(controllers = [MtbFileRestController::class]) +@ExtendWith(value = [MockitoExtension::class, SpringExtension::class]) +@ContextConfiguration( + classes = [ + MtbFileRestController::class, + AppSecurityConfiguration::class + ] +) +@MockBean(TokenRepository::class, RequestProcessor::class) +@TestPropertySource( + properties = [ + "app.pseudonymize.generator=BUILDIN", + "app.security.admin-user=admin", + "app.security.admin-password={noop}very-secret", + "app.security.enable-tokens=true" + ] +) +class MtbFileRestControllerTest { + + private lateinit var mockMvc: MockMvc + + private lateinit var requestProcessor: RequestProcessor + + @BeforeEach + fun setup( + @Autowired mockMvc: MockMvc, + @Autowired requestProcessor: RequestProcessor + ) { + this.mockMvc = mockMvc + this.requestProcessor = requestProcessor + } + + @Test + fun testShouldGrantPermissionToSendMtbFile() { + mockMvc.post("/mtbfile") { + with(user("onkostarserver").roles("MTBFILE")) + contentType = MediaType.APPLICATION_JSON + content = ObjectMapper().writeValueAsString(mtbFile) + }.andExpect { + status { isAccepted() } + } + + verify(requestProcessor, times(1)).processMtbFile(any()) + } + + @Test + fun testShouldDenyPermissionToSendMtbFile() { + mockMvc.post("/mtbfile") { + with(anonymous()) + contentType = MediaType.APPLICATION_JSON + content = ObjectMapper().writeValueAsString(mtbFile) + }.andExpect { + status { isUnauthorized() } + } + + verify(requestProcessor, never()).processMtbFile(any()) + } + + @Test + fun testShouldGrantPermissionToDeletePatientData() { + mockMvc.delete("/mtbfile/12345678") { + with(user("onkostarserver").roles("MTBFILE")) + }.andExpect { + status { isAccepted() } + } + + verify(requestProcessor, times(1)).processDeletion(anyString()) + } + + @Test + fun testShouldDenyPermissionToDeletePatientData() { + mockMvc.delete("/mtbfile/12345678") { + with(anonymous()) + }.andExpect { + status { isUnauthorized() } + } + + verify(requestProcessor, never()).processDeletion(anyString()) + } + + companion object { + + val mtbFile: MtbFile = MtbFile.builder() + .withPatient( + Patient.builder() + .withId("PID") + .withBirthDate("2000-08-08") + .withGender(Patient.Gender.MALE) + .build() + ) + .withConsent( + Consent.builder() + .withId("1") + .withStatus(Consent.Status.ACTIVE) + .withPatient("PID") + .build() + ) + .withEpisode( + Episode.builder() + .withId("1") + .withPatient("PID") + .withPeriod(PeriodStart("2023-08-08")) + .build() + ) + .build() + + } + +} diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/MtbFileRestControllerTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/MtbFileRestControllerTest.kt deleted file mode 100644 index 0ffee29..0000000 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/MtbFileRestControllerTest.kt +++ /dev/null @@ -1,157 +0,0 @@ -/* - * This file is part of ETL-Processor - * - * Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package dev.dnpm.etl.processor.web - -import com.fasterxml.jackson.databind.ObjectMapper -import de.ukw.ccc.bwhc.dto.* -import dev.dnpm.etl.processor.config.AppSecurityConfiguration -import dev.dnpm.etl.processor.services.RequestProcessor -import dev.dnpm.etl.processor.services.TokenRepository -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.mockito.ArgumentMatchers.anyString -import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.kotlin.any -import org.mockito.kotlin.never -import org.mockito.kotlin.times -import org.mockito.kotlin.verify -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean -import org.springframework.http.MediaType -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.anonymous -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user -import org.springframework.test.context.ContextConfiguration -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.delete -import org.springframework.test.web.servlet.post - -@WebMvcTest(controllers = [MtbFileRestController::class]) -@ExtendWith(value = [MockitoExtension::class, SpringExtension::class]) -@ContextConfiguration( - classes = [ - MtbFileRestController::class, - AppSecurityConfiguration::class - ] -) -@MockBean(TokenRepository::class, RequestProcessor::class) -@TestPropertySource( - properties = [ - "app.pseudonymize.generator=BUILDIN", - "app.security.admin-user=admin", - "app.security.admin-password={noop}very-secret", - "app.security.enable-tokens=true" - ] -) -class MtbFileRestControllerTest { - - private lateinit var mockMvc: MockMvc - - private lateinit var requestProcessor: RequestProcessor - - @BeforeEach - fun setup( - @Autowired mockMvc: MockMvc, - @Autowired requestProcessor: RequestProcessor - ) { - this.mockMvc = mockMvc - this.requestProcessor = requestProcessor - } - - @Test - fun testShouldGrantPermissionToSendMtbFile() { - mockMvc.post("/mtbfile") { - with(user("onkostarserver").roles("MTBFILE")) - contentType = MediaType.APPLICATION_JSON - content = ObjectMapper().writeValueAsString(mtbFile) - }.andExpect { - status { isAccepted() } - } - - verify(requestProcessor, times(1)).processMtbFile(any()) - } - - @Test - fun testShouldDenyPermissionToSendMtbFile() { - mockMvc.post("/mtbfile") { - with(anonymous()) - contentType = MediaType.APPLICATION_JSON - content = ObjectMapper().writeValueAsString(mtbFile) - }.andExpect { - status { isUnauthorized() } - } - - verify(requestProcessor, never()).processMtbFile(any()) - } - - @Test - fun testShouldGrantPermissionToDeletePatientData() { - mockMvc.delete("/mtbfile/12345678") { - with(user("onkostarserver").roles("MTBFILE")) - }.andExpect { - status { isAccepted() } - } - - verify(requestProcessor, times(1)).processDeletion(anyString()) - } - - @Test - fun testShouldDenyPermissionToDeletePatientData() { - mockMvc.delete("/mtbfile/12345678") { - with(anonymous()) - }.andExpect { - status { isUnauthorized() } - } - - verify(requestProcessor, never()).processDeletion(anyString()) - } - - companion object { - - val mtbFile: MtbFile = MtbFile.builder() - .withPatient( - Patient.builder() - .withId("PID") - .withBirthDate("2000-08-08") - .withGender(Patient.Gender.MALE) - .build() - ) - .withConsent( - Consent.builder() - .withId("1") - .withStatus(Consent.Status.ACTIVE) - .withPatient("PID") - .build() - ) - .withEpisode( - Episode.builder() - .withId("1") - .withPatient("PID") - .withPeriod(PeriodStart("2023-08-08")) - .build() - ) - .build() - - } - -} diff --git a/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt b/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt new file mode 100644 index 0000000..8259288 --- /dev/null +++ b/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt @@ -0,0 +1,61 @@ +/* + * This file is part of ETL-Processor + * + * Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package dev.dnpm.etl.processor.input + +import de.ukw.ccc.bwhc.dto.Consent +import de.ukw.ccc.bwhc.dto.MtbFile +import dev.dnpm.etl.processor.services.RequestProcessor +import org.slf4j.LoggerFactory +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping(path = ["mtbfile"]) +class MtbFileRestController( + private val requestProcessor: RequestProcessor, +) { + + private val logger = LoggerFactory.getLogger(MtbFileRestController::class.java) + + @GetMapping + fun info(): ResponseEntity { + return ResponseEntity.ok("Test") + } + + @PostMapping + fun mtbFile(@RequestBody mtbFile: MtbFile): ResponseEntity { + if (mtbFile.consent.status == Consent.Status.ACTIVE) { + logger.debug("Accepted MTB File for processing") + requestProcessor.processMtbFile(mtbFile) + } else { + logger.debug("Accepted MTB File and process deletion") + requestProcessor.processDeletion(mtbFile.patient.id) + } + return ResponseEntity.accepted().build() + } + + @DeleteMapping(path = ["{patientId}"]) + fun deleteData(@PathVariable patientId: String): ResponseEntity { + logger.debug("Accepted patient ID to process deletion") + requestProcessor.processDeletion(patientId) + return ResponseEntity.accepted().build() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/dev/dnpm/etl/processor/web/MtbFileRestController.kt b/src/main/kotlin/dev/dnpm/etl/processor/web/MtbFileRestController.kt deleted file mode 100644 index d417a1f..0000000 --- a/src/main/kotlin/dev/dnpm/etl/processor/web/MtbFileRestController.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of ETL-Processor - * - * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package dev.dnpm.etl.processor.web - -import de.ukw.ccc.bwhc.dto.Consent -import de.ukw.ccc.bwhc.dto.MtbFile -import dev.dnpm.etl.processor.services.RequestProcessor -import org.slf4j.LoggerFactory -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* - -@RestController -@RequestMapping(path = ["mtbfile"]) -class MtbFileRestController( - private val requestProcessor: RequestProcessor, -) { - - private val logger = LoggerFactory.getLogger(MtbFileRestController::class.java) - - @GetMapping - fun info(): ResponseEntity { - return ResponseEntity.ok("Test") - } - - @PostMapping - fun mtbFile(@RequestBody mtbFile: MtbFile): ResponseEntity { - if (mtbFile.consent.status == Consent.Status.ACTIVE) { - logger.debug("Accepted MTB File for processing") - requestProcessor.processMtbFile(mtbFile) - } else { - logger.debug("Accepted MTB File and process deletion") - requestProcessor.processDeletion(mtbFile.patient.id) - } - return ResponseEntity.accepted().build() - } - - @DeleteMapping(path = ["{patientId}"]) - fun deleteData(@PathVariable patientId: String): ResponseEntity { - logger.debug("Accepted patient ID to process deletion") - requestProcessor.processDeletion(patientId) - return ResponseEntity.accepted().build() - } - -} \ No newline at end of file diff --git a/src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt new file mode 100644 index 0000000..0b076a1 --- /dev/null +++ b/src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt @@ -0,0 +1,150 @@ +/* + * This file is part of ETL-Processor + * + * Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package dev.dnpm.etl.processor.input + +import com.fasterxml.jackson.databind.ObjectMapper +import de.ukw.ccc.bwhc.dto.* +import dev.dnpm.etl.processor.services.RequestProcessor +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mock +import org.mockito.Mockito.times +import org.mockito.Mockito.verify +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.any +import org.mockito.kotlin.argumentCaptor +import org.springframework.http.MediaType +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.delete +import org.springframework.test.web.servlet.post +import org.springframework.test.web.servlet.setup.MockMvcBuilders + +@ExtendWith(MockitoExtension::class) +class MtbFileRestControllerTest { + + private lateinit var mockMvc: MockMvc + + private lateinit var requestProcessor: RequestProcessor + + private val objectMapper = ObjectMapper() + + @BeforeEach + fun setup( + @Mock requestProcessor: RequestProcessor + ) { + this.requestProcessor = requestProcessor + val controller = MtbFileRestController(requestProcessor) + this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build() + } + + @Test + fun shouldProcessMtbFilePostRequest() { + 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() + ) + .build() + + mockMvc.post("/mtbfile") { + content = objectMapper.writeValueAsString(mtbFile) + contentType = MediaType.APPLICATION_JSON + }.andExpect { + status { + isAccepted() + } + } + + verify(requestProcessor, times(1)).processMtbFile(any()) + } + + @Test + fun shouldProcessMtbFilePostRequestWithRejectedConsent() { + 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.REJECTED) + .withPatient("TEST_12345678") + .build() + ) + .withEpisode( + Episode.builder() + .withId("1") + .withPatient("TEST_12345678") + .withPeriod(PeriodStart("2023-08-08")) + .build() + ) + .build() + + mockMvc.post("/mtbfile") { + content = objectMapper.writeValueAsString(mtbFile) + contentType = MediaType.APPLICATION_JSON + }.andExpect { + status { + isAccepted() + } + } + + val captor = argumentCaptor() + verify(requestProcessor, times(1)).processDeletion(captor.capture()) + assertThat(captor.firstValue).isEqualTo("TEST_12345678") + } + + @Test + fun shouldProcessMtbFileDeleteRequest() { + mockMvc.delete("/mtbfile/TEST_12345678").andExpect { + status { + isAccepted() + } + } + + val captor = argumentCaptor() + verify(requestProcessor, times(1)).processDeletion(captor.capture()) + assertThat(captor.firstValue).isEqualTo("TEST_12345678") + } + +} \ No newline at end of file diff --git a/src/test/kotlin/dev/dnpm/etl/processor/web/MtbFileRestControllerTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/web/MtbFileRestControllerTest.kt deleted file mode 100644 index 2fde35a..0000000 --- a/src/test/kotlin/dev/dnpm/etl/processor/web/MtbFileRestControllerTest.kt +++ /dev/null @@ -1,150 +0,0 @@ -/* - * This file is part of ETL-Processor - * - * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package dev.dnpm.etl.processor.web - -import com.fasterxml.jackson.databind.ObjectMapper -import de.ukw.ccc.bwhc.dto.* -import dev.dnpm.etl.processor.services.RequestProcessor -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.mockito.Mock -import org.mockito.Mockito.times -import org.mockito.Mockito.verify -import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.kotlin.any -import org.mockito.kotlin.argumentCaptor -import org.springframework.http.MediaType -import org.springframework.test.web.servlet.MockMvc -import org.springframework.test.web.servlet.delete -import org.springframework.test.web.servlet.post -import org.springframework.test.web.servlet.setup.MockMvcBuilders - -@ExtendWith(MockitoExtension::class) -class MtbFileRestControllerTest { - - private lateinit var mockMvc: MockMvc - - private lateinit var requestProcessor: RequestProcessor - - private val objectMapper = ObjectMapper() - - @BeforeEach - fun setup( - @Mock requestProcessor: RequestProcessor - ) { - this.requestProcessor = requestProcessor - val controller = MtbFileRestController(requestProcessor) - this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build() - } - - @Test - fun shouldProcessMtbFilePostRequest() { - 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() - ) - .build() - - mockMvc.post("/mtbfile") { - content = objectMapper.writeValueAsString(mtbFile) - contentType = MediaType.APPLICATION_JSON - }.andExpect { - status { - isAccepted() - } - } - - verify(requestProcessor, times(1)).processMtbFile(any()) - } - - @Test - fun shouldProcessMtbFilePostRequestWithRejectedConsent() { - 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.REJECTED) - .withPatient("TEST_12345678") - .build() - ) - .withEpisode( - Episode.builder() - .withId("1") - .withPatient("TEST_12345678") - .withPeriod(PeriodStart("2023-08-08")) - .build() - ) - .build() - - mockMvc.post("/mtbfile") { - content = objectMapper.writeValueAsString(mtbFile) - contentType = MediaType.APPLICATION_JSON - }.andExpect { - status { - isAccepted() - } - } - - val captor = argumentCaptor() - verify(requestProcessor, times(1)).processDeletion(captor.capture()) - assertThat(captor.firstValue).isEqualTo("TEST_12345678") - } - - @Test - fun shouldProcessMtbFileDeleteRequest() { - mockMvc.delete("/mtbfile/TEST_12345678").andExpect { - status { - isAccepted() - } - } - - val captor = argumentCaptor() - verify(requestProcessor, times(1)).processDeletion(captor.capture()) - assertThat(captor.firstValue).isEqualTo("TEST_12345678") - } - -} \ No newline at end of file -- cgit v1.2.3