It is a tool for creating mock responses. It allows to quick setup of different responses (using url and parameters) for REST services.
- JDK 8
- Maven 3
mvn clean package
It will create build project and prepare zip file in target directory. It can be unzipped in any location. To run project use
java - jar <jar file name>
in unzipped directory
Test mock can be retrieved by calling address:8090/rjmock/test
config - there is config file for application RJMockData - all mocks files
Configuration is in application.properties file
server.port - application port - default: 8090
data.dir - directory with RJMockData - default is in project directory
To call mocks server link should look like that: http://<address>:8090/rjmock/<package_name>/<subpath><query_parameters>
<package_name> tells which <package_name>.json file in descriptors directory should be used.
/<subpath><query_parameters> allows to select response which has been defined in package file
Example of package file:
{
"responses": [
{
"response": "test/test.json",
"subpath": "test",
"code": 200,
"type": "json",
"conditions":[
{
"param": "test",
"value": "value"
}
]
},
{
"response": "s",
"subpath":"_any_",
"code": 404,
"type": "text"
}
]
}
Each response has:
- response - string of response or path to file with response
- subpath - what subpath in link suggest this response. _any_ is special reponse type used when no other subpath is valid (conditions still can be checked)
- code - what is http return code
- type - what is response type (example: json or text)
- conditions - what are requested parameters and their values
Conditions are array and each has
- param - that is parameter name
- value - required value
Link that will call first response http://localhost:8090/rjmock/test/test?test=value
Packages and responses are read when called so can be changed without restarting application
If request has response kept in file then this file should be put in RJMockData/responses directory directory structure inside is not important. The only requirement is that path inside responses has to be given in package description
Package fragment
"responses": [
{
"response": "test/test.json",
(...)
Structure
RJMockData
|
|---responses
|
|---test
|
|---test.json