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:
Phillip Webb
2014-03-27 11:04:20 -07:00
parent d117a6b22b
commit aca67066bf
24 changed files with 141 additions and 128 deletions

View File

@@ -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 {