Class MockLowLevelHttpRequest
- java.lang.Object
-
- com.google.api.client.http.LowLevelHttpRequest
-
- com.google.api.client.testing.http.MockLowLevelHttpRequest
-
@Beta public class MockLowLevelHttpRequest extends LowLevelHttpRequest
- Since:
- 1.3
- Author:
- Yaniv Inbar
-
-
Constructor Summary
Constructors Constructor Description MockLowLevelHttpRequest()MockLowLevelHttpRequest(String url)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(String name, String value)Adds a header to the HTTP request.LowLevelHttpResponseexecute()Executes the request and returns a low-level HTTP response object.StringgetContentAsString()Returns HTTP content as a string, taking care of any encodings of the content if necessary.StringgetFirstHeaderValue(String name)Returns the value of the first header of the given name ornullfor none.Map<String,List<String>>getHeaders()Returns an unmodifiable view of the map of lowercase header name to values.List<String>getHeaderValues(String name)Returns the unmodifiable list of values of the headers of the given name (may be empty).MockLowLevelHttpResponsegetResponse()HTTP response to return fromexecute().StringgetUrl()Returns the request URL ornullfor none.MockLowLevelHttpRequestsetResponse(MockLowLevelHttpResponse response)Sets the HTTP response to return fromexecute().MockLowLevelHttpRequestsetUrl(String url)Sets the request URL ornullfor none.-
Methods inherited from class com.google.api.client.http.LowLevelHttpRequest
getContentEncoding, getContentLength, getContentType, getStreamingContent, setContentEncoding, setContentLength, setContentType, setStreamingContent, setTimeout
-
-
-
-
Constructor Detail
-
MockLowLevelHttpRequest
public MockLowLevelHttpRequest()
-
MockLowLevelHttpRequest
public MockLowLevelHttpRequest(String url)
- Parameters:
url- Request URL ornullfor none- Since:
- 1.4
-
-
Method Detail
-
addHeader
public void addHeader(String name, String value) throws IOException
Description copied from class:LowLevelHttpRequestAdds a header to the HTTP request.Note that multiple headers of the same name need to be supported, in which case
LowLevelHttpRequest.addHeader(java.lang.String, java.lang.String)will be called for each instance of the header.- Specified by:
addHeaderin classLowLevelHttpRequest- Parameters:
name- header namevalue- header value- Throws:
IOException
-
execute
public LowLevelHttpResponse execute() throws IOException
Description copied from class:LowLevelHttpRequestExecutes the request and returns a low-level HTTP response object.- Specified by:
executein classLowLevelHttpRequest- Throws:
IOException
-
getUrl
public String getUrl()
Returns the request URL ornullfor none.- Since:
- 1.5
-
getHeaders
public Map<String,List<String>> getHeaders()
Returns an unmodifiable view of the map of lowercase header name to values.Note that unlike this method,
getFirstHeaderValue(String)andgetHeaderValues(String)are not case sensitive with respect to the input header name.- Since:
- 1.5
-
getFirstHeaderValue
public String getFirstHeaderValue(String name)
Returns the value of the first header of the given name ornullfor none.- Parameters:
name- header name (may be any case)- Since:
- 1.13
-
getHeaderValues
public List<String> getHeaderValues(String name)
Returns the unmodifiable list of values of the headers of the given name (may be empty).- Parameters:
name- header name (may be any case)- Since:
- 1.13
-
setUrl
public MockLowLevelHttpRequest setUrl(String url)
Sets the request URL ornullfor none.- Since:
- 1.5
-
getContentAsString
public String getContentAsString() throws IOException
Returns HTTP content as a string, taking care of any encodings of the content if necessary.Returns an empty string if there is no HTTP content.
- Throws:
IOException- Since:
- 1.12
-
getResponse
public MockLowLevelHttpResponse getResponse()
HTTP response to return fromexecute().- Since:
- 1.8
-
setResponse
public MockLowLevelHttpRequest setResponse(MockLowLevelHttpResponse response)
Sets the HTTP response to return fromexecute().By default this is a new instance of
MockLowLevelHttpResponse.
-
-