com.google.api.client.testing.http.javanet
Class MockHttpURLConnection

java.lang.Object
  extended by java.net.URLConnection
      extended by java.net.HttpURLConnection
          extended by com.google.api.client.testing.http.javanet.MockHttpURLConnection

public class MockHttpURLConnection
extends HttpURLConnection

Mock for HttpURLConnection.

Implementation is not thread-safe.

Since:
1.11
Author:
Yaniv Inbar

Field Summary
 
Fields inherited from class java.net.HttpURLConnection
chunkLength, fixedContentLength, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessage
 
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
 
Constructor Summary
MockHttpURLConnection(URL u)
           
 
Method Summary
 void connect()
           
 void disconnect()
           
 boolean doOutputCalled()
          Returns whether URLConnection.doOutput was called.
 OutputStream getOutputStream()
           
 int getResponseCode()
           
 void setDoOutput(boolean dooutput)
           
 MockHttpURLConnection setOutputStream(OutputStream outputStream)
          Sets the output stream or null to throw an UnknownServiceException when getOutputStream() is called.
 MockHttpURLConnection setResponseCode(int responseCode)
          Sets the HTTP response status code.
 boolean usingProxy()
           
 
Methods inherited from class java.net.HttpURLConnection
getErrorStream, getFollowRedirects, getHeaderField, getHeaderFieldDate, getHeaderFieldKey, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseMessage, setChunkedStreamingMode, setFixedLengthStreamingMode, setFollowRedirects, setInstanceFollowRedirects, setRequestMethod
 
Methods inherited from class java.net.URLConnection
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderFieldInt, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockHttpURLConnection

public MockHttpURLConnection(URL u)
Parameters:
u - the URL or null for none
Method Detail

disconnect

public void disconnect()
Specified by:
disconnect in class HttpURLConnection

usingProxy

public boolean usingProxy()
Specified by:
usingProxy in class HttpURLConnection

connect

public void connect()
             throws IOException
Specified by:
connect in class URLConnection
Throws:
IOException

getResponseCode

public int getResponseCode()
                    throws IOException
Overrides:
getResponseCode in class HttpURLConnection
Throws:
IOException

setDoOutput

public void setDoOutput(boolean dooutput)
Overrides:
setDoOutput in class URLConnection

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Overrides:
getOutputStream in class URLConnection
Throws:
IOException

doOutputCalled

public final boolean doOutputCalled()
Returns whether URLConnection.doOutput was called.


setOutputStream

public MockHttpURLConnection setOutputStream(OutputStream outputStream)
Sets the output stream or null to throw an UnknownServiceException when getOutputStream() is called.

By default it is null.


setResponseCode

public MockHttpURLConnection setResponseCode(int responseCode)
Sets the HTTP response status code.



Copyright © 2011-2012 Google. All Rights Reserved.