|
1 | 1 | /* |
2 | | - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
25 | 25 | import io.micrometer.core.instrument.Tag; |
26 | 26 | import io.micrometer.core.instrument.simple.SimpleConfig; |
27 | 27 | import io.micrometer.core.instrument.simple.SimpleMeterRegistry; |
| 28 | +import org.assertj.core.api.InstanceOfAssertFactories; |
28 | 29 | import org.junit.jupiter.api.BeforeEach; |
29 | 30 | import org.junit.jupiter.api.Test; |
30 | 31 |
|
31 | 32 | import org.springframework.boot.actuate.metrics.AutoTimer; |
| 33 | +import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; |
| 34 | +import org.springframework.boot.web.client.RestTemplateBuilder; |
| 35 | +import org.springframework.boot.web.client.RootUriTemplateHandler; |
32 | 36 | import org.springframework.http.HttpMethod; |
33 | 37 | import org.springframework.http.HttpRequest; |
34 | 38 | import org.springframework.http.MediaType; |
35 | 39 | import org.springframework.http.client.ClientHttpRequestExecution; |
36 | 40 | import org.springframework.http.client.ClientHttpRequestInterceptor; |
37 | 41 | import org.springframework.http.client.ClientHttpResponse; |
| 42 | +import org.springframework.mock.env.MockEnvironment; |
38 | 43 | import org.springframework.test.web.client.MockRestServiceServer; |
39 | 44 | import org.springframework.test.web.client.match.MockRestRequestMatchers; |
40 | 45 | import org.springframework.test.web.client.response.MockRestResponseCreators; |
@@ -136,6 +141,18 @@ void interceptNestedRequest() { |
136 | 141 | nestedMockServer.verify(); |
137 | 142 | } |
138 | 143 |
|
| 144 | + @Test |
| 145 | + void whenCustomizerAndLocalHostUriTemplateHandlerAreUsedTogetherThenRestTemplateBuilderCanBuild() { |
| 146 | + MockEnvironment environment = new MockEnvironment(); |
| 147 | + environment.setProperty("local.server.port", "8443"); |
| 148 | + LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(environment, "https"); |
| 149 | + RestTemplate restTemplate = new RestTemplateBuilder(this.customizer).uriTemplateHandler(uriTemplateHandler) |
| 150 | + .build(); |
| 151 | + assertThat(restTemplate.getUriTemplateHandler()) |
| 152 | + .asInstanceOf(InstanceOfAssertFactories.type(RootUriTemplateHandler.class)) |
| 153 | + .extracting(RootUriTemplateHandler::getRootUri).isEqualTo("https://localhost:8443"); |
| 154 | + } |
| 155 | + |
139 | 156 | private static final class TestInterceptor implements ClientHttpRequestInterceptor { |
140 | 157 |
|
141 | 158 | private final RestTemplate restTemplate; |
|
0 commit comments