Merge branch '1.4.x' into 1.5.x
This commit is contained in:
@@ -41,7 +41,7 @@ import org.springframework.web.util.UriTemplateHandler;
|
||||
* {@link RequestExpectationManager} that strips the specified root URI from the request
|
||||
* before verification. Can be used to simply test declarations when all REST calls start
|
||||
* the same way. For example: <pre class="code">
|
||||
* RestTemplate restTemplate = new RestTemplateBuilder().rootUri("http://example.com").build();
|
||||
* RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://example.com").build();
|
||||
* MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
|
||||
* server.expect(requestTo("/hello")).andRespond(withSuccess());
|
||||
* restTemplate.getForEntity("/hello", String.class);
|
||||
|
||||
@@ -791,7 +791,7 @@ public class TestRestTemplate {
|
||||
* {@link ParameterizedTypeReference} is used to pass generic type information:
|
||||
* <pre class="code">
|
||||
* ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",HttpMethod.GET, null, myBean);
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
|
||||
* </pre>
|
||||
* @param url the URL
|
||||
* @param method the HTTP method (GET, POST, etc)
|
||||
@@ -819,7 +819,7 @@ public class TestRestTemplate {
|
||||
* {@link ParameterizedTypeReference} is used to pass generic type information:
|
||||
* <pre class="code">
|
||||
* ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",HttpMethod.GET, null, myBean);
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
|
||||
* </pre>
|
||||
* @param url the URL
|
||||
* @param method the HTTP method (GET, POST, etc)
|
||||
@@ -847,7 +847,7 @@ public class TestRestTemplate {
|
||||
* {@link ParameterizedTypeReference} is used to pass generic type information:
|
||||
* <pre class="code">
|
||||
* ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",HttpMethod.GET, null, myBean);
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
|
||||
* </pre>
|
||||
* @param url the URL
|
||||
* @param method the HTTP method (GET, POST, etc)
|
||||
@@ -873,7 +873,7 @@ public class TestRestTemplate {
|
||||
* response as {@link ResponseEntity}. Typically used in combination with the static
|
||||
* builder methods on {@code RequestEntity}, for instance: <pre class="code">
|
||||
* MyRequest body = ...
|
||||
* RequestEntity request = RequestEntity.post(new URI("http://example.com/foo")).accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* RequestEntity request = RequestEntity.post(new URI("https://example.com/foo")).accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
|
||||
* </pre>
|
||||
* @param requestEntity the entity to write to the request
|
||||
@@ -894,7 +894,7 @@ public class TestRestTemplate {
|
||||
* response as {@link ResponseEntity}. The given {@link ParameterizedTypeReference} is
|
||||
* used to pass generic type information: <pre class="code">
|
||||
* MyRequest body = ...
|
||||
* RequestEntity request = RequestEntity.post(new URI("http://example.com/foo")).accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* RequestEntity request = RequestEntity.post(new URI("https://example.com/foo")).accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* ParameterizedTypeReference<List<MyResponse>> myBean = new ParameterizedTypeReference<List<MyResponse>>() {};
|
||||
* ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);
|
||||
* </pre>
|
||||
|
||||
@@ -78,7 +78,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);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class MockServerRestTemplateCustomizerTests {
|
||||
public void setDetectRootUriShouldDisableRootUriDetection() throws Exception {
|
||||
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);
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RootUriRequestExpectationManagerTests {
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private String uri = "http://example.com";
|
||||
private String uri = "https://example.com";
|
||||
|
||||
@Mock
|
||||
private RequestExpectationManager delegate;
|
||||
@@ -97,7 +97,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);
|
||||
}
|
||||
@@ -121,9 +121,9 @@ public class RootUriRequestExpectationManagerTests {
|
||||
given(request.getURI()).willReturn(new URI(this.uri + "/hello"));
|
||||
given(this.delegate.validateRequest((ClientHttpRequest) any()))
|
||||
.willThrow(new AssertionError(
|
||||
"Request URI expected:</hello> was:<http://example.com/bad>"));
|
||||
"Request URI expected:</hello> was:<https://example.com/bad>"));
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Request URI expected:<http://example.com/hello>");
|
||||
this.thrown.expectMessage("Request URI expected:<https://example.com/hello>");
|
||||
this.manager.validateRequest(request);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,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());
|
||||
@@ -182,14 +182,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());
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"expected:<http://example.com/hello> but was:<http://spring.io/hello>");
|
||||
restTemplate.getForEntity("http://spring.io/hello", String.class);
|
||||
"expected:<https://example.com/hello> but was:<https://spring.io/hello>");
|
||||
restTemplate.getForEntity("https://spring.io/hello", String.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user