简体   繁体   中英

How can i get a max value for userId from this rest endpoint? I have to use RestAssured with Gpath syntax

I have to get a max value for userId using RestAssured and Gpath syntax. I dont know what i should type in body after then.

I have tried so many ways but it does not work.

@BeforeClass
public void setUp() {
    endpoint = "https://jsonplaceholder.typicode.com/posts/";
}


public static Response getJsonPath(String endpoint) {
    return
            when().
                    get(endpoint).
                    then().
                    statusCode(200).
                    contentType(ContentType.JSON).extract().response();
}


@Test
public void maxUserId() {

    Response response = getJsonPath(endpoint)
            .then()
            .assertThat()
            .body();
}

You can use like this. i tried and i got 10 as max value.

public static void maxUserId() {

    int maxValue = getJsonPath(endpoint).jsonPath().get("userId.max()");
    System.out.println(maxValue);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM