Skip to content

Instantly share code, notes, and snippets.

@eugenp
Created October 9, 2011 20:08
Show Gist options
  • Save eugenp/1274091 to your computer and use it in GitHub Desktop.
Save eugenp/1274091 to your computer and use it in GitHub Desktop.
Integration testing of a REST API - retrieve utilities
public static String retrieveJsonFromResponse( final HttpResponse response )
throws IOException{
Preconditions.checkNotNull( response );
return IOUtils.toString( response.getEntity().getContent() );
}
public static < T >T retrieveResourceFromResponse
( final HttpResponse response, final Class< T > clazz ) throws IOException{
Preconditions.checkNotNull( response );
Preconditions.checkNotNull( clazz );
final String jsonFromResponse = retrieveJsonFromResponse( response );
return ConvertUtil.convertJsonToResource( jsonFromResponse, clazz );
}
@eugenp
Copy link
Author

eugenp commented Feb 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment