public class MockWebConnection extends Object implements WebConnection
WebConnection designed to mock out the actual HTTP connections.| Constructor and Description |
|---|
MockWebConnection() |
| Modifier and Type | Method and Description |
|---|---|
Map<String,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().
|
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,
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 org.apache.commons.httpclient.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 org.apache.commons.httpclient.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 org.apache.commons.httpclient.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 org.apache.commons.httpclient.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 org.apache.commons.httpclient.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.
|
public WebResponse getResponse(WebRequestSettings settings) throws IOException
getResponse in interface WebConnectionsettings - Settings to make the request withIOException - if an IO error occurspublic HttpMethod getLastMethod()
public List<org.apache.commons.httpclient.NameValuePair> getLastParameters()
public void setResponse(URL url, String content, int statusCode, String statusMessage, String contentType, List<? extends org.apache.commons.httpclient.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 returnpublic void setResponse(URL url, String content, int statusCode, String statusMessage, String contentType, String charset, List<? extends org.apache.commons.httpclient.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 returnpublic void setResponse(URL url, byte[] content, int statusCode, String statusMessage, String contentType, List<? extends org.apache.commons.httpclient.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 returnpublic 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 returnpublic 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 returnpublic 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 charsetpublic void setResponseAsGenericHtml(URL url, String title)
url - the URL that will return the given responsetitle - the title of the pagepublic 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 returnpublic 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 returnpublic void setDefaultResponse(String content, String contentType)
content - the content to returncontentType - the content type to returnpublic void setDefaultResponse(String content, String contentType, String charset)
content - the content to returncontentType - the content type to returncharset - the name of a supported charsetpublic void setDefaultResponse(String content, int statusCode, String statusMessage, String contentType, List<? extends org.apache.commons.httpclient.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 returnpublic void setDefaultResponse(String content, int statusCode, String statusMessage, String contentType, String charset, List<? extends org.apache.commons.httpclient.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(WebRequestSettings).getResponse(WebRequestSettings)public WebRequestSettings getLastWebRequestSettings()
WebRequestSettings that was used in the in the last call
to getResponse(WebRequestSettings).WebRequestSettings that was used in the in the last call
to getResponse(WebRequestSettings)public int getRequestCount()
Copyright © 2002–2014 Gargoyle Software Inc.. All rights reserved.