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);
}
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"));
}
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();
}
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();
}
Aggregations