diff options
| author | Paul-Christian Volkmer | 2024-05-07 18:45:07 +0200 |
|---|---|---|
| committer | Paul-Christian Volkmer | 2024-05-07 18:45:07 +0200 |
| commit | a2124ba83dc274f7c765b6ed6aba386c5bf3a2a5 (patch) | |
| tree | 44a9a723e8bda9e47f09078eab5d80b9b117d2bf /src/integrationTest/kotlin | |
| parent | a046203339f2c96ac6e80836e03723bc9801cbf8 (diff) | |
test: add test for SSE endpoint
Diffstat (limited to 'src/integrationTest/kotlin')
| -rw-r--r-- | src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt index ed2a682..81a12d3 100644 --- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt +++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/web/StatisticsRestControllerTest.kt @@ -39,15 +39,22 @@ import org.mockito.kotlin.whenever 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.http.MediaType.TEXT_EVENT_STREAM import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource 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.client.MockMvcWebTestClient 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.temporal.ChronoUnit import java.util.* + @WebMvcTest(controllers = [StatisticsRestController::class]) @ExtendWith(value = [MockitoExtension::class, SpringExtension::class]) @ContextConfiguration( @@ -65,21 +72,23 @@ import java.util.* ] ) @MockBean( - RequestService::class, - MockSink::class + RequestService::class ) class StatisticsRestControllerTest { private lateinit var mockMvc: MockMvc + private lateinit var statisticsUpdateProducer: Sinks.Many<Any> private lateinit var requestService: RequestService @BeforeEach fun setup( @Autowired mockMvc: MockMvc, + @Autowired statisticsUpdateProducer: Sinks.Many<Any>, @Autowired requestService: RequestService ) { this.mockMvc = mockMvc + this.statisticsUpdateProducer = statisticsUpdateProducer 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() + } + } + } |
