https://linen.dev logo
Title
j

Jorge Pereira

01/30/2023, 4:49 PM
Hello! I’m looking at documentation https://wiremock.org/docs/stateful-behaviour/ - Setting the state of an individual scenario and it seems an HTTP request can be made to change the state of the scenario. I’ve tried but I’m getting 404 error. In the admin rest API this endpoint seems to not be documented https://wiremock.org/docs/api/#tag/Scenarios. Am i missing something or is not possible to set the state using HTTP?
t

Tom

01/30/2023, 6:32 PM
Can you share what you’re doing in a bit more detail? What is the URL of the API function are you trying to call?
j

Jorge Pereira

01/30/2023, 6:42 PM
yes sure. my scenario:
// 20230130183849
// <http://localhost:8777/__admin/scenarios>

{
  "scenarios": [
    {
      "id": "d9de1aa5-8f44-454d-8433-0f1d38f704e6",
      "name": "my_scenario",
      "state": "Started",
      "possibleStates": [
        "Started"
      ],
      "mappings": [
        {
          "id": "72a892bb-927d-4ea1-86b7-68e6981a59e5",
          "request": {
            "method": "GET"
          },
          "response": {
            "status": 200
          },
          "uuid": "72a892bb-927d-4ea1-86b7-68e6981a59e5",
          "scenarioName": "my_scenario",
          "requiredScenarioState": "Started"
        }
      ]
    }
  ]
}
PUT /__admin/scenarios/my_scenario/state
{
    "state": "state_2"
}
I’m actually running a curl.
curl -X PUT -H "Content-Type: application/json" -d '{"state": "state_2"}' <http://localhost:8777/__admin/scenarios/my_scenario/state>
I would expect the scenario state to be updated to state_2 but the response it’s Started
t

Tom

01/30/2023, 7:36 PM
OK, the issue is that you haven’t created any stubs that transition to or depend on
state_2
so that PUT won’t work. Try creating the stub the requires
state_2
first, then do the PUT (I’ve just done this and it worked).
j

Jorge Pereira

01/30/2023, 7:39 PM
Originally I had another stub. I’ve re added it but no luck
// 20230130193816
// <http://localhost:8777/__admin/scenarios>

{
  "scenarios": [
    {
      "id": "6c53d978-9d36-416e-8837-de71845b3e51",
      "name": "my_scenario",
      "state": "Started",
      "possibleStates": [
        "state_2",
        "Started"
      ],
      "mappings": [
        {
          "id": "caba6671-d115-49a6-b44d-9b776315a2a4",
          "request": {
            "method": "GET"
          },
          "response": {
            "status": 200
          },
          "uuid": "caba6671-d115-49a6-b44d-9b776315a2a4",
          "scenarioName": "my_scenario",
          "requiredScenarioState": "state_2"
        },
        {
          "id": "805e541a-9499-4c1f-a2db-e4e40b9fbaf6",
          "request": {
            "method": "GET"
          },
          "response": {
            "status": 200
          },
          "uuid": "805e541a-9499-4c1f-a2db-e4e40b9fbaf6",
          "scenarioName": "my_scenario",
          "requiredScenarioState": "Started"
        }
      ]
    }
  ]
}
Ok, I figured out the problem. I’ve updated the version of wiremock 2.22 -> 2.35
t

Tom

01/30/2023, 8:10 PM
Ah yes, that'll be it!