use of cn.taketoday.http.codec.ServerSentEvent in project today-infrastructure by TAKETODAY.
the class BodyInsertersTests method ofServerSentEventFlux.
@Test
public void ofServerSentEventFlux() {
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 cn.taketoday.http.codec.ServerSentEvent in project today-framework by TAKETODAY.
the class ReactiveTypeHandlerTests method writeServerSentEventsWithBuilder.
@Test
public void writeServerSentEventsWithBuilder() throws Exception {
ResolvableType type = ResolvableType.fromClassWithGenerics(ServerSentEvent.class, String.class);
Sinks.Many<ServerSentEvent<?>> sink = Sinks.many().unicast().onBackpressureBuffer();
SseEmitter sseEmitter = (SseEmitter) handleValue(sink.asFlux(), Flux.class, type);
EmitterHandler emitterHandler = new EmitterHandler();
sseEmitter.initialize(emitterHandler);
sink.tryEmitNext(ServerSentEvent.builder("foo").id("1").build());
sink.tryEmitNext(ServerSentEvent.builder("bar").id("2").build());
sink.tryEmitNext(ServerSentEvent.builder("baz").id("3").build());
sink.tryEmitComplete();
assertThat(emitterHandler.getValuesAsText()).isEqualTo("id:1\ndata:foo\n\nid:2\ndata:bar\n\nid:3\ndata:baz\n\n");
}
use of cn.taketoday.http.codec.ServerSentEvent in project today-framework by TAKETODAY.
the class BodyInsertersTests method ofServerSentEventFlux.
@Test
public void ofServerSentEventFlux() {
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 cn.taketoday.http.codec.ServerSentEvent in project today-infrastructure by TAKETODAY.
the class ReactiveTypeHandlerTests method writeServerSentEventsWithBuilder.
@Test
public void writeServerSentEventsWithBuilder() throws Exception {
ResolvableType type = ResolvableType.fromClassWithGenerics(ServerSentEvent.class, String.class);
Sinks.Many<ServerSentEvent<?>> sink = Sinks.many().unicast().onBackpressureBuffer();
SseEmitter sseEmitter = (SseEmitter) handleValue(sink.asFlux(), Flux.class, type);
EmitterHandler emitterHandler = new EmitterHandler();
sseEmitter.initialize(emitterHandler);
sink.tryEmitNext(ServerSentEvent.builder("foo").id("1").build());
sink.tryEmitNext(ServerSentEvent.builder("bar").id("2").build());
sink.tryEmitNext(ServerSentEvent.builder("baz").id("3").build());
sink.tryEmitComplete();
assertThat(emitterHandler.getValuesAsText()).isEqualTo("id:1\ndata:foo\n\nid:2\ndata:bar\n\nid:3\ndata:baz\n\n");
}
Aggregations