Search in sources :

Example 11 with LinkedMultiValueMap

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();
}
Also used : LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) MockClientHttpRequest(cn.taketoday.web.testfixture.http.client.reactive.MockClientHttpRequest) Test(org.junit.jupiter.api.Test)

Example 12 with LinkedMultiValueMap

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();
}
Also used : LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) MockClientHttpRequest(cn.taketoday.web.testfixture.http.client.reactive.MockClientHttpRequest) Test(org.junit.jupiter.api.Test)

Example 13 with LinkedMultiValueMap

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();
}
Also used : LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) MockClientHttpRequest(cn.taketoday.web.testfixture.http.client.reactive.MockClientHttpRequest) MockClientHttpRequest(cn.taketoday.web.testfixture.http.client.reactive.MockClientHttpRequest) ClientHttpRequest(cn.taketoday.http.client.reactive.ClientHttpRequest) LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) MultiValueMap(cn.taketoday.core.MultiValueMap) Test(org.junit.jupiter.api.Test)

Example 14 with LinkedMultiValueMap

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);
}
Also used : LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) ResponseCookie(cn.taketoday.http.ResponseCookie) Test(org.junit.jupiter.api.Test)

Aggregations

LinkedMultiValueMap (cn.taketoday.core.LinkedMultiValueMap)14 Test (org.junit.jupiter.api.Test)12 MultiValueMap (cn.taketoday.core.MultiValueMap)6 MockClientHttpRequest (cn.taketoday.web.testfixture.http.client.reactive.MockClientHttpRequest)6 ServletException (jakarta.servlet.ServletException)4 IOException (java.io.IOException)4 ByteArrayResource (cn.taketoday.core.io.ByteArrayResource)2 ContentDisposition (cn.taketoday.http.ContentDisposition)2 HttpEntity (cn.taketoday.http.HttpEntity)2 HttpHeaders (cn.taketoday.http.HttpHeaders)2 ResponseCookie (cn.taketoday.http.ResponseCookie)2 ClientHttpRequest (cn.taketoday.http.client.reactive.ClientHttpRequest)2 MultipartException (cn.taketoday.web.bind.MultipartException)2 NotMultipartRequestException (cn.taketoday.web.bind.NotMultipartRequestException)2 RestTemplate (cn.taketoday.web.client.RestTemplate)2 MaxUploadSizeExceededException (cn.taketoday.web.multipart.MaxUploadSizeExceededException)2 MultipartFile (cn.taketoday.web.multipart.MultipartFile)2 MultipartConfigElement (jakarta.servlet.MultipartConfigElement)2 ServletContext (jakarta.servlet.ServletContext)2 Dynamic (jakarta.servlet.ServletRegistration.Dynamic)2