Does wiremock currently support having multiple response/request pairs in the same json? I saw an issue from a while back but there was no apparent resolution to it.
https://groups.google.com/forum/#!msg/wiremock-user/GQCGLoZlWEk/WgTl1I9AAgAJ
No, not been done yet. I'll mark this as a feature request.
Random thought that it would be nice if scenario could be optionally shared:
{
"scenarioName": "To do list",
"requests": [
{
"requiredScenarioState": "Started",
"request": {
"method": "GET",
"url": "/todo/items"
},
"response": {
"status": 200,
"body": "<items><item>Buy milk</item></items>"
}
},
{
"requiredScenarioState": "Started",
"newScenarioState": "Cancel newspaper item added",
"request": {
"method": "POST",
"url": "/todo/items",
"bodyPatterns": [
{
"contains": "Cancel newspaper subscription"
}
]
},
"response": {
"status": 201
}
},
{
"requiredScenarioState": "Cancel newspaper item added",
"request": {
"method": "GET",
"url": "/todo/items"
},
"response": {
"status": 200,
"body": "<items><item>Buy milk</item><item>Cancel newspaper subscription</item></items>"
}
}
]
}
My two cents
Agree that would be nice
Multi-stub files now implemented in abfe4e6340fb5ce57a24b7da6a7dd7d00b48cf46.
No multi-scenario support yet, suggest that becomes a new feature request.
@tomakehurst great to see it's implemented, thanks! When will it be released?
Is the above has been released? if so what is the standalone version?
It was released in 2.22.0. You can find this out for yourself in the commit page linked to in my last comment (https://github.com/tomakehurst/wiremock/commit/abfe4e6340fb5ce57a24b7da6a7dd7d00b48cf46)
@tomakehurst Thanks for your reply. I am using stand-alone wiremock-standalone-2.26.3.jar. But I get below error when I try to pass multiple stubs in the request as an array.
POST call http://localhost:8080/__admin/mappings
Request:
{
"mappings": [
{
"id": "58e3e0df-1424-4cdd-b015-8d51c3d42873",
"name": "Some Name",
"request": {
"url": "/url/...",
"method": "POST",
"bodyPatterns": [
{
"equalToJson": "{\"type\":\"011\",..."}",
"ignoreArrayOrder": true,
"ignoreExtraElements": true
}
]
},
"response": {
"status": 504,
"body": "{\"resultName\"..."}",
"headers": {
"Content-Type": "application/json",
"Date": "Wed, 18 Mar 2020 06:23:56 GMT"
}
},
"uuid": "58e3e0df-1424-4cdd-b015-8d51c3d42873",
"persistent": true
},
{
"id": "58e3e0df-1424-4cdd-b015-8d51c3d42873",
"name": "Some Name",
"request": {
"url": "/url/...",
"method": "POST",
"bodyPatterns": [
{
"equalToJson": "{\"type\":\"0991\",..."}",
"ignoreArrayOrder": true,
"ignoreExtraElements": true
}
]
},
"response": {
"status": 504,
"body": "{\"resultName\"..."}",
"headers": {
"Content-Type": "application/json",
"Date": "Wed, 18 Mar 2020 06:23:56 GMT"
}
},
"uuid": "58e3e0df-1424-4cdd-b015-8d51c3d42873",
"persistent": true
}
]
}
Response: 422
{
"errors": [
{
"code": 10,
"source": {
"pointer": "/mappings"
},
"title": "Error parsing JSON",
"detail": "Unrecognized field \"mappings\" (class com.github.tomakehurst.wiremock.stubbing.StubMapping), not marked as ignorable"
}
]
}
Do you think I am missing anything here?
Cheers
Try POSTing it to http://localhost:8080/__admin/mappings/import
Most helpful comment
Try POSTing it to
http://localhost:8080/__admin/mappings/import