use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class EncoderHttpMessageWriterTests method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
this.mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class);
this.response = new MockServerHttpResponse();
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageWriterTests method writePojo.
@Test
public void writePojo() {
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:{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n\n" + "data:{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\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 writeMultiLineString.
@Test
public void writeMultiLineString() {
Flux<String> source = Flux.just("foo\nbar", "foo\nbaz");
MockServerHttpResponse outputMessage = new MockServerHttpResponse();
messageWriter.write(source, ResolvableType.forClass(String.class), new MediaType("text", "event-stream"), outputMessage, Collections.emptyMap()).block(Duration.ofMillis(5000));
StepVerifier.create(outputMessage.getBodyAsString()).expectNext("data:foo\n" + "data:bar\n\n" + "data:foo\n" + "data:baz\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 writeString.
@Test
public void writeString() {
Flux<String> source = Flux.just("foo", "bar");
MockServerHttpResponse outputMessage = new MockServerHttpResponse();
messageWriter.write(source, ResolvableType.forClass(String.class), new MediaType("text", "event-stream"), outputMessage, Collections.emptyMap()).block(Duration.ofMillis(5000));
StepVerifier.create(outputMessage.getBodyAsString()).expectNext("data:foo\n\ndata: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 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();
}
Aggregations