Rename RestTemplates to TestRestTemplate
Rename the RestTemplates to TestRestTemplate to help indicate that it's primarily intended for testing. Also now extend RestTemplate to allow direct use, rather than via factory methods. Fixes gh-599
This commit is contained in:
@@ -1476,7 +1476,7 @@ interaction. For Example:
|
||||
@Autowired
|
||||
CityRepository repository;
|
||||
|
||||
RestTemplate restTemplate = RestTemplates.get();
|
||||
RestTemplate restTemplate = new TestRestTemplate();
|
||||
|
||||
// ... interact with the running server
|
||||
|
||||
@@ -1547,22 +1547,22 @@ public class MyTest {
|
||||
----
|
||||
|
||||
[[boot-features-rest-templates-test-utility]]
|
||||
==== RestTemplates
|
||||
==== TestRestTemplate
|
||||
|
||||
`RestTemplates` is a static convenience factory for instances of `RestTemplate` that are
|
||||
`TestRestTemplate` is a convenience subclass of Spring's `RestTemplate` that is
|
||||
useful in integration tests. You can get a vanilla template or one that sends Basic HTTP
|
||||
authentication (with a username and password). And in either case the template will behave
|
||||
in a friendly way for testing, not following redirects (so you can assert the response
|
||||
location), ignoring cookies (so the template is stateless), and not throwing exceptions
|
||||
on server-side errors. It is recommended, but not mandatory, to use Apache HTTP Client
|
||||
(version 4.3.2 or better), and if you have that on your classpath the `RestTemplates` will
|
||||
respond by configuring the client appropriately.
|
||||
(version 4.3.2 or better), and if you have that on your classpath the `TestRestTemplate`
|
||||
will respond by configuring the client appropriately.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
public class MyTest {
|
||||
|
||||
RestTemplate template = RestTemplates.get();
|
||||
RestTemplate template = new TestRestTemplate();
|
||||
|
||||
@Test
|
||||
public void testRequest() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user