You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the features that I miss in wiremock and it is available in mockserver is the ability to set the number of times a given stub mapping should be served, for instance, just once or n times.
This works like a countdown on the stub.
After reaching that number of requests served, it automatically removes the stub and further requests should return 404 Not Found, if there's no other stub matching.
I know there's a .reset() thing, or we can even manually remove the stub, but I believe it would be good to have this per stub.
@TestpublicvoidexactUrlOnly() {
stubFor(get(urlEqualTo("/some/thing"))
.times(1)
.willReturn(aResponse()
.withHeader("Content-Type", "text/plain")
.withBody("Hello world!")));
assertThat(testClient.get("/some/thing").statusCode(), is(200));
assertThat(testClient.get("/some/thing").statusCode(), is(404)); // second request (no match)assertThat(testClient.get("/some/thing/else").statusCode(), is(404));
}
or even something like the below. (this is how mock-server would behave)
@TestpublicvoidexactUrlOnly() {
stubFor(get(urlEqualTo("/some/thing")) // first stub
.times(1)
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/plain")
.withBody("Hello world!")));
stubFor(get(urlEqualTo("/some/thing")) // second stub
.times(1)
.willReturn(aResponse()
.withStatus(409)));
assertThat(testClient.get("/some/thing").statusCode(), is(200)); // first request (matches first stub)assertThat(testClient.get("/some/thing").statusCode(), is(409)); // second request (matches second stub)assertThat(testClient.get("/some/thing").statusCode(), is(404)); // third request (no match)assertThat(testClient.get("/some/thing/else").statusCode(), is(404));
}
I know that this is kinda possible to do by the Stateful stuff, however, in this case, we don't need to worry so much about the states, we can simply stub in order that must be served once each.
Example from mock-server that can be used as reference.
7robertodantas
changed the title
Allow wiremock stub when it was called one or more times
Remove/disable wiremock stub when it was called one time
Feb 2, 2024
7robertodantas
changed the title
Remove/disable wiremock stub when it was called one time
Remove/disable stub when it was called one time
Feb 2, 2024
Proposal
One of the features that I miss in
wiremock
and it is available inmockserver
is the ability to set the number of times a given stub mapping should be served, for instance, just once or n times.This works like a countdown on the stub.
After reaching that number of requests served, it automatically removes the stub and further requests should return 404 Not Found, if there's no other stub matching.
I know there's a
.reset()
thing, or we can even manually remove the stub, but I believe it would be good to have this per stub.References
Proposal
I was thinking something like
or even something like the below. (this is how mock-server would behave)
I know that this is kinda possible to do by the Stateful stuff, however, in this case, we don't need to worry so much about the states, we can simply stub in order that must be served once each.
Example from mock-server that can be used as reference.
https://www.mock-server.com/mock_server/creating_expectations.html#button_match_request_by_path_exactly_twice
The text was updated successfully, but these errors were encountered: