Questions tagged [rest-assured]

REST Assured is a Java library that provides a domain-specific language (DSL) for writing powerful, maintainable tests for RESTful APIs.

REST Assured enables testing of REST services in Java.

It uses a fluid syntax inspired by similar libraries for and .

2207 questions
120
votes
9 answers

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.testing.models.Account

I'm getting below error: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.testing.models.Account with below code final int expectedId = 1; Test newTest = create(); int expectedResponseCode =…
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168
65
votes
9 answers

REST Assured - Generic List deserialization

Let's say I have a Java Person class: class Person { String name; String email; } With REST Assured, you can deserialize this JSON object {"name":"Bob", "email":"bob@email.com"} to a Java Person instance using Person bob =…
spg
  • 9,309
  • 4
  • 36
  • 41
58
votes
6 answers

Rest-assured. Is it possible to extract value from request json?

I'm getting response this way: Response response = expect().statusCode(200).given().body(requestBody).contentType("application/json") .when().post("/admin"); String responseBody = response.getBody().asString(); I have a json in…
Jay
  • 1,389
  • 1
  • 10
  • 15
45
votes
6 answers

java.lang.NoClassDefFoundError: io/restassured/mapper/factory/GsonObjectMapperFactory

I am getting error when I try to execute script with rest assured framework. Please guide me to resolve the same. And I used below jars Java version -…
user3415045
  • 491
  • 1
  • 6
  • 12
37
votes
4 answers

Set restAssured to log all requests and responses globally

I want to enable logging for all RestAssured responses and requests by default. Here's what I do: RestAssured.requestSpecification = new RequestSpecBuilder(). setBaseUri("api"). setContentType(ContentType.JSON). build(). …
MuchHelping
  • 581
  • 1
  • 4
  • 12
37
votes
6 answers

Rest Assured - deserialize Response JSON as List

I have a POJO Artwork. I'm retrieving a List of those objects from a RESTful webservice in the HTTP response body in JSON format. I'm trying to write a Rest Assured-based test that would analyze the returned list. The code looks like this: Response…
Wojtek
  • 2,514
  • 5
  • 26
  • 31
36
votes
4 answers

In REST Assured, how can I check if a field is present or not in the response?

How can I make sure that my response, let's say it is in JSON, either contains or does not contain a specific field? when() .get("/person/12345") .then() .body("surname", isPresent()) // Doesn't work... .body("age", isNotPresent()); //…
juliaaano
  • 1,307
  • 1
  • 13
  • 11
36
votes
8 answers

RestAssured: How to check the length of json array response?

I have an endpoint that returns a JSON like: [ {"id" : 4, "name" : "Name4"}, {"id" : 5, "name" : "Name5"} ] and a DTO class: public class FooDto { public int id; public String name; } Now, I'm testing the length of the returned json…
Héctor
  • 24,444
  • 35
  • 132
  • 243
33
votes
2 answers

Access elements of an anonymous array via JsonPath in RestAssured

I have an anonymous array in JSON returned from a service like: [ {"foo":1, "bar":2 , "baz":3 }, {"foo":3, "bar":4 , "baz":5 } ] How can I access the bar elements e.g. in expect().body("$[*].bar", hasItems(2,4)) I tried a few possibilities…
Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
29
votes
9 answers

testing spring boot rest application with restAssured

I've been struggling with this for some time now. I'd like to use restAssured to test my SpringBoot REST application. While it looks like container spins up properly, rest assured (and anything else seems to have problems reaching out to it. All the…
klubi
  • 1,373
  • 1
  • 14
  • 25
29
votes
4 answers

Connection refused with rest assured junit test case

The below test case gives me a connection refused exception and when i comment the method body it is success. So i believe there is no problem with ports but a problem with the rest assured invocation which i cant figure out. Even when i check with…
Harshana
  • 7,297
  • 25
  • 99
  • 173
28
votes
3 answers

In REST Assured, how do I set a timeout?

I'm using RestAssured 2.8.0 and I'm trying to set my own timeout (for gateway timeout), so if I don't get response after X milliseconds I want to abort. I tried: public static ValidatableResponse postWithConnectionConfig(String url, String body,…
TomH
  • 283
  • 1
  • 4
  • 6
24
votes
8 answers

Full Json match with RestAssured

I'm using REST-Assured to test some API. My API clearly respond with a JSON and according to the doc if this is the response: { "id": "390", "data": { "leagueId": 35, "homeTeam": "Norway", "visitingTeam": "England", …
BAD_SEED
  • 4,840
  • 11
  • 53
  • 110
24
votes
2 answers

Assert that response body is empty list with rest-assured

How can I check with rest-assured (2.4.0) if the response json is an empty list? Given the response [] (with header content-type=application/json) I tried: .body(Matchers.emptyArray()) // expected: an empty array, actual: [] .body("/",…
atamanroman
  • 11,607
  • 7
  • 57
  • 81
23
votes
4 answers

How do I access the underlying Jackson ObjectMapper in REST Assured?

I need to configure the underlying Jackson ObjectMapper in REST Assured. I am writing REST API tests using REST Assured and I need to define some filters to register with the ObjectMapper that is used to serialize my objects to JSON: String…
Selena
  • 2,208
  • 8
  • 29
  • 49
1
2 3
99 100