use of org.springframework.http.codec.ServerSentEvent in project spring-framework by spring-projects.
the class BodyInsertersTests method ofServerSentEventFlux.
@Test
public void ofServerSentEventFlux() throws Exception {
ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
Flux<ServerSentEvent<String>> body = Flux.just(event);
BodyInserter<Flux<ServerSentEvent<String>>, ServerHttpResponse> inserter = BodyInserters.fromServerSentEvents(body);
MockServerHttpResponse response = new MockServerHttpResponse();
Mono<Void> result = inserter.insert(response, this.context);
StepVerifier.create(result).expectNextCount(0).expectComplete().verify();
}
use of org.springframework.http.codec.ServerSentEvent 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