mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-07-02 22:42:55 +00:00
feat: use RequestId type
This commit is contained in:
29
src/test/kotlin/dev/dnpm/etl/processor/helpers.kt
Normal file
29
src/test/kotlin/dev/dnpm/etl/processor/helpers.kt
Normal 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
|
||||
}
|
@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import de.ukw.ccc.bwhc.dto.Consent
|
||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||
import de.ukw.ccc.bwhc.dto.Patient
|
||||
import dev.dnpm.etl.processor.anyValueClass
|
||||
import dev.dnpm.etl.processor.services.RequestProcessor
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord
|
||||
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())
|
||||
)
|
||||
|
||||
verify(requestProcessor, times(1)).processMtbFile(any(), anyString())
|
||||
verify(requestProcessor, times(1)).processMtbFile(any(), anyValueClass())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -106,7 +107,7 @@ class KafkaInputListenerTest {
|
||||
kafkaInputListener.onMessage(
|
||||
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())
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,7 @@ package dev.dnpm.etl.processor.output
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import de.ukw.ccc.bwhc.dto.*
|
||||
import dev.dnpm.etl.processor.RequestId
|
||||
import dev.dnpm.etl.processor.config.KafkaProperties
|
||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@ -72,7 +73,7 @@ class KafkaMtbFileSenderTest {
|
||||
completedFuture(SendResult<String, String>(null, null))
|
||||
}.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)
|
||||
}
|
||||
|
||||
@ -86,7 +87,7 @@ class KafkaMtbFileSenderTest {
|
||||
completedFuture(SendResult<String, String>(null, null))
|
||||
}.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)
|
||||
}
|
||||
|
||||
@ -96,14 +97,14 @@ class KafkaMtbFileSenderTest {
|
||||
completedFuture(SendResult<String, String>(null, null))
|
||||
}.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>()
|
||||
verify(kafkaTemplate, times(1)).send(anyString(), captor.capture(), captor.capture())
|
||||
assertThat(captor.firstValue).isNotNull
|
||||
assertThat(captor.firstValue).isEqualTo("{\"pid\": \"PID\"}")
|
||||
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
|
||||
@ -112,14 +113,14 @@ class KafkaMtbFileSenderTest {
|
||||
completedFuture(SendResult<String, String>(null, null))
|
||||
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
|
||||
|
||||
kafkaMtbFileSender.send(MtbFileSender.DeleteRequest("TestID", "PID"))
|
||||
kafkaMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, "PID"))
|
||||
|
||||
val captor = argumentCaptor<String>()
|
||||
verify(kafkaTemplate, times(1)).send(anyString(), captor.capture(), captor.capture())
|
||||
assertThat(captor.firstValue).isNotNull
|
||||
assertThat(captor.firstValue).isEqualTo("{\"pid\": \"PID\"}")
|
||||
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
|
||||
@ -136,7 +137,7 @@ class KafkaMtbFileSenderTest {
|
||||
completedFuture(SendResult<String, String>(null, null))
|
||||
}.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) {
|
||||
// OK - No Retry
|
||||
@ -162,7 +163,7 @@ class KafkaMtbFileSenderTest {
|
||||
completedFuture(SendResult<String, String>(null, null))
|
||||
}.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) {
|
||||
// OK - No Retry
|
||||
@ -175,6 +176,8 @@ class KafkaMtbFileSenderTest {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TEST_REQUEST_ID = RequestId("TestId")
|
||||
|
||||
fun mtbFile(consentStatus: Consent.Status): MtbFile {
|
||||
return if (consentStatus == Consent.Status.ACTIVE) {
|
||||
MtbFile.builder()
|
||||
@ -210,7 +213,7 @@ class KafkaMtbFileSenderTest {
|
||||
}.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))
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
package dev.dnpm.etl.processor.output
|
||||
|
||||
import de.ukw.ccc.bwhc.dto.*
|
||||
import dev.dnpm.etl.processor.RequestId
|
||||
import dev.dnpm.etl.processor.config.RestTargetProperties
|
||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@ -64,7 +65,7 @@ class RestMtbFileSenderTest {
|
||||
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.body).isEqualTo(requestWithResponse.response.body)
|
||||
}
|
||||
@ -79,7 +80,7 @@ class RestMtbFileSenderTest {
|
||||
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.body).isEqualTo(requestWithResponse.response.body)
|
||||
}
|
||||
@ -108,7 +109,7 @@ class RestMtbFileSenderTest {
|
||||
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.body).isEqualTo(requestWithResponse.response.body)
|
||||
}
|
||||
@ -137,7 +138,7 @@ class RestMtbFileSenderTest {
|
||||
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.body).isEqualTo(requestWithResponse.response.body)
|
||||
}
|
||||
@ -149,6 +150,8 @@ class RestMtbFileSenderTest {
|
||||
val response: MtbFileSender.Response
|
||||
)
|
||||
|
||||
val TEST_REQUEST_ID = RequestId("TestId")
|
||||
|
||||
private val warningBody = """
|
||||
{
|
||||
"patient_id": "PID",
|
||||
|
@ -22,8 +22,11 @@ package dev.dnpm.etl.processor.services
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import de.ukw.ccc.bwhc.dto.*
|
||||
import dev.dnpm.etl.processor.Fingerprint
|
||||
import dev.dnpm.etl.processor.randomRequestId
|
||||
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.RestMtbFileSender
|
||||
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
|
||||
@ -40,7 +43,6 @@ import org.mockito.kotlin.argumentCaptor
|
||||
import org.mockito.kotlin.whenever
|
||||
import org.springframework.context.ApplicationEventPublisher
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
@ -88,7 +90,7 @@ class RequestProcessorTest {
|
||||
doAnswer {
|
||||
Request(
|
||||
1L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga"),
|
||||
@ -147,7 +149,7 @@ class RequestProcessorTest {
|
||||
doAnswer {
|
||||
Request(
|
||||
1L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga"),
|
||||
@ -206,7 +208,7 @@ class RequestProcessorTest {
|
||||
doAnswer {
|
||||
Request(
|
||||
1L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("different"),
|
||||
@ -269,7 +271,7 @@ class RequestProcessorTest {
|
||||
doAnswer {
|
||||
Request(
|
||||
1L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("different"),
|
||||
|
@ -20,6 +20,7 @@
|
||||
package dev.dnpm.etl.processor.services
|
||||
|
||||
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.RequestRepository
|
||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||
@ -33,7 +34,6 @@ import org.mockito.Mockito.*
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.kotlin.whenever
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
class RequestServiceTest {
|
||||
@ -44,7 +44,7 @@ class RequestServiceTest {
|
||||
|
||||
private fun anyRequest() = any(Request::class.java) ?: Request(
|
||||
0L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_dummy",
|
||||
"PX",
|
||||
Fingerprint("dummy"),
|
||||
@ -66,7 +66,7 @@ class RequestServiceTest {
|
||||
val requests = listOf(
|
||||
Request(
|
||||
1L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("0123456789abcdef1"),
|
||||
@ -76,7 +76,7 @@ class RequestServiceTest {
|
||||
),
|
||||
Request(
|
||||
2L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("0123456789abcdefd"),
|
||||
@ -86,7 +86,7 @@ class RequestServiceTest {
|
||||
),
|
||||
Request(
|
||||
3L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("0123456789abcdef1"),
|
||||
@ -106,7 +106,7 @@ class RequestServiceTest {
|
||||
val requests = listOf(
|
||||
Request(
|
||||
1L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("0123456789abcdef1"),
|
||||
@ -116,7 +116,7 @@ class RequestServiceTest {
|
||||
),
|
||||
Request(
|
||||
2L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("0123456789abcdef1"),
|
||||
@ -126,7 +126,7 @@ class RequestServiceTest {
|
||||
),
|
||||
Request(
|
||||
3L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("0123456789abcdef1"),
|
||||
@ -146,7 +146,7 @@ class RequestServiceTest {
|
||||
val requests = listOf(
|
||||
Request(
|
||||
1L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("0123456789abcdef1"),
|
||||
@ -156,7 +156,7 @@ class RequestServiceTest {
|
||||
),
|
||||
Request(
|
||||
1L,
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678902",
|
||||
"P2",
|
||||
Fingerprint("0123456789abcdef2"),
|
||||
@ -189,7 +189,7 @@ class RequestServiceTest {
|
||||
}.whenever(requestRepository).save(anyRequest())
|
||||
|
||||
val request = Request(
|
||||
UUID.randomUUID().toString(),
|
||||
randomRequestId(),
|
||||
"TEST_12345678901",
|
||||
"P1",
|
||||
Fingerprint("0123456789abcdef1"),
|
||||
|
@ -20,6 +20,8 @@
|
||||
package dev.dnpm.etl.processor.services
|
||||
|
||||
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.RequestStatus
|
||||
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.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.kotlin.*
|
||||
@ -47,7 +48,7 @@ class ResponseProcessorTest {
|
||||
|
||||
private val testRequest = Request(
|
||||
1L,
|
||||
"TestID1234",
|
||||
RequestId("TestID1234"),
|
||||
"PSEUDONYM-A",
|
||||
"1",
|
||||
Fingerprint("dummyfingerprint"),
|
||||
@ -70,10 +71,10 @@ class ResponseProcessorTest {
|
||||
fun shouldNotSaveStatusForUnknownRequest() {
|
||||
doAnswer {
|
||||
Optional.empty<Request>()
|
||||
}.whenever(requestService).findByUuid(anyString())
|
||||
}.whenever(requestService).findByUuid(anyValueClass())
|
||||
|
||||
val event = ResponseEvent(
|
||||
"TestID1234",
|
||||
RequestId("TestID1234"),
|
||||
Instant.parse("2023-09-09T00:00:00Z"),
|
||||
RequestStatus.SUCCESS
|
||||
)
|
||||
@ -87,17 +88,17 @@ class ResponseProcessorTest {
|
||||
fun shouldNotSaveStatusWithUnknownState() {
|
||||
doAnswer {
|
||||
Optional.of(testRequest)
|
||||
}.whenever(requestService).findByUuid(anyString())
|
||||
}.whenever(requestService).findByUuid(anyValueClass())
|
||||
|
||||
val event = ResponseEvent(
|
||||
"TestID1234",
|
||||
RequestId("TestID1234"),
|
||||
Instant.parse("2023-09-09T00:00:00Z"),
|
||||
RequestStatus.UNKNOWN
|
||||
)
|
||||
|
||||
this.responseProcessor.handleResponseEvent(event)
|
||||
|
||||
verify(requestService, never()).save(any())
|
||||
verify(requestService, never()).save(any<Request>())
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ -105,10 +106,10 @@ class ResponseProcessorTest {
|
||||
fun shouldSaveStatusForKnownRequest(requestStatus: RequestStatus) {
|
||||
doAnswer {
|
||||
Optional.of(testRequest)
|
||||
}.whenever(requestService).findByUuid(anyString())
|
||||
}.whenever(requestService).findByUuid(anyValueClass())
|
||||
|
||||
val event = ResponseEvent(
|
||||
"TestID1234",
|
||||
RequestId("TestID1234"),
|
||||
Instant.parse("2023-09-09T00:00:00Z"),
|
||||
requestStatus
|
||||
)
|
||||
|
Reference in New Issue
Block a user