1
0
mirror of https://github.com/pcvolkmer/etl-processor.git synced 2025-07-04 23:42:54 +00:00

feat: use RequestId type

This commit is contained in:
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.Fingerprint
import dev.dnpm.etl.processor.output.MtbFileSender
import dev.dnpm.etl.processor.randomRequestId
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@ -61,7 +62,7 @@ class RequestRepositoryTest : AbstractTestcontainerTest() {
@Test
fun shouldSaveRequest() {
val request = Request(
RequestId.randomUUID().toString(),
randomRequestId(),
"TEST_12345678901",
"P1",
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.RequestType
import dev.dnpm.etl.processor.output.MtbFileSender
import dev.dnpm.etl.processor.randomRequestId
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
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.testcontainers.junit.jupiter.Testcontainers
import java.time.Instant
import java.util.*
@Testcontainers
@ExtendWith(SpringExtension::class)
@ -77,7 +77,7 @@ class RequestServiceIntegrationTest : AbstractTestcontainerTest() {
this.requestRepository.saveAll(
listOf(
Request(
UUID.randomUUID().toString(),
randomRequestId(),
"TEST_12345678901",
"P1",
Fingerprint("0123456789abcdef1"),
@ -87,7 +87,7 @@ class RequestServiceIntegrationTest : AbstractTestcontainerTest() {
),
// Should be ignored - wrong patient ID -->
Request(
UUID.randomUUID().toString(),
randomRequestId(),
"TEST_12345678902",
"P2",
Fingerprint("0123456789abcdef2"),
@ -97,7 +97,7 @@ class RequestServiceIntegrationTest : AbstractTestcontainerTest() {
),
// <--
Request(
UUID.randomUUID().toString(),
randomRequestId(),
"TEST_12345678901",
"P2",
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.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType
import dev.dnpm.etl.processor.randomRequestId
import dev.dnpm.etl.processor.services.RequestService
import org.assertj.core.api.Assertions.assertThat
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.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.anyString
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.any
@ -81,6 +83,13 @@ class HomeControllerTest {
private lateinit var mockMvc: MockMvc
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
fun setup(
@Autowired mockMvc: MockMvc,
@ -119,7 +128,7 @@ class HomeControllerTest {
listOf(
Request(
2L,
UUID.randomUUID().toString(),
randomRequestId(),
"PSEUDO1",
"PATIENT1",
Fingerprint("ashdkasdh"),
@ -128,7 +137,7 @@ class HomeControllerTest {
),
Request(
1L,
UUID.randomUUID().toString(),
randomRequestId(),
"PSEUDO1",
"PATIENT1",
Fingerprint("asdasdasd"),
@ -147,9 +156,9 @@ class HomeControllerTest {
@Test
@WithMockUser(username = "admin", roles = ["ADMIN"])
fun testShouldShowRequestDetails() {
val requestId = UUID.randomUUID().toString()
val requestId = randomRequestId()
whenever(requestService.findByUuid(any())).thenReturn(
whenever(requestService.findByUuid(anyValueClass())).thenReturn(
Optional.of(
Request(
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("div.notification.info")).isEmpty()
}
@ -178,7 +187,7 @@ class HomeControllerTest {
listOf(
Request(
2L,
UUID.randomUUID().toString(),
randomRequestId(),
"PSEUDO1",
"PATIENT1",
Fingerprint("ashdkasdh"),
@ -187,7 +196,7 @@ class HomeControllerTest {
),
Request(
1L,
UUID.randomUUID().toString(),
randomRequestId(),
"PSEUDO1",
"PATIENT1",
Fingerprint("asdasdasd"),
@ -229,14 +238,14 @@ class HomeControllerTest {
@Test
@WithMockUser(username = "admin", roles = ["ADMIN"])
fun testShouldThrowNotFoundExceptionForUnknownReport() {
val requestId = UUID.randomUUID().toString()
val requestId = randomRequestId()
whenever(requestService.findByUuid(any())).thenReturn(
whenever(requestService.findByUuid(anyValueClass())).thenReturn(
Optional.empty()
)
assertThrows<IOException> {
webClient.getPage<HtmlPage>("http://localhost/report/${requestId}")
webClient.getPage<HtmlPage>("http://localhost/report/${requestId.value}")
}.also {
assertThat(it).hasRootCauseInstanceOf(NotFoundException::class.java)
}

View File

@ -22,14 +22,12 @@ package dev.dnpm.etl.processor.web
import com.gargoylesoftware.htmlunit.WebClient
import dev.dnpm.etl.processor.config.AppConfiguration
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.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.junit.jupiter.MockitoExtension
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.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
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.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType
import dev.dnpm.etl.processor.randomRequestId
import dev.dnpm.etl.processor.services.RequestService
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.hasSize
@ -52,7 +53,6 @@ import reactor.core.publisher.Sinks
import reactor.test.StepVerifier
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.*
@WebMvcTest(controllers = [StatisticsRestController::class])
@ -187,7 +187,7 @@ class StatisticsRestControllerTest {
listOf(
Request(
1,
UUID.randomUUID().toString(),
randomRequestId(),
"TEST_12345678901",
"P1",
Fingerprint("0123456789abcdef1"),
@ -197,7 +197,7 @@ class StatisticsRestControllerTest {
),
Request(
2,
UUID.randomUUID().toString(),
randomRequestId(),
"TEST_12345678902",
"P2",
Fingerprint("0123456789abcdef2"),
@ -207,7 +207,7 @@ class StatisticsRestControllerTest {
),
Request(
3,
UUID.randomUUID().toString(),
randomRequestId(),
"TEST_12345678901",
"P2",
Fingerprint("0123456789abcdee1"),
@ -217,7 +217,7 @@ class StatisticsRestControllerTest {
),
Request(
4,
UUID.randomUUID().toString(),
randomRequestId(),
"TEST_12345678902",
"P2",
Fingerprint("0123456789abcdef2"),
@ -227,7 +227,7 @@ class StatisticsRestControllerTest {
),
Request(
5,
UUID.randomUUID().toString(),
randomRequestId(),
"TEST_12345678902",
"P2",
Fingerprint("0123456789abcdef2"),