Body parameters are not getting matched. Using jsonEquals

901 views
Skip to first unread message

Sandeep Reddy Sambidi

unread,
May 26, 2017, 6:13:30 AM5/26/17
to wiremock-user
Request json one:

{
"request": {
"url": "/services/data/v1/IntegrationTestingOS?offline=true",
"method": "POST",
"headers":{
"X-Http-Method-Override":{"equalTo" : "GET"},
"Content-Type": {"equalTo" : "application/json"},
"X-ReportingParams": {"equalTo" : "Reporting_Params"},
"X-DeviceTimestamp": {"equalTo" : "Device_Timestamp"}
   },
   "bodyPatterns":[{
        "equalToJson":"{\"delta_context\":{\"objs\":{\"profile\":{\"delta\":\"2017-05-25T18:35:10+05:30\"},\"address\":{\"delta\":\"2017-05-25T19:47:41+05:30\"},\"user\":{\"delta\":\"2017-05-25T19:29:28+05:30\"},\"socialnetwork\":{\"delta\":\"2017-05-25T18:24:40+05:30\"}}}}"
}]},
"response": {
"status": 200,
"bodyFileName" : "objectservice_incremental_download_response.json"
}
}

Request json two: 
{
"request": {
"url": "/services/data/v1/IntegrationTestingOS?offline=true",
"method": "POST",
"headers":{
"X-Http-Method-Override":{"equalTo" : "GET"},
"Content-Type": {"equalTo" : "application/json"},
"X-ReportingParams": {"equalTo" : "Reporting_Params"},
"X-DeviceTimestamp": {"equalTo" : "Device_Timestamp"}
   }},
"response": {
"status": 200,
"bodyFileName" : "objectservice_initial_download.json"
}
}


I have above two requests in my mappings folder. 
If i post a request with some body parameters, the second json is getting matched when i expect the first one to be matched.
So with or without body parameters, it matches the send json only.
If i remove the second json, my request which has body matches the first json.
Can someone please help

Tom Akehurst

unread,
May 26, 2017, 8:56:01 AM5/26/17
to wiremock-user
Since they're both identical other than the body condition, I'd expect the second one always to match if it was inserted more recently (WireMock evaluates in most -> least recent order when all stub priorities are the same). You might want to try setting a lower priority than 5 (which is the default) on the second stub, which will guarantee the first one is checked before it.

Sandeep Reddy Sambidi

unread,
May 28, 2017, 8:45:07 AM5/28/17
to Tom Akehurst, wiremock-user
Thank you Tom. It worked.
But how is it getting mapped when the bodyPatters is not even available in the request json. Does it mean that, only url,method and headers are considered for basic matching and then body is considered depending on priority or content of body.

--
You received this message because you are subscribed to a topic in the Google Groups "wiremock-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wiremock-user/08Ay5TBV7Bw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wiremock-user+unsubscribe@googlegroups.com.
To post to this group, send email to wiremo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wiremock-user/a302c7d2-ad17-4993-90e0-57bca6c79a8e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards
Sandeep S

Tom Akehurst

unread,
May 28, 2017, 11:59:23 AM5/28/17
to wiremock-user
It's helpful to think of all of the request parts (URL, query, headers, cookies and body) as constraints. If you specify one of them you're saying this must match in order for the stub to get served. Not specifying any of these things means anything will match, so the non-body stub you have will match a request with any body provided the URL, method etc. are correct. Conversely the one with the body requires that this is a match in addition to URL etc.
Reply all
Reply to author
Forward
0 new messages