I have a URL (GET REQUEST) of the following pattern
where pathid query string parameters are comma separated
I have the following stubby mappings to match these url patterns
- request:
url: ^/testpath/(.*)/test
query:
pathid: '1'
method: GET
response:
headers:
Content-Type: application/json
status: 200
file: response/path-1.json
- request:
url: ^/testpath/(.*)/test
query:
pathid: '1,2'
method: GET
response:
headers:
Content-Type: application/json
status: 200
file: response/path-2.json
- request:
url: ^/testpath/(.*)/test
query:
pathid: '1,2,5'
method: GET
response:
headers:
Content-Type: application/json
status: 200
file: response/path-3.json
but I can't get this URL mapping to properly deliver different payloads based on different parameter combinations.
how can this be done?
@Sanath, short answer - yes, stubby4j matches on different stubbed query parameters combinations.
Few questions:
I wrote a test to validate the YAML configuration you provided in your question: https://github.com/azagniotov/stubby4j/pull/434/files (do note, I did change the url a little, but it is still a regex similar to your posted YAML).
The requests that test makes do match the stubs. (I did try without $ and with a $, like @code suggested). In addition, I also tested with cURL against a running standalone JAR:
curl -X GET http://localhost:8882/stackoverflow/70417269/1/test?pathid=1,2,5
and
curl -X GET http://localhost:8882/stackoverflow/70417269/1/test?pathid=1,2
Again, I got the expected responses from the server.
If the above does not help you, please feel free to raise a bug report https://github.com/azagniotov/stubby4j/issues/new/choose
The trick here is to change the order of request/response mappings in the yaml file.
- request:
url: ^/testpath/(.*)/test
query:
**pathid: '1,2,5'**
method: GET
response:
headers:
Content-Type: application/json
status: 200
file: response/path-3.json
- request:
url: ^/testpath/(.*)/test
query:
**pathid: '1,2'**
method: GET
response:
headers:
Content-Type: application/json
status: 200
file: response/path-2.json
- request:
url: ^/testpath/(.*)/test
query:
**pathid: '1'**
method: GET
response:
headers:
Content-Type: application/json
status: 200
file: response/path-1.json
note the path ids added in the descending order, so that more deeper matches will be executed first.
This way I was able to achieve this following requirement, of passing different path ids separated by a comma