Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wiremock query parameter JSON stub file

I'm trying to mock query parameter using a wiremock JSON stub file.

It works when I do it this way :

{
  "request": {
    "method": "GET",
    "url": "/posts?id=1",
  },
//...
}

However when I change my query parameter to use the dedicated field like this it doesn't work anymore :

{
  "request": {
    "method": "GET",
    "urlPath": "/posts",
    "queryParameters": {
      "id": {
        "equalTo": "1"
      }
    }
  },
  //...
}

Any idea why ?

The test request looks like http://some-host/posts?id=1

like image 510
Robert jardonneau Avatar asked May 25 '18 06:05

Robert jardonneau


2 Answers

This works for me, change your "urlPath" to "urlPathPattern" but be careful in structuring this JSON. so urlPath is exact matching pattern, but urlPathPattern is regex matching on path and query parameter

  {
        "request": {
            "urlPathPattern": "/posts",
            "method": "GET",
            "queryParameters": {
                "id": {
                    "equalTo": "1"
                }
            }
        },
        "response": {
            "status": 200,
            "body":"This is successful"
        }
    }
like image 180
Deadpool Avatar answered Oct 01 '22 07:10

Deadpool


You can try with urlPathPattern instead of urlPath.

As said by here urlPath which is for an exact match, and urlPathPattern is for regex.

So using urlPathPattern in QueryParameter your query get resolve.

{
  "request": {
    "method": "GET",
    "urlPathPattern": "/posts",
    "queryParameters": {
      "id": {
        "equalTo": "1"
      }
    }
  },
  //...
}

Try and understand below concept for Wiremock.

like image 20
Sagar Gangwal Avatar answered Oct 01 '22 07:10

Sagar Gangwal