Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wiremock - "URL does not match" even though it is same

Tags:

java

wiremock

I am facing an issue that Wiremock says my URLs don't match even though they are the same. Obviously I am missing something. What am I doing wrong?

WireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo("/test/url?bookingCode=XYZ123&lastName=TEST"))
    .willReturn(WireMock.aResponse()
    .withStatus(200))
)

Below is the console log.

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
GET                                                        | GET
/test/url?bookingCode=XYZ123&lastName=TEST                 | /test/url?bookingCode=XYZ123&lastName=TEST            <<<<< URL does not match
                                                           |
                                                           |
-----------------------------------------------------------------------------------------------------------------------

Is it because I am not including Headers in the matchers?

If yes, how can I avoid matching the headers? I would like to get a response irrespective of what header I am sending.

like image 648
Abbin Varghese Avatar asked Feb 06 '20 14:02

Abbin Varghese


2 Answers

Found the reason.. WireMock.urlPathEqualTo("/test/url?bookingCode=XYZ123&lastName=TEST") should not have query params.

Changing it to WireMock.urlPathEqualTo("/test/url") resolved the issue.

Documentation says it is allowed. Also, the log URL does not match was causing the confusion. Considering the match check is separate, wiremock could have added a separate log for query param.

Created issue : https://github.com/tomakehurst/wiremock/issues/1262

like image 177
Abbin Varghese Avatar answered Oct 14 '22 02:10

Abbin Varghese


You can go with withQueryParam method for the parameters while keeping urlPathEqualTo method dedicated to URL path.

WireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo("/test/url"))
         .withQueryParam("bookingCode", WireMock.equalTo("XYZ123"))
         .withQueryParam("lastName", WireMock.equalTo("TEST"))
         .willReturn(WireMock.aResponse()
         .withStatus(200))

For more information, please refer http://wiremock.org/docs/request-matching/

like image 25
dhana1310 Avatar answered Oct 14 '22 03:10

dhana1310