public class MockServer extends Object
| Modifier and Type | Method and Description |
|---|---|
int |
getPort() |
RequestDataHolder |
getRequest() |
RequestDataHolder |
getRequest(int requestNumber) |
String |
getRequestAuthType() |
String |
getRequestAuthType(int requestNumber) |
String |
getRequestBody() |
String |
getRequestBody(int requestNumber) |
int |
getRequestCount() |
Map<String,String> |
getRequestHeaders() |
Map<String,String> |
getRequestHeaders(int requestNumber) |
String |
getRequestMethod() |
String |
getRequestMethod(int requestNumber) |
String |
getRequestQueryString() |
String |
getRequestQueryString(int requestNumber) |
void |
initializeServer(int port)
Initialize mock server.
|
void |
resetRequestData()
Reset all saved data from requests made against this mock.
|
void |
resetResponseData()
Reset all set response values back to defaults.
|
void |
setDefaultResponse(String body,
String contentType,
Integer code,
Map<String,String> headers)
Sets default response to return in case when request URL, method, query string and/or SOAP action does not match any REST or SOAP
response configured into this mock server.
|
void |
setDefaultResponseFromFile(String filePath,
String contentType,
Integer code,
Map<String,String> headers)
Sets default response to return in case when request URL, method, query string and/or SOAP action does not match any REST or SOAP
response configured into this mock server.
|
void |
setRestResponseData(String path,
String method,
Map<String,String> queryParameters,
String body,
String contentType,
Integer code,
Map<String,String> headers)
Sets REST response to return in case when request URL, method, and optional query string matches into given values.
|
void |
setRestResponseDataFromFile(String path,
String method,
Map<String,String> queryParameters,
String filePath,
String contentType,
Integer code,
Map<String,String> headers)
Sets REST response to return in case when request URL, method, and optional query string matches into given values.
|
void |
setSoapResponseData(String path,
String soapAction,
String body,
String contentType,
Integer code,
Map<String,String> headers)
Sets REST response to return in case when request URL, and SOAP action matches into given values.
|
void |
setSoapResponseDataFromFile(String path,
String soapAction,
String filePath,
String contentType,
Integer code,
Map<String,String> headers)
Sets REST response to return in case when request URL, and SOAP action matches into given values.
|
void |
start()
Start mock server
|
void |
stop()
Stop mock server.
|
public void initializeServer(int port)
throws IOException
port - - Port to listen when started. If 0 then first available port is selectedIOException - - If selecting the first available port fails.public void start()
throws Exception
Exception - - If starting fails.public int getPort()
public RequestDataHolder getRequest()
public RequestDataHolder getRequest(int requestNumber)
requestNumber - - Number of request to check after initialize or resetpublic String getRequestAuthType()
public String getRequestAuthType(int requestNumber)
requestNumber - - Number of request to check after initialize or resetpublic String getRequestBody()
public String getRequestBody(int requestNumber)
requestNumber - - Number of request to check after initialize or resetpublic int getRequestCount()
public Map<String,String> getRequestHeaders()
public Map<String,String> getRequestHeaders(int requestNumber)
requestNumber - - Number of request to check after initialize or resetpublic String getRequestMethod()
public String getRequestMethod(int requestNumber)
requestNumber - - Number of request to check after initialize or resetpublic String getRequestQueryString()
public String getRequestQueryString(int requestNumber)
requestNumber - - Number of request to check after initialize or resetpublic void resetRequestData()
public void resetResponseData()
public void setDefaultResponse(String body, String contentType, Integer code, Map<String,String> headers)
body - - Response body content. Can be null, default is empty responsecontentType - - Response body content type. Can be null, default is content type from requestcode - - Response HTTP status code, Can be null, default is 200.headers - - Response headers, Can be null.public void setDefaultResponseFromFile(String filePath, String contentType, Integer code, Map<String,String> headers)
filePath - - Path to file which content is used for response body contentcontentType - - Response body content type. Can be null, default is content type from requestcode - - Response HTTP status code, Can be null, default is 200.headers - - Response headers, Can be null.public void setRestResponseData(String path, String method, Map<String,String> queryParameters, String body, String contentType, Integer code, Map<String,String> headers)
path - - Request URL path to matchmethod - - Request method to matchqueryParameters - - Optional request query parameters to matchbody - - Body content to return in responsecontentType - - Response body content typecode - - Response HTTP codeheaders - - Response HTTP headerspublic void setRestResponseDataFromFile(String path, String method, Map<String,String> queryParameters, String filePath, String contentType, Integer code, Map<String,String> headers)
path - - Request URL path to matchmethod - - Request method to matchqueryParameters - - Optional request query parameters to matchfilePath - - Path to file which content is used for response body contentcontentType - - Response body content typecode - - Response HTTP codeheaders - - Response HTTP headerspublic void setSoapResponseData(String path, String soapAction, String body, String contentType, Integer code, Map<String,String> headers)
path - - Request URL path to matchsoapAction - - SOAP action to matchbody - - Body content to return in responsecontentType - - Response body content typecode - - Response HTTP codeheaders - - Response HTTP headerspublic void setSoapResponseDataFromFile(String path, String soapAction, String filePath, String contentType, Integer code, Map<String,String> headers)
path - - Request URL path to matchsoapAction - - SOAP action to matchfilePath - - Path to file which content is used for response body contentcontentType - - Response body content typecode - - Response HTTP codeheaders - - Response HTTP headersCopyright © 2019. All rights reserved.