|
21 | 21 | import java.nio.charset.StandardCharsets;
|
22 | 22 | import java.nio.file.Files;
|
23 | 23 | import java.util.ArrayList;
|
| 24 | +import java.util.Arrays; |
24 | 25 | import java.util.Collections;
|
25 | 26 | import java.util.HashMap;
|
26 | 27 | import java.util.List;
|
|
64 | 65 | import org.springframework.util.MultiValueMap;
|
65 | 66 |
|
66 | 67 | import static java.nio.charset.StandardCharsets.UTF_8;
|
| 68 | +import static org.hamcrest.Matchers.*; |
67 | 69 | import static org.junit.Assert.*;
|
68 | 70 | import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT;
|
69 | 71 |
|
@@ -320,6 +322,35 @@ public void fromMultipartData() throws Exception {
|
320 | 322 |
|
321 | 323 | }
|
322 | 324 |
|
| 325 | + @Test // SPR-16350 |
| 326 | + public void fromMultipartDataWithMultipleValues() { |
| 327 | + MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); |
| 328 | + map.put("name", Arrays.asList("value1", "value2")); |
| 329 | + BodyInserters.FormInserter<Object> inserter = BodyInserters.fromMultipartData(map); |
| 330 | + |
| 331 | + MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("http://example.com")); |
| 332 | + Mono<Void> result = inserter.insert(request, this.context); |
| 333 | + StepVerifier.create(result).expectComplete().verify(); |
| 334 | + |
| 335 | + StepVerifier.create(request.getBody().reduce(DataBuffer::write)) |
| 336 | + .consumeNextWith(dataBuffer -> { |
| 337 | + byte[] resultBytes = new byte[dataBuffer.readableByteCount()]; |
| 338 | + dataBuffer.read(resultBytes); |
| 339 | + DataBufferUtils.release(dataBuffer); |
| 340 | + String content = new String(resultBytes, StandardCharsets.UTF_8); |
| 341 | + assertThat(content, containsString("Content-Disposition: form-data; name=\"name\"\r\n" + |
| 342 | + "Content-Type: text/plain;charset=UTF-8\r\n" + |
| 343 | + "\r\n" + |
| 344 | + "value1")); |
| 345 | + assertThat(content, containsString("Content-Disposition: form-data; name=\"name\"\r\n" + |
| 346 | + "Content-Type: text/plain;charset=UTF-8\r\n" + |
| 347 | + "\r\n" + |
| 348 | + "value2")); |
| 349 | + }) |
| 350 | + .expectComplete() |
| 351 | + .verify(); |
| 352 | + } |
| 353 | + |
323 | 354 | @Test
|
324 | 355 | public void ofDataBuffers() throws Exception {
|
325 | 356 | DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
|
0 commit comments