SK176H
SK176H

Reputation: 1319

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 use to get away from this limitation?

Upvotes: 3

Views: 1707

Answers (1)

Johan
Johan

Reputation: 40510

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). ..

Upvotes: 5

Related Questions