SK176H SK176H - 1 year ago 163
reST (reStructuredText) Question

Multiple instances of REST Assured

Is there a way I can have multiple instances of Rest Assured Client.

I have to test two different endpoints that need

  1. Different serializers and deserializers

  2. Different headers and content types

how can I achieve that. I think Rest Assured is really good but I am severely limited by its globalness

Are there any design patterns that I can used to get away from this limitation ?

Answer Source

If you don't apply any global configuration statically you can create two different RequestSpecifications. For example:

RequestSpecification spec1 = new RequestSpecBuilder().addHeader("x", "1").setContentType("application/xml").config(RestAssured.config().objectMapperConfig(objectMapperConfig().defaultObjectMapper(..)).build();
RequestSpecification spec2 = new RequestSpecBuilder().addHeader("y", "2").setContentType("application/json").config(RestAssured.config().objectMapperConfig(objectMapperConfig().defaultObjectMapper(..)).build();

// Endpoint 1
given().spec(spec1). ..
// Endpoint 2
given().spec(spec2). ..
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download