Search in sources :

Example 26 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method requestFactoryShouldApply.

@Test
public void requestFactoryShouldApply() throws Exception {
    ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);
    RestTemplate template = this.builder.requestFactory(requestFactory).build();
    assertThat(template.getRequestFactory()).isSameAs(requestFactory);
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) Netty4ClientHttpRequestFactory(org.springframework.http.client.Netty4ClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(org.springframework.http.client.OkHttp3ClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 27 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method rootUriShouldApply.

@Test
public void rootUriShouldApply() throws Exception {
    RestTemplate restTemplate = this.builder.rootUri("http://example.com").build();
    MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
    server.expect(requestTo("http://example.com/hello")).andRespond(withSuccess());
    restTemplate.getForEntity("/hello", String.class);
    server.verify();
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) Test(org.junit.Test)

Example 28 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method requestFactoryClassShouldApply.

@Test
public void requestFactoryClassShouldApply() throws Exception {
    RestTemplate template = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).build();
    assertThat(template.getRequestFactory()).isInstanceOf(SimpleClientHttpRequestFactory.class);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 29 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate.

@Test
public void unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    RestTemplate template = this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory)).build();
    assertThat(template.getRequestFactory()).isInstanceOf(BufferingClientHttpRequestFactory.class);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.Test)

Example 30 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method defaultMessageConvertersShouldSetDefaultList.

@Test
public void defaultMessageConvertersShouldSetDefaultList() throws Exception {
    RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(new StringHttpMessageConverter()));
    this.builder.defaultMessageConverters().configure(template);
    assertThat(template.getMessageConverters()).hasSameSizeAs(new RestTemplate().getMessageConverters());
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Test(org.junit.Test)

Aggregations

RestTemplate (org.springframework.web.client.RestTemplate)206 Test (org.junit.Test)107 URI (java.net.URI)39 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)29 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)22 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)22 HttpHeaders (org.springframework.http.HttpHeaders)19 HttpEntity (org.springframework.http.HttpEntity)16 MapPropertySource (org.springframework.core.env.MapPropertySource)15 StandardEnvironment (org.springframework.core.env.StandardEnvironment)15 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)15 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)15 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)13 IOException (java.io.IOException)12 JSONObject (org.json.JSONObject)12 Before (org.junit.Before)11 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)11 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)11