https://linen.dev logo
#wiremock-java
Title
# wiremock-java
a

Alex P

03/23/2023, 3:41 PM
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
DELETE
endpoint, and I have a response
bodyFileName
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
metadata
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
t

Tom

03/23/2023, 3:43 PM
You can use transformer parameters on a stub for this. Accessed via
{{parameters.myParam}}
You set them under the
transformerParameters
in the
response
element in the stub JSON
a

Alex P

03/23/2023, 3:45 PM
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
scenarioName
when it uses
requiredScenarioState
? 🤔
a

Aaron

03/23/2023, 4:13 PM
Yes - Scenarios require a name and a required state.
a

Alex P

03/23/2023, 4:33 PM
Ah okay, I guess it's easier to understand like that anyway 🙂