Commit d1e1796f authored by Andy Wilkinson's avatar Andy Wilkinson

Consider overridden getRootUri() when getting root URI

Fixes gh-26812
parent 1f6983c4
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -25,16 +25,21 @@ import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.simple.SimpleConfig;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.metrics.AutoTimer;
import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.client.RootUriTemplateHandler;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.client.match.MockRestRequestMatchers;
import org.springframework.test.web.client.response.MockRestResponseCreators;
......@@ -136,6 +141,18 @@ class MetricsRestTemplateCustomizerTests {
nestedMockServer.verify();
}
@Test
void whenCustomizerAndLocalHostUriTemplateHandlerAreUsedTogetherThenRestTemplateBuilderCanBuild() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("local.server.port", "8443");
LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(environment, "https");
RestTemplate restTemplate = new RestTemplateBuilder(this.customizer).uriTemplateHandler(uriTemplateHandler)
.build();
assertThat(restTemplate.getUriTemplateHandler())
.asInstanceOf(InstanceOfAssertFactories.type(RootUriTemplateHandler.class))
.extracting(RootUriTemplateHandler::getRootUri).isEqualTo("https://localhost:8443");
}
private static final class TestInterceptor implements ClientHttpRequestInterceptor {
private final RestTemplate restTemplate;
......
......@@ -93,7 +93,7 @@ public class RootUriTemplateHandler implements UriTemplateHandler {
* @since 2.3.10
*/
public RootUriTemplateHandler withHandlerWrapper(Function<UriTemplateHandler, UriTemplateHandler> wrapper) {
return new RootUriTemplateHandler(this.rootUri, wrapper.apply(this.handler));
return new RootUriTemplateHandler(getRootUri(), wrapper.apply(this.handler));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment