I wonder if I can set some values in the stub to u...
# wiremock-java
I wonder if I can set some values in the stub to use as template values in the response. For example, let's say I have a generic response for a
endpoint, and I have a response
that has something like
Copy code
  "message": "Deleted {{arguments.count}} items"
And then I would have a stub like this
Copy code
  "request": ...,
  "response": {
    "bodyFileName": ...,
    "arguments": {
      "count": 1
Or can I use the
for that? 🤔
My actual use case is that I have a scenario where a GET returns 404 initially (i.e., in STARTED state), until a POST moves it to STORED state. So DELETE should return "count: 0" in STARTED state, but "count: 1" in STORED state (and then move to STARTED again. I probably need 2 stubs anyway, but I wonder if I can get around having 2 response bodies
You can use transformer parameters on a stub for this. Accessed via
You set them under the
in the
element in the stub JSON
Ooh, interesting, let me check that out 👍
Great, I think that will work!
Is it possible to access scenario state, even though my stub is valid for multiple scenarios? For example in the above case: can I have two stub outsides of the scenarios that handle DELETE? Or does a stub need to have
when it uses
? 🤔
Yes - Scenarios require a name and a required state.
Ah okay, I guess it's easier to understand like that anyway 🙂