mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-04-20 17:56:50 +00:00
test: add test for SSE endpoint
This commit is contained in:
parent
a046203339
commit
a2124ba83d
@ -89,6 +89,7 @@ dependencies {
|
|||||||
integrationTestImplementation("org.testcontainers:postgresql")
|
integrationTestImplementation("org.testcontainers:postgresql")
|
||||||
integrationTestImplementation("com.tngtech.archunit:archunit:${versions["archunit"]}")
|
integrationTestImplementation("com.tngtech.archunit:archunit:${versions["archunit"]}")
|
||||||
integrationTestImplementation("net.sourceforge.htmlunit:htmlunit")
|
integrationTestImplementation("net.sourceforge.htmlunit:htmlunit")
|
||||||
|
integrationTestImplementation("org.springframework:spring-webflux")
|
||||||
// Override dependency version from org.testcontainers:junit-jupiter - CVE-2024-26308, CVE-2024-25710
|
// Override dependency version from org.testcontainers:junit-jupiter - CVE-2024-26308, CVE-2024-25710
|
||||||
integrationTestImplementation("org.apache.commons:commons-compress:1.26.1")
|
integrationTestImplementation("org.apache.commons:commons-compress:1.26.1")
|
||||||
}
|
}
|
||||||
|
@ -39,15 +39,22 @@ import org.mockito.kotlin.whenever
|
|||||||
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.boot.test.mock.mockito.MockBean
|
||||||
|
import org.springframework.http.MediaType.TEXT_EVENT_STREAM
|
||||||
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
|
||||||
|
import org.springframework.test.web.reactive.server.WebTestClient
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
|
import org.springframework.test.web.servlet.client.MockMvcWebTestClient
|
||||||
import org.springframework.test.web.servlet.get
|
import org.springframework.test.web.servlet.get
|
||||||
|
import org.springframework.web.context.WebApplicationContext
|
||||||
|
import reactor.core.publisher.Sinks
|
||||||
|
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.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
@WebMvcTest(controllers = [StatisticsRestController::class])
|
@WebMvcTest(controllers = [StatisticsRestController::class])
|
||||||
@ExtendWith(value = [MockitoExtension::class, SpringExtension::class])
|
@ExtendWith(value = [MockitoExtension::class, SpringExtension::class])
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
@ -65,21 +72,23 @@ import java.util.*
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(
|
@MockBean(
|
||||||
RequestService::class,
|
RequestService::class
|
||||||
MockSink::class
|
|
||||||
)
|
)
|
||||||
class StatisticsRestControllerTest {
|
class StatisticsRestControllerTest {
|
||||||
|
|
||||||
private lateinit var mockMvc: MockMvc
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
||||||
|
private lateinit var statisticsUpdateProducer: Sinks.Many<Any>
|
||||||
private lateinit var requestService: RequestService
|
private lateinit var requestService: RequestService
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup(
|
fun setup(
|
||||||
@Autowired mockMvc: MockMvc,
|
@Autowired mockMvc: MockMvc,
|
||||||
|
@Autowired statisticsUpdateProducer: Sinks.Many<Any>,
|
||||||
@Autowired requestService: RequestService
|
@Autowired requestService: RequestService
|
||||||
) {
|
) {
|
||||||
this.mockMvc = mockMvc
|
this.mockMvc = mockMvc
|
||||||
|
this.statisticsUpdateProducer = statisticsUpdateProducer
|
||||||
this.requestService = requestService
|
this.requestService = requestService
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,4 +280,31 @@ class StatisticsRestControllerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class SseTest {
|
||||||
|
private lateinit var webClient: WebTestClient
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup(
|
||||||
|
applicationContext: WebApplicationContext,
|
||||||
|
) {
|
||||||
|
this.webClient = MockMvcWebTestClient
|
||||||
|
.bindToApplicationContext(applicationContext).build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testShouldRequestSSE() {
|
||||||
|
statisticsUpdateProducer.emitComplete { _, _ -> true }
|
||||||
|
|
||||||
|
val result = webClient.get().uri("http://localhost/statistics/events").accept(TEXT_EVENT_STREAM).exchange()
|
||||||
|
.expectStatus().isOk()
|
||||||
|
.expectHeader().contentType(TEXT_EVENT_STREAM)
|
||||||
|
.returnResult(String::class.java)
|
||||||
|
|
||||||
|
StepVerifier.create(result.responseBody)
|
||||||
|
.expectComplete()
|
||||||
|
.verify()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user