Skip to content

Commit e9db595

Browse files
committed
Restore TestRestTemplate#getRootUri
This commit adapts TestRestTemplate#getRootUri to the recently introduced LocalTestWebServer. The behavior invokes the UriTemplateHandler to provide the value. If the implementation expands full URL, then it will provide the expected behavior. If not, it should return the empty string as before. Closes gh-48330
1 parent c6c6ff0 commit e9db595

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void setUriTemplateHandler(UriTemplateHandler handler) {
193193
if (uriTemplateHandler instanceof RootUriTemplateHandler rootHandler) {
194194
return rootHandler.getRootUri();
195195
}
196-
return "";
196+
return uriTemplateHandler.expand("").toString();
197197
}
198198

199199
/**

module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ void getRootUriRootUriSetViaRestTemplateBuilder() {
120120
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo(rootUri);
121121
}
122122

123+
@Test
124+
void getRootUriRootUriSetViaLocalTestWebServer() {
125+
LocalTestWebServer localTestWebServer = LocalTestWebServer.of(Scheme.HTTPS, 7070);
126+
RestTemplateBuilder delegate = new RestTemplateBuilder()
127+
.uriTemplateHandler(localTestWebServer.uriBuilderFactory());
128+
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo("https://localhost:7070");
129+
}
130+
123131
@Test
124132
void getRootUriRootUriNotSet() {
125133
assertThat(new TestRestTemplate().getRootUri()).isEmpty();

0 commit comments

Comments
 (0)