|
37 | 37 | import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
38 | 38 |
|
39 | 39 | import static org.junit.Assert.*;
|
40 |
| -import static org.springframework.core.ResolvableType.*; |
| 40 | +import static org.springframework.core.ResolvableType.forClass; |
41 | 41 |
|
42 | 42 | /**
|
43 | 43 | * Unit tests for {@link ServerSentEventHttpMessageWriter}.
|
@@ -81,6 +81,24 @@ public void writeServerSentEvent() {
|
81 | 81 | .verify();
|
82 | 82 | }
|
83 | 83 |
|
| 84 | + @Test |
| 85 | + @SuppressWarnings("rawtypes") |
| 86 | + public void writeServerSentEventError() { |
| 87 | + ServerSentEvent<?> event = ServerSentEvent.builder().data("bar").id("c42").event("foo") |
| 88 | + .comment("bla\nbla bla\nbla bla bla").retry(Duration.ofMillis(123L)).build(); |
| 89 | + |
| 90 | + Flux<ServerSentEvent> source = Flux.concat( |
| 91 | + Flux.just(event), |
| 92 | + Flux.error(new RuntimeException())); |
| 93 | + MockServerHttpResponse outputMessage = new MockServerHttpResponse(); |
| 94 | + |
| 95 | + Mono<Void> result = this.messageWriter.write(source, forClass(ServerSentEvent.class), |
| 96 | + MediaType.TEXT_EVENT_STREAM, outputMessage, HINTS); |
| 97 | + |
| 98 | + StepVerifier.create(result) |
| 99 | + .verifyError(RuntimeException.class); |
| 100 | + } |
| 101 | + |
84 | 102 | @Test
|
85 | 103 | public void writeString() {
|
86 | 104 | Flux<String> source = Flux.just("foo", "bar");
|
@@ -172,8 +190,11 @@ private <T> void testWrite(Publisher<T> source, MockServerHttpResponse response,
|
172 | 190 | private <T> void testWrite(
|
173 | 191 | Publisher<T> source, MediaType mediaType, MockServerHttpResponse response, Class<T> clazz) {
|
174 | 192 |
|
175 |
| - this.messageWriter.write(source, forClass(clazz), mediaType, response, HINTS) |
176 |
| - .block(Duration.ofMillis(5000)); |
| 193 | + Mono<Void> result = |
| 194 | + this.messageWriter.write(source, forClass(clazz), mediaType, response, HINTS); |
| 195 | + |
| 196 | + StepVerifier.create(result) |
| 197 | + .verifyComplete(); |
177 | 198 | }
|
178 | 199 |
|
179 | 200 | }
|
0 commit comments