übereinstimmen Ich benutze Wiremock für verspotten Rest Service für Junit im Frühjahr Boot-Anwendung. Mein Problem ist, dass ich nicht mehrere Match-Muster zuordnen kann.Wie genau Json in Wiremock für JUNIT
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-Schnipsel, ich bin mit (. *) Für Spiel. Es funktioniert gut. Aber, ich brauche genaue Dinge anzupassen, die in wiremock des Mapping-Ordner in der entfalteten JSON ist
"matchesJsonPath" : "$.name",
"matchesJsonPath" : "$.protocol",
"matchesJsonPath" : "$.website",
"matchesJsonPath" : "$.website.user",
"matchesJsonPath" : "$.website.urlpath",
"matchesJsonPath" : "$.website.userlist",
"matchesJsonPath" : "$.website.resources.friendsList"
Probe Json-die in wiremock des Mapping-Ordner bereitgestellt wird
{
"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\"}"
}
}