Match query parameter value which contains "=" (equality) sign within the value

1,119 views
Skip to first unread message

Sunil Kumar

unread,
Sep 23, 2021, 2:04:59 AM9/23/21
to wiremock-user
Hi,
TLDR; I am not able to match a query parameter because it contains "=" sign within the value. is there a way to match that? Am I missing something basic?

My url looks something like this:
/my/relative/path?param1=some_thing&param1=condition1 AND condition2 OR condition3

Here param1 accepts a sql like query (not completely but something of that sort). Here each condition can be of following form:
<some_field> <operand> <some_value>
for ex, projectId = 12

I am mocking this request like this:
MockServer
.Given('/my/relative/path') 
.WithParam("param1", new RegexMatcher("*10001*"))
.RespondWith(Response .Create()
.WithStatusCode(200) 
.WithHeader("content-type", "application/json;charset=UTF-8") 
.WithBody("some body value"));

I have to mock based on projectIds from the conditions, for example: above mock is for projectId 10001. But this never matches. I have identified that if the query value doesn't contain equal to sign (ie. should not be  "=",  ">=",  "<=",  "!="), then it matches my request. But when it contains equal to sign, it returns me no matching mapping found.

Does any one know how do I resolve this?




Sunil Kumar

unread,
Sep 23, 2021, 2:11:55 AM9/23/21
to wiremock-user
Sorry, made a little mistake in the URL. it should be something like:
/my/relative/path?param1=some_thing&param2=condition1 AND condition2 OR condition3

And while mocking, it should be .WithParam("param2", new RegexMatcher("*10001*") )


thilmano_wiremockuser

unread,
Sep 23, 2021, 2:41:06 AM9/23/21
to wiremock-user
Hi, your URL formation seems to be incorrect. /my/relative/path?param1=some_thing&param2=condition1 AND condition2 OR condition3

Could you please share the exact URL path and the condition you need to check? (you can remove the original data)

Sunil Kumar

unread,
Sep 23, 2021, 3:17:59 AM9/23/21
to wiremock-user
Sure,  I am using this API,  
GET /rest/api/2/search
It takes jql as a query parameter. jql could be any valid jql. I am using this jql: PROJECT=10005 AND ID >20154
I build this jql in the application logic (written in .Net) using StringBuilder. 

Actual API call snapshot from postman:
Actual API call.png

The URL seems to be fine. But when I mock this through WireMock, I think it might be resolving the parameters differently? 

thilmano_wiremockuser

unread,
Sep 23, 2021, 8:13:14 AM9/23/21
to wiremock-user
I am able to get this working with the JSON stubs

{
    "request" : {
"method": "GET",
    "urlPath": "/rest/api/2/search",
"queryParameters" : {
"jql" : {
"contains" : "10005"
}
}
},
"response": {
        "status": 200,
        "body": "Hello world!",
        "headers": {
            "Content-Type": "text/plain"
        }
    }
}

2 points to note here..
You need to relax your match ONLY to urlPath (not including the query params)
and then do a queryParameters match with whatever condition you want.. you can use 'equalTo', 'contains' etc.

Sunil Kumar

unread,
Sep 23, 2021, 10:17:21 AM9/23/21
to wiremock-user
Hey, I just found out that this is a bug in .NET Wiremock version 1.0.17 (which I am using). This was reported here: https://github.com/WireMock-Net/WireMock.Net/issues/283 and got fixed in version 1.0.19. Thanks for providing the alternate approach. 
Reply all
Reply to author
Forward
0 new messages