Search in sources :

Example 31 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class ServerSentEventHttpMessageReaderTests method decodeFullContentAsString.

// SPR-15331
@Test
public void decodeFullContentAsString() {
    String body = "data:foo\ndata:bar\n\ndata:baz\n\n";
    MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
    String actual = messageReader.readMono(ResolvableType.forClass(String.class), request, Collections.emptyMap()).cast(String.class).block(Duration.ZERO);
    assertEquals(body, actual);
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) Test(org.junit.Test)

Example 32 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class FormHttpMessageReaderTests method readFormAsMono.

@Test
public void readFormAsMono() {
    String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
    MockServerHttpRequest request = request(body);
    MultiValueMap<String, String> result = this.reader.readMono(null, request, null).block();
    assertEquals("Invalid result", 3, result.size());
    assertEquals("Invalid result", "value 1", result.getFirst("name 1"));
    List<String> values = result.get("name 2");
    assertEquals("Invalid result", 2, values.size());
    assertEquals("Invalid result", "value 2+1", values.get(0));
    assertEquals("Invalid result", "value 2+2", values.get(1));
    assertNull("Invalid result", result.getFirst("name 3"));
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) Test(org.junit.Test)

Example 33 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class ResourceHttpMessageWriterTests method shouldWriteResource.

@Test
public void shouldWriteResource() throws Exception {
    MockServerHttpRequest request = get("/").build();
    testWrite(request);
    assertThat(this.response.getHeaders().getContentType(), is(MediaType.TEXT_PLAIN));
    assertThat(this.response.getHeaders().getContentLength(), is(39L));
    assertThat(this.response.getHeaders().getFirst(HttpHeaders.ACCEPT_RANGES), is("bytes"));
    Mono<String> result = this.response.getBodyAsString();
    StepVerifier.create(result).expectNext("Spring Framework test resource content.").expectComplete().verify();
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) Test(org.junit.Test)

Example 34 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.

the class ResourceHttpMessageWriterTests method shouldWriteResourceRange.

@Test
public void shouldWriteResourceRange() throws Exception {
    MockServerHttpRequest request = get("/").range(HttpRange.createByteRange(0, 5)).build();
    testWrite(request);
    assertThat(this.response.getHeaders().getContentType(), is(MediaType.TEXT_PLAIN));
    assertThat(this.response.getHeaders().getFirst(HttpHeaders.CONTENT_RANGE), is("bytes 0-5/39"));
    assertThat(this.response.getHeaders().getFirst(HttpHeaders.ACCEPT_RANGES), is("bytes"));
    assertThat(this.response.getHeaders().getContentLength(), is(6L));
    Mono<String> result = this.response.getBodyAsString();
    StepVerifier.create(result).expectNext("Spring").expectComplete().verify();
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) Test(org.junit.Test)

Aggregations

MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)34 Test (org.junit.Test)33 Mono (reactor.core.publisher.Mono)14 MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)12 StepVerifier (reactor.test.StepVerifier)11 HttpHandler (org.springframework.http.server.reactive.HttpHandler)9 Flux (reactor.core.publisher.Flux)8 Assert (org.junit.Assert)7 DataBuffer (org.springframework.core.io.buffer.DataBuffer)7 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)7 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)7 Mockito (org.mockito.Mockito)6 HttpHeaders (org.springframework.http.HttpHeaders)6 HttpStatus (org.springframework.http.HttpStatus)6 ReactiveHttpInputMessage (org.springframework.http.ReactiveHttpInputMessage)6 ResponseStatusException (org.springframework.web.server.ResponseStatusException)6 ServerWebExchange (org.springframework.web.server.ServerWebExchange)6 Collections (java.util.Collections)5 MediaType (org.springframework.http.MediaType)5 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)5