|
28 | 28 |
|
29 | 29 | import org.springframework.beans.testfixture.beans.ITestBean; |
30 | 30 | import org.springframework.beans.testfixture.beans.TestBean; |
| 31 | +import org.springframework.core.ResolvableType; |
31 | 32 | import org.springframework.core.io.ClassPathResource; |
32 | 33 | import org.springframework.http.HttpMethod; |
33 | 34 | import org.springframework.http.MediaType; |
@@ -219,6 +220,19 @@ public void testMultipart() throws Exception { |
219 | 220 | assertThat(bean.getSomePartList().get(1).filename()).isEqualTo("spring.png"); |
220 | 221 | } |
221 | 222 |
|
| 223 | + @Test |
| 224 | + public void testConstructorMultipart() throws Exception { |
| 225 | + WebExchangeDataBinder binder = new WebExchangeDataBinder(null); |
| 226 | + binder.setTargetType(ResolvableType.forClass(ConstructorMultipartBean.class)); |
| 227 | + |
| 228 | + MultiValueMap<String, Object> data = new LinkedMultiValueMap<>(); |
| 229 | + data.add("part", new ClassPathResource("org/springframework/http/codec/multipart/foo.txt")); |
| 230 | + binder.construct(exchangeMultipart(data)).block(Duration.ofMillis(5000)); |
| 231 | + ConstructorMultipartBean bean = (ConstructorMultipartBean) binder.getTarget(); |
| 232 | + |
| 233 | + assertThat(bean.getPart().filename()).isEqualTo("foo.txt"); |
| 234 | + assertThat(bean.getNullableFilePart()).isNull(); |
| 235 | + } |
222 | 236 |
|
223 | 237 |
|
224 | 238 | private ServerWebExchange exchange(MultiValueMap<String, String> formData) { |
@@ -313,4 +327,24 @@ public void setSomePartList(List<FilePart> somePartList) { |
313 | 327 | } |
314 | 328 | } |
315 | 329 |
|
| 330 | + private static class ConstructorMultipartBean { |
| 331 | + private final FilePart part; |
| 332 | + private final FilePart nullableFilePart; |
| 333 | + |
| 334 | + public ConstructorMultipartBean( |
| 335 | + FilePart part, |
| 336 | + FilePart nullableFilePart |
| 337 | + ) { |
| 338 | + this.part = part; |
| 339 | + this.nullableFilePart = nullableFilePart; |
| 340 | + } |
| 341 | + |
| 342 | + public FilePart getPart() { |
| 343 | + return part; |
| 344 | + } |
| 345 | + |
| 346 | + public FilePart getNullableFilePart() { |
| 347 | + return nullableFilePart; |
| 348 | + } |
| 349 | + } |
316 | 350 | } |
0 commit comments