From 5fcc24f915f0e91106b5890e81854720e9ead1a4 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 29 Apr 2024 10:11:25 +0200 Subject: [PATCH] refactor: add additional constructors --- .../services/RequestServiceIntegrationTest.kt | 42 ++--- .../dnpm/etl/processor/monitoring/Request.kt | 23 ++- .../processor/services/RequestProcessor.kt | 24 +-- .../services/RequestProcessorTest.kt | 68 ++++---- .../processor/services/RequestServiceTest.kt | 158 +++++++++--------- 5 files changed, 167 insertions(+), 148 deletions(-) diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/services/RequestServiceIntegrationTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/services/RequestServiceIntegrationTest.kt index 88a3a08..3b8c0a7 100644 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/services/RequestServiceIntegrationTest.kt +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/services/RequestServiceIntegrationTest.kt @@ -76,33 +76,33 @@ class RequestServiceIntegrationTest : AbstractTestcontainerTest() { this.requestRepository.saveAll( listOf( Request( - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdef1", - type = RequestType.MTB_FILE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-07-07T02:00:00Z") + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdef1", + RequestType.MTB_FILE, + RequestStatus.SUCCESS, + Instant.parse("2023-07-07T02:00:00Z") ), // Should be ignored - wrong patient ID --> Request( - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678902", - pid = "P2", - fingerprint = "0123456789abcdef2", - type = RequestType.MTB_FILE, - status = RequestStatus.WARNING, - processedAt = Instant.parse("2023-08-08T00:00:00Z") + UUID.randomUUID().toString(), + "TEST_12345678902", + "P2", + "0123456789abcdef2", + RequestType.MTB_FILE, + RequestStatus.WARNING, + Instant.parse("2023-08-08T00:00:00Z") ), // <-- Request( - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P2", - fingerprint = "0123456789abcdee1", - type = RequestType.DELETE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-08-08T02:00:00Z") + UUID.randomUUID().toString(), + "TEST_12345678901", + "P2", + "0123456789abcdee1", + RequestType.DELETE, + RequestStatus.SUCCESS, + Instant.parse("2023-08-08T02:00:00Z") ) ) ) diff --git a/src/main/kotlin/dev/dnpm/etl/processor/monitoring/Request.kt b/src/main/kotlin/dev/dnpm/etl/processor/monitoring/Request.kt index 976c333..79a3a5b 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/monitoring/Request.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/monitoring/Request.kt @@ -43,7 +43,28 @@ data class Request( var status: RequestStatus, var processedAt: Instant = Instant.now(), @Embedded.Nullable var report: Report? = null -) +) { + constructor( + uuid: String, + patientId: String, + pid: String, + fingerprint: String, + type: RequestType, + status: RequestStatus + ) : + this(null, uuid, patientId, pid, fingerprint, type, status, Instant.now()) + + constructor( + uuid: String, + patientId: String, + pid: String, + fingerprint: String, + type: RequestType, + status: RequestStatus, + processedAt: Instant + ) : + this(null, uuid, patientId, pid, fingerprint, type, status, processedAt) +} @JvmRecord data class Report( diff --git a/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt b/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt index bdf07cb..939af16 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt @@ -62,12 +62,12 @@ class RequestProcessor( requestService.save( Request( - uuid = requestId, - patientId = request.mtbFile.patient.id, - pid = pid, - fingerprint = fingerprint(request.mtbFile), - status = RequestStatus.UNKNOWN, - type = RequestType.MTB_FILE + requestId, + request.mtbFile.patient.id, + pid, + fingerprint(request.mtbFile), + RequestType.MTB_FILE, + RequestStatus.UNKNOWN ) ) @@ -117,12 +117,12 @@ class RequestProcessor( requestService.save( Request( - uuid = requestId, - patientId = patientPseudonym, - pid = patientId, - fingerprint = fingerprint(patientPseudonym), - status = RequestStatus.UNKNOWN, - type = RequestType.DELETE + requestId, + patientPseudonym, + patientId, + fingerprint(patientPseudonym), + RequestType.DELETE, + RequestStatus.UNKNOWN ) ) diff --git a/src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt index 611c0ff..c82bccd 100644 --- a/src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt +++ b/src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt @@ -22,9 +22,7 @@ package dev.dnpm.etl.processor.services import com.fasterxml.jackson.databind.ObjectMapper import de.ukw.ccc.bwhc.dto.* import dev.dnpm.etl.processor.config.AppConfigProperties -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.monitoring.* import dev.dnpm.etl.processor.output.MtbFileSender import dev.dnpm.etl.processor.output.RestMtbFileSender import dev.dnpm.etl.processor.pseudonym.PseudonymizeService @@ -88,14 +86,14 @@ class RequestProcessorTest { fun testShouldSendMtbFileDuplicationAndSaveUnknownRequestStatusAtFirst() { doAnswer { Request( - id = 1L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga", - type = RequestType.MTB_FILE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-08-08T02:00:00Z") + 1L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga", + RequestType.MTB_FILE, + RequestStatus.SUCCESS, + Instant.parse("2023-08-08T02:00:00Z") ) }.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString()) @@ -147,14 +145,14 @@ class RequestProcessorTest { fun testShouldDetectMtbFileDuplicationAndSendDuplicationEvent() { doAnswer { Request( - id = 1L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga", - type = RequestType.MTB_FILE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-08-08T02:00:00Z") + 1L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga", + RequestType.MTB_FILE, + RequestStatus.SUCCESS, + Instant.parse("2023-08-08T02:00:00Z") ) }.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString()) @@ -206,14 +204,14 @@ class RequestProcessorTest { fun testShouldSendMtbFileAndSendSuccessEvent() { doAnswer { Request( - id = 1L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "different", - type = RequestType.MTB_FILE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-08-08T02:00:00Z") + 1L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "different", + RequestType.MTB_FILE, + RequestStatus.SUCCESS, + Instant.parse("2023-08-08T02:00:00Z") ) }.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString()) @@ -269,14 +267,14 @@ class RequestProcessorTest { fun testShouldSendMtbFileAndSendErrorEvent() { doAnswer { Request( - id = 1L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "different", - type = RequestType.MTB_FILE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-08-08T02:00:00Z") + 1L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "different", + RequestType.MTB_FILE, + RequestStatus.SUCCESS, + Instant.parse("2023-08-08T02:00:00Z") ) }.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString()) diff --git a/src/test/kotlin/dev/dnpm/etl/processor/services/RequestServiceTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/services/RequestServiceTest.kt index 3cf8804..02cd2cf 100644 --- a/src/test/kotlin/dev/dnpm/etl/processor/services/RequestServiceTest.kt +++ b/src/test/kotlin/dev/dnpm/etl/processor/services/RequestServiceTest.kt @@ -41,14 +41,14 @@ class RequestServiceTest { private lateinit var requestService: RequestService private fun anyRequest() = any(Request::class.java) ?: Request( - id = 0L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_dummy", - pid = "PX", - fingerprint = "dummy", - type = RequestType.MTB_FILE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-08-08T02:00:00Z") + 0L, + UUID.randomUUID().toString(), + "TEST_dummy", + "PX", + "dummy", + RequestType.MTB_FILE, + RequestStatus.SUCCESS, + Instant.parse("2023-08-08T02:00:00Z") ) @BeforeEach @@ -63,34 +63,34 @@ class RequestServiceTest { fun shouldIndicateLastRequestIsDeleteRequest() { val requests = listOf( Request( - id = 1L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdef1", - type = RequestType.MTB_FILE, - status = RequestStatus.WARNING, - processedAt = Instant.parse("2023-07-07T00:00:00Z") + 1L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdef1", + RequestType.MTB_FILE, + RequestStatus.WARNING, + Instant.parse("2023-07-07T00:00:00Z") ), Request( - id = 2L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdefd", - type = RequestType.DELETE, - status = RequestStatus.WARNING, - processedAt = Instant.parse("2023-07-07T02:00:00Z") + 2L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdefd", + RequestType.DELETE, + RequestStatus.WARNING, + Instant.parse("2023-07-07T02:00:00Z") ), Request( - id = 3L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdef1", - type = RequestType.MTB_FILE, - status = RequestStatus.UNKNOWN, - processedAt = Instant.parse("2023-08-11T00:00:00Z") + 3L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdef1", + RequestType.MTB_FILE, + RequestStatus.UNKNOWN, + Instant.parse("2023-08-11T00:00:00Z") ) ) @@ -103,34 +103,34 @@ class RequestServiceTest { fun shouldIndicateLastRequestIsNotDeleteRequest() { val requests = listOf( Request( - id = 1L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdef1", - type = RequestType.MTB_FILE, - status = RequestStatus.WARNING, - processedAt = Instant.parse("2023-07-07T00:00:00Z") + 1L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdef1", + RequestType.MTB_FILE, + RequestStatus.WARNING, + Instant.parse("2023-07-07T00:00:00Z") ), Request( - id = 2L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdef1", - type = RequestType.MTB_FILE, - status = RequestStatus.WARNING, - processedAt = Instant.parse("2023-07-07T02:00:00Z") + 2L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdef1", + RequestType.MTB_FILE, + RequestStatus.WARNING, + Instant.parse("2023-07-07T02:00:00Z") ), Request( - id = 3L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdef1", - type = RequestType.MTB_FILE, - status = RequestStatus.UNKNOWN, - processedAt = Instant.parse("2023-08-11T00:00:00Z") + 3L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdef1", + RequestType.MTB_FILE, + RequestStatus.UNKNOWN, + Instant.parse("2023-08-11T00:00:00Z") ) ) @@ -143,24 +143,24 @@ class RequestServiceTest { fun shouldReturnPatientsLastRequest() { val requests = listOf( Request( - id = 1L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdef1", - type = RequestType.DELETE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-07-07T02:00:00Z") + 1L, + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdef1", + RequestType.DELETE, + RequestStatus.SUCCESS, + Instant.parse("2023-07-07T02:00:00Z") ), Request( - id = 1L, - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678902", - pid = "P2", - fingerprint = "0123456789abcdef2", - type = RequestType.MTB_FILE, - status = RequestStatus.WARNING, - processedAt = Instant.parse("2023-08-08T00:00:00Z") + 1L, + UUID.randomUUID().toString(), + "TEST_12345678902", + "P2", + "0123456789abcdef2", + RequestType.MTB_FILE, + RequestStatus.WARNING, + Instant.parse("2023-08-08T00:00:00Z") ) ) @@ -187,13 +187,13 @@ class RequestServiceTest { }.`when`(requestRepository).save(anyRequest()) val request = Request( - uuid = UUID.randomUUID().toString(), - patientId = "TEST_12345678901", - pid = "P1", - fingerprint = "0123456789abcdef1", - type = RequestType.DELETE, - status = RequestStatus.SUCCESS, - processedAt = Instant.parse("2023-07-07T02:00:00Z") + UUID.randomUUID().toString(), + "TEST_12345678901", + "P1", + "0123456789abcdef1", + RequestType.DELETE, + RequestStatus.SUCCESS, + Instant.parse("2023-07-07T02:00:00Z") ) requestService.save(request)