|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.gargoylesoftware.htmlunit.MockWebConnection
public class MockWebConnection
A fake WebConnection designed to mock out the actual HTTP connections.
| Constructor Summary | |
|---|---|
MockWebConnection()
|
|
| Method Summary | |
|---|---|
Map<String,String> |
getLastAdditionalHeaders()
Returns the additional headers that were used in the in the last call to getResponse(WebRequest). |
HttpMethod |
getLastMethod()
Returns the method that was used in the last call to submitRequest(). |
List<NameValuePair> |
getLastParameters()
Returns the parameters that were used in the last call to submitRequest(). |
WebRequest |
getLastWebRequest()
Returns the WebRequest that was used in the in the last call
to getResponse(WebRequest). |
WebRequest |
getLastWebRequestSettings()
Deprecated. as of 2.8, please use getLastWebRequest() instead |
int |
getRequestCount()
Returns the number of requests made to this mock web connection. |
List<String> |
getRequestedUrls(URL relativeTo)
Gets the list of requested URLs relative to the provided URL. |
WebResponse |
getResponse(WebRequest request)
Submits a request and retrieves a response. |
boolean |
hasResponse(URL url)
Indicates if a response has already been configured for this URL. |
void |
setDefaultResponse(byte[] content,
int statusCode,
String statusMessage,
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(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(String content,
int statusCode,
String statusMessage,
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(String content,
int statusCode,
String statusMessage,
String contentType,
List<? extends NameValuePair> responseHeaders)
Sets the response that will be returned when the specified URL is requested. |
void |
setDefaultResponse(String content,
int statusCode,
String statusMessage,
String contentType,
String charset,
List<? extends NameValuePair> responseHeaders)
Sets the response that will be returned when the specified URL is requested. |
void |
setDefaultResponse(String content,
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(String content,
String contentType,
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(URL url,
byte[] content,
int statusCode,
String statusMessage,
String contentType,
List<? extends NameValuePair> responseHeaders)
Sets the response that will be returned when the specified URL is requested. |
void |
setResponse(URL url,
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(URL url,
String content,
int statusCode,
String statusMessage,
String contentType,
List<? extends NameValuePair> responseHeaders)
Sets the response that will be returned when the specified URL is requested. |
void |
setResponse(URL url,
String content,
int statusCode,
String statusMessage,
String contentType,
String charset,
List<? extends NameValuePair> responseHeaders)
Sets the response that will be returned when the specified URL is requested. |
void |
setResponse(URL url,
String content,
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(URL url,
String content,
String contentType,
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(URL url,
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 |
|---|
public MockWebConnection()
| Method Detail |
|---|
public WebResponse getResponse(WebRequest request)
throws IOException
getResponse in interface WebConnectionrequest - the request
IOException - if an IO error occurspublic List<String> getRequestedUrls(URL relativeTo)
relativeTo - what should be removed from the requested URLs.
public HttpMethod getLastMethod()
public List<NameValuePair> getLastParameters()
public void setResponse(URL url,
String content,
int statusCode,
String statusMessage,
String contentType,
List<? extends NameValuePair> responseHeaders)
url - the URL that will return the given responsecontent - the content to returnstatusCode - the status code to returnstatusMessage - the status message to returncontentType - the content type to returnresponseHeaders - the response headers to return
public void setResponse(URL url,
String content,
int statusCode,
String statusMessage,
String contentType,
String charset,
List<? extends NameValuePair> responseHeaders)
url - the URL that will return the given responsecontent - the content to returnstatusCode - the status code to returnstatusMessage - the status message to returncontentType - the content type to returncharset - the name of a supported charsetresponseHeaders - the response headers to return
public void setResponse(URL url,
byte[] content,
int statusCode,
String statusMessage,
String contentType,
List<? extends NameValuePair> responseHeaders)
url - the URL that will return the given responsecontent - the content to returnstatusCode - the status code to returnstatusMessage - the status message to returncontentType - the content type to returnresponseHeaders - the response headers to return
public void setResponse(URL url,
String content)
setResponse(URL,String,int,String,String,List) with a status
of "200 OK", a content type of "text/html" and no additional headers.
url - the URL that will return the given responsecontent - the content to return
public void setResponse(URL url,
String content,
String contentType)
setResponse(URL,String,int,String,String,List) with a status
of "200 OK" and no additional headers.
url - the URL that will return the given responsecontent - the content to returncontentType - the content type to return
public void setResponse(URL url,
String content,
String contentType,
String charset)
setResponse(URL,String,int,String,String,String,List) with a status
of "200 OK" and no additional headers.
url - the URL that will return the given responsecontent - the content to returncontentType - the content type to returncharset - the name of a supported charset
public void setResponseAsGenericHtml(URL url,
String title)
url - the URL that will return the given responsetitle - the title of the page
public void setDefaultResponse(String content,
int statusCode,
String statusMessage,
String contentType)
content - the content to returnstatusCode - the status code to returnstatusMessage - the status message to returncontentType - the content type to return
public void setDefaultResponse(byte[] content,
int statusCode,
String statusMessage,
String contentType)
content - the content to returnstatusCode - the status code to returnstatusMessage - the status message to returncontentType - the content type to returnpublic void setDefaultResponse(String content)
content - the content to return
public void setDefaultResponse(String content,
String contentType)
content - the content to returncontentType - the content type to return
public void setDefaultResponse(String content,
String contentType,
String charset)
content - the content to returncontentType - the content type to returncharset - the name of a supported charset
public void setDefaultResponse(String content,
int statusCode,
String statusMessage,
String contentType,
List<? extends NameValuePair> responseHeaders)
content - the content to returnstatusCode - the status code to returnstatusMessage - the status message to returncontentType - the content type to returnresponseHeaders - the response headers to return
public void setDefaultResponse(String content,
int statusCode,
String statusMessage,
String contentType,
String charset,
List<? extends NameValuePair> responseHeaders)
content - the content to returnstatusCode - the status code to returnstatusMessage - the status message to returncontentType - the content type to returncharset - the name of a supported charsetresponseHeaders - the response headers to returnpublic Map<String,String> getLastAdditionalHeaders()
getResponse(WebRequest).
getResponse(WebRequest)@Deprecated public WebRequest getLastWebRequestSettings()
getLastWebRequest() instead
WebRequest that was used in the in the last call
to getResponse(WebRequest).
WebRequest that was used in the in the last call
to getResponse(WebRequest)public WebRequest getLastWebRequest()
WebRequest that was used in the in the last call
to getResponse(WebRequest).
WebRequest that was used in the in the last call
to getResponse(WebRequest)public int getRequestCount()
public boolean hasResponse(URL url)
url - the url
false if no response has been configured
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||