Garmaine Staff asked 1 year ago

I have a Rest Assured test where I am trying to validate that the dates in the response are between the date params passed in. I am trying to use Hamcrest-Date but the dates passed back in my json response are in yyyy-MM-dd and Hamcrest-Date seems to be in Day, Date Month Year. I cannot use .format(DateTimeFormatter.BASIC_ISO_DATE) in the body assertion because DateTimeFormatter converts it into a String and Hamcrest-Date doesnt seem to support it. How could this work?

This is the error in the code:

"The method sameOrBefore(Date) in the type DateMatchers is not applicable for the arguments (String)"

        ValidatableResponse vr = given().

                param("startDate", LocalDate.now().minusMonths(1).format(DateTimeFormatter.BASIC_ISO_DATE)).
                param("endDate", LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)).
                pathParam("accountid", accountId_DP).

                header("trace-id", UUID.randomUUID().toString()).
                header("organization", ORGANIZATION).
                header("session-id", SESSION_ID_734548).
                when().
                get("/transactions/{accountid}/pra").           
                then();

        LOGGER.info("test prefix to find in console {}", vr.extract().response().getBody().asString());

        vr.assertThat().statusCode(200).
        and().contentType(ContentType.JSON).
        and().
        body("transactions.postedDate.toString()", everyItem(DateMatchers.sameOrBefore(LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)))).
        and().
        extract().
        response();

    }