use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageWriterTests method writeServerSentEvent.
@Test
public void writeServerSentEvent() {
ServerSentEvent<String> event = ServerSentEvent.<String>builder().data("bar").id("c42").event("foo").comment("bla\nbla bla\nbla bla bla").retry(Duration.ofMillis(123L)).build();
Mono<ServerSentEvent<String>> source = Mono.just(event);
MockServerHttpResponse outputMessage = new MockServerHttpResponse();
messageWriter.write(source, ResolvableType.forClass(ServerSentEvent.class), new MediaType("text", "event-stream"), outputMessage, Collections.emptyMap()).block(Duration.ofMillis(5000));
StepVerifier.create(outputMessage.getBodyAsString()).expectNext("id:c42\n" + "event:foo\n" + "retry:123\n" + ":bla\n" + ":bla bla\n" + ":bla bla bla\n" + "data:bar\n\n").expectComplete().verify();
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageWriterTests method writePojoWithPrettyPrint.
// SPR-14899
@Test
public void writePojoWithPrettyPrint() {
ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().indentOutput(true).build();
this.messageWriter = new ServerSentEventHttpMessageWriter(Collections.singletonList(new Jackson2JsonEncoder(mapper)));
Flux<Pojo> source = Flux.just(new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
MockServerHttpResponse outputMessage = new MockServerHttpResponse();
messageWriter.write(source, ResolvableType.forClass(Pojo.class), MediaType.TEXT_EVENT_STREAM, outputMessage, Collections.emptyMap()).block(Duration.ofMillis(5000));
StepVerifier.create(outputMessage.getBodyAsString()).expectNext("data:{\n" + "data: \"foo\" : \"foofoo\",\n" + "data: \"bar\" : \"barbar\"\n" + "data:}\n\n" + "data:{\n" + "data: \"foo\" : \"foofoofoo\",\n" + "data: \"bar\" : \"barbarbar\"\n" + "data:}\n\n").expectComplete().verify();
}
Aggregations