use of cn.taketoday.core.LinkedMultiValueMap in project today-infrastructure by TAKETODAY.
the class BodyInsertersTests method fromMultipartData.
@Test
public void fromMultipartData() {
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.set("name 3", "value 3");
BodyInserters.FormInserter<Object> inserter = BodyInserters.fromMultipartData("name 1", "value 1").withPublisher("name 2", Flux.just("foo", "bar", "baz"), String.class).with(map);
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("https://example.com"));
Mono<Void> result = inserter.insert(request, this.context);
StepVerifier.create(result).expectComplete().verify();
}
use of cn.taketoday.core.LinkedMultiValueMap in project today-infrastructure by TAKETODAY.
the class BodyInsertersTests method fromMultipartDataWithMultipleValues.
// SPR-16350
@Test
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("https://example.com"));
Mono<Void> result = inserter.insert(request, this.context);
StepVerifier.create(result).expectComplete().verify();
StepVerifier.create(DataBufferUtils.join(request.getBody())).consumeNextWith(dataBuffer -> {
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(resultBytes);
DataBufferUtils.release(dataBuffer);
String content = new String(resultBytes, StandardCharsets.UTF_8);
assertThat(content).contains("Content-Disposition: form-data; name=\"name\"\r\n" + "Content-Type: text/plain;charset=UTF-8\r\n" + "Content-Length: 6\r\n" + "\r\n" + "value1");
assertThat(content).contains("Content-Disposition: form-data; name=\"name\"\r\n" + "Content-Type: text/plain;charset=UTF-8\r\n" + "Content-Length: 6\r\n" + "\r\n" + "value2");
}).expectComplete().verify();
}
use of cn.taketoday.core.LinkedMultiValueMap in project today-infrastructure by TAKETODAY.
the class BodyInsertersTests method fromFormDataMap.
@Test
public void fromFormDataMap() {
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.set("name 1", "value 1");
body.add("name 2", "value 2+1");
body.add("name 2", "value 2+2");
body.add("name 3", null);
BodyInserter<MultiValueMap<String, String>, ClientHttpRequest> inserter = BodyInserters.fromFormData(body);
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("https://example.com"));
Mono<Void> result = inserter.insert(request, this.context);
StepVerifier.create(result).expectComplete().verify();
StepVerifier.create(request.getBody()).consumeNextWith(dataBuffer -> {
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(resultBytes);
DataBufferUtils.release(dataBuffer);
assertThat(resultBytes).isEqualTo("name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8));
}).expectComplete().verify();
}
use of cn.taketoday.core.LinkedMultiValueMap in project today-infrastructure by TAKETODAY.
the class DefaultClientResponseTests method cookies.
@Test
public void cookies() {
ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>();
cookies.add("foo", cookie);
given(mockResponse.getCookies()).willReturn(cookies);
assertThat(defaultClientResponse.cookies()).isSameAs(cookies);
}
Aggregations