Describe schema validation parameter

Change-Id: I45e2a2d5af6317c626d797613028693635e3c936
This commit is contained in:
Dominik Adam Przybysz 2015-10-24 14:16:26 +02:00
parent 9a14f9bfab
commit faf8f8006a

View file

@ -2,19 +2,24 @@
# HTTP MOCK SERVER # HTTP MOCK SERVER
## Create server jar (in mockserver directory) ## Create server jar
``` ```
cd mockserver
mvn clean package assembly:single mvn clean package assembly:single
``` ```
## Start server on port (default 9999) ## Start server
``` ```
java -jar mockserver-<VERSION>-jar-with-dependencies.jar [PORT] java -jar mockserver-<VERSION>-jar-with-dependencies.jar [PORT]
``` ```
## Create mock on server via client Default port is 9999.
## Create mock on server
### Via client
```java ```java
RemoteMockServer remoteMockServer = new RemoteMockServer('localhost', <PORT>) RemoteMockServer remoteMockServer = new RemoteMockServer('localhost', <PORT>)
@ -27,11 +32,13 @@ remoteMockServer.addMock(new AddMock(
soap: ..., soap: ...,
statusCode: ..., statusCode: ...,
method: ..., method: ...,
responseHeaders: ... responseHeaders: ...,
schema: ...
)) ))
``` ```
### Via HTTP
or via sending POST request to localhost:<PORT>/serverControl
Send POST request to localhost:<PORT>/serverControl
```xml ```xml
@ -45,9 +52,12 @@ or via sending POST request to localhost:<PORT>/serverControl
<statusCode>...</statusCode> <statusCode>...</statusCode>
<method>...</method> <method>...</method>
<responseHeaders>...</responseHeaders> <responseHeaders>...</responseHeaders>
<schema>...</schema>
</addMock> </addMock>
``` ```
### Parameters
* name - name of mock, must be unique * name - name of mock, must be unique
* path - path on which mock should be created * 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 * 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:<PORT>/serverControl
* statusCode - integer, status code of response when predicate is satisfied, default 200 * 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 * 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 { _ -> [:] } * 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: In closures input parameter (called req) contains properties:
* text - request body as java.util.String * text - request body as java.util.String
* headers - java.util.Map with request headers * headers - java.util.Map with request headers
* query - java.util.Map with query parameters * query - java.util.Map with query parameters
* xml - groovy.util.slurpersupport.GPathResult created from request body (if request body is valid xml) * 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) * 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) * json - java.lang.Object created from request body (if request body is valid json)
* path - java.util.List<String> with not empty parts of request path * path - java.util.List<String> with not empty parts of request path
Response if success: Response if success:
@ -81,14 +93,17 @@ Response with error message if failure:
<exceptionOccured xmlns="http://touk.pl/mockserver/api/response">...</exceptionOccured> <exceptionOccured xmlns="http://touk.pl/mockserver/api/response">...</exceptionOccured>
``` ```
## Mock could be peeked to get get report of its invocations. ## Peek mock
Via client: Mock could be peeked to get get report of its invocations.
### Via client
```java ```java
List<MockEvent> mockEvents = remoteMockServer.peekMock('...') List<MockEvent> mockEvents = remoteMockServer.peekMock('...')
``` ```
Via sending POST request to localhost:<PORT>/serverControl ### Via HTTP
Send POST request to localhost:<PORT>/serverControl
```xml ```xml
<peekMock xmlns="http://touk.pl/mockserver/api/request"> <peekMock xmlns="http://touk.pl/mockserver/api/request">
@ -134,14 +149,17 @@ Response with error message if failure:
<exceptionOccured xmlns="http://touk.pl/mockserver/api/response">...</exceptionOccured> <exceptionOccured xmlns="http://touk.pl/mockserver/api/response">...</exceptionOccured>
``` ```
## When mock was used it could be unregistered by name. It also optionally returns report of mock invocations if second parameter is true. ## Remove mock
Via client:
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 ```java
List<MockEvent> mockEvents = remoteMockServer.removeMock('...', ...) List<MockEvent> mockEvents = remoteMockServer.removeMock('...', ...)
``` ```
### Via HTTP
Via sending POST request to localhost:<PORT>/serverControl Send POST request to localhost:<PORT>/serverControl
```xml ```xml
<removeMock xmlns="http://touk.pl/mockserver/api/request"> <removeMock xmlns="http://touk.pl/mockserver/api/request">
@ -188,22 +206,23 @@ If skipReport is set to true then response will be:
<mockRemoved xmlns="http://touk.pl/mockserver/api/response"/> <mockRemoved xmlns="http://touk.pl/mockserver/api/response"/>
``` ```
Response with error message if failure: Response with error message if failure:
```xml ```xml
<exceptionOccured xmlns="http://touk.pl/mockserver/api/response">...</exceptionOccured> <exceptionOccured xmlns="http://touk.pl/mockserver/api/response">...</exceptionOccured>
``` ```
## List mocks definitions
## List of current registered mocks could be retrieved: ### Via client
Via client:
```java ```java
List<RegisteredMock> mocks = remoteMockServer.listMocks() List<RegisteredMock> mocks = remoteMockServer.listMocks()
``` ```
or via sending GET request to localhost:<PORT>/serverControl ### Via HTTP
Send GET request to localhost:<PORT>/serverControl
Response: Response: