如何将场景应用于列出元素?

时间:2018-03-29 14:01:39

标签: mocking stubbing wiremock

我有列表元素(10-50个元素)和一个改变元素状态的方法。它们有三种状态:start,active,stop,我在一个场景中加入了它们。

但是在调用此方法(三次)之后,方法返回404错误并且我重新启动了场景,这非常不舒服。

不同元素的方法不唯一,即为每个元素调用一个。

  {
  "scenarioName": "scenario",
  "requiredScenarioState": "Started",
  "newScenarioState": "wait_start",
  "request": {
    "method": "GET",
    "urlPathPattern": "/cashboxes/[0-9]+/registration/[0-9]+"
  },

  "response": {
    "status": 200,
    "fixedDelayMilliseconds": 3000,
    "jsonBody": {
      "id": "$(registration_id)",
      "cashbox_id": "$(cashbox_id)",
      "status": "start"
    },
    "transformers": ["body-transformer"],
    "headers": {
      "Content-Type": "application/json"
    }
  }
}
  {
  "scenarioName": "scenario",
  "requiredScenarioState": "wait_start",
  "newScenarioState": "wait_active",
  "request": {
    "method": "GET",
    "urlPathPattern": "/cashboxes/[0-9]+/registration/[0-9]+"
  },

  "response": {
    "status": 200,
    "fixedDelayMilliseconds": 3000,
    "jsonBody": {
      "id": "$(registration_id)",
      "cashbox_id": "$(cashbox_id)",
      "status": "active"
    },
    "transformers": ["body-transformer"],
    "headers": {
      "Content-Type": "application/json"
    }
  }
}
  {
  "scenarioName": "scenario",
  "requiredScenarioState": "wait_active",
  "newScenarioState": "wait_stop",
  "request": {
    "method": "GET",
    "urlPathPattern": "/cashboxes/[0-9]+/registration/[0-9]+"
  },

  "response": {
    "status": 200,
    "fixedDelayMilliseconds": 3000,
    "jsonBody": {
      "id": "$(registration_id)",
      "cashbox_id": "$(cashbox_id)",
      "status": "stop"
    },
    "transformers": ["body-transformer"],
    "headers": {
      "Content-Type": "application/json"
    }
  }
}

这个问题有解决方法吗?

1 个答案:

答案 0 :(得分:0)

与预期相反,在场景完成后,场景不会重置为“已启动”状态。它需要重置所有方案才能重置单个方案。

在我看来,当WireMock以独立方式永久运行时,场景的自动重置应该是预期的行为。

我的建议是在GitHub项目页面上创建一个问题,如果可能的话,使用解决方案创建Pull Request,如果这在您的能力范围内。