Merge branch '2.1.x'

This commit is contained in:
Andy Wilkinson
2019-03-28 11:48:47 +00:00
125 changed files with 450 additions and 447 deletions

View File

@@ -101,7 +101,7 @@ public class LocalHostUriTemplateHandlerTests {
MockEnvironment environment = new MockEnvironment();
UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
Map<String, ?> uriVariables = new HashMap<>();
URI uri = URI.create("http://www.example.com");
URI uri = URI.create("https://www.example.com");
given(uriTemplateHandler.expand("https://localhost:8080/", uriVariables))
.willReturn(uri);
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(environment,

View File

@@ -74,7 +74,7 @@ public class MockServerRestTemplateCustomizerTests {
MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer(
UnorderedRequestExpectationManager.class);
customizer.customize(
new RestTemplateBuilder().rootUri("http://example.com").build());
new RestTemplateBuilder().rootUri("https://example.com").build());
assertThat(customizer.getServer()).extracting("expectationManager")
.hasAtLeastOneElementOfType(RootUriRequestExpectationManager.class);
}
@@ -83,7 +83,7 @@ public class MockServerRestTemplateCustomizerTests {
public void setDetectRootUriShouldDisableRootUriDetection() {
this.customizer.setDetectRootUri(false);
this.customizer.customize(
new RestTemplateBuilder().rootUri("http://example.com").build());
new RestTemplateBuilder().rootUri("https://example.com").build());
assertThat(this.customizer.getServer()).extracting("expectationManager")
.hasAtLeastOneElementOfType(SimpleRequestExpectationManager.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -51,7 +51,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
*/
public class RootUriRequestExpectationManagerTests {
private String uri = "http://example.com";
private String uri = "https://example.com";
@Mock
private RequestExpectationManager delegate;
@@ -94,7 +94,7 @@ public class RootUriRequestExpectationManagerTests {
public void validateRequestWhenUriDoesNotStartWithRootUriShouldDelegateToExpectationManager()
throws Exception {
ClientHttpRequest request = mock(ClientHttpRequest.class);
given(request.getURI()).willReturn(new URI("http://spring.io/test"));
given(request.getURI()).willReturn(new URI("https://spring.io/test"));
this.manager.validateRequest(request);
verify(this.delegate).validateRequest(request);
}
@@ -118,10 +118,11 @@ public class RootUriRequestExpectationManagerTests {
given(request.getURI()).willReturn(new URI(this.uri + "/hello"));
given(this.delegate.validateRequest(any(ClientHttpRequest.class)))
.willThrow(new AssertionError(
"Request URI expected:</hello> was:<http://example.com/bad>"));
"Request URI expected:</hello> was:<https://example.com/bad>"));
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> this.manager.validateRequest(request))
.withMessageContaining("Request URI expected:<http://example.com/hello>");
.withMessageContaining(
"Request URI expected:<https://example.com/hello>");
}
@Test
@@ -166,7 +167,7 @@ public class RootUriRequestExpectationManagerTests {
@Test
public void boundRestTemplateShouldPrefixRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder()
.rootUri("http://example.com").build();
.rootUri("https://example.com").build();
MockRestServiceServer server = RootUriRequestExpectationManager
.bindTo(restTemplate);
server.expect(requestTo("/hello")).andRespond(withSuccess());
@@ -176,14 +177,14 @@ public class RootUriRequestExpectationManagerTests {
@Test
public void boundRestTemplateWhenUrlIncludesDomainShouldNotPrefixRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder()
.rootUri("http://example.com").build();
.rootUri("https://example.com").build();
MockRestServiceServer server = RootUriRequestExpectationManager
.bindTo(restTemplate);
server.expect(requestTo("/hello")).andRespond(withSuccess());
assertThatExceptionOfType(AssertionError.class).isThrownBy(
() -> restTemplate.getForEntity("http://spring.io/hello", String.class))
() -> restTemplate.getForEntity("https://spring.io/hello", String.class))
.withMessageContaining(
"expected:<http://example.com/hello> but was:<http://spring.io/hello>");
"expected:<https://example.com/hello> but was:<https://spring.io/hello>");
}
}

View File

@@ -125,14 +125,14 @@ public class TestRestTemplateTests {
@Test
public void getRootUriRootUriSetViaRestTemplateBuilder() {
String rootUri = "http://example.com";
String rootUri = "https://example.com";
RestTemplateBuilder delegate = new RestTemplateBuilder().rootUri(rootUri);
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo(rootUri);
}
@Test
public void getRootUriRootUriSetViaLocalHostUriTemplateHandler() {
String rootUri = "http://example.com";
String rootUri = "https://example.com";
TestRestTemplate template = new TestRestTemplate();
LocalHostUriTemplateHandler templateHandler = mock(
LocalHostUriTemplateHandler.class);