Étienne Miret
Étienne Miret

Reputation: 6660

Request order verification with WireMock

I have an API I'm supposed to PUT to several times, in a specific order. I'm testing my client using WireMock, and I'd like to check in my test that the requests were made in the proper order.

Since this API will return a 204 No Content, my code doesn't need the result of previous requests to make the next one, which seems me to rule out WireMock scenarios.

So, does WireMock have a feature similar to Mockito's inOrder ?

Upvotes: 1

Views: 1358

Answers (1)

A. Kootstra
A. Kootstra

Reputation: 6971

This can be achieved through WireMock Scenario feature, an example of this in the documentation:

For example, suppose we’re writing a to-do list application consisting of a rich client of some kind talking to a REST service. We want to test that our UI can read the to-do list, add an item and refresh itself, showing the updated list.

{
    "scenarioName": "To do list",
    "requiredScenarioState": "Started",
    "request": {
        "method": "GET",
        "url": "/todo/items"
    },
    "response": {
        "status": 200,
        "body" : "<items><item>Buy milk</item></items>"
    }
}

{
    "scenarioName": "To do list",
    "requiredScenarioState": "Started",
    "newScenarioState": "Cancel newspaper item added",
    "request": {
        "method": "POST",
        "url": "/todo/items",
        "bodyPatterns": [
            { "contains": "Cancel newspaper subscription" }
         ]
    },
    "response": {
        "status": 201
    }
}

{
    "scenarioName": "To do list",
    "requiredScenarioState": "Cancel newspaper item added",
    "request": {
        "method": "GET",
        "url": "/todo/items"
    },
    "response": {
        "status": 200,
        "body" : "<items><item>Buy milk</item><item>Cancel newspaper subscription</item></items>"
    }
}

Upvotes: 0

Related Questions