|
2 | 2 |
|
3 | 3 | import io.github.wimdeblauwe.errorhandlingspringbootstarter.exception.MyCustomHttpResponseStatusException; |
4 | 4 | import io.github.wimdeblauwe.errorhandlingspringbootstarter.mapper.HttpResponseStatusFromExceptionMapper; |
| 5 | +import org.hamcrest.Matchers; |
5 | 6 | import org.junit.jupiter.api.Test; |
6 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
7 | 8 | import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; |
8 | 9 | import org.springframework.context.annotation.Bean; |
9 | 10 | import org.springframework.context.annotation.Import; |
10 | 11 | import org.springframework.http.HttpStatusCode; |
| 12 | +import org.springframework.http.MediaType; |
11 | 13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
12 | 14 | import org.springframework.security.web.SecurityFilterChain; |
13 | 15 | import org.springframework.test.web.servlet.MockMvc; |
| 16 | +import org.springframework.test.web.servlet.MvcResult; |
14 | 17 |
|
15 | 18 | import java.time.Instant; |
16 | 19 |
|
| 20 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; |
17 | 21 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
18 | 22 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; |
19 | | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
20 | | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 23 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; |
21 | 24 |
|
22 | 25 | @WebMvcTest(value = IntegrationTestRestController.class, |
23 | 26 | properties = {"spring.main.allow-bean-definition-overriding=true", |
@@ -58,6 +61,18 @@ void testExceptionWithCustomStatus() throws Exception { |
58 | 61 | ; |
59 | 62 | } |
60 | 63 |
|
| 64 | + @Test |
| 65 | + void testSse() throws Exception { |
| 66 | + MvcResult result = mockMvc.perform(get("/integration-test/sse") |
| 67 | + .accept(MediaType.TEXT_EVENT_STREAM)) |
| 68 | + .andExpect(request().asyncStarted()) |
| 69 | + .andReturn(); |
| 70 | + |
| 71 | + mockMvc.perform(asyncDispatch(result)) |
| 72 | + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
| 73 | + .andExpect(content().string(Matchers.containsString("Simulated SSE error"))); |
| 74 | + } |
| 75 | + |
61 | 76 | static class WebSecurityConfig { |
62 | 77 | @Bean |
63 | 78 | public SecurityFilterChain securityFilterChain(HttpSecurity http) { |
|
0 commit comments