Search in sources :

Example 1 with MockServerHttpResponse

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();
}
Also used : MediaType(org.springframework.http.MediaType) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Before(org.junit.Before)

Example 2 with 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();
}
Also used : MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Example 3 with MockServerHttpResponse

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();
}
Also used : MediaType(org.springframework.http.MediaType) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Example 4 with MockServerHttpResponse

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();
}
Also used : MediaType(org.springframework.http.MediaType) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Example 5 with MockServerHttpResponse

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();
}
Also used : MediaType(org.springframework.http.MediaType) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Aggregations

MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)7 Test (org.junit.Test)6 MediaType (org.springframework.http.MediaType)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Before (org.junit.Before)1 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)1 ServerHttpResponse (org.springframework.http.server.reactive.ServerHttpResponse)1 Flux (reactor.core.publisher.Flux)1