Search code examples
testingjunitquarkusrest-assured

Convert response body of a Quarkus Test


I'm trying to test my Quarkus application. I want to check that a response is greater than 0, the problem is that the endpoint I'm calling return a String and not a number. How can I convert the response to a number and check that it is greater than 0?

   @Test
   void getAdminListSize() {
       given()
               .when()
               .header("Authorization", token_admin)
               .get(PATH + "/get?listSize=true")
               .then()
               .statusCode(200)
               .body(greaterThan(0))
       ;
   }

This is the response I receive: "28357". This is the error I get:

java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: a value greater than <0>
Actual: 28357

Solution

  • Just extract the body to a variable and work with it

    @Test
       void getAdminListSize() {
           String s = given()
                   .when()
                   .header("Authorization", token_admin)
                   .get(PATH + "/get?listSize=true")
                   .then()
                   .assertThat()
                   .statusCode(200)
                   .extract()
                   .body()
                   .asString();
    
           
                  convert s into a integer and do the assert
       }
    

    Other option is use .as(Clazz.class) and work with your dto if you have one