Search in sources :

Example 1 with UriTemplateHandler

use of org.springframework.web.util.UriTemplateHandler in project spring-boot by spring-projects.

the class RootUriRequestExpectationManager method forRestTemplate.

/**
	 * Return {@link RequestExpectationManager} to be used for binding with the specified
	 * {@link RestTemplate}. If the {@link RestTemplate} is using a
	 * {@link RootUriTemplateHandler} then a {@link RootUriRequestExpectationManager} is
	 * returned, otherwise the source manager is returned unchanged.
	 * @param restTemplate the source REST template
	 * @param expectationManager the source {@link RequestExpectationManager}
	 * @return a {@link RequestExpectationManager} to be bound to the template
	 */
public static RequestExpectationManager forRestTemplate(RestTemplate restTemplate, RequestExpectationManager expectationManager) {
    Assert.notNull(restTemplate, "RestTemplate must not be null");
    UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler();
    if (templateHandler instanceof RootUriTemplateHandler) {
        return new RootUriRequestExpectationManager(((RootUriTemplateHandler) templateHandler).getRootUri(), expectationManager);
    }
    return expectationManager;
}
Also used : RootUriTemplateHandler(org.springframework.boot.web.client.RootUriTemplateHandler) UriTemplateHandler(org.springframework.web.util.UriTemplateHandler) RootUriTemplateHandler(org.springframework.boot.web.client.RootUriTemplateHandler)

Example 2 with UriTemplateHandler

use of org.springframework.web.util.UriTemplateHandler in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method uriTemplateHandlerShouldApply.

@Test
public void uriTemplateHandlerShouldApply() throws Exception {
    UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
    RestTemplate template = this.builder.uriTemplateHandler(uriTemplateHandler).build();
    assertThat(template.getUriTemplateHandler()).isSameAs(uriTemplateHandler);
}
Also used : UriTemplateHandler(org.springframework.web.util.UriTemplateHandler) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 3 with UriTemplateHandler

use of org.springframework.web.util.UriTemplateHandler in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method rootUriShouldApplyAfterUriTemplateHandler.

@Test
public void rootUriShouldApplyAfterUriTemplateHandler() throws Exception {
    UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
    RestTemplate template = this.builder.uriTemplateHandler(uriTemplateHandler).rootUri("http://example.com").build();
    UriTemplateHandler handler = template.getUriTemplateHandler();
    handler.expand("/hello");
    assertThat(handler).isInstanceOf(RootUriTemplateHandler.class);
    verify(uriTemplateHandler).expand("http://example.com/hello");
}
Also used : UriTemplateHandler(org.springframework.web.util.UriTemplateHandler) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Aggregations

UriTemplateHandler (org.springframework.web.util.UriTemplateHandler)3 Test (org.junit.Test)2 RestTemplate (org.springframework.web.client.RestTemplate)2 RootUriTemplateHandler (org.springframework.boot.web.client.RootUriTemplateHandler)1