jeudi 4 avril 2019

How to test invalid encoding REST response with RestAssured

I am trying to test error message returned by our API when invalid encoding is specified in the request. I am sending POST request with plain text body and Content-Type header "application/html". I am able to do that successfully from Postman. However RestAssured prompts to specify encoding directly.

Don't know how to encode  {...} as a byte stream.
Please use EncoderConfig (EncoderConfig#encodeContentTypeAs) to specify how to serialize data for this content-type.
For example: "given().config(RestAssured.config().encoderConfig(encoderConfig().encodeContentTypeAs("application/html", ContentType.TEXT))). .."

But even when I do that directly I get the same error from RestAssured:

RestAssured.given().config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("application/html", ContentType.HTML)));

Here are the headers I use:

RestAssured.given().header("Content-Type", "application/html")

.header("accept", "application/json");

Aucun commentaire:

Enregistrer un commentaire