use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class MultipartHttpMessageWriterTests method parse.
static MultiValueMap<String, Part> parse(MockServerHttpResponse response, Map<String, Object> hints) {
MediaType contentType = response.getHeaders().getContentType();
assertThat(contentType.getParameter("boundary")).as("No boundary found").isNotNull();
// see if we can read what we wrote
DefaultPartHttpMessageReader partReader = new DefaultPartHttpMessageReader();
MultipartHttpMessageReader reader = new MultipartHttpMessageReader(partReader);
MockServerHttpRequest request = MockServerHttpRequest.post("/").contentType(MediaType.parseMediaType(contentType.toString())).body(response.getBody());
ResolvableType elementType = ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, Part.class);
MultiValueMap<String, Part> result = reader.readMono(elementType, request, hints).block(Duration.ofSeconds(5));
assertThat(result).isNotNull();
return result;
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize.
// gh-24312
@Test
public void maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize() {
int limit = this.jsonDecoder.getMaxInMemorySize();
String fooValue = getStringOfSize(limit) + "and then some more";
String content = "data:{\"foo\": \"" + fooValue + "\"}\n\n";
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Mono.just(stringBuffer(content)));
Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
ServerSentEventHttpMessageReader messageReader = new ServerSentEventHttpMessageReader(jacksonDecoder);
jacksonDecoder.setMaxInMemorySize(limit + 1024);
messageReader.setMaxInMemorySize(limit + 1024);
Flux<Pojo> data = messageReader.read(ResolvableType.forClass(Pojo.class), request, Collections.emptyMap()).cast(Pojo.class);
StepVerifier.create(data).consumeNextWith(pojo -> assertThat(pojo.getFoo()).isEqualTo(fooValue)).expectComplete().verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method readPojoWithCommentOnly.
// gh-24389
@Test
void readPojoWithCommentOnly() {
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Flux.just(stringBuffer(":ping\n"), stringBuffer("\n")));
Flux<Object> data = this.reader.read(ResolvableType.forType(String.class), request, Collections.emptyMap());
StepVerifier.create(data).expectComplete().verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method maxInMemoryLimit.
@Test
public void maxInMemoryLimit() {
this.reader.setMaxInMemorySize(17);
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Flux.just(stringBuffer("data:\"TOO MUCH DATA\"\ndata:bar\n\ndata:baz\n\n")));
Flux<String> data = this.reader.read(ResolvableType.forClass(String.class), request, Collections.emptyMap()).cast(String.class);
StepVerifier.create(data).expectError(DataBufferLimitException.class).verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method trimWhitespace.
@Test
public void trimWhitespace() {
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Mono.just(stringBuffer("data: \tfoo \ndata:bar\t\n\n")));
Flux<String> data = reader.read(ResolvableType.forClass(String.class), request, Collections.emptyMap()).cast(String.class);
StepVerifier.create(data).expectNext("\tfoo \nbar\t").expectComplete().verify();
}
Aggregations