Search in sources :

Example 96 with RestTemplate

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

the class ErrorHandlerIntegrationTests method responseBodyError.

@ParameterizedHttpServerTest
void responseBodyError(HttpServer httpServer) throws Exception {
    startServer(httpServer);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
    URI url = new URI("http://localhost:" + port + "/response-body-error");
    ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) URI(java.net.URI)

Example 97 with RestTemplate

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

the class AsyncIntegrationTests method basicTest.

@ParameterizedHttpServerTest
void basicTest(HttpServer httpServer) throws Exception {
    startServer(httpServer);
    URI url = new URI("http://localhost:" + port);
    ResponseEntity<String> response = new RestTemplate().exchange(RequestEntity.get(url).build(), String.class);
    assertThat(response.getBody()).isEqualTo("hello");
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) URI(java.net.URI)

Example 98 with RestTemplate

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

the class ContentRequestMatchersIntegrationTests 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)

Example 99 with RestTemplate

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

the class SampleTests method repeatedAccessToResponseViaResource.

// SPR-14694
@Test
public void repeatedAccessToResponseViaResource() {
    Resource resource = new ClassPathResource("ludwig.json", this.getClass());
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setInterceptors(Collections.singletonList(new ContentInterceptor(resource)));
    MockRestServiceServer mockServer = MockRestServiceServer.bindTo(restTemplate).ignoreExpectOrder(true).bufferContent().build();
    mockServer.expect(requestTo("/composers/42")).andExpect(method(HttpMethod.GET)).andRespond(withSuccess(resource, MediaType.APPLICATION_JSON));
    restTemplate.getForObject("/composers/{id}", Person.class, 42);
    mockServer.verify();
}
Also used : Resource(cn.taketoday.core.io.Resource) ClassPathResource(cn.taketoday.core.io.ClassPathResource) RestTemplate(cn.taketoday.web.client.RestTemplate) MockRestServiceServer(cn.taketoday.test.web.client.MockRestServiceServer) ClassPathResource(cn.taketoday.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 100 with RestTemplate

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

the class SampleTests method setup.

@BeforeEach
public void setup() {
    this.restTemplate = new RestTemplate();
    this.mockServer = MockRestServiceServer.bindTo(this.restTemplate).ignoreExpectOrder(true).build();
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) 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