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: 1.3 $
Author:
Mike Bowler, Noboru Sinohara, Marc Guillemot, Brad Clarke, Ahmed Ashour

Constructor Summary
MockWebConnection(WebClient webClient)
 Create an instance
 
Method Summary
 java.util.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()
 java.util.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).
 WebResponse getResponse(WebRequestSettings webRequestSettings)
 Submit a request and retrieve a response
 org.apache.commons.httpclient.HttpState getState()
 Return the HttpState
 void setDefaultResponse(byte[] content, int statusCode, java.lang.String statusMessage, java.lang.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(java.lang.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(java.lang.String content, int statusCode, java.lang.String statusMessage, java.lang.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(java.net.URL url, byte[] content, int statusCode, java.lang.String statusMessage, java.lang.String contentType, java.util.List responseHeaders)
 Set the response that will be returned when the specified url is requested.
 void setResponse(java.net.URL url, java.lang.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(java.net.URL url, java.lang.String content, int statusCode, java.lang.String statusMessage, java.lang.String contentType, java.util.List responseHeaders)
 Set 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)
 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(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 com.gargoylesoftware.htmlunit.WebConnectionImpl
getWebClient
 
Methods inherited from class java.lang.Object
equals, 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

getLastAdditionalHeaders

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

Returns:
See above

getLastMethod

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

Returns:
See above

getLastParameters

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

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

getResponse

public WebResponse getResponse(WebRequestSettings webRequestSettings)
                        throws java.io.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:
java.io.IOException - (only for extending classes)

getState

public org.apache.commons.httpclient.HttpState getState()
Return the HttpState

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

setDefaultResponse

public void setDefaultResponse(byte[] content,
                               int statusCode,
                               java.lang.String statusMessage,
                               java.lang.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(java.lang.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

setDefaultResponse

public void setDefaultResponse(java.lang.String content,
                               int statusCode,
                               java.lang.String statusMessage,
                               java.lang.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

setResponse

public void setResponse(java.net.URL url,
                        byte[] content,
                        int statusCode,
                        java.lang.String statusMessage,
                        java.lang.String contentType,
                        java.util.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(java.net.URL url,
                        java.lang.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(java.net.URL url,
                        java.lang.String content,
                        int statusCode,
                        java.lang.String statusMessage,
                        java.lang.String contentType,
                        java.util.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(java.net.URL url,
                        java.lang.String content,
                        java.lang.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(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


Copyright © 2003-2016 AppPerfect Corporation. All Rights Reserved.