|
|
|
|
@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
@@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
@ -64,6 +65,7 @@ import org.springframework.util.LinkedMultiValueMap;
@@ -64,6 +65,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8; |
|
|
|
|
import static org.hamcrest.Matchers.*; |
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT; |
|
|
|
|
|
|
|
|
|
@ -320,6 +322,35 @@ public class BodyInsertersTests {
@@ -320,6 +322,35 @@ public class BodyInsertersTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-16350
|
|
|
|
|
public void fromMultipartDataWithMultipleValues() { |
|
|
|
|
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); |
|
|
|
|
map.put("name", Arrays.asList("value1", "value2")); |
|
|
|
|
BodyInserters.FormInserter<Object> inserter = BodyInserters.fromMultipartData(map); |
|
|
|
|
|
|
|
|
|
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("http://example.com")); |
|
|
|
|
Mono<Void> result = inserter.insert(request, this.context); |
|
|
|
|
StepVerifier.create(result).expectComplete().verify(); |
|
|
|
|
|
|
|
|
|
StepVerifier.create(request.getBody().reduce(DataBuffer::write)) |
|
|
|
|
.consumeNextWith(dataBuffer -> { |
|
|
|
|
byte[] resultBytes = new byte[dataBuffer.readableByteCount()]; |
|
|
|
|
dataBuffer.read(resultBytes); |
|
|
|
|
DataBufferUtils.release(dataBuffer); |
|
|
|
|
String content = new String(resultBytes, StandardCharsets.UTF_8); |
|
|
|
|
assertThat(content, containsString("Content-Disposition: form-data; name=\"name\"\r\n" + |
|
|
|
|
"Content-Type: text/plain;charset=UTF-8\r\n" + |
|
|
|
|
"\r\n" + |
|
|
|
|
"value1")); |
|
|
|
|
assertThat(content, containsString("Content-Disposition: form-data; name=\"name\"\r\n" + |
|
|
|
|
"Content-Type: text/plain;charset=UTF-8\r\n" + |
|
|
|
|
"\r\n" + |
|
|
|
|
"value2")); |
|
|
|
|
}) |
|
|
|
|
.expectComplete() |
|
|
|
|
.verify(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void ofDataBuffers() throws Exception { |
|
|
|
|
DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); |
|
|
|
|
|