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>>
headersMap
Map of lowercase header name to values.private MockLowLevelHttpResponse
response
HTTP response to return fromexecute()
.private java.lang.String
url
Request URL ornull
for 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 void
addHeader(java.lang.String name, java.lang.String value)
Adds a header to the HTTP request.LowLevelHttpResponse
execute()
Executes the request and returns a low-level HTTP response object.java.lang.String
getContentAsString()
Returns HTTP content as a string, taking care of any encodings of the content if necessary.java.lang.String
getFirstHeaderValue(java.lang.String name)
Returns the value of the first header of the given name ornull
for 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).MockLowLevelHttpResponse
getResponse()
HTTP response to return fromexecute()
.java.lang.String
getUrl()
Returns the request URL ornull
for none.MockLowLevelHttpRequest
setResponse(MockLowLevelHttpResponse response)
Sets the HTTP response to return fromexecute()
.MockLowLevelHttpRequest
setUrl(java.lang.String url)
Sets the request URL ornull
for 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 ornull
for 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.IOException
Description copied from class:LowLevelHttpRequest
Adds 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:
addHeader
in classLowLevelHttpRequest
- Parameters:
name
- header namevalue
- header value- Throws:
java.io.IOException
-
execute
public LowLevelHttpResponse execute() throws java.io.IOException
Description copied from class:LowLevelHttpRequest
Executes the request and returns a low-level HTTP response object.- Specified by:
execute
in classLowLevelHttpRequest
- Throws:
java.io.IOException
-
getUrl
public java.lang.String getUrl()
Returns the request URL ornull
for 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 ornull
for 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 ornull
for none.- Since:
- 1.5
-
getContentAsString
public java.lang.String getContentAsString() throws java.io.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:
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
.
-
-