use of org.springframework.http.MediaType.TEXT_EVENT_STREAM in project spring-framework by spring-projects.
the class SseIntegrationTests method sseAsEvent.
@Test
public void sseAsEvent() throws Exception {
ResolvableType type = forClassWithGenerics(ServerSentEvent.class, String.class);
Flux<ServerSentEvent<String>> result = this.webClient.get().uri("/event").accept(TEXT_EVENT_STREAM).exchange().flatMap(response -> response.body(toFlux(type)));
StepVerifier.create(result).consumeNextWith(event -> {
assertEquals("0", event.id().get());
assertEquals("foo", event.data().get());
assertEquals("bar", event.comment().get());
assertFalse(event.event().isPresent());
assertFalse(event.retry().isPresent());
}).consumeNextWith(event -> {
assertEquals("1", event.id().get());
assertEquals("foo", event.data().get());
assertEquals("bar", event.comment().get());
assertFalse(event.event().isPresent());
assertFalse(event.retry().isPresent());
}).thenCancel().verify(Duration.ofSeconds(5L));
}
Aggregations