0

嘿,我是新手,请放心,设法让 POST 路由测试用例工作,下面的测试用例的响应主体是

public void submissionsUserPostTest() {

    JSONObject data = new JSONObject();
    data.put("username", "XYZ");

    String jsonString = data.toJSONString();

    Response request = given().contentType("application/json")
            .body(jsonString).expect().statusCode(201).when()
            .post(postRoute);

    request.print();
}

身体

{"createdAt":"2014-04-16T20:04:40.560Z","updatedAt":"2014-04-16T20:04:40.560Z","id":"51de8ae0-","_links":{"self":{"href":"/assignments/51de8ae0-c43e-44c3-b46d-f48a25739385"}},"username":"XYZ","uploadDate":"2014-04-16T20:04:40.560Z"}

所以我的问题是如何使用 POST 路由生成的 id 到我的 GET 路由 /assignments/{id} 使用请求?

4

2 回答 2

0

你的意思是自我链接?在这种情况下,您可以这样做:

String assignment = 
given().
        contentType("application/json").
        body(jsonString)
when().
        post(postRoute).
then().
        statusCode(201).
extract().
      path("_links.self.href");

when().
       get(assignment).
then().
       ...
于 2014-07-16T19:31:23.630 回答
0

使用类似的东西

String id = response.jsonPath().getString("id");

然后将存储的值 [ie id] 传递给您的 GET 请求。

于 2016-12-22T11:41:02.873 回答