Search in sources :

Example 11 with RestTemplate

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

the class MockServerRestTemplateCustomizerTests method customizeShouldBindServer.

@Test
public void customizeShouldBindServer() throws Exception {
    RestTemplate template = new RestTemplateBuilder(this.customizer).build();
    this.customizer.getServer().expect(requestTo("/test")).andRespond(withSuccess());
    template.getForEntity("/test", String.class);
    this.customizer.getServer().verify();
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 12 with RestTemplate

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

the class MockServerRestTemplateCustomizerTests method createShouldUseExpectationManagerClass.

@Test
public void createShouldUseExpectationManagerClass() throws Exception {
    MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer(UnorderedRequestExpectationManager.class);
    customizer.customize(new RestTemplate());
    assertThat(customizer.getServer()).extracting("expectationManager").hasAtLeastOneElementOfType(UnorderedRequestExpectationManager.class);
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 13 with RestTemplate

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

the class MockServerRestTemplateCustomizerTests method getServerWhenMultipleServersAreBoundShouldThrowException.

@Test
public void getServerWhenMultipleServersAreBoundShouldThrowException() throws Exception {
    this.customizer.customize(new RestTemplate());
    this.customizer.customize(new RestTemplate());
    this.thrown.expect(IllegalStateException.class);
    this.thrown.expectMessage("Unable to return a single MockRestServiceServer since " + "MockServerRestTemplateCustomizer has been bound to more than one RestTemplate");
    this.customizer.getServer();
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 14 with RestTemplate

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

the class RestTemplateBuilderTests method messageConvertersShouldApply.

@Test
public void messageConvertersShouldApply() throws Exception {
    RestTemplate template = this.builder.messageConverters(this.messageConverter).build();
    assertThat(template.getMessageConverters()).containsOnly(this.messageConverter);
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 15 with RestTemplate

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

the class RestTemplateBuilderTests method basicAuthorizationShouldApply.

@Test
public void basicAuthorizationShouldApply() throws Exception {
    RestTemplate template = this.builder.basicAuthorization("spring", "boot").build();
    ClientHttpRequestInterceptor interceptor = template.getInterceptors().get(0);
    assertThat(interceptor).isInstanceOf(BasicAuthorizationInterceptor.class);
    assertThat(interceptor).extracting("username").containsExactly("spring");
    assertThat(interceptor).extracting("password").containsExactly("boot");
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) Test(org.junit.Test)

Aggregations

RestTemplate (org.springframework.web.client.RestTemplate)189 Test (org.junit.Test)107 URI (java.net.URI)39 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)29 ArrayList (java.util.ArrayList)24 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)20 HashMap (java.util.HashMap)19 MapPropertySource (org.springframework.core.env.MapPropertySource)15 StandardEnvironment (org.springframework.core.env.StandardEnvironment)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 HttpHeaders (org.springframework.http.HttpHeaders)13 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)13 IOException (java.io.IOException)12 JSONObject (org.json.JSONObject)12 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)11 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)11 JSONException (org.json.JSONException)10 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)10