Multiple Mock Data Files
- 11 Jan 2023
-
DarkLight
-
PDF
Multiple Mock Data Files
- Updated on 11 Jan 2023
-
DarkLight
-
PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
Multiple Mock Data Files
The adapter has a hierarchy for determining which response to use for a request.
Mock data hierarchy:
- Match data in the body.
- Match data in a path variable.
- Match data in a query or option.
- If there is a body (withBody).
- If there is a path variable (withPathv#).
- If there is a query (withQuery).
- If there is an option (withOption).
- Otherwise default.
Note: The old mock data format will still work since #5-8 are effectively the old way.
- On a call with a body { name: ‘abc123’ } the a.json would be returned.
- On a call with a path variable – http://system:80/path/ver/addresses/error the b.json would be returned.
- On a call with a query variable – http://system:80/path/ver/addresses?name=happy the c.json would be returned.
Example: Action.json
{
"name": "getIP",
"entitypath": "{base_path}/{version}/addresses/{pathv1}?{query}",
….
"responseObjects": [
{
"type": "name-abc123",
"key": "",
"mockFile": "a.json"
},
{
"type": "error",
"key": "",
"mockFile": "b.json"
},
{
"type": "name=happy",
"key": "",
"mockFile": "c.json"
}
]
},
- Can still support different mock data based on the URI structure:
- path variables (withPathv#)
- query (withQuery)
- On a call with a path variable – http://system:80/path/ver/addresses/abc123 the y.json is returned
- On a call with a query variable – http://system:80/path/ver/addresses?name=abc123 the z.json is returned.
- Otherwise the x.json is returned.
Example: Action.json
{
"name": "getIP",
"entitypath": "{base_path}/{version}/addresses/{pathv1}?{query}",
….
"responseObjects": [
{
"type": "default",
"key": "",
"mockFile": "x.json"
},
{
"type": "withPathv1",
"key": "",
"mockFile": "y.json"
},
{
"type": "withQuery",
"key": "",
"mockFile": "z.json"
}
]
},
Was this article helpful?