Search in sources :

Example 1 with ResponseErrorHandler

use of cn.taketoday.web.client.ResponseErrorHandler in project today-infrastructure by TAKETODAY.

the class RestTemplateBuilderTests method errorHandlerShouldApply.

@Test
void errorHandlerShouldApply() {
    ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
    RestTemplate template = this.builder.errorHandler(errorHandler).build();
    assertThat(template.getErrorHandler()).isSameAs(errorHandler);
}
Also used : ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) RestTemplate(cn.taketoday.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 2 with ResponseErrorHandler

use of cn.taketoday.web.client.ResponseErrorHandler in project today-infrastructure by TAKETODAY.

the class RestTemplateBuilderTests method customizerShouldBeAppliedAtTheEnd.

@Test
void customizerShouldBeAppliedAtTheEnd() {
    ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
    ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    this.builder.interceptors(this.interceptor).messageConverters(this.messageConverter).rootUri("http://localhost:8080").errorHandler(errorHandler).basicAuthentication("spring", "boot").requestFactory(() -> requestFactory).customizers((restTemplate) -> {
        assertThat(restTemplate.getInterceptors()).hasSize(1);
        assertThat(restTemplate.getMessageConverters()).contains(this.messageConverter);
        assertThat(restTemplate.getUriTemplateHandler()).isInstanceOf(RootUriTemplateHandler.class);
        assertThat(restTemplate.getErrorHandler()).isEqualTo(errorHandler);
        ClientHttpRequestFactory actualRequestFactory = restTemplate.getRequestFactory();
        assertThat(actualRequestFactory).isInstanceOf(InterceptingClientHttpRequestFactory.class);
        ClientHttpRequestInitializer initializer = restTemplate.getHttpRequestInitializers().get(0);
        assertThat(initializer).isInstanceOf(RestTemplateBuilderClientHttpRequestInitializer.class);
    }).build();
}
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) ClientHttpRequestInitializer(cn.taketoday.http.client.ClientHttpRequestInitializer) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 3 with ResponseErrorHandler

use of cn.taketoday.web.client.ResponseErrorHandler in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method errorHandlerShouldApply.

@Test
void errorHandlerShouldApply() {
    ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
    RestTemplate template = this.builder.errorHandler(errorHandler).build();
    assertThat(template.getErrorHandler()).isSameAs(errorHandler);
}
Also used : ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) RestTemplate(cn.taketoday.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 4 with ResponseErrorHandler

use of cn.taketoday.web.client.ResponseErrorHandler in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method customizerShouldBeAppliedAtTheEnd.

@Test
void customizerShouldBeAppliedAtTheEnd() {
    ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
    ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    this.builder.interceptors(this.interceptor).messageConverters(this.messageConverter).rootUri("http://localhost:8080").errorHandler(errorHandler).basicAuthentication("spring", "boot").requestFactory(() -> requestFactory).customizers((restTemplate) -> {
        assertThat(restTemplate.getInterceptors()).hasSize(1);
        assertThat(restTemplate.getMessageConverters()).contains(this.messageConverter);
        assertThat(restTemplate.getUriTemplateHandler()).isInstanceOf(RootUriTemplateHandler.class);
        assertThat(restTemplate.getErrorHandler()).isEqualTo(errorHandler);
        ClientHttpRequestFactory actualRequestFactory = restTemplate.getRequestFactory();
        assertThat(actualRequestFactory).isInstanceOf(InterceptingClientHttpRequestFactory.class);
        ClientHttpRequestInitializer initializer = restTemplate.getHttpRequestInitializers().get(0);
        assertThat(initializer).isInstanceOf(RestTemplateBuilderClientHttpRequestInitializer.class);
    }).build();
}
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) ClientHttpRequestInitializer(cn.taketoday.http.client.ClientHttpRequestInitializer) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ResponseErrorHandler (cn.taketoday.web.client.ResponseErrorHandler)4 RestTemplate (cn.taketoday.web.client.RestTemplate)4 Test (org.junit.jupiter.api.Test)4 HttpHeaders (cn.taketoday.http.HttpHeaders)2 HttpMethod (cn.taketoday.http.HttpMethod)2 MediaType (cn.taketoday.http.MediaType)2 BufferingClientHttpRequestFactory (cn.taketoday.http.client.BufferingClientHttpRequestFactory)2 ClientHttpRequest (cn.taketoday.http.client.ClientHttpRequest)2 ClientHttpRequestFactory (cn.taketoday.http.client.ClientHttpRequestFactory)2 ClientHttpRequestInitializer (cn.taketoday.http.client.ClientHttpRequestInitializer)2 ClientHttpRequestInterceptor (cn.taketoday.http.client.ClientHttpRequestInterceptor)2 HttpComponentsClientHttpRequestFactory (cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory)2 InterceptingClientHttpRequestFactory (cn.taketoday.http.client.InterceptingClientHttpRequestFactory)2 OkHttp3ClientHttpRequestFactory (cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory)2 SimpleClientHttpRequestFactory (cn.taketoday.http.client.SimpleClientHttpRequestFactory)2 HttpMessageConverter (cn.taketoday.http.converter.HttpMessageConverter)2 ResourceHttpMessageConverter (cn.taketoday.http.converter.ResourceHttpMessageConverter)2 StringHttpMessageConverter (cn.taketoday.http.converter.StringHttpMessageConverter)2 ReflectionTestUtils (cn.taketoday.util.ReflectionTestUtils)2 UriTemplateHandler (cn.taketoday.web.util.UriTemplateHandler)2