-
Notifications
You must be signed in to change notification settings - Fork 14
04.0 Response Resolution Strategy
Amit Gupta edited this page Mar 6, 2017
·
2 revisions
You can use captured data from request mappings into response mapping session to select the response file dynamically. You can use this captured information in response body, and headers too.
- request:
url: /stubs/employee/([0-9]+)
response:
file: "<% url.1 %>.xml"
- If I use url:
/stubs/employee/999
whereas 999.xml doesn't exist, Stubmatic will respond back with 404 status. What if I want to serve some default response? - What if you want to serve some random error every time as response to test negative scenarios?
- what if .... ?
Well!! Stubmatic provides you strategy based solution to decide which file has to be picked from files array at runtime.
- request:
url: /stubs/employee/([0-9]+)
response:
strategy: random
files: ["<% url.1 %>.xml","file2.xml","file3.xml"]
Stubmatic is currently supporting following strategies;
- first-found : Whichever file in files array is found first, will be served.
- random : Any file from files arrays will be served randomly.
- round-robin : files would be served in sequential order. It is circular. So once last file is served, stubbydb will serve first file next time.
- first-found + random : if randomly select file is not found then check for next file.
- first-found + round-robin : if sequentially selected file is not found then check for next file.
Now if you want that a particular file should be served with different response code, you can change the mapping like below;
- request:
url: /stubs/employee/([0-9]+)
response:
strategy: random
files: ["<% url.1 %>.xml","file2.xml",{"name":"file3.xml","status":500}]
- request:
url: /stubs/employee/([0-9]+)
response:
strategy: ["round-robin","first-found"]
files: ["<% url.1 %>.xml","file2.xml",{"name":"file3.xml","status":500}]
Keep watching this page for more strategies.