Reputation: 2904
I want to run standalone jar file of wiremock with sending some json data after user hitting specific url.
I created one sample json file and placed it in mappings directory of my app.
sample.json
{
"request":
{
"url": "/data?date=date",
"method": "GET",
"queryParameters" : {
"date" : {
"matches" : "^\\d{4}-\\d{2}-\\d{2}$"
}
}
},
"response":
{
"status": 200,
"headers":
{
"Content-Type" : "application/json"
},
"body": "[{\"a\":\"A\",\"b\":\"B\",\"c\":\"C\"},{\"a\":\"A\",\"b\":\"B\",\"c\":\"C\"}]"
}
}
I want to ping below url in browser so that I can get json response on browser.
Edited url -
192.168.0.5:8080/data?date=2017-02-02
I'm using below command to run my app -
java -jar wiremock-standalone-2.6.0.jar
I want to match query parameter date value with requested query parameter date value.
I'm not able to see the json response in a browser because it didn't recognize requested url.
What I'm missing in writing mappings json file?
How I can write query parameter so that my input request get identified and it will serve json response on browser?
Upvotes: 2
Views: 16652
Reputation: 348
One way of doing is by using regex
mockMvc.perform(get(uri)).withQueryParam("query_param_name", matching("^(.*)wiremock([A-Za-z]+)$"))
.
We can also use regex for query param name as well, so that it can mock any query param name and its value.
Upvotes: 0
Reputation: 741
In my case I have a constant string query params and I use this method:
@Rule
public WireMockRule wireMockRule = new WireMockRule(8080);
...
private void stubApiEndPoint() {
stubFor(get(urlEqualTo("/api/users?id=123&name=Tom"))
.willReturn(aResponse()
.withStatus(200)));
}
Upvotes: 1
Reputation: 4149
The problem is how you've set up the URL pattern. You can either specify query params in directly in the url part or in a queryParameters block but not both.
Try: "urlPath": "/data"
Upvotes: 5