use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTests method interceptorsShouldReplaceExisting.
@Test
void interceptorsShouldReplaceExisting() {
RestTemplate template = this.builder.interceptors(mock(ClientHttpRequestInterceptor.class)).interceptors(Collections.singleton(this.interceptor)).build();
assertThat(template.getInterceptors()).containsOnly(this.interceptor);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTests method detectRequestFactoryWhenFalseShouldDisableDetection.
@Test
void detectRequestFactoryWhenFalseShouldDisableDetection() {
RestTemplate restTemplate = this.builder.detectRequestFactory(false).build();
assertThat(restTemplate.getRequestFactory()).isInstanceOf(SimpleClientHttpRequestFactory.class);
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTests method additionalMessageConvertersShouldAddToExisting.
@Test
void additionalMessageConvertersShouldAddToExisting() {
HttpMessageConverter<?> resourceConverter = new ResourceHttpMessageConverter();
RestTemplate template = this.builder.messageConverters(resourceConverter).additionalMessageConverters(this.messageConverter).build();
assertThat(template.getMessageConverters()).containsOnly(resourceConverter, this.messageConverter);
}
use of cn.taketoday.web.client.RestTemplate 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")));
}
use of cn.taketoday.web.client.RestTemplate in project today-infrastructure by TAKETODAY.
the class ErrorHandlerIntegrationTests method handlingError.
@ParameterizedHttpServerTest
void handlingError(HttpServer httpServer) throws Exception {
startServer(httpServer);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
URI url = new URI("http://localhost:" + port + "/handling-error");
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
Aggregations