question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WireMock: Not able to mock url path only regardless the query parameters

See original GitHub issue

It’s not possible to mock url path only using WireMock solution Zerocode provide for step scenarios. Because of that it’s not possible to mock a simple url without considering the query parameters. This is easily fixed by using WireMock method called urlPathEqualTo(url) more here.

Solution: A simple and easy solution would be to change RestEndPointMocker.class to use urlEqualTo(url) if the url has query parameters and urlPathEqualTo(url) if the url doesn’t have query parameters. To check if url has parameters we can just check for ? character is placed in the url.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sparrowVcommented, Jan 24, 2021

@MrXavier thanks for clarification. if you make url "url": "cart/price?param1=param1" it should work.

1reaction
MrXaviercommented, Jan 23, 2021

Hello @sparrowV, I’m talking about mocking only the path of a http request, disregarding the query parameters. For instance, if I mock the path cart/price, then the request cart/price?para1=value1&param2=value2 won’t be matched and the mock’s response won’t be returned.

Example of a mock step scenario that should work for the path cart/price regardless the query params but currently isn’t working.

...
"mocks":
[
    {
        "name": "mocking_a_GET_endpoint",
        "operation": "GET",
        "url": "cart/price",
        "response": {
            "status": 200,
            "headers": {
                "Accept": "application/json"
            },
            "body": {
                "id": "UK001",
                "price": "33,00"
            }
        }
    }
]
...

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Stubbing | WireMock
It's usually a good idea to use path only URL matching with query parameter matches. When multiple match clauses are added a request...
Read more >
Wiremock - "URL does not match" even though it is same
Found the reason.. WireMock.urlPathEqualTo("/test/url?bookingCode=XYZ123&lastName=TEST") should not have query params.
Read more >
Postman Mock Server vs. MockLab
A comparison of Postman mock servers and MockLab for building mock ... so it's possible to include URL path elements, query parameters, ...
Read more >
How to Use Mock Services For Testing in BlazeMeter
Request matching could be defined by the exact match of the URL path, HTTP operation, by query parameters, request headers, request body, ...
Read more >
Introduction to WireMock - Baeldung
WireMock is a library for stubbing and mocking web services. ... In case no arguments are provided, the server host defaults to localhost ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found