Tool that simplifies creation of fake http based services.
Example - fake implementation of JSONRpc service:
- Define which method should be mocked:
<?xml version="1.0" encoding="utf-8"?>
<!-- config/config.xml -->
<handlers>
<handler response="foo_response.xml">
<matcher type="equals" name="request.method" value="foo" />
</handler>
...
</handlers>
Response attributes tell where is stored information about response. Matcher tells when this response should be returned.
Currently supported matchers:
- any - always true,
- none - always false,
- equals - matches whether specified attribute (see below for more details) has specified value,
- logical and - true when submatchers returns true, false otherwise.
Currently supported attributes:
- request.method - represents http method used in request,
- request.jsonrpc - represents jsonrpc attributes,
- request.get - represents query string attributes.
Request attributes may be nested e.g.:
{
"result": {
"name": "foo"
},
"errors": null,
"id": 12
}
To use value of name in matcher definition reference to it with result.data.name.
<matcher type="equals" name="request.jsonrpc.result.name" value="foo" />
- Define proxy to use original service for other calls:
<?xml version="1.0" encoding="utf-8"?>
<!-- config/config.xml -->
<handlers>
...
<handler url="http://localhost:3500">
<matcher type="any" />
</handler>
</handlers>
- Define response
<?xml version="1.0" encoding="utf-8"?>
<!-- config/foo_response.xml -->
<response>
<body><![CDATA[FOO]]></body>
</response>
This response will return "FOO".
- Run Service Double server:
bin/service_double.sh start
and use your new service.