Skip to content

Commit

Permalink
Merge branch '2.4.x'
Browse files Browse the repository at this point in the history
Closes gh-26827
  • Loading branch information
wilkinsona committed Jun 9, 2021
2 parents 850088d + 303edac commit c5728c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* 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.
Expand All @@ -25,16 +25,21 @@
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;
Expand Down Expand Up @@ -136,6 +141,18 @@ void interceptNestedRequest() {
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;
Expand Down
Expand Up @@ -93,7 +93,7 @@ public String getRootUri() {
* @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));
}

/**
Expand Down

0 comments on commit c5728c9

Please sign in to comment.