I am using wiremock for mocking rest service for Junit in Spring boot application. My problem is, i am not able to match multiple match patterns.
Junit.java
StringValuePattern pattern = WireMock.matching(".*");
givenThat(post(urlEqualTo("/softwares"))
.withHeader("Content-Type", equalTo("application/json"))
//TODO: Matching exact JSON body
.withRequestBody(pattern)
.willReturn(aResponse()
.withStatus(201)
.withHeader("Content-Type", "application/json")
.withBody("{\"userId\":\"ID009\"}")));
Above code snippets, i am using (.*) for match. It works fine. But, i need to match exact things which is in deployed JSON in wiremock's mapping folder
"matchesJsonPath" : "$.name",
"matchesJsonPath" : "$.protocol",
"matchesJsonPath" : "$.website",
"matchesJsonPath" : "$.website.user",
"matchesJsonPath" : "$.website.urlpath",
"matchesJsonPath" : "$.website.userlist",
"matchesJsonPath" : "$.website.resources.friendsList"
Sample Json-which is deployed in wiremock's mapping folder
{
"request" : {
"urlPath" : "/softwares",
"method" : "POST",
"basicAuthCredentials" : {"username" : "username", "password" : "password"},
"headers" : {
"Content-Type" : {
"equalTo" : "application/json"
}
},
"bodyPatterns" : [ {
"matchesJsonPath" : "$.name",
"matchesJsonPath" : "$.protocol",
"matchesJsonPath" : "$.website",
"matchesJsonPath" : "$.website.user",
"matchesJsonPath" : "$.website.urlpath",
"matchesJsonPath" : "$.website.userlist",
"matchesJsonPath" : "$.website.resources.friendsList"
} ]
},
"response" : {
"status" : 201,
"headers" : { "Content-Type" : "application/json"},
"body": "{ \"userId\" : \"ID009\"}"
}
}