I am pretty new to testing with RestAssured and using the methods. the json body returns me an arraylist and I and checking wheather the given response body has book title as mention using assertEquals. As the returned response body is stored in arraylist I thought to iterate over it, which it did but it didn't iterarte through whole array list instead in stopped as 0th index. Please help me if anyone know how use assert while using an array or list. Ps If you wanna execute my code you are welcome to do so.
My code:
import java.util.ArrayList;
import org.hamcrest.Matchers;
import org.testng.Assert;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.Method;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import io.restassured.response.ResponseBody;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
public class rest_tets {
@Test
public void GetBookingIds_VerifyStatusCode() {
RestAssured.baseURI = "https://demoqa.com/BookStore";
RequestSpecification httpRequest = RestAssured.given();
Response response = httpRequest.get("/v1/Books");
JsonPath jsonPathEvaluator = response.jsonPath();
ArrayList<String> list_text=new ArrayList<String>();
list_text = jsonPathEvaluator.get("books.title");
// Let us print the city variable to see what we got
System.out.println("City received from Response " + list_text);
for (int i=0;i<list_text.size();i++) {
Assert.assertEquals(list_text.get(i), "Learning JavaScript Design Patterns", "Correct book name received in the Response");
}
}