This message was deleted.
# wiremock-java
s
This message was deleted.
t
Hi @Neal Hawman you can use scenarios to create a sequence of responses for a given request, so you could set it up to do 429, 429, 429, 200 or something like that.
n
Thanks. Is there a way to move automatically from one scenario state to the next? From the documentation it looked as if you had to change the state by sending a web request.
t
By setting the
newScenarioState
attribute on the stub, calling that stub will automatically advance the scenario’s state. Here are the relevant docs: https://wiremock.org/docs/stateful-behaviour/
Here’s a full example of how to do what you’re looking for:
Copy code
{
  "mappings": [
    {
      "scenarioName": "rate-limiting",
      "requiredScenarioState": "Started",
      "newScenarioState": "error-1",
      "request": {
        "method": "GET",
        "urlPath": "/something"
      },
      "response": {
        "status": 429,
        "body": "Too fast!"
      }
    },
    {
      "scenarioName": "rate-limiting",
      "requiredScenarioState": "error-1",
      "newScenarioState": "error-2",
      "request": {
        "method": "GET",
        "urlPath": "/something"
      },
      "response": {
        "status": 429,
        "body": "Too fast!"
      }
    },
    {
      "scenarioName": "rate-limiting",
      "requiredScenarioState": "error-2",
      "newScenarioState": "success",
      "request": {
        "method": "GET",
        "urlPath": "/something"
      },
      "response": {
        "status": 429,
        "body": "Too fast!"
      }
    },
    {
      "scenarioName": "rate-limiting",
      "requiredScenarioState": "success",
      "request": {
        "method": "GET",
        "urlPath": "/something"
      },
      "response": {
        "status": 200,
        "body": "OK"
      }
    }
  ]
}
n
Many thanks. That's sounds like exactly what I want.
👍 1