Fix TestRestTemplate example in the doc

Closes gh-12132
This commit is contained in:
Stephane Nicoll
2018-02-27 09:58:59 +01:00
parent 98f58caeaf
commit 14ff776f68
5 changed files with 134 additions and 28 deletions

View File

@@ -50,6 +50,7 @@ Phillip Webb; Dave Syer; Josh Long; Stéphane Nicoll; Rob Winch; Andy Wilkinson;
:propdeps-plugin: https://github.com/spring-projects/gradle-plugins/tree/master/propdeps-plugin
:ant-manual: http://ant.apache.org/manual
:code-examples: ../java/org/springframework/boot
:test-examples: ../../test/java/org/springframework/boot
:gradle-user-guide: https://docs.gradle.org/2.14.1/userguide
:gradle-dsl: https://docs.gradle.org/2.14.1/dsl
// ======================================================================================

View File

@@ -6207,8 +6207,9 @@ features will be enabled:
@Test
public void testRequest() throws Exception {
HttpHeaders headers = template.getForEntity("http://myhost.com/example", String.class).getHeaders();
assertThat(headers.getLocation().toString(), containsString("myotherhost"));
HttpHeaders headers = this.template.getForEntity(
"http://myhost.example.com/example", String.class).getHeaders();
assertThat(headers.getLocation()).hasHost("other.example.com");
}
}
@@ -6222,32 +6223,7 @@ specify a host and port will automatically connect to the embedded server:
[source,java,indent=0]
----
@RunWith(SpringRunner.class)
@SpringBootTest
public class MyTest {
@Autowired
private TestRestTemplate template;
@Test
public void testRequest() throws Exception {
HttpHeaders headers = template.getForEntity("/example", String.class).getHeaders();
assertThat(headers.getLocation().toString(), containsString("myotherhost"));
}
@TestConfiguration
static class Config {
@Bean
public RestTemplateBuilder restTemplateBuilder() {
return new RestTemplateBuilder()
.additionalMessageConverters(...)
.customizers(...);
}
}
}
include::{test-examples}/web/client/SampleWebClientTests.java[tag=test]
----