From 2352688ccb1bd6a78fc2fb398aad869e0b235846 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 8 May 2019 11:48:41 +0200 Subject: [PATCH] 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. --- .../annotation/MultipartIntegrationTests.java | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartIntegrationTests.java index 523f06f609..e5c68c84ff 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartIntegrationTests.java @@ -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 .verifyComplete(); } + @Test + public void filePartsFlux() { + Mono 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 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 result = webClient @@ -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 filePartsMono, - @RequestPart("fileParts") Flux filePartsFlux, - @RequestPart("jsonPart") Person person, @RequestPart("jsonPart") Mono 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 return partFluxDescription(parts); } + @PostMapping("/filePartFlux") + Mono filePartsFlux(@RequestPart("fileParts") Flux parts) { + return partFluxDescription(parts); + } + + @PostMapping("/filePartMono") + Mono filePartsFlux(@RequestPart("fileParts") Mono parts) { + return partFluxDescription(Flux.from(parts)); + } + @PostMapping("/modelAttribute") String modelAttribute(@ModelAttribute FormBean formBean) { return formBean.toString();