com.google.api.client.testing.http
Class MockLowLevelHttpResponse

java.lang.Object
  extended by com.google.api.client.http.LowLevelHttpResponse
      extended by com.google.api.client.testing.http.MockLowLevelHttpResponse

public class MockLowLevelHttpResponse
extends LowLevelHttpResponse

Mock for LowLevelHttpResponse.

Implementation is not thread-safe.

Since:
1.3
Author:
Yaniv Inbar

Constructor Summary
MockLowLevelHttpResponse()
           
 
Method Summary
 void addHeader(String name, String value)
          Adds a header to the response.
 InputStream getContent()
          Returns the HTTP response content input stream or null for none.
 String getContentEncoding()
          Returns the content encoding (for example "gzip") or null for none.
 long getContentLength()
          Returns the content length or 0 for none.
 String getContentType()
          Returns the content type or null for none.
 int getHeaderCount()
          Returns the number of HTTP response headers.
 String getHeaderName(int index)
          Returns the HTTP response header name at the given zero-based index.
 List<String> getHeaderNames()
          Returns the list of header names of HTTP response.
 String getHeaderValue(int index)
          Returns the HTTP response header value at the given zero-based index.
 List<String> getHeaderValues()
          Returns the list of header values of HTTP response.
 String getReasonPhrase()
          Returns the HTTP reason phrase or null for none.
 int getStatusCode()
          Returns the response status code or 0 for none.
 String getStatusLine()
          Returns the response status line or null for none.
 MockLowLevelHttpResponse setContent(InputStream content)
          Sets the input stream content of HTTP response or null for none.
 MockLowLevelHttpResponse setContent(String stringContent)
          Sets the response content to the given content string.
 MockLowLevelHttpResponse setContentEncoding(String contentEncoding)
          Sets the content encoding or null for none.
 MockLowLevelHttpResponse setContentLength(long contentLength)
          Sets the content length or -1 for unknown.
 MockLowLevelHttpResponse setContentType(String contentType)
          Sets the content type of HTTP response or null for none.
 MockLowLevelHttpResponse setHeaderNames(List<String> headerNames)
          Sets the list of header names of HTTP response.
 MockLowLevelHttpResponse setHeaderValues(List<String> headerValues)
          Sets the list of header values of HTTP response.
 MockLowLevelHttpResponse setReasonPhrase(String reasonPhrase)
          Sets the HTTP reason phrase or null for none.
 MockLowLevelHttpResponse setStatusCode(int statusCode)
          Sets the status code of HTTP response.
 
Methods inherited from class com.google.api.client.http.LowLevelHttpResponse
disconnect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockLowLevelHttpResponse

public MockLowLevelHttpResponse()
Method Detail

addHeader

public void addHeader(String name,
                      String value)
Adds a header to the response.

Parameters:
name - header name
value - header value

setContent

public MockLowLevelHttpResponse setContent(String stringContent)
Sets the response content to the given content string.

Parameters:
stringContent - content string or null for none

getContent

public InputStream getContent()
                       throws IOException
Description copied from class: LowLevelHttpResponse
Returns the HTTP response content input stream or null for none.

Specified by:
getContent in class LowLevelHttpResponse
Throws:
IOException - I/O exception

getContentEncoding

public String getContentEncoding()
Description copied from class: LowLevelHttpResponse
Returns the content encoding (for example "gzip") or null for none.

Specified by:
getContentEncoding in class LowLevelHttpResponse

getContentLength

public long getContentLength()
Description copied from class: LowLevelHttpResponse
Returns the content length or 0 for none.

Specified by:
getContentLength in class LowLevelHttpResponse

getContentType

public final String getContentType()
Description copied from class: LowLevelHttpResponse
Returns the content type or null for none.

Specified by:
getContentType in class LowLevelHttpResponse

getHeaderCount

public int getHeaderCount()
Description copied from class: LowLevelHttpResponse
Returns the number of HTTP response headers.

Note that multiple headers of the same name need to be supported, in which case each header value is treated as a separate header.

Specified by:
getHeaderCount in class LowLevelHttpResponse

getHeaderName

public String getHeaderName(int index)
Description copied from class: LowLevelHttpResponse
Returns the HTTP response header name at the given zero-based index.

Specified by:
getHeaderName in class LowLevelHttpResponse

getHeaderValue

public String getHeaderValue(int index)
Description copied from class: LowLevelHttpResponse
Returns the HTTP response header value at the given zero-based index.

Specified by:
getHeaderValue in class LowLevelHttpResponse

getReasonPhrase

public String getReasonPhrase()
Description copied from class: LowLevelHttpResponse
Returns the HTTP reason phrase or null for none.

Specified by:
getReasonPhrase in class LowLevelHttpResponse

getStatusCode

public int getStatusCode()
Description copied from class: LowLevelHttpResponse
Returns the response status code or 0 for none.

Specified by:
getStatusCode in class LowLevelHttpResponse

getStatusLine

public String getStatusLine()
Description copied from class: LowLevelHttpResponse
Returns the response status line or null for none.

Specified by:
getStatusLine in class LowLevelHttpResponse

getHeaderNames

public final List<String> getHeaderNames()
Returns the list of header names of HTTP response.

Since:
1.5

setHeaderNames

public MockLowLevelHttpResponse setHeaderNames(List<String> headerNames)
Sets the list of header names of HTTP response.

Default value is an empty list.

Since:
1.5

getHeaderValues

public final List<String> getHeaderValues()
Returns the list of header values of HTTP response.

Default value is an empty list.

Since:
1.5

setHeaderValues

public MockLowLevelHttpResponse setHeaderValues(List<String> headerValues)
Sets the list of header values of HTTP response.

Since:
1.5

setContent

public MockLowLevelHttpResponse setContent(InputStream content)
Sets the input stream content of HTTP response or null for none.

Since:
1.5

setContentType

public MockLowLevelHttpResponse setContentType(String contentType)
Sets the content type of HTTP response or null for none.

Since:
1.5

setContentEncoding

public MockLowLevelHttpResponse setContentEncoding(String contentEncoding)
Sets the content encoding or null for none.

Since:
1.5

setContentLength

public MockLowLevelHttpResponse setContentLength(long contentLength)
Sets the content length or -1 for unknown.

By default it is -1.

Warning: in prior version 0 was the default, but now the default is -1.

Since:
1.5

setStatusCode

public MockLowLevelHttpResponse setStatusCode(int statusCode)
Sets the status code of HTTP response.

Default value is 200.

Since:
1.5

setReasonPhrase

public MockLowLevelHttpResponse setReasonPhrase(String reasonPhrase)
Sets the HTTP reason phrase or null for none.

Since:
1.6


Copyright © 2011-2012 Google. All Rights Reserved.