Search in sources :

Example 21 with RestTemplate

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

the class ErrorHandlerIntegrationTests method emptyPathSegments.

@ParameterizedHttpServerTest
// SPR-15560
void emptyPathSegments(HttpServer httpServer) throws Exception {
    startServer(httpServer);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
    URI url = new URI("http://localhost:" + port + "//");
    ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
    // Jetty 10+ rejects empty path segments, see https://github.com/eclipse/jetty.project/issues/6302,
    // but an application can apply CompactPathRule via RewriteHandler:
    // https://www.eclipse.org/jetty/documentation/jetty-11/programming_guide.php
    HttpStatus expectedStatus = (httpServer instanceof JettyHttpServer ? HttpStatus.BAD_REQUEST : HttpStatus.OK);
    assertThat(response.getStatusCode()).isEqualTo(expectedStatus);
}
Also used : HttpStatus(cn.taketoday.http.HttpStatus) RestTemplate(cn.taketoday.web.client.RestTemplate) URI(java.net.URI) JettyHttpServer(cn.taketoday.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer)

Example 22 with RestTemplate

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

the class EchoHandlerIntegrationTests method echo.

@ParameterizedHttpServerTest
public void echo(HttpServer httpServer) throws Exception {
    startServer(httpServer);
    RestTemplate restTemplate = new RestTemplate();
    byte[] body = randomBytes();
    RequestEntity<byte[]> request = RequestEntity.post(new URI("http://localhost:" + port)).body(body);
    ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
    assertThat(response.getBody()).isEqualTo(body);
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) URI(java.net.URI)

Example 23 with RestTemplate

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

the class RandomHandlerIntegrationTests method random.

@ParameterizedHttpServerTest
void random(HttpServer httpServer) throws Exception {
    startServer(httpServer);
    // TODO: fix Reactor support
    RestTemplate restTemplate = new RestTemplate();
    byte[] body = randomBytes();
    RequestEntity<byte[]> request = RequestEntity.post(new URI("http://localhost:" + port)).body(body);
    ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
    assertThat(response.getBody()).isNotNull();
    assertThat(response.getHeaders().getContentLength()).isEqualTo(RESPONSE_SIZE);
    assertThat(response.getBody().length).isEqualTo(RESPONSE_SIZE);
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) URI(java.net.URI)

Example 24 with RestTemplate

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

the class RootUriTemplateHandlerTests method applyShouldWrapExistingTemplate.

@Test
void applyShouldWrapExistingTemplate() {
    given(this.delegate.expand(anyString(), any(Object[].class))).willReturn(this.uri);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setUriTemplateHandler(this.delegate);
    this.handler = RootUriTemplateHandler.addTo(restTemplate, "https://example.com");
    Object[] uriVariables = new Object[0];
    URI expanded = this.handler.expand("/hello", uriVariables);
    then(this.delegate).should().expand("https://example.com/hello", uriVariables);
    assertThat(expanded).isEqualTo(this.uri);
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 25 with RestTemplate

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

the class HeaderRequestMatchersIntegrationTests method setup.

@BeforeEach
public void setup() {
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new StringHttpMessageConverter());
    converters.add(new MappingJackson2HttpMessageConverter());
    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);
    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
Also used : MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) ArrayList(java.util.ArrayList) RestTemplate(cn.taketoday.web.client.RestTemplate) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

RestTemplate (cn.taketoday.web.client.RestTemplate)100 Test (org.junit.jupiter.api.Test)66 URI (java.net.URI)30 StringHttpMessageConverter (cn.taketoday.http.converter.StringHttpMessageConverter)14 ClientHttpRequest (cn.taketoday.http.client.ClientHttpRequest)12 SimpleClientHttpRequestFactory (cn.taketoday.http.client.SimpleClientHttpRequestFactory)12 BufferingClientHttpRequestFactory (cn.taketoday.http.client.BufferingClientHttpRequestFactory)10 ClientHttpRequestInterceptor (cn.taketoday.http.client.ClientHttpRequestInterceptor)10 HttpComponentsClientHttpRequestFactory (cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory)10 HttpMessageConverter (cn.taketoday.http.converter.HttpMessageConverter)10 ResourceHttpMessageConverter (cn.taketoday.http.converter.ResourceHttpMessageConverter)10 UriTemplateHandler (cn.taketoday.web.util.UriTemplateHandler)10 HttpHeaders (cn.taketoday.http.HttpHeaders)8 ClientHttpRequestFactory (cn.taketoday.http.client.ClientHttpRequestFactory)8 InterceptingClientHttpRequestFactory (cn.taketoday.http.client.InterceptingClientHttpRequestFactory)8 OkHttp3ClientHttpRequestFactory (cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory)8 ResponseErrorHandler (cn.taketoday.web.client.ResponseErrorHandler)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 InOrder (org.mockito.InOrder)8 HttpMethod (cn.taketoday.http.HttpMethod)6