Search in sources :

Example 1 with UriTemplateHandler

use of cn.taketoday.web.util.UriTemplateHandler in project today-framework by TAKETODAY.

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 : UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) RootUriTemplateHandler(cn.taketoday.web.client.config.RootUriTemplateHandler) RootUriTemplateHandler(cn.taketoday.web.client.config.RootUriTemplateHandler)

Example 2 with UriTemplateHandler

use of cn.taketoday.web.util.UriTemplateHandler in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method uriTemplateHandlerShouldApply.

@Test
void uriTemplateHandlerShouldApply() {
    UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
    RestTemplate template = this.builder.uriTemplateHandler(uriTemplateHandler).build();
    assertThat(template.getUriTemplateHandler()).isSameAs(uriTemplateHandler);
}
Also used : UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) RestTemplate(cn.taketoday.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 3 with UriTemplateHandler

use of cn.taketoday.web.util.UriTemplateHandler in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method rootUriShouldApplyAfterUriTemplateHandler.

// @Test
// void rootUriShouldApply() {
// RestTemplate restTemplate = this.builder.rootUri("https://example.com").build();
// MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
// server.expect(requestTo("https://example.com/hello")).andRespond(withSuccess());
// restTemplate.getForEntity("/hello", String.class);
// server.verify();
// }
@Test
void rootUriShouldApplyAfterUriTemplateHandler() {
    UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
    RestTemplate template = this.builder.uriTemplateHandler(uriTemplateHandler).rootUri("https://example.com").build();
    UriTemplateHandler handler = template.getUriTemplateHandler();
    handler.expand("/hello");
    assertThat(handler).isInstanceOf(RootUriTemplateHandler.class);
    verify(uriTemplateHandler).expand("https://example.com/hello");
}
Also used : UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) RestTemplate(cn.taketoday.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 4 with UriTemplateHandler

use of cn.taketoday.web.util.UriTemplateHandler in project today-infrastructure by TAKETODAY.

the class RestTemplateBuilderTests method uriTemplateHandlerShouldApply.

@Test
void uriTemplateHandlerShouldApply() {
    UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
    RestTemplate template = this.builder.uriTemplateHandler(uriTemplateHandler).build();
    assertThat(template.getUriTemplateHandler()).isSameAs(uriTemplateHandler);
}
Also used : UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) RestTemplate(cn.taketoday.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 5 with UriTemplateHandler

use of cn.taketoday.web.util.UriTemplateHandler in project today-infrastructure by TAKETODAY.

the class RestTemplateBuilderTests method rootUriShouldApplyAfterUriTemplateHandler.

// @Test
// void rootUriShouldApply() {
// RestTemplate restTemplate = this.builder.rootUri("https://example.com").build();
// MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
// server.expect(requestTo("https://example.com/hello")).andRespond(withSuccess());
// restTemplate.getForEntity("/hello", String.class);
// server.verify();
// }
@Test
void rootUriShouldApplyAfterUriTemplateHandler() {
    UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
    RestTemplate template = this.builder.uriTemplateHandler(uriTemplateHandler).rootUri("https://example.com").build();
    UriTemplateHandler handler = template.getUriTemplateHandler();
    handler.expand("/hello");
    assertThat(handler).isInstanceOf(RootUriTemplateHandler.class);
    verify(uriTemplateHandler).expand("https://example.com/hello");
}
Also used : UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) RestTemplate(cn.taketoday.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

UriTemplateHandler (cn.taketoday.web.util.UriTemplateHandler)6 RestTemplate (cn.taketoday.web.client.RestTemplate)4 Test (org.junit.jupiter.api.Test)4 RootUriTemplateHandler (cn.taketoday.web.client.config.RootUriTemplateHandler)2