我試圖測試以下兩個REST調用:柑橘框架 - 可以從響應分配變量嗎?
請求1
GET getLatestVersion
Response: {"version": 10}
請求2
POST getVersionData (body={"version": 10})
Response: {"version": 10, data: [...]}
是否有可能從指定的 「版本」在同一個測試中請求1給請求2中使用的變量?
@CitrusTest(name = "SimpleIT.getVersionTest")
public void getVersionTest() {
// Request 1
http()
.client("restClient")
.send()
.get("/getLatestVersion")
.accept("application/json");
http()
.client("restClient")
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.JSON)
// Can the version be assigned to a variable here?
.payload("{\"version\":10}");
// Request 2
http()
.client("restClient")
.send()
.post("/getVersionData")
// Idealy this would be a Citrus variable from the previous response
.payload("{\"version\":10}")
.accept("application/json");
http()
.client("restClient")
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.JSON)
.payload("\"version\": 10, data: [...]");
}
謝謝Christoph! –