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
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.List<java.lang.String>>headersMapMap of lowercase header name to values.private MockLowLevelHttpResponseresponseHTTP response to return fromexecute().private java.lang.StringurlRequest URL ornullfor none.
-
Constructor Summary
Constructors Constructor Description MockLowLevelHttpRequest()MockLowLevelHttpRequest(java.lang.String url)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(java.lang.String name, java.lang.String value)Adds a header to the HTTP request.LowLevelHttpResponseexecute()Executes the request and returns a low-level HTTP response object.java.lang.StringgetContentAsString()Returns HTTP content as a string, taking care of any encodings of the content if necessary.java.lang.StringgetFirstHeaderValue(java.lang.String name)Returns the value of the first header of the given name ornullfor none.java.util.Map<java.lang.String,java.util.List<java.lang.String>>getHeaders()Returns an unmodifiable view of the map of lowercase header name to values.java.util.List<java.lang.String>getHeaderValues(java.lang.String name)Returns the unmodifiable list of values of the headers of the given name (may be empty).MockLowLevelHttpResponsegetResponse()HTTP response to return fromexecute().java.lang.StringgetUrl()Returns the request URL ornullfor none.MockLowLevelHttpRequestsetResponse(MockLowLevelHttpResponse response)Sets the HTTP response to return fromexecute().MockLowLevelHttpRequestsetUrl(java.lang.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
-
-
-
-
Field Detail
-
url
private java.lang.String url
Request URL ornullfor none.
-
headersMap
private final java.util.Map<java.lang.String,java.util.List<java.lang.String>> headersMap
Map of lowercase header name to values.
-
response
private MockLowLevelHttpResponse response
HTTP response to return fromexecute().By default this is a new instance of
MockLowLevelHttpResponse.
-
-
Method Detail
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
execute
public LowLevelHttpResponse execute() throws java.io.IOException
Description copied from class:LowLevelHttpRequestExecutes the request and returns a low-level HTTP response object.- Specified by:
executein classLowLevelHttpRequest- Throws:
java.io.IOException
-
getUrl
public java.lang.String getUrl()
Returns the request URL ornullfor none.- Since:
- 1.5
-
getHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.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 java.lang.String getFirstHeaderValue(java.lang.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 java.util.List<java.lang.String> getHeaderValues(java.lang.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(java.lang.String url)
Sets the request URL ornullfor none.- Since:
- 1.5
-
getContentAsString
public java.lang.String getContentAsString() throws java.io.IOExceptionReturns 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:
java.io.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.
-
-