Merge branch '2.1.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);
|
||||
|
||||
@@ -826,7 +826,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)
|
||||
@@ -854,7 +854,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)
|
||||
@@ -882,7 +882,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)
|
||||
@@ -908,7 +908,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
|
||||
@@ -929,7 +929,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>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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>");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user