Search in sources :

Example 1 with RootUriTemplateHandler

use of cn.taketoday.web.client.config.RootUriTemplateHandler 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 RootUriTemplateHandler

use of cn.taketoday.web.client.config.RootUriTemplateHandler in project today-framework by TAKETODAY.

the class RootUriTemplateHandlerTests method setup.

@BeforeEach
void setup() throws URISyntaxException {
    this.uri = new URI("https://example.com/hello");
    this.handler = new RootUriTemplateHandler("https://example.com", this.delegate);
}
Also used : RootUriTemplateHandler(cn.taketoday.web.client.config.RootUriTemplateHandler) URI(java.net.URI) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with RootUriTemplateHandler

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

the class RootUriTemplateHandlerTests method setup.

@BeforeEach
void setup() throws URISyntaxException {
    this.uri = new URI("https://example.com/hello");
    this.handler = new RootUriTemplateHandler("https://example.com", this.delegate);
}
Also used : RootUriTemplateHandler(cn.taketoday.web.client.config.RootUriTemplateHandler) URI(java.net.URI) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with RootUriTemplateHandler

use of cn.taketoday.web.client.config.RootUriTemplateHandler in project today-infrastructure 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)

Aggregations

RootUriTemplateHandler (cn.taketoday.web.client.config.RootUriTemplateHandler)4 UriTemplateHandler (cn.taketoday.web.util.UriTemplateHandler)2 URI (java.net.URI)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2