com.gargoylesoftware.htmlunit
Class MockWebConnection

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.WebConnectionImpl
      extended by com.gargoylesoftware.htmlunit.MockWebConnection
All Implemented Interfaces:
WebConnection

public class MockWebConnection
extends WebConnectionImpl

A fake WebConnection designed to mock out the actual http connections.

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

Constructor Summary
MockWebConnection(WebClient webClient)
          Create an instance
 
Method Summary
 Map getLastAdditionalHeaders()
          Return the additional headers that were used in the in the last call to getResponse(WebRequestSettings).
 SubmitMethod getLastMethod()
          Return the method that was used in the last call to submitRequest()
 List getLastParameters()
          Return the parameters that were used in the last call to submitRequest()
 WebRequestSettings getLastWebRequestSettings()
          Return the WebRequestSettings that was used in the in the last call to getResponse(WebRequestSettings).
protected  Log getLog()
          Return the log that is being used for all scripting objects
 WebResponse getResponse(WebRequestSettings webRequestSettings)
          Submit a request and retrieve a response
 HttpState getState()
          Return the HttpState
 void setDefaultResponse(byte[] content, int statusCode, String statusMessage, String contentType)
          Set the response that will be returned when a url is requested that does not have a specific content set for it.
 void setDefaultResponse(String content)
          Set the response that will be returned when a url is requested that does not have a specific content set for it.
 void setDefaultResponse(String content, int statusCode, String statusMessage, String contentType)
          Set the response that will be returned when a url is requested that does not have a specific content set for it.
 void setResponse(URL url, byte[] content, int statusCode, String statusMessage, String contentType, List responseHeaders)
          Set the response that will be returned when the specified url is requested.
 void setResponse(URL url, String content)
          Convenience 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(URL url, String content, int statusCode, String statusMessage, String contentType, List responseHeaders)
          Set the response that will be returned when the specified url is requested.
 void setResponse(URL url, String content, String contentType)
          Convenience 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 setResponseAsGenericHtml(URL url, String title)
          Specify a generic html page that will be returned when the given url is specified.
 
Methods inherited from class com.gargoylesoftware.htmlunit.WebConnectionImpl
getWebClient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockWebConnection

public MockWebConnection(WebClient webClient)
Create an instance

Parameters:
webClient - The web client
Method Detail

getLog

protected final Log getLog()
Return the log that is being used for all scripting objects

Returns:
The log.

getResponse

public WebResponse getResponse(WebRequestSettings webRequestSettings)
                        throws IOException
Submit a request and retrieve a response

Specified by:
getResponse in interface WebConnection
Specified by:
getResponse in class WebConnectionImpl
Parameters:
webRequestSettings - Settings to make the request with
Returns:
See above
Throws:
IOException - (only for extending classes)

getLastMethod

public SubmitMethod getLastMethod()
Return the method that was used in the last call to submitRequest()

Returns:
See above

getLastParameters

public List getLastParameters()
Return the parameters that were used in the last call to submitRequest()

Returns:
See above

setResponse

public void setResponse(URL url,
                        String content,
                        int statusCode,
                        String statusMessage,
                        String contentType,
                        List responseHeaders)
Set 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 - A list of KeyValuePairs that will be returned as response headers.

setResponse

public void setResponse(URL url,
                        byte[] content,
                        int statusCode,
                        String statusMessage,
                        String contentType,
                        List responseHeaders)
Set 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 - A list of KeyValuePairs that will be returned as response headers.

setResponse

public void setResponse(URL url,
                        String content)
Convenience 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(URL url,
                        String content,
                        String contentType)
Convenience 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

setResponseAsGenericHtml

public void setResponseAsGenericHtml(URL url,
                                     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(String content,
                               int statusCode,
                               String statusMessage,
                               String contentType)
Set 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,
                               String statusMessage,
                               String contentType)
Set 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(String content)
Set 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

getState

public HttpState getState()
Return the HttpState

Specified by:
getState in interface WebConnection
Specified by:
getState in class WebConnectionImpl
Returns:
The state.

getLastAdditionalHeaders

public Map getLastAdditionalHeaders()
Return the additional headers that were used in the in the last call to getResponse(WebRequestSettings).

Returns:
See above

getLastWebRequestSettings

public WebRequestSettings getLastWebRequestSettings()
Return the WebRequestSettings that was used in the in the last call to getResponse(WebRequestSettings).

Returns:
See above


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