1
0
mirror of https://github.com/pcvolkmer/etl-processor.git synced 2025-04-19 17:26:51 +00:00

feat: use RequestId type

This commit is contained in:
Paul-Christian Volkmer 2024-05-27 11:23:03 +02:00
parent a846a8765a
commit 8fc0609aa4
22 changed files with 169 additions and 84 deletions

View File

@ -22,6 +22,7 @@ package dev.dnpm.etl.processor.monitoring
import dev.dnpm.etl.processor.AbstractTestcontainerTest import dev.dnpm.etl.processor.AbstractTestcontainerTest
import dev.dnpm.etl.processor.Fingerprint import dev.dnpm.etl.processor.Fingerprint
import dev.dnpm.etl.processor.output.MtbFileSender import dev.dnpm.etl.processor.output.MtbFileSender
import dev.dnpm.etl.processor.randomRequestId
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.ExtendWith
@ -61,7 +62,7 @@ class RequestRepositoryTest : AbstractTestcontainerTest() {
@Test @Test
fun shouldSaveRequest() { fun shouldSaveRequest() {
val request = Request( val request = Request(
RequestId.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),

View File

@ -26,6 +26,7 @@ import dev.dnpm.etl.processor.monitoring.RequestRepository
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType import dev.dnpm.etl.processor.monitoring.RequestType
import dev.dnpm.etl.processor.output.MtbFileSender import dev.dnpm.etl.processor.output.MtbFileSender
import dev.dnpm.etl.processor.randomRequestId
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@ -38,7 +39,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.transaction.annotation.Transactional import org.springframework.transaction.annotation.Transactional
import org.testcontainers.junit.jupiter.Testcontainers import org.testcontainers.junit.jupiter.Testcontainers
import java.time.Instant import java.time.Instant
import java.util.*
@Testcontainers @Testcontainers
@ExtendWith(SpringExtension::class) @ExtendWith(SpringExtension::class)
@ -77,7 +77,7 @@ class RequestServiceIntegrationTest : AbstractTestcontainerTest() {
this.requestRepository.saveAll( this.requestRepository.saveAll(
listOf( listOf(
Request( Request(
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),
@ -87,7 +87,7 @@ class RequestServiceIntegrationTest : AbstractTestcontainerTest() {
), ),
// Should be ignored - wrong patient ID --> // Should be ignored - wrong patient ID -->
Request( Request(
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678902", "TEST_12345678902",
"P2", "P2",
Fingerprint("0123456789abcdef2"), Fingerprint("0123456789abcdef2"),
@ -97,7 +97,7 @@ class RequestServiceIntegrationTest : AbstractTestcontainerTest() {
), ),
// <-- // <--
Request( Request(
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P2", "P2",
Fingerprint("0123456789abcdee1"), Fingerprint("0123456789abcdee1"),

View File

@ -29,6 +29,7 @@ import dev.dnpm.etl.processor.monitoring.Report
import dev.dnpm.etl.processor.monitoring.Request import dev.dnpm.etl.processor.monitoring.Request
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType import dev.dnpm.etl.processor.monitoring.RequestType
import dev.dnpm.etl.processor.randomRequestId
import dev.dnpm.etl.processor.services.RequestService import dev.dnpm.etl.processor.services.RequestService
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
@ -36,6 +37,7 @@ import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
import org.mockito.junit.jupiter.MockitoExtension import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.any import org.mockito.kotlin.any
@ -81,6 +83,13 @@ class HomeControllerTest {
private lateinit var mockMvc: MockMvc private lateinit var mockMvc: MockMvc
private lateinit var webClient: WebClient private lateinit var webClient: WebClient
inline fun <reified T> anyValueClass(): T {
val unboxedClass = T::class.java.declaredFields.first().type
return ArgumentMatchers.any(unboxedClass as Class<T>)
?: T::class.java.getDeclaredMethod("box-impl", unboxedClass)
.invoke(null, null) as T
}
@BeforeEach @BeforeEach
fun setup( fun setup(
@Autowired mockMvc: MockMvc, @Autowired mockMvc: MockMvc,
@ -119,7 +128,7 @@ class HomeControllerTest {
listOf( listOf(
Request( Request(
2L, 2L,
UUID.randomUUID().toString(), randomRequestId(),
"PSEUDO1", "PSEUDO1",
"PATIENT1", "PATIENT1",
Fingerprint("ashdkasdh"), Fingerprint("ashdkasdh"),
@ -128,7 +137,7 @@ class HomeControllerTest {
), ),
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"PSEUDO1", "PSEUDO1",
"PATIENT1", "PATIENT1",
Fingerprint("asdasdasd"), Fingerprint("asdasdasd"),
@ -147,9 +156,9 @@ class HomeControllerTest {
@Test @Test
@WithMockUser(username = "admin", roles = ["ADMIN"]) @WithMockUser(username = "admin", roles = ["ADMIN"])
fun testShouldShowRequestDetails() { fun testShouldShowRequestDetails() {
val requestId = UUID.randomUUID().toString() val requestId = randomRequestId()
whenever(requestService.findByUuid(any())).thenReturn( whenever(requestService.findByUuid(anyValueClass())).thenReturn(
Optional.of( Optional.of(
Request( Request(
2L, 2L,
@ -165,7 +174,7 @@ class HomeControllerTest {
) )
) )
val page = webClient.getPage<HtmlPage>("http://localhost/report/${requestId}") val page = webClient.getPage<HtmlPage>("http://localhost/report/${requestId.value}")
assertThat(page.querySelectorAll("tbody tr")).hasSize(1) assertThat(page.querySelectorAll("tbody tr")).hasSize(1)
assertThat(page.querySelectorAll("div.notification.info")).isEmpty() assertThat(page.querySelectorAll("div.notification.info")).isEmpty()
} }
@ -178,7 +187,7 @@ class HomeControllerTest {
listOf( listOf(
Request( Request(
2L, 2L,
UUID.randomUUID().toString(), randomRequestId(),
"PSEUDO1", "PSEUDO1",
"PATIENT1", "PATIENT1",
Fingerprint("ashdkasdh"), Fingerprint("ashdkasdh"),
@ -187,7 +196,7 @@ class HomeControllerTest {
), ),
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"PSEUDO1", "PSEUDO1",
"PATIENT1", "PATIENT1",
Fingerprint("asdasdasd"), Fingerprint("asdasdasd"),
@ -229,14 +238,14 @@ class HomeControllerTest {
@Test @Test
@WithMockUser(username = "admin", roles = ["ADMIN"]) @WithMockUser(username = "admin", roles = ["ADMIN"])
fun testShouldThrowNotFoundExceptionForUnknownReport() { fun testShouldThrowNotFoundExceptionForUnknownReport() {
val requestId = UUID.randomUUID().toString() val requestId = randomRequestId()
whenever(requestService.findByUuid(any())).thenReturn( whenever(requestService.findByUuid(anyValueClass())).thenReturn(
Optional.empty() Optional.empty()
) )
assertThrows<IOException> { assertThrows<IOException> {
webClient.getPage<HtmlPage>("http://localhost/report/${requestId}") webClient.getPage<HtmlPage>("http://localhost/report/${requestId.value}")
}.also { }.also {
assertThat(it).hasRootCauseInstanceOf(NotFoundException::class.java) assertThat(it).hasRootCauseInstanceOf(NotFoundException::class.java)
} }

View File

@ -22,14 +22,12 @@ package dev.dnpm.etl.processor.web
import com.gargoylesoftware.htmlunit.WebClient import com.gargoylesoftware.htmlunit.WebClient
import dev.dnpm.etl.processor.config.AppConfiguration import dev.dnpm.etl.processor.config.AppConfiguration
import dev.dnpm.etl.processor.config.AppSecurityConfiguration import dev.dnpm.etl.processor.config.AppSecurityConfiguration
import dev.dnpm.etl.processor.security.TokenService
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.junit.jupiter.MockitoExtension import org.mockito.junit.jupiter.MockitoExtension
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit.jupiter.SpringExtension import org.springframework.test.context.junit.jupiter.SpringExtension

View File

@ -26,6 +26,7 @@ import dev.dnpm.etl.processor.monitoring.CountedState
import dev.dnpm.etl.processor.monitoring.Request import dev.dnpm.etl.processor.monitoring.Request
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType import dev.dnpm.etl.processor.monitoring.RequestType
import dev.dnpm.etl.processor.randomRequestId
import dev.dnpm.etl.processor.services.RequestService import dev.dnpm.etl.processor.services.RequestService
import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.hasSize import org.hamcrest.Matchers.hasSize
@ -52,7 +53,6 @@ import reactor.core.publisher.Sinks
import reactor.test.StepVerifier import reactor.test.StepVerifier
import java.time.Instant import java.time.Instant
import java.time.temporal.ChronoUnit import java.time.temporal.ChronoUnit
import java.util.*
@WebMvcTest(controllers = [StatisticsRestController::class]) @WebMvcTest(controllers = [StatisticsRestController::class])
@ -187,7 +187,7 @@ class StatisticsRestControllerTest {
listOf( listOf(
Request( Request(
1, 1,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),
@ -197,7 +197,7 @@ class StatisticsRestControllerTest {
), ),
Request( Request(
2, 2,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678902", "TEST_12345678902",
"P2", "P2",
Fingerprint("0123456789abcdef2"), Fingerprint("0123456789abcdef2"),
@ -207,7 +207,7 @@ class StatisticsRestControllerTest {
), ),
Request( Request(
3, 3,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P2", "P2",
Fingerprint("0123456789abcdee1"), Fingerprint("0123456789abcdee1"),
@ -217,7 +217,7 @@ class StatisticsRestControllerTest {
), ),
Request( Request(
4, 4,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678902", "TEST_12345678902",
"P2", "P2",
Fingerprint("0123456789abcdef2"), Fingerprint("0123456789abcdef2"),
@ -227,7 +227,7 @@ class StatisticsRestControllerTest {
), ),
Request( Request(
5, 5,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678902", "TEST_12345678902",
"P2", "P2",
Fingerprint("0123456789abcdef2"), Fingerprint("0123456789abcdef2"),

View File

@ -22,6 +22,7 @@ package dev.dnpm.etl.processor.input
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import de.ukw.ccc.bwhc.dto.Consent import de.ukw.ccc.bwhc.dto.Consent
import de.ukw.ccc.bwhc.dto.MtbFile import de.ukw.ccc.bwhc.dto.MtbFile
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.services.RequestProcessor import dev.dnpm.etl.processor.services.RequestProcessor
import org.apache.kafka.clients.consumer.ConsumerRecord import org.apache.kafka.clients.consumer.ConsumerRecord
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@ -37,9 +38,9 @@ class KafkaInputListener(
val mtbFile = objectMapper.readValue(data.value(), MtbFile::class.java) val mtbFile = objectMapper.readValue(data.value(), MtbFile::class.java)
val firstRequestIdHeader = data.headers().headers("requestId")?.firstOrNull() val firstRequestIdHeader = data.headers().headers("requestId")?.firstOrNull()
val requestId = if (null != firstRequestIdHeader) { val requestId = if (null != firstRequestIdHeader) {
String(firstRequestIdHeader.value()) RequestId(String(firstRequestIdHeader.value()))
} else { } else {
"" RequestId("")
} }
if (mtbFile.consent.status == Consent.Status.ACTIVE) { if (mtbFile.consent.status == Consent.Status.ACTIVE) {

View File

@ -20,6 +20,8 @@
package dev.dnpm.etl.processor.monitoring package dev.dnpm.etl.processor.monitoring
import dev.dnpm.etl.processor.Fingerprint import dev.dnpm.etl.processor.Fingerprint
import dev.dnpm.etl.processor.randomRequestId
import dev.dnpm.etl.processor.RequestId
import org.springframework.data.annotation.Id import org.springframework.data.annotation.Id
import org.springframework.data.domain.Page import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable import org.springframework.data.domain.Pageable
@ -32,12 +34,10 @@ import org.springframework.data.repository.PagingAndSortingRepository
import java.time.Instant import java.time.Instant
import java.util.* import java.util.*
typealias RequestId = UUID
@Table("request") @Table("request")
data class Request( data class Request(
@Id val id: Long? = null, @Id val id: Long? = null,
val uuid: String = RequestId.randomUUID().toString(), val uuid: RequestId = randomRequestId(),
val patientId: String, val patientId: String,
val pid: String, val pid: String,
@Column("fingerprint") @Column("fingerprint")
@ -48,7 +48,7 @@ data class Request(
@Embedded.Nullable var report: Report? = null @Embedded.Nullable var report: Report? = null
) { ) {
constructor( constructor(
uuid: String, uuid: RequestId,
patientId: String, patientId: String,
pid: String, pid: String,
fingerprint: Fingerprint, fingerprint: Fingerprint,
@ -58,7 +58,7 @@ data class Request(
this(null, uuid, patientId, pid, fingerprint, type, status, Instant.now()) this(null, uuid, patientId, pid, fingerprint, type, status, Instant.now())
constructor( constructor(
uuid: String, uuid: RequestId,
patientId: String, patientId: String,
pid: String, pid: String,
fingerprint: Fingerprint, fingerprint: Fingerprint,
@ -85,7 +85,7 @@ interface RequestRepository : CrudRepository<Request, Long>, PagingAndSortingRep
fun findAllByPatientIdOrderByProcessedAtDesc(patientId: String): List<Request> fun findAllByPatientIdOrderByProcessedAtDesc(patientId: String): List<Request>
fun findByUuidEquals(uuid: String): Optional<Request> fun findByUuidEquals(uuid: RequestId): Optional<Request>
fun findRequestByPatientId(patientId: String, pageable: Pageable): Page<Request> fun findRequestByPatientId(patientId: String, pageable: Pageable): Page<Request>

View File

@ -22,6 +22,7 @@ package dev.dnpm.etl.processor.output
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import de.ukw.ccc.bwhc.dto.Consent import de.ukw.ccc.bwhc.dto.Consent
import de.ukw.ccc.bwhc.dto.MtbFile import de.ukw.ccc.bwhc.dto.MtbFile
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.config.KafkaProperties import dev.dnpm.etl.processor.config.KafkaProperties
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@ -101,5 +102,5 @@ class KafkaMtbFileSender(
return "{\"pid\": \"${request.patientId}\"}" return "{\"pid\": \"${request.patientId}\"}"
} }
data class Data(val requestId: String, val content: MtbFile) data class Data(val requestId: RequestId, val content: MtbFile)
} }

View File

@ -20,6 +20,7 @@
package dev.dnpm.etl.processor.output package dev.dnpm.etl.processor.output
import de.ukw.ccc.bwhc.dto.MtbFile import de.ukw.ccc.bwhc.dto.MtbFile
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import org.springframework.http.HttpStatusCode import org.springframework.http.HttpStatusCode
@ -32,9 +33,9 @@ interface MtbFileSender {
data class Response(val status: RequestStatus, val body: String = "") data class Response(val status: RequestStatus, val body: String = "")
data class MtbFileRequest(val requestId: String, val mtbFile: MtbFile) data class MtbFileRequest(val requestId: RequestId, val mtbFile: MtbFile)
data class DeleteRequest(val requestId: String, val patientId: String) data class DeleteRequest(val requestId: RequestId, val patientId: String)
} }

View File

@ -22,6 +22,8 @@ package dev.dnpm.etl.processor.services
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import de.ukw.ccc.bwhc.dto.MtbFile import de.ukw.ccc.bwhc.dto.MtbFile
import dev.dnpm.etl.processor.Fingerprint import dev.dnpm.etl.processor.Fingerprint
import dev.dnpm.etl.processor.randomRequestId
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.config.AppConfigProperties import dev.dnpm.etl.processor.config.AppConfigProperties
import dev.dnpm.etl.processor.monitoring.Report import dev.dnpm.etl.processor.monitoring.Report
import dev.dnpm.etl.processor.monitoring.Request import dev.dnpm.etl.processor.monitoring.Request
@ -50,10 +52,10 @@ class RequestProcessor(
) { ) {
fun processMtbFile(mtbFile: MtbFile) { fun processMtbFile(mtbFile: MtbFile) {
processMtbFile(mtbFile, UUID.randomUUID().toString()) processMtbFile(mtbFile, randomRequestId())
} }
fun processMtbFile(mtbFile: MtbFile, requestId: String) { fun processMtbFile(mtbFile: MtbFile, requestId: RequestId) {
val pid = mtbFile.patient.id val pid = mtbFile.patient.id
mtbFile pseudonymizeWith pseudonymizeService mtbFile pseudonymizeWith pseudonymizeService
@ -109,10 +111,10 @@ class RequestProcessor(
} }
fun processDeletion(patientId: String) { fun processDeletion(patientId: String) {
processDeletion(patientId, UUID.randomUUID().toString()) processDeletion(patientId, randomRequestId())
} }
fun processDeletion(patientId: String, requestId: String) { fun processDeletion(patientId: String, requestId: RequestId) {
try { try {
val patientPseudonym = pseudonymizeService.patientPseudonym(patientId) val patientPseudonym = pseudonymizeService.patientPseudonym(patientId)

View File

@ -19,6 +19,7 @@
package dev.dnpm.etl.processor.services package dev.dnpm.etl.processor.services
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.monitoring.* import dev.dnpm.etl.processor.monitoring.*
import org.springframework.data.domain.Page import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable import org.springframework.data.domain.Pageable
@ -36,7 +37,7 @@ class RequestService(
fun findAll(pageable: Pageable): Page<Request> = requestRepository.findAll(pageable) fun findAll(pageable: Pageable): Page<Request> = requestRepository.findAll(pageable)
fun findByUuid(uuid: String): Optional<Request> = fun findByUuid(uuid: RequestId): Optional<Request> =
requestRepository.findByUuidEquals(uuid) requestRepository.findByUuidEquals(uuid)
fun findRequestByPatientId(patientId: String, pageable: Pageable): Page<Request> = requestRepository.findRequestByPatientId(patientId, pageable) fun findRequestByPatientId(patientId: String, pageable: Pageable): Page<Request> = requestRepository.findRequestByPatientId(patientId, pageable)

View File

@ -19,6 +19,7 @@
package dev.dnpm.etl.processor.services package dev.dnpm.etl.processor.services
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.monitoring.Report import dev.dnpm.etl.processor.monitoring.Report
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@ -86,7 +87,7 @@ class ResponseProcessor(
} }
data class ResponseEvent( data class ResponseEvent(
val requestUuid: String, val requestUuid: RequestId,
val timestamp: Instant, val timestamp: Instant,
val status: RequestStatus, val status: RequestStatus,
val body: Optional<String> = Optional.empty() val body: Optional<String> = Optional.empty()

View File

@ -22,6 +22,7 @@ package dev.dnpm.etl.processor.services.kafka
import com.fasterxml.jackson.annotation.JsonAlias import com.fasterxml.jackson.annotation.JsonAlias
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.output.asRequestStatus import dev.dnpm.etl.processor.output.asRequestStatus
import dev.dnpm.etl.processor.services.ResponseEvent import dev.dnpm.etl.processor.services.ResponseEvent
@ -47,7 +48,7 @@ class KafkaResponseProcessor(
Optional.empty() Optional.empty()
}.ifPresentOrElse({ responseBody -> }.ifPresentOrElse({ responseBody ->
val event = ResponseEvent( val event = ResponseEvent(
responseBody.requestId, RequestId(responseBody.requestId),
Instant.ofEpochMilli(data.timestamp()), Instant.ofEpochMilli(data.timestamp()),
responseBody.statusCode.asRequestStatus(), responseBody.statusCode.asRequestStatus(),
when (responseBody.statusCode.asRequestStatus()) { when (responseBody.statusCode.asRequestStatus()) {

View File

@ -1,5 +1,26 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package dev.dnpm.etl.processor package dev.dnpm.etl.processor
import java.util.*
class Fingerprint(val value: String) { class Fingerprint(val value: String) {
override fun hashCode() = value.hashCode() override fun hashCode() = value.hashCode()
@ -9,3 +30,12 @@ class Fingerprint(val value: String) {
fun empty() = Fingerprint("") fun empty() = Fingerprint("")
} }
} }
@JvmInline
value class RequestId(val value: String) {
fun isBlank() = value.isBlank()
}
fun randomRequestId() = RequestId(UUID.randomUUID().toString())

View File

@ -20,8 +20,8 @@
package dev.dnpm.etl.processor.web package dev.dnpm.etl.processor.web
import dev.dnpm.etl.processor.NotFoundException import dev.dnpm.etl.processor.NotFoundException
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.monitoring.ReportService import dev.dnpm.etl.processor.monitoring.ReportService
import dev.dnpm.etl.processor.monitoring.RequestId
import dev.dnpm.etl.processor.services.RequestService import dev.dnpm.etl.processor.services.RequestService
import org.springframework.data.domain.Pageable import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Sort import org.springframework.data.domain.Sort
@ -65,7 +65,7 @@ class HomeController(
@GetMapping(path = ["/report/{id}"]) @GetMapping(path = ["/report/{id}"])
fun report(@PathVariable id: RequestId, model: Model): String { fun report(@PathVariable id: RequestId, model: Model): String {
val request = requestService.findByUuid(id.toString()).orElse(null) ?: throw NotFoundException() val request = requestService.findByUuid(id).orElse(null) ?: throw NotFoundException()
model.addAttribute("request", request) model.addAttribute("request", request)
model.addAttribute("issues", reportService.deserialize(request.report?.dataQualityReport)) model.addAttribute("issues", reportService.deserialize(request.report?.dataQualityReport))

View File

@ -0,0 +1,29 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package dev.dnpm.etl.processor
import org.mockito.ArgumentMatchers
inline fun <reified T> anyValueClass(): T {
val unboxedClass = T::class.java.declaredFields.first().type
return ArgumentMatchers.any(unboxedClass as Class<T>)
?: T::class.java.getDeclaredMethod("box-impl", unboxedClass)
.invoke(null, null) as T
}

View File

@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import de.ukw.ccc.bwhc.dto.Consent import de.ukw.ccc.bwhc.dto.Consent
import de.ukw.ccc.bwhc.dto.MtbFile import de.ukw.ccc.bwhc.dto.MtbFile
import de.ukw.ccc.bwhc.dto.Patient import de.ukw.ccc.bwhc.dto.Patient
import dev.dnpm.etl.processor.anyValueClass
import dev.dnpm.etl.processor.services.RequestProcessor import dev.dnpm.etl.processor.services.RequestProcessor
import org.apache.kafka.clients.consumer.ConsumerRecord import org.apache.kafka.clients.consumer.ConsumerRecord
import org.apache.kafka.common.header.internals.RecordHeader import org.apache.kafka.common.header.internals.RecordHeader
@ -92,7 +93,7 @@ class KafkaInputListenerTest {
ConsumerRecord("testtopic", 0, 0, -1L, TimestampType.NO_TIMESTAMP_TYPE, -1, -1, "", this.objectMapper.writeValueAsString(mtbFile), headers, Optional.empty()) ConsumerRecord("testtopic", 0, 0, -1L, TimestampType.NO_TIMESTAMP_TYPE, -1, -1, "", this.objectMapper.writeValueAsString(mtbFile), headers, Optional.empty())
) )
verify(requestProcessor, times(1)).processMtbFile(any(), anyString()) verify(requestProcessor, times(1)).processMtbFile(any(), anyValueClass())
} }
@Test @Test
@ -106,7 +107,7 @@ class KafkaInputListenerTest {
kafkaInputListener.onMessage( kafkaInputListener.onMessage(
ConsumerRecord("testtopic", 0, 0, -1L, TimestampType.NO_TIMESTAMP_TYPE, -1, -1, "", this.objectMapper.writeValueAsString(mtbFile), headers, Optional.empty()) ConsumerRecord("testtopic", 0, 0, -1L, TimestampType.NO_TIMESTAMP_TYPE, -1, -1, "", this.objectMapper.writeValueAsString(mtbFile), headers, Optional.empty())
) )
verify(requestProcessor, times(1)).processDeletion(anyString(), anyString()) verify(requestProcessor, times(1)).processDeletion(anyString(), anyValueClass())
} }
} }

View File

@ -21,6 +21,7 @@ package dev.dnpm.etl.processor.output
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import de.ukw.ccc.bwhc.dto.* import de.ukw.ccc.bwhc.dto.*
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.config.KafkaProperties import dev.dnpm.etl.processor.config.KafkaProperties
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
@ -72,7 +73,7 @@ class KafkaMtbFileSenderTest {
completedFuture(SendResult<String, String>(null, null)) completedFuture(SendResult<String, String>(null, null))
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString()) }.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
val response = kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest("TestID", mtbFile(Consent.Status.ACTIVE))) val response = kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile(Consent.Status.ACTIVE)))
assertThat(response.status).isEqualTo(testData.requestStatus) assertThat(response.status).isEqualTo(testData.requestStatus)
} }
@ -86,7 +87,7 @@ class KafkaMtbFileSenderTest {
completedFuture(SendResult<String, String>(null, null)) completedFuture(SendResult<String, String>(null, null))
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString()) }.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
val response = kafkaMtbFileSender.send(MtbFileSender.DeleteRequest("TestID", "PID")) val response = kafkaMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, "PID"))
assertThat(response.status).isEqualTo(testData.requestStatus) assertThat(response.status).isEqualTo(testData.requestStatus)
} }
@ -96,14 +97,14 @@ class KafkaMtbFileSenderTest {
completedFuture(SendResult<String, String>(null, null)) completedFuture(SendResult<String, String>(null, null))
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString()) }.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest("TestID", mtbFile(Consent.Status.ACTIVE))) kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile(Consent.Status.ACTIVE)))
val captor = argumentCaptor<String>() val captor = argumentCaptor<String>()
verify(kafkaTemplate, times(1)).send(anyString(), captor.capture(), captor.capture()) verify(kafkaTemplate, times(1)).send(anyString(), captor.capture(), captor.capture())
assertThat(captor.firstValue).isNotNull assertThat(captor.firstValue).isNotNull
assertThat(captor.firstValue).isEqualTo("{\"pid\": \"PID\"}") assertThat(captor.firstValue).isEqualTo("{\"pid\": \"PID\"}")
assertThat(captor.secondValue).isNotNull assertThat(captor.secondValue).isNotNull
assertThat(captor.secondValue).isEqualTo(objectMapper.writeValueAsString(kafkaRecordData("TestID", Consent.Status.ACTIVE))) assertThat(captor.secondValue).isEqualTo(objectMapper.writeValueAsString(kafkaRecordData(TEST_REQUEST_ID, Consent.Status.ACTIVE)))
} }
@Test @Test
@ -112,14 +113,14 @@ class KafkaMtbFileSenderTest {
completedFuture(SendResult<String, String>(null, null)) completedFuture(SendResult<String, String>(null, null))
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString()) }.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
kafkaMtbFileSender.send(MtbFileSender.DeleteRequest("TestID", "PID")) kafkaMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, "PID"))
val captor = argumentCaptor<String>() val captor = argumentCaptor<String>()
verify(kafkaTemplate, times(1)).send(anyString(), captor.capture(), captor.capture()) verify(kafkaTemplate, times(1)).send(anyString(), captor.capture(), captor.capture())
assertThat(captor.firstValue).isNotNull assertThat(captor.firstValue).isNotNull
assertThat(captor.firstValue).isEqualTo("{\"pid\": \"PID\"}") assertThat(captor.firstValue).isEqualTo("{\"pid\": \"PID\"}")
assertThat(captor.secondValue).isNotNull assertThat(captor.secondValue).isNotNull
assertThat(captor.secondValue).isEqualTo(objectMapper.writeValueAsString(kafkaRecordData("TestID", Consent.Status.REJECTED))) assertThat(captor.secondValue).isEqualTo(objectMapper.writeValueAsString(kafkaRecordData(TEST_REQUEST_ID, Consent.Status.REJECTED)))
} }
@ParameterizedTest @ParameterizedTest
@ -136,7 +137,7 @@ class KafkaMtbFileSenderTest {
completedFuture(SendResult<String, String>(null, null)) completedFuture(SendResult<String, String>(null, null))
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString()) }.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest("TestID", mtbFile(Consent.Status.ACTIVE))) kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile(Consent.Status.ACTIVE)))
val expectedCount = when (testData.exception) { val expectedCount = when (testData.exception) {
// OK - No Retry // OK - No Retry
@ -162,7 +163,7 @@ class KafkaMtbFileSenderTest {
completedFuture(SendResult<String, String>(null, null)) completedFuture(SendResult<String, String>(null, null))
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString()) }.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
kafkaMtbFileSender.send(MtbFileSender.DeleteRequest("TestID", "PID")) kafkaMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, "PID"))
val expectedCount = when (testData.exception) { val expectedCount = when (testData.exception) {
// OK - No Retry // OK - No Retry
@ -175,6 +176,8 @@ class KafkaMtbFileSenderTest {
} }
companion object { companion object {
val TEST_REQUEST_ID = RequestId("TestId")
fun mtbFile(consentStatus: Consent.Status): MtbFile { fun mtbFile(consentStatus: Consent.Status): MtbFile {
return if (consentStatus == Consent.Status.ACTIVE) { return if (consentStatus == Consent.Status.ACTIVE) {
MtbFile.builder() MtbFile.builder()
@ -210,7 +213,7 @@ class KafkaMtbFileSenderTest {
}.build() }.build()
} }
fun kafkaRecordData(requestId: String, consentStatus: Consent.Status): KafkaMtbFileSender.Data { fun kafkaRecordData(requestId: RequestId, consentStatus: Consent.Status): KafkaMtbFileSender.Data {
return KafkaMtbFileSender.Data(requestId, mtbFile(consentStatus)) return KafkaMtbFileSender.Data(requestId, mtbFile(consentStatus))
} }

View File

@ -20,6 +20,7 @@
package dev.dnpm.etl.processor.output package dev.dnpm.etl.processor.output
import de.ukw.ccc.bwhc.dto.* import de.ukw.ccc.bwhc.dto.*
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.config.RestTargetProperties import dev.dnpm.etl.processor.config.RestTargetProperties
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
@ -64,7 +65,7 @@ class RestMtbFileSenderTest {
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it) withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
} }
val response = restMtbFileSender.send(MtbFileSender.DeleteRequest("TestID", "PID")) val response = restMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, "PID"))
assertThat(response.status).isEqualTo(requestWithResponse.response.status) assertThat(response.status).isEqualTo(requestWithResponse.response.status)
assertThat(response.body).isEqualTo(requestWithResponse.response.body) assertThat(response.body).isEqualTo(requestWithResponse.response.body)
} }
@ -79,7 +80,7 @@ class RestMtbFileSenderTest {
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it) withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
} }
val response = restMtbFileSender.send(MtbFileSender.MtbFileRequest("TestID", mtbFile)) val response = restMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile))
assertThat(response.status).isEqualTo(requestWithResponse.response.status) assertThat(response.status).isEqualTo(requestWithResponse.response.status)
assertThat(response.body).isEqualTo(requestWithResponse.response.body) assertThat(response.body).isEqualTo(requestWithResponse.response.body)
} }
@ -108,7 +109,7 @@ class RestMtbFileSenderTest {
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it) withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
} }
val response = restMtbFileSender.send(MtbFileSender.MtbFileRequest("TestID", mtbFile)) val response = restMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile))
assertThat(response.status).isEqualTo(requestWithResponse.response.status) assertThat(response.status).isEqualTo(requestWithResponse.response.status)
assertThat(response.body).isEqualTo(requestWithResponse.response.body) assertThat(response.body).isEqualTo(requestWithResponse.response.body)
} }
@ -137,7 +138,7 @@ class RestMtbFileSenderTest {
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it) withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
} }
val response = restMtbFileSender.send(MtbFileSender.DeleteRequest("TestID", "PID")) val response = restMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, "PID"))
assertThat(response.status).isEqualTo(requestWithResponse.response.status) assertThat(response.status).isEqualTo(requestWithResponse.response.status)
assertThat(response.body).isEqualTo(requestWithResponse.response.body) assertThat(response.body).isEqualTo(requestWithResponse.response.body)
} }
@ -149,6 +150,8 @@ class RestMtbFileSenderTest {
val response: MtbFileSender.Response val response: MtbFileSender.Response
) )
val TEST_REQUEST_ID = RequestId("TestId")
private val warningBody = """ private val warningBody = """
{ {
"patient_id": "PID", "patient_id": "PID",

View File

@ -22,8 +22,11 @@ package dev.dnpm.etl.processor.services
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import de.ukw.ccc.bwhc.dto.* import de.ukw.ccc.bwhc.dto.*
import dev.dnpm.etl.processor.Fingerprint import dev.dnpm.etl.processor.Fingerprint
import dev.dnpm.etl.processor.randomRequestId
import dev.dnpm.etl.processor.config.AppConfigProperties import dev.dnpm.etl.processor.config.AppConfigProperties
import dev.dnpm.etl.processor.monitoring.* import dev.dnpm.etl.processor.monitoring.Request
import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType
import dev.dnpm.etl.processor.output.MtbFileSender import dev.dnpm.etl.processor.output.MtbFileSender
import dev.dnpm.etl.processor.output.RestMtbFileSender import dev.dnpm.etl.processor.output.RestMtbFileSender
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
@ -40,7 +43,6 @@ import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.whenever import org.mockito.kotlin.whenever
import org.springframework.context.ApplicationEventPublisher import org.springframework.context.ApplicationEventPublisher
import java.time.Instant import java.time.Instant
import java.util.*
@ExtendWith(MockitoExtension::class) @ExtendWith(MockitoExtension::class)
@ -88,7 +90,7 @@ class RequestProcessorTest {
doAnswer { doAnswer {
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga"), Fingerprint("zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga"),
@ -147,7 +149,7 @@ class RequestProcessorTest {
doAnswer { doAnswer {
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga"), Fingerprint("zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga"),
@ -206,7 +208,7 @@ class RequestProcessorTest {
doAnswer { doAnswer {
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("different"), Fingerprint("different"),
@ -269,7 +271,7 @@ class RequestProcessorTest {
doAnswer { doAnswer {
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("different"), Fingerprint("different"),

View File

@ -20,6 +20,7 @@
package dev.dnpm.etl.processor.services package dev.dnpm.etl.processor.services
import dev.dnpm.etl.processor.Fingerprint import dev.dnpm.etl.processor.Fingerprint
import dev.dnpm.etl.processor.randomRequestId
import dev.dnpm.etl.processor.monitoring.Request import dev.dnpm.etl.processor.monitoring.Request
import dev.dnpm.etl.processor.monitoring.RequestRepository import dev.dnpm.etl.processor.monitoring.RequestRepository
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
@ -33,7 +34,6 @@ import org.mockito.Mockito.*
import org.mockito.junit.jupiter.MockitoExtension import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.whenever import org.mockito.kotlin.whenever
import java.time.Instant import java.time.Instant
import java.util.*
@ExtendWith(MockitoExtension::class) @ExtendWith(MockitoExtension::class)
class RequestServiceTest { class RequestServiceTest {
@ -44,7 +44,7 @@ class RequestServiceTest {
private fun anyRequest() = any(Request::class.java) ?: Request( private fun anyRequest() = any(Request::class.java) ?: Request(
0L, 0L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_dummy", "TEST_dummy",
"PX", "PX",
Fingerprint("dummy"), Fingerprint("dummy"),
@ -66,7 +66,7 @@ class RequestServiceTest {
val requests = listOf( val requests = listOf(
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),
@ -76,7 +76,7 @@ class RequestServiceTest {
), ),
Request( Request(
2L, 2L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdefd"), Fingerprint("0123456789abcdefd"),
@ -86,7 +86,7 @@ class RequestServiceTest {
), ),
Request( Request(
3L, 3L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),
@ -106,7 +106,7 @@ class RequestServiceTest {
val requests = listOf( val requests = listOf(
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),
@ -116,7 +116,7 @@ class RequestServiceTest {
), ),
Request( Request(
2L, 2L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),
@ -126,7 +126,7 @@ class RequestServiceTest {
), ),
Request( Request(
3L, 3L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),
@ -146,7 +146,7 @@ class RequestServiceTest {
val requests = listOf( val requests = listOf(
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),
@ -156,7 +156,7 @@ class RequestServiceTest {
), ),
Request( Request(
1L, 1L,
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678902", "TEST_12345678902",
"P2", "P2",
Fingerprint("0123456789abcdef2"), Fingerprint("0123456789abcdef2"),
@ -189,7 +189,7 @@ class RequestServiceTest {
}.whenever(requestRepository).save(anyRequest()) }.whenever(requestRepository).save(anyRequest())
val request = Request( val request = Request(
UUID.randomUUID().toString(), randomRequestId(),
"TEST_12345678901", "TEST_12345678901",
"P1", "P1",
Fingerprint("0123456789abcdef1"), Fingerprint("0123456789abcdef1"),

View File

@ -20,6 +20,8 @@
package dev.dnpm.etl.processor.services package dev.dnpm.etl.processor.services
import dev.dnpm.etl.processor.Fingerprint import dev.dnpm.etl.processor.Fingerprint
import dev.dnpm.etl.processor.RequestId
import dev.dnpm.etl.processor.anyValueClass
import dev.dnpm.etl.processor.monitoring.Request import dev.dnpm.etl.processor.monitoring.Request
import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType import dev.dnpm.etl.processor.monitoring.RequestType
@ -29,7 +31,6 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource import org.junit.jupiter.params.provider.MethodSource
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mock import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.* import org.mockito.kotlin.*
@ -47,7 +48,7 @@ class ResponseProcessorTest {
private val testRequest = Request( private val testRequest = Request(
1L, 1L,
"TestID1234", RequestId("TestID1234"),
"PSEUDONYM-A", "PSEUDONYM-A",
"1", "1",
Fingerprint("dummyfingerprint"), Fingerprint("dummyfingerprint"),
@ -70,10 +71,10 @@ class ResponseProcessorTest {
fun shouldNotSaveStatusForUnknownRequest() { fun shouldNotSaveStatusForUnknownRequest() {
doAnswer { doAnswer {
Optional.empty<Request>() Optional.empty<Request>()
}.whenever(requestService).findByUuid(anyString()) }.whenever(requestService).findByUuid(anyValueClass())
val event = ResponseEvent( val event = ResponseEvent(
"TestID1234", RequestId("TestID1234"),
Instant.parse("2023-09-09T00:00:00Z"), Instant.parse("2023-09-09T00:00:00Z"),
RequestStatus.SUCCESS RequestStatus.SUCCESS
) )
@ -87,17 +88,17 @@ class ResponseProcessorTest {
fun shouldNotSaveStatusWithUnknownState() { fun shouldNotSaveStatusWithUnknownState() {
doAnswer { doAnswer {
Optional.of(testRequest) Optional.of(testRequest)
}.whenever(requestService).findByUuid(anyString()) }.whenever(requestService).findByUuid(anyValueClass())
val event = ResponseEvent( val event = ResponseEvent(
"TestID1234", RequestId("TestID1234"),
Instant.parse("2023-09-09T00:00:00Z"), Instant.parse("2023-09-09T00:00:00Z"),
RequestStatus.UNKNOWN RequestStatus.UNKNOWN
) )
this.responseProcessor.handleResponseEvent(event) this.responseProcessor.handleResponseEvent(event)
verify(requestService, never()).save(any()) verify(requestService, never()).save(any<Request>())
} }
@ParameterizedTest @ParameterizedTest
@ -105,10 +106,10 @@ class ResponseProcessorTest {
fun shouldSaveStatusForKnownRequest(requestStatus: RequestStatus) { fun shouldSaveStatusForKnownRequest(requestStatus: RequestStatus) {
doAnswer { doAnswer {
Optional.of(testRequest) Optional.of(testRequest)
}.whenever(requestService).findByUuid(anyString()) }.whenever(requestService).findByUuid(anyValueClass())
val event = ResponseEvent( val event = ResponseEvent(
"TestID1234", RequestId("TestID1234"),
Instant.parse("2023-09-09T00:00:00Z"), Instant.parse("2023-09-09T00:00:00Z"),
requestStatus requestStatus
) )