Created
October 9, 2011 20:17
-
-
Save eugenp/1274103 to your computer and use it in GitHub Desktop.
Integration testing of a REST API - decorate utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static < T >HttpEntityEnclosingRequest decorateRequestWithResource | |
( final HttpEntityEnclosingRequest request, final T resource ) | |
throws IOException{ | |
Preconditions.checkNotNull( request ); | |
Preconditions.checkNotNull( resource ); | |
final String resourceAsJson = JsonUtil.convertResourceToJson( resource ); | |
return JsonUtil.decorateRequestWithJson( request, resourceAsJson ); | |
} | |
public static HttpEntityEnclosingRequest decorateRequestWithJson | |
( final HttpEntityEnclosingRequest request, final String json ) | |
throws UnsupportedEncodingException{ | |
Preconditions.checkNotNull( request ); | |
Preconditions.checkNotNull( json ); | |
request.setHeader( HttpConstants.CONTENT_TYPE_HEADER, "application/json" ); | |
request.setEntity( new StringEntity( json ) ); | |
return request; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is used in:
http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/