Browse Source

MultipartIntegrationTests should not bind to same part multiple times

DefaultMultipartMessageReader does not cache the part contents, so
binding to the same part multiple times does not work.
Rewrote this test to use separate HTTP request instead.
pull/22926/head
Arjen Poutsma 6 years ago
parent
commit
2352688ccb
  1. 57
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartIntegrationTests.java

57
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -119,6 +119,36 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes @@ -119,6 +119,36 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.verifyComplete();
}
@Test
public void filePartsFlux() {
Mono<String> result = webClient
.post()
.uri("/filePartFlux")
.syncBody(generateBody())
.retrieve()
.bodyToMono(String.class);
StepVerifier.create(result)
.consumeNextWith(body -> assertEquals(
"[fileParts:foo.txt,fileParts:logo.png]", body))
.verifyComplete();
}
@Test
public void filePartsMono() {
Mono<String> result = webClient
.post()
.uri("/filePartMono")
.syncBody(generateBody())
.retrieve()
.bodyToMono(String.class);
StepVerifier.create(result)
.consumeNextWith(body -> assertEquals(
"[fileParts:foo.txt]", body))
.verifyComplete();
}
@Test
public void modelAttribute() {
Mono<String> result = webClient
@ -160,25 +190,12 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes @@ -160,25 +190,12 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
static class MultipartController {
@PostMapping("/requestPart")
void requestPart(
@RequestPart FormFieldPart fieldPart,
void requestPart(@RequestPart FormFieldPart fieldPart,
@RequestPart("fileParts") FilePart fileParts,
@RequestPart("fileParts") Mono<FilePart> filePartsMono,
@RequestPart("fileParts") Flux<FilePart> filePartsFlux,
@RequestPart("jsonPart") Person person,
@RequestPart("jsonPart") Mono<Person> personMono) {
assertEquals("fieldValue", fieldPart.value());
assertEquals("fileParts:foo.txt", partDescription(fileParts));
assertEquals("Jason", person.getName());
StepVerifier.create(partFluxDescription(filePartsFlux))
.consumeNextWith(content -> assertEquals("[fileParts:foo.txt,fileParts:logo.png]", content))
.verifyComplete();
StepVerifier.create(filePartsMono)
.consumeNextWith(filePart -> assertEquals("fileParts:foo.txt", partDescription(filePart)))
.verifyComplete();
StepVerifier.create(personMono)
.consumeNextWith(p -> assertEquals("Jason", p.getName()))
@ -195,6 +212,16 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes @@ -195,6 +212,16 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
return partFluxDescription(parts);
}
@PostMapping("/filePartFlux")
Mono<String> filePartsFlux(@RequestPart("fileParts") Flux<FilePart> parts) {
return partFluxDescription(parts);
}
@PostMapping("/filePartMono")
Mono<String> filePartsFlux(@RequestPart("fileParts") Mono<FilePart> parts) {
return partFluxDescription(Flux.from(parts));
}
@PostMapping("/modelAttribute")
String modelAttribute(@ModelAttribute FormBean formBean) {
return formBean.toString();

Loading…
Cancel
Save