mercredi 28 février 2018

RestAssured - assert body when response is a text/plain

In the controller I return ResponseEntity with body as a String:

    @RequestMapping(path = "/message", method = RequestMethod.POST)
    public ResponseEntity<String> sendMessage(){
        return new ResponseEntity<>("message sent", HttpStatus.OK);
    }

The response happens to be a text/plain. When I test it using RestAssured, I do:

    RestAssured
            .given()
            .when()
            .post(URL + "/message")
            .then()
            .assertThat()
            .statusCode(200)
            .contentType("text/plain")
            .body(Matchers.is("message sent"));

Test fails with this message:

Expected: is "message sent"
Actual: message sent

Does anyone has idea how can I get rid of " " or parse String to text/plain? I also tried using other Hamcrest Matchers but none of them worked for me.

Aucun commentaire:

Enregistrer un commentaire