use of cn.taketoday.core.MultiValueMap in project today-infrastructure by TAKETODAY.
the class BodyExtractorsTests method toFormData.
@Test
public void toFormData() {
byte[] bytes = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
MockServerHttpRequest request = MockServerHttpRequest.post("/").contentType(MediaType.APPLICATION_FORM_URLENCODED).body(body);
Mono<MultiValueMap<String, String>> result = BodyExtractors.toFormData().extract(request, this.context);
StepVerifier.create(result).consumeNextWith(form -> {
assertThat(form.size()).as("Invalid result").isEqualTo(3);
assertThat(form.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = form.get("name 2");
assertThat(values.size()).as("Invalid result").isEqualTo(2);
assertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
assertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
assertThat(form.getFirst("name 3")).as("Invalid result").isNull();
}).expectComplete().verify();
}
Aggregations