Mocker un serveur avec Wiremock
Don't mock what you don't own.
– Quelqu'un de bien
2 possibilités
Client
Serveur
{
"request": {
"method": "GET",
"url": "/body-file"
},
"response": {
"status": 200,
"bodyFileName": "path/to/myfile.xml"
}
}
{
"request" : {
"urlPath" : "/everything",
"method" : "ANY",
"headers" : {
"Accept" : {
"contains" : "xml"
}
},
"queryParameters" : {
"search_term" : {
"equalTo" : "WireMock"
}
},
"cookies" : {
"session" : {
"matches" : ".*12345.*"
}
},
"bodyPatterns" : [ {
"equalToXml" : "<search-results />"
}, {
"matchesXPath" : "//search-results"
} ],
"multipartPatterns" : [ {
"matchingType" : "ANY",
"headers" : {
"Content-Disposition" : {
"contains" : "name=\"info\""
},
"Content-Type" : {
"contains" : "charset"
}
},
"bodyPatterns" : [ {
"equalToJson" : "{}"
} ]
} ],
"basicAuthCredentials" : {
"username" : "jeff@example.com",
"password" : "jeffteenjefftyjeff"
}
},
"response" : {
"status" : 200
}
}
{
"scenarioName": "To do list",
"requiredScenarioState": "Started",
"newScenarioState": "Cancel newspaper item added",
"request": {
"method": "POST",
"url": "/todo/items",
"bodyPatterns": [
{ "contains": "Cancel newspaper subscription" }
]
},
"response": {
"status": 201
}
}