Add support for new PATCH methods to TestRestTemplate

Closes gh-7412
pull/7351/merge
Andy Wilkinson 8 years ago
parent 971e5e834c
commit 6361a6728a

@ -78,6 +78,7 @@ import org.springframework.web.util.UriTemplateHandler;
*
* @author Dave Syer
* @author Phillip Webb
* @author Andy Wilkinson
* @since 1.4.0
*/
public class TestRestTemplate {
@ -172,7 +173,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand the template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error on-client side HTTP error
* @throws RestClientException on client-side HTTP error on client-side HTTP error
* @see RestTemplate#getForObject(String, Class, Object...)
*/
public <T> T getForObject(String url, Class<T> responseType, Object... urlVariables)
@ -190,7 +191,7 @@ public class TestRestTemplate {
* @param urlVariables the map containing variables for the URI template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#getForObject(String, Class, Object...)
*/
public <T> T getForObject(String url, Class<T> responseType,
@ -205,7 +206,7 @@ public class TestRestTemplate {
* @param responseType the type of the return value
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#getForObject(java.net.URI, java.lang.Class)
*/
public <T> T getForObject(URI url, Class<T> responseType) throws RestClientException {
@ -222,7 +223,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand the template
* @param <T> the type of the return value
* @return the entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#getForEntity(java.lang.String, java.lang.Class,
* java.lang.Object[])
*/
@ -241,7 +242,7 @@ public class TestRestTemplate {
* @param urlVariables the map containing variables for the URI template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#getForEntity(java.lang.String, java.lang.Class, java.util.Map)
*/
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType,
@ -256,7 +257,7 @@ public class TestRestTemplate {
* @param responseType the type of the return value
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#getForEntity(java.net.URI, java.lang.Class)
*/
public <T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType)
@ -271,7 +272,7 @@ public class TestRestTemplate {
* @param url the URL
* @param urlVariables the variables to expand the template
* @return all HTTP headers of that resource
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#headForHeaders(java.lang.String, java.lang.Object[])
*/
public HttpHeaders headForHeaders(String url, Object... urlVariables)
@ -286,7 +287,7 @@ public class TestRestTemplate {
* @param url the URL
* @param urlVariables the map containing variables for the URI template
* @return all HTTP headers of that resource
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#headForHeaders(java.lang.String, java.util.Map)
*/
public HttpHeaders headForHeaders(String url, Map<String, ?> urlVariables)
@ -298,7 +299,7 @@ public class TestRestTemplate {
* Retrieve all headers of the resource specified by the URL.
* @param url the URL
* @return all HTTP headers of that resource
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#headForHeaders(java.net.URI)
*/
public HttpHeaders headForHeaders(URI url) throws RestClientException {
@ -318,7 +319,7 @@ public class TestRestTemplate {
* @param request the Object to be POSTed, may be {@code null}
* @param urlVariables the variables to expand the template
* @return the value for the {@code Location} header
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForLocation(java.lang.String, java.lang.Object,
* java.lang.Object[])
@ -341,7 +342,7 @@ public class TestRestTemplate {
* @param request the Object to be POSTed, may be {@code null}
* @param urlVariables the variables to expand the template
* @return the value for the {@code Location} header
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForLocation(java.lang.String, java.lang.Object,
* java.util.Map)
@ -361,7 +362,7 @@ public class TestRestTemplate {
* @param url the URL
* @param request the Object to be POSTed, may be {@code null}
* @return the value for the {@code Location} header
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForLocation(java.net.URI, java.lang.Object)
*/
@ -383,7 +384,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand the template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForObject(java.lang.String, java.lang.Object,
* java.lang.Class, java.lang.Object[])
@ -407,7 +408,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand the template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForObject(java.lang.String, java.lang.Object,
* java.lang.Class, java.util.Map)
@ -428,7 +429,7 @@ public class TestRestTemplate {
* @param responseType the type of the return value
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForObject(java.net.URI, java.lang.Object, java.lang.Class)
*/
@ -451,7 +452,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand the template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForEntity(java.lang.String, java.lang.Object,
* java.lang.Class, java.lang.Object[])
@ -475,7 +476,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand the template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForEntity(java.lang.String, java.lang.Object,
* java.lang.Class, java.util.Map)
@ -497,7 +498,7 @@ public class TestRestTemplate {
* @param responseType the response type to return
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#postForEntity(java.net.URI, java.lang.Object, java.lang.Class)
*/
@ -516,7 +517,7 @@ public class TestRestTemplate {
* @param url the URL
* @param request the Object to be PUT, may be {@code null}
* @param urlVariables the variables to expand the template
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#put(java.lang.String, java.lang.Object, java.lang.Object[])
*/
@ -535,7 +536,7 @@ public class TestRestTemplate {
* @param url the URL
* @param request the Object to be PUT, may be {@code null}
* @param urlVariables the variables to expand the template
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#put(java.lang.String, java.lang.Object, java.util.Map)
*/
@ -551,7 +552,7 @@ public class TestRestTemplate {
* additional HTTP headers to the request.
* @param url the URL
* @param request the Object to be PUT, may be {@code null}
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @see RestTemplate#put(java.net.URI, java.lang.Object)
*/
@ -559,13 +560,80 @@ public class TestRestTemplate {
this.restTemplate.put(url, request);
}
/**
* Update a resource by PATCHing the given object to the URI template, and returns the
* representation found in the response.
* <p>
* URI Template variables are expanded using the given URI variables, if any.
* <p>
* The {@code request} parameter can be a {@link HttpEntity} in order to add
* additional HTTP headers to the request.
* @param url the URL
* @param request the Object to be PATCHed, may be {@code null}
* @param responseType the type of the return value
* @param uriVariables the variables to expand the template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @since 2.0
*/
<T> T patchForObject(String url, Object request, Class<T> responseType,
Object... uriVariables) throws RestClientException {
return this.restTemplate.patchForObject(url, request, responseType, uriVariables);
}
/**
* Update a resource by PATCHing the given object to the URI template, and returns the
* representation found in the response.
* <p>
* URI Template variables are expanded using the given map.
* <p>
* The {@code request} parameter can be a {@link HttpEntity} in order to add
* additional HTTP headers to the request.
* @param url the URL
* @param request the Object to be PATCHed, may be {@code null}
* @param responseType the type of the return value
* @param uriVariables the variables to expand the template
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @since 2.0
*/
<T> T patchForObject(String url, Object request, Class<T> responseType,
Map<String, ?> uriVariables) throws RestClientException {
return this.restTemplate.patchForObject(url, request, responseType, uriVariables);
}
/**
* Update a resource by PATCHing the given object to the URL, and returns the
* representation found in the response.
* <p>
* The {@code request} parameter can be a {@link HttpEntity} in order to add
* additional HTTP headers to the request.
* @param url the URL
* @param request the Object to be POSTed, may be {@code null}
* @param responseType the type of the return value
* @param <T> the type of the return value
* @return the converted object
* @throws RestClientException on client-side HTTP error
* @see HttpEntity
* @since 2.0
*/
<T> T patchForObject(URI url, Object request, Class<T> responseType)
throws RestClientException {
return this.restTemplate.patchForObject(url, request, responseType);
}
/**
* Delete the resources at the specified URI.
* <p>
* URI Template variables are expanded using the given URI variables, if any.
* @param url the URL
* @param urlVariables the variables to expand in the template
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#delete(java.lang.String, java.lang.Object[])
*/
public void delete(String url, Object... urlVariables) throws RestClientException {
@ -578,7 +646,7 @@ public class TestRestTemplate {
* URI Template variables are expanded using the given map.
* @param url the URL
* @param urlVariables the variables to expand the template
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#delete(java.lang.String, java.util.Map)
*/
public void delete(String url, Map<String, ?> urlVariables)
@ -589,7 +657,7 @@ public class TestRestTemplate {
/**
* Delete the resources at the specified URL.
* @param url the URL
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#delete(java.net.URI)
*/
public void delete(URI url) throws RestClientException {
@ -603,7 +671,7 @@ public class TestRestTemplate {
* @param url the URL
* @param urlVariables the variables to expand in the template
* @return the value of the allow header
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#optionsForAllow(java.lang.String, java.lang.Object[])
*/
public Set<HttpMethod> optionsForAllow(String url, Object... urlVariables)
@ -618,7 +686,7 @@ public class TestRestTemplate {
* @param url the URL
* @param urlVariables the variables to expand in the template
* @return the value of the allow header
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#optionsForAllow(java.lang.String, java.util.Map)
*/
public Set<HttpMethod> optionsForAllow(String url, Map<String, ?> urlVariables)
@ -630,7 +698,7 @@ public class TestRestTemplate {
* Return the value of the Allow header for the given URL.
* @param url the URL
* @return the value of the allow header
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#optionsForAllow(java.net.URI)
*/
public Set<HttpMethod> optionsForAllow(URI url) throws RestClientException {
@ -650,7 +718,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand in the template
* @param <T> the type of the return value
* @return the response as entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#exchange(java.lang.String, org.springframework.http.HttpMethod,
* org.springframework.http.HttpEntity, java.lang.Class, java.lang.Object[])
*/
@ -674,7 +742,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand in the template
* @param <T> the type of the return value
* @return the response as entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#exchange(java.lang.String, org.springframework.http.HttpMethod,
* org.springframework.http.HttpEntity, java.lang.Class, java.util.Map)
*/
@ -695,7 +763,7 @@ public class TestRestTemplate {
* @param responseType the type of the return value
* @param <T> the type of the return value
* @return the response as entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#exchange(java.net.URI, org.springframework.http.HttpMethod,
* org.springframework.http.HttpEntity, java.lang.Class)
*/
@ -721,7 +789,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand in the template
* @param <T> the type of the return value
* @return the response as entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#exchange(java.lang.String, org.springframework.http.HttpMethod,
* org.springframework.http.HttpEntity,
* org.springframework.core.ParameterizedTypeReference, java.lang.Object[])
@ -749,7 +817,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand in the template
* @param <T> the type of the return value
* @return the response as entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#exchange(java.lang.String, org.springframework.http.HttpMethod,
* org.springframework.http.HttpEntity,
* org.springframework.core.ParameterizedTypeReference, java.util.Map)
@ -776,7 +844,7 @@ public class TestRestTemplate {
* @param responseType the type of the return value
* @param <T> the type of the return value
* @return the response as entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#exchange(java.net.URI, org.springframework.http.HttpMethod,
* org.springframework.http.HttpEntity,
* org.springframework.core.ParameterizedTypeReference)
@ -799,7 +867,7 @@ public class TestRestTemplate {
* @param responseType the type of the return value
* @param <T> the type of the return value
* @return the response as entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#exchange(org.springframework.http.RequestEntity, java.lang.Class)
*/
public <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity,
@ -820,7 +888,7 @@ public class TestRestTemplate {
* @param responseType the type of the return value
* @param <T> the type of the return value
* @return the response as entity
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#exchange(org.springframework.http.RequestEntity,
* org.springframework.core.ParameterizedTypeReference)
*/
@ -841,7 +909,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand in the template
* @param <T> the type of the return value
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#execute(java.lang.String, org.springframework.http.HttpMethod,
* org.springframework.web.client.RequestCallback,
* org.springframework.web.client.ResponseExtractor, java.lang.Object[])
@ -865,7 +933,7 @@ public class TestRestTemplate {
* @param urlVariables the variables to expand in the template
* @param <T> the type of the return value
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#execute(java.lang.String, org.springframework.http.HttpMethod,
* org.springframework.web.client.RequestCallback,
* org.springframework.web.client.ResponseExtractor, java.util.Map)
@ -886,7 +954,7 @@ public class TestRestTemplate {
* @param responseExtractor object that extracts the return value from the response
* @param <T> the type of the return value
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
* @throws RestClientException on-client side HTTP error
* @throws RestClientException on client-side HTTP error
* @see RestTemplate#execute(java.net.URI, org.springframework.http.HttpMethod,
* org.springframework.web.client.RequestCallback,
* org.springframework.web.client.ResponseExtractor)

Loading…
Cancel
Save