## com.gargoylesoftware.htmlunit
Class MockWebConnection

    java.lang.Object
      com.gargoylesoftware.htmlunit.MockWebConnection

All Implemented Interfaces:
  WebConnection

    public class MockWebConnection

extends java.lang.Object
implements WebConnection

A fake `WebConnection` designed to mock out the actual HTTP connections.

Version:
  $Revision: 4789 $
Author:
  Mike Bowler, Noboru Sinohara, Marc Guillemot, Brad Clarke, Ahmed Ashour

Constructor Summary
`MockWebConnection()`

Method Summary
`java.util.Map<java.lang.String,java.lang.String>` `getLastAdditionalHeaders()` Returns the additional headers that were used in the in the last call to `getResponse(WebRequestSettings)`.
`HttpMethod` `getLastMethod()` Returns the method that was used in the last call to submitRequest().
`java.util.List<org.apache.commons.httpclient.NameValuePair>` `getLastParameters()` Returns the parameters that were used in the last call to submitRequest().
`WebRequestSettings` `getLastWebRequestSettings()` Returns the `WebRequestSettings` that was used in the in the last call to `getResponse(WebRequestSettings)`.
`int` `getRequestCount()` Returns the number of requests made to this mock web connection.
`WebResponse` `getResponse(WebRequestSettings settings)` Submits a request and retrieves a response.
`void` `setDefaultResponse(byte[] content, int statusCode, java.lang.String statusMessage, java.lang.String contentType)` Sets the response that will be returned when a URL is requested that does not have a specific content set for it.
`void` `setDefaultResponse(java.lang.String content)` Sets the response that will be returned when a URL is requested that does not have a specific content set for it.
`void` `setDefaultResponse(java.lang.String content, int statusCode, java.lang.String statusMessage, java.lang.String contentType)` Sets the response that will be returned when a URL is requested that does not have a specific content set for it.
`void` `setDefaultResponse(java.lang.String content, int statusCode, java.lang.String statusMessage, java.lang.String contentType, java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)` Sets the response that will be returned when the specified URL is requested.
`void` `setDefaultResponse(java.lang.String content, int statusCode, java.lang.String statusMessage, java.lang.String contentType, java.lang.String charset, java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)` Sets the response that will be returned when the specified URL is requested.
`void` `setDefaultResponse(java.lang.String content, java.lang.String contentType)` Sets the response that will be returned when a URL is requested that does not have a specific content set for it.
`void` `setDefaultResponse(java.lang.String content, java.lang.String contentType, java.lang.String charset)` Sets the response that will be returned when a URL is requested that does not have a specific content set for it.
`void` `setResponse(java.net.URL url, byte[] content, int statusCode, java.lang.String statusMessage, java.lang.String contentType, java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)` Sets the response that will be returned when the specified URL is requested.
`void` `setResponse(java.net.URL url, java.lang.String content)` Convenient method that is the same as calling `setResponse(URL,String,int,String,String,List)` with a status of "200 OK", a content type of "text/html" and no additional headers.
`void` `setResponse(java.net.URL url, java.lang.String content, int statusCode, java.lang.String statusMessage, java.lang.String contentType, java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)` Sets the response that will be returned when the specified URL is requested.
`void` `setResponse(java.net.URL url, java.lang.String content, int statusCode, java.lang.String statusMessage, java.lang.String contentType, java.lang.String charset, java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)` Sets the response that will be returned when the specified URL is requested.
`void` `setResponse(java.net.URL url, java.lang.String content, java.lang.String contentType)` Convenient method that is the same as calling `setResponse(URL,String,int,String,String,List)` with a status of "200 OK" and no additional headers.
`void` `setResponse(java.net.URL url, java.lang.String content, java.lang.String contentType, java.lang.String charset)` Convenient method that is the same as calling `setResponse(URL,String,int,String,String,String,List)` with a status of "200 OK" and no additional headers.
`void` `setResponseAsGenericHtml(java.net.URL url, java.lang.String title)` Specify a generic HTML page that will be returned when the given URL is specified.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MockWebConnection

    public MockWebConnection()

Method Detail

### getResponse

    public WebResponse getResponse(WebRequestSettings settings)
                            throws java.io.IOException

  Submits a request and retrieves a response.

  Specified by:
    `getResponse` in interface `WebConnection`
  Parameters:
    `settings` - Settings to make the request with
  Returns:
    the response to the request defined by the specified request settings
  Throws:
    `java.io.IOException` - if an IO error occurs

### getLastMethod

    public HttpMethod getLastMethod()

  Returns the method that was used in the last call to submitRequest().

  Returns:
    the method that was used in the last call to submitRequest()

### getLastParameters

    public java.util.List<org.apache.commons.httpclient.NameValuePair> getLastParameters()

  Returns the parameters that were used in the last call to submitRequest().

  Returns:
    the parameters that were used in the last call to submitRequest()

### setResponse

    public void setResponse(java.net.URL url,
                            java.lang.String content,
                            int statusCode,
                            java.lang.String statusMessage,
                            java.lang.String contentType,
                            java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)

  Sets the response that will be returned when the specified URL is requested.

  Parameters:
    `url` - the URL that will return the given response
    `content` - the content to return
    `statusCode` - the status code to return
    `statusMessage` - the status message to return
    `contentType` - the content type to return
    `responseHeaders` - the response headers to return

### setResponse

    public void setResponse(java.net.URL url,
                            java.lang.String content,
                            int statusCode,
                            java.lang.String statusMessage,
                            java.lang.String contentType,
                            java.lang.String charset,
                            java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)

  Sets the response that will be returned when the specified URL is requested.

  Parameters:
    `url` - the URL that will return the given response
    `content` - the content to return
    `statusCode` - the status code to return
    `statusMessage` - the status message to return
    `contentType` - the content type to return
    `charset` - the name of a supported charset
    `responseHeaders` - the response headers to return

### setResponse

    public void setResponse(java.net.URL url,
                            byte[] content,
                            int statusCode,
                            java.lang.String statusMessage,
                            java.lang.String contentType,
                            java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)

  Sets the response that will be returned when the specified URL is requested.

  Parameters:
    `url` - the URL that will return the given response
    `content` - the content to return
    `statusCode` - the status code to return
    `statusMessage` - the status message to return
    `contentType` - the content type to return
    `responseHeaders` - the response headers to return

### setResponse

    public void setResponse(java.net.URL url,
                            java.lang.String content)

  Convenient method that is the same as calling `setResponse(URL,String,int,String,String,List)` with a status of "200 OK", a content type of "text/html" and no additional headers.

  Parameters:
    `url` - the URL that will return the given response
    `content` - the content to return

### setResponse

    public void setResponse(java.net.URL url,
                            java.lang.String content,
                            java.lang.String contentType)

  Convenient method that is the same as calling `setResponse(URL,String,int,String,String,List)` with a status of "200 OK" and no additional headers.

  Parameters:
    `url` - the URL that will return the given response
    `content` - the content to return
    `contentType` - the content type to return

### setResponse

    public void setResponse(java.net.URL url,
                            java.lang.String content,
                            java.lang.String contentType,
                            java.lang.String charset)

  Convenient method that is the same as calling `setResponse(URL,String,int,String,String,String,List)` with a status of "200 OK" and no additional headers.

  Parameters:
    `url` - the URL that will return the given response
    `content` - the content to return
    `contentType` - the content type to return
    `charset` - the name of a supported charset

### setResponseAsGenericHtml

    public void setResponseAsGenericHtml(java.net.URL url,
                                         java.lang.String title)

  Specify a generic HTML page that will be returned when the given URL is specified. The page will contain only minimal HTML to satisfy the HTML parser but will contain the specified title so that tests can check for titleText.

  Parameters:
    `url` - the URL that will return the given response
    `title` - the title of the page

### setDefaultResponse

    public void setDefaultResponse(java.lang.String content,
                                   int statusCode,
                                   java.lang.String statusMessage,
                                   java.lang.String contentType)

  Sets the response that will be returned when a URL is requested that does not have a specific content set for it.

  Parameters:
    `content` - the content to return
    `statusCode` - the status code to return
    `statusMessage` - the status message to return
    `contentType` - the content type to return

### setDefaultResponse

    public void setDefaultResponse(byte[] content,
                                   int statusCode,
                                   java.lang.String statusMessage,
                                   java.lang.String contentType)

  Sets the response that will be returned when a URL is requested that does not have a specific content set for it.

  Parameters:
    `content` - the content to return
    `statusCode` - the status code to return
    `statusMessage` - the status message to return
    `contentType` - the content type to return

### setDefaultResponse

    public void setDefaultResponse(java.lang.String content)

  Sets the response that will be returned when a URL is requested that does not have a specific content set for it.

  Parameters:
    `content` - the content to return

### setDefaultResponse

    public void setDefaultResponse(java.lang.String content,
                                   java.lang.String contentType)

  Sets the response that will be returned when a URL is requested that does not have a specific content set for it.

  Parameters:
    `content` - the content to return
    `contentType` - the content type to return

### setDefaultResponse

    public void setDefaultResponse(java.lang.String content,
                                   java.lang.String contentType,
                                   java.lang.String charset)

  Sets the response that will be returned when a URL is requested that does not have a specific content set for it.

  Parameters:
    `content` - the content to return
    `contentType` - the content type to return
    `charset` - the name of a supported charset

### setDefaultResponse

    public void setDefaultResponse(java.lang.String content,
                                   int statusCode,
                                   java.lang.String statusMessage,
                                   java.lang.String contentType,
                                   java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)

  Sets the response that will be returned when the specified URL is requested.

  Parameters:
    `content` - the content to return
    `statusCode` - the status code to return
    `statusMessage` - the status message to return
    `contentType` - the content type to return
    `responseHeaders` - the response headers to return

### setDefaultResponse

    public void setDefaultResponse(java.lang.String content,
                                   int statusCode,
                                   java.lang.String statusMessage,
                                   java.lang.String contentType,
                                   java.lang.String charset,
                                   java.util.List<? extends org.apache.commons.httpclient.NameValuePair> responseHeaders)

  Sets the response that will be returned when the specified URL is requested.

  Parameters:
    `content` - the content to return
    `statusCode` - the status code to return
    `statusMessage` - the status message to return
    `contentType` - the content type to return
    `charset` - the name of a supported charset
    `responseHeaders` - the response headers to return

### getLastAdditionalHeaders

    public java.util.Map<java.lang.String,java.lang.String> getLastAdditionalHeaders()

  Returns the additional headers that were used in the in the last call to `getResponse(WebRequestSettings)`.

  Returns:
    the additional headers that were used in the in the last call to `getResponse(WebRequestSettings)`

### getLastWebRequestSettings

    public WebRequestSettings getLastWebRequestSettings()

  Returns the `WebRequestSettings` that was used in the in the last call to `getResponse(WebRequestSettings)`.

  Returns:
    the `WebRequestSettings` that was used in the in the last call to `getResponse(WebRequestSettings)`

### getRequestCount

    public int getRequestCount()

  Returns the number of requests made to this mock web connection.

  Returns:
    the number of requests made to this mock web connection

Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.