Search in sources :

Example 1 with ClientHttpRequest

use of cn.taketoday.http.client.ClientHttpRequest in project today-infrastructure by TAKETODAY.

the class RestTemplateBuilderTests method requestCustomizersAddsCustomizers.

// @Test
// // gh-17885
// void defaultHeaderWhenUsingMockRestServiceServerAddsHeader() {
// RestTemplate template = this.builder.defaultHeader("spring", "boot").build();
// MockRestServiceServer.bindTo(template).build();
// ClientHttpRequest request = createRequest(template);
// assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("boot")));
// }
@Test
void requestCustomizersAddsCustomizers() {
    RestTemplate template = this.builder.requestCustomizers((request) -> request.getHeaders().add("spring", "framework")).build();
    ClientHttpRequest request = createRequest(template);
    assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("framework")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) Arrays(java.util.Arrays) Mock(org.mockito.Mock) HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequestConfig(org.apache.http.client.config.RequestConfig) Mockito.spy(org.mockito.Mockito.spy) Supplier(java.util.function.Supplier) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) HttpMethod(cn.taketoday.http.HttpMethod) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) HttpHeaders(cn.taketoday.http.HttpHeaders) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) ClientHttpRequestInitializer(cn.taketoday.http.client.ClientHttpRequestInitializer) ReflectionTestUtils(cn.taketoday.util.ReflectionTestUtils) URI(java.net.URI) ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) InOrder(org.mockito.InOrder) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Set(java.util.Set) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) Mockito.inOrder(org.mockito.Mockito.inOrder) RestTemplate(cn.taketoday.web.client.RestTemplate) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) ClientHttpRequestInterceptor(cn.taketoday.http.client.ClientHttpRequestInterceptor) Mockito.mock(org.mockito.Mockito.mock) RestTemplate(cn.taketoday.web.client.RestTemplate) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Test(org.junit.jupiter.api.Test)

Example 2 with ClientHttpRequest

use of cn.taketoday.http.client.ClientHttpRequest in project today-infrastructure by TAKETODAY.

the class RestTemplateBuilderTests method additionalRequestCustomizersAddsCustomizers.

@Test
void additionalRequestCustomizersAddsCustomizers() {
    RestTemplate template = this.builder.requestCustomizers((request) -> request.getHeaders().add("spring", "framework")).additionalRequestCustomizers((request) -> request.getHeaders().add("for", "java")).build();
    ClientHttpRequest request = createRequest(template);
    assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("framework"))).contains(entry("for", Collections.singletonList("java")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) Arrays(java.util.Arrays) Mock(org.mockito.Mock) HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequestConfig(org.apache.http.client.config.RequestConfig) Mockito.spy(org.mockito.Mockito.spy) Supplier(java.util.function.Supplier) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) HttpMethod(cn.taketoday.http.HttpMethod) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) HttpHeaders(cn.taketoday.http.HttpHeaders) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) ClientHttpRequestInitializer(cn.taketoday.http.client.ClientHttpRequestInitializer) ReflectionTestUtils(cn.taketoday.util.ReflectionTestUtils) URI(java.net.URI) ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) InOrder(org.mockito.InOrder) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Set(java.util.Set) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) Mockito.inOrder(org.mockito.Mockito.inOrder) RestTemplate(cn.taketoday.web.client.RestTemplate) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) ClientHttpRequestInterceptor(cn.taketoday.http.client.ClientHttpRequestInterceptor) Mockito.mock(org.mockito.Mockito.mock) RestTemplate(cn.taketoday.web.client.RestTemplate) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Test(org.junit.jupiter.api.Test)

Example 3 with ClientHttpRequest

use of cn.taketoday.http.client.ClientHttpRequest in project today-infrastructure by TAKETODAY.

the class AbstractRequestExpectationManager method getRequestDetails.

/**
 * Return details of executed requests.
 */
protected String getRequestDetails() {
    StringBuilder sb = new StringBuilder();
    sb.append(this.requests.size()).append(" request(s) executed");
    if (!this.requests.isEmpty()) {
        sb.append(":\n");
        for (ClientHttpRequest request : this.requests) {
            sb.append(request.toString()).append('\n');
        }
    } else {
        sb.append(".\n");
    }
    return sb.toString();
}
Also used : ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest)

Example 4 with ClientHttpRequest

use of cn.taketoday.http.client.ClientHttpRequest in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method additionalRequestCustomizersAddsCustomizers.

@Test
void additionalRequestCustomizersAddsCustomizers() {
    RestTemplate template = this.builder.requestCustomizers((request) -> request.getHeaders().add("spring", "framework")).additionalRequestCustomizers((request) -> request.getHeaders().add("for", "java")).build();
    ClientHttpRequest request = createRequest(template);
    assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("framework"))).contains(entry("for", Collections.singletonList("java")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) Arrays(java.util.Arrays) Mock(org.mockito.Mock) HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequestConfig(org.apache.http.client.config.RequestConfig) Mockito.spy(org.mockito.Mockito.spy) Supplier(java.util.function.Supplier) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) HttpMethod(cn.taketoday.http.HttpMethod) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) HttpHeaders(cn.taketoday.http.HttpHeaders) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) ClientHttpRequestInitializer(cn.taketoday.http.client.ClientHttpRequestInitializer) ReflectionTestUtils(cn.taketoday.util.ReflectionTestUtils) URI(java.net.URI) ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) InOrder(org.mockito.InOrder) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Set(java.util.Set) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) Mockito.inOrder(org.mockito.Mockito.inOrder) RestTemplate(cn.taketoday.web.client.RestTemplate) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) ClientHttpRequestInterceptor(cn.taketoday.http.client.ClientHttpRequestInterceptor) Mockito.mock(org.mockito.Mockito.mock) RestTemplate(cn.taketoday.web.client.RestTemplate) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Test(org.junit.jupiter.api.Test)

Example 5 with ClientHttpRequest

use of cn.taketoday.http.client.ClientHttpRequest in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method requestCustomizersAddsCustomizers.

// @Test
// // gh-17885
// void defaultHeaderWhenUsingMockRestServiceServerAddsHeader() {
// RestTemplate template = this.builder.defaultHeader("spring", "boot").build();
// MockRestServiceServer.bindTo(template).build();
// ClientHttpRequest request = createRequest(template);
// assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("boot")));
// }
@Test
void requestCustomizersAddsCustomizers() {
    RestTemplate template = this.builder.requestCustomizers((request) -> request.getHeaders().add("spring", "framework")).build();
    ClientHttpRequest request = createRequest(template);
    assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("framework")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) Arrays(java.util.Arrays) Mock(org.mockito.Mock) HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequestConfig(org.apache.http.client.config.RequestConfig) Mockito.spy(org.mockito.Mockito.spy) Supplier(java.util.function.Supplier) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) HttpMethod(cn.taketoday.http.HttpMethod) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) HttpHeaders(cn.taketoday.http.HttpHeaders) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) ClientHttpRequestInitializer(cn.taketoday.http.client.ClientHttpRequestInitializer) ReflectionTestUtils(cn.taketoday.util.ReflectionTestUtils) URI(java.net.URI) ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) InOrder(org.mockito.InOrder) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Set(java.util.Set) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) Mockito.inOrder(org.mockito.Mockito.inOrder) RestTemplate(cn.taketoday.web.client.RestTemplate) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) ClientHttpRequestInterceptor(cn.taketoday.http.client.ClientHttpRequestInterceptor) Mockito.mock(org.mockito.Mockito.mock) RestTemplate(cn.taketoday.web.client.RestTemplate) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ClientHttpRequest (cn.taketoday.http.client.ClientHttpRequest)18 RestTemplate (cn.taketoday.web.client.RestTemplate)10 Test (org.junit.jupiter.api.Test)10 URI (java.net.URI)8 ClientHttpRequestInitializer (cn.taketoday.http.client.ClientHttpRequestInitializer)6 SimpleClientHttpRequestFactory (cn.taketoday.http.client.SimpleClientHttpRequestFactory)6 HttpHeaders (cn.taketoday.http.HttpHeaders)4 HttpMethod (cn.taketoday.http.HttpMethod)4 MediaType (cn.taketoday.http.MediaType)4 BufferingClientHttpRequestFactory (cn.taketoday.http.client.BufferingClientHttpRequestFactory)4 ClientHttpRequestFactory (cn.taketoday.http.client.ClientHttpRequestFactory)4 ClientHttpRequestInterceptor (cn.taketoday.http.client.ClientHttpRequestInterceptor)4 HttpComponentsClientHttpRequestFactory (cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory)4 InterceptingClientHttpRequestFactory (cn.taketoday.http.client.InterceptingClientHttpRequestFactory)4 OkHttp3ClientHttpRequestFactory (cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory)4 HttpMessageConverter (cn.taketoday.http.converter.HttpMessageConverter)4 ResourceHttpMessageConverter (cn.taketoday.http.converter.ResourceHttpMessageConverter)4 StringHttpMessageConverter (cn.taketoday.http.converter.StringHttpMessageConverter)4 ReflectionTestUtils (cn.taketoday.util.ReflectionTestUtils)4 ResponseErrorHandler (cn.taketoday.web.client.ResponseErrorHandler)4