use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework by TAKETODAY.
the class RestTemplateBuilderTests method connectTimeoutCanBeConfiguredOnHttpComponentsRequestFactory.
@Test
void connectTimeoutCanBeConfiguredOnHttpComponentsRequestFactory() {
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(HttpComponentsClientHttpRequestFactory.class).setConnectTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
assertThat(((RequestConfig) ReflectionTestUtils.getField(requestFactory, "requestConfig")).getConnectTimeout()).isEqualTo(1234);
}
use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework by TAKETODAY.
the class RestTemplateBuilderTests method connectTimeoutCanBeNullToUseDefault.
@Test
void connectTimeoutCanBeNullToUseDefault() {
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).setConnectTimeout(null).build().getRequestFactory();
assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", -1);
}
use of cn.taketoday.http.client.ClientHttpRequestFactory 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();
}
use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework by TAKETODAY.
the class RestTemplateBuilderTests method bufferRequestBodyCanBeConfiguredOnSimpleRequestFactory.
@Test
void bufferRequestBodyCanBeConfiguredOnSimpleRequestFactory() {
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).setBufferRequestBody(false).build().getRequestFactory();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", false);
requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).setBufferRequestBody(true).build().getRequestFactory();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).build().getRequestFactory();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
}
use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework by TAKETODAY.
the class RestTemplateBuilderTestsOkHttp3Tests method readTimeoutCanBeConfiguredOnOkHttpRequestFactory.
@Test
void readTimeoutCanBeConfiguredOnOkHttpRequestFactory() {
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(OkHttp3ClientHttpRequestFactory.class).setReadTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
assertThat(requestFactory).extracting("client", InstanceOfAssertFactories.type(OkHttpClient.class)).extracting(OkHttpClient::readTimeoutMillis).isEqualTo(1234);
}
Aggregations