I have a complex API, where I need to send get/post requests and validate the responses. So it is more complex, than validating the response code, or the body contains some string.
How can I store json file and handle them as object using restassured?
If I understood correct, the problem is creating the complex payload for POST and verifying the response JSON.
Serialization and De-serialization can help you out here.
What I meant by that you can create JSON payload from a java pojo (model file) and the vice-versa. So every-time you want to create a complex payload, just use GSON to serialize your model file to json. If you want to verify a specific part of a response, de-serialize that to the corresponding model file and then use getters() to extract the exact info.
RestAssured has inbuilt mechanism to do so. I prefer google's GSON for the same. Just go thru GSON documentation.
The below link might help.
http://toolsqa.com/rest-assured/deserialize-json-response-to-an-array-or-list/
If you want to verify the response status, call the getStatusCode()
of Response
class.