WireMock is an HTTP mock server. At its core it is web
server that can be primed to serve canned responses to particular requests
(stubbing) and that captures incoming requests so that they can be checked
later (verification).
It can be used as a library by any JVM application, or run
as a standalone process either on the same host as the system under test or a
remote server.
Example
I want to match part of the json, eg oib == ""
Request example:
{
"oib": "",
"status": "IN_PROGRESS",
}
For all request default stub is
stubFor(post(urlMatching(".*/documentationStatusMock")).atPriority(10)
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type",
"application/json; charset=utf-8")
.withBodyFile("documentationStatus/response.json")))
response.json
{
"statusCode": 0,
"statusName": "OK",
"rowNumber": 18,
}
For error cases, when oib is empty:
stubFor(post(urlMatching(".*/documentationStatusMock")).atPriority(1)
.withRequestBody(matchingJsonPath("\$.oib", equalTo("")))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type",
"application/json; charset=utf-8")
.withBodyFile("documentationStatus/responseError.json")))
}
responseError.json
{
"statusCode": -2,
"statusName":
"ERROR",
"rowNumber": -1,
}
No comments:
Post a Comment