diff --git a/README.md b/README.md index 9f46938..366ef30 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,24 @@ # HTTP MOCK SERVER -## Create server jar (in mockserver directory) +## Create server jar ``` +cd mockserver mvn clean package assembly:single ``` -## Start server on port (default 9999) +## Start server ``` java -jar mockserver--jar-with-dependencies.jar [PORT] ``` -## Create mock on server via client +Default port is 9999. + +## Create mock on server + +### Via client ```java RemoteMockServer remoteMockServer = new RemoteMockServer('localhost', ) @@ -27,11 +32,13 @@ remoteMockServer.addMock(new AddMock( soap: ..., statusCode: ..., method: ..., - responseHeaders: ... + responseHeaders: ..., + schema: ... )) ``` - -or via sending POST request to localhost:/serverControl +### Via HTTP + +Send POST request to localhost:/serverControl ```xml @@ -45,9 +52,12 @@ or via sending POST request to localhost:/serverControl ... ... ... + ... ``` +### Parameters + * name - name of mock, must be unique * path - path on which mock should be created * port - inteer, port on which mock should be created, cannot be the same as mock server port @@ -57,17 +67,19 @@ or via sending POST request to localhost:/serverControl * statusCode - integer, status code of response when predicate is satisfied, default 200 * method - POST|PUT|DELETE|GET|TRACE|OPTION|HEAD, expected http method of request, default POST * responseHeaders - groovyClosure as string which must evaluate to Map which will be added to response headers, default { _ -> [:] } +* schema - path to xsd schema file on mockserver classpath; default empty, so no vallidation of request is performed; if validation fails then response has got status 400 and response is raw message from validator + +### Closures request properties In closures input parameter (called req) contains properties: - * text - request body as java.util.String * headers - java.util.Map with request headers * query - java.util.Map with query parameters * xml - groovy.util.slurpersupport.GPathResult created from request body (if request body is valid xml) * soap - groovy.util.slurpersupport.GPathResult created from request body without Envelope and Body elements (if request body is valid soap xml) * json - java.lang.Object created from request body (if request body is valid json) -* path - java.util.List with not empty parts of request path +* path - java.util.List with not empty parts of request path Response if success: @@ -81,14 +93,17 @@ Response with error message if failure: ... ``` -## Mock could be peeked to get get report of its invocations. -Via client: +## Peek mock +Mock could be peeked to get get report of its invocations. + +### Via client ```java List mockEvents = remoteMockServer.peekMock('...') ``` -Via sending POST request to localhost:/serverControl +### Via HTTP +Send POST request to localhost:/serverControl ```xml @@ -134,14 +149,17 @@ Response with error message if failure: ... ``` -## When mock was used it could be unregistered by name. It also optionally returns report of mock invocations if second parameter is true. -Via client: +## Remove mock + +When mock was used it could be unregistered by name. It also optionally returns report of mock invocations if second parameter is true. + +### Via client ```java List mockEvents = remoteMockServer.removeMock('...', ...) ``` - -Via sending POST request to localhost:/serverControl +### Via HTTP +Send POST request to localhost:/serverControl ```xml @@ -188,22 +206,23 @@ If skipReport is set to true then response will be: ``` - Response with error message if failure: ```xml ... ``` +## List mocks definitions -## List of current registered mocks could be retrieved: -Via client: +### Via client ```java List mocks = remoteMockServer.listMocks() ``` -or via sending GET request to localhost:/serverControl +### Via HTTP + +Send GET request to localhost:/serverControl Response: