I want to verify that id: 1 belongs to Tiger Nixon
{"status":"success","data":[{"id":"1","employee_name":"Tiger Nixon","employee_salary":"320800","employee_age":"61","profile_image":""}
I have been following this document: https://github.com/rest-assured/rest-assured/wiki/Usage#json-using-jsonpath , this section body("shopping.category.find { it.@type == 'groceries' }.item", hasItems("Chocolate", "Coffee"));
Currently I am getting a null pointer exception. I could use some help to come up with a solution. Thanks in advance for your time.
import com.google.gson.JsonObject;
import io.restassured.RestAssured;
import org.testng.Assert;
public class RestAssuredExample_2 {
public void getResponse() {
JsonObject responseObject = RestAssured.get("http://dummy.restapiexample.com/api/v1/employees")
.then()
.extract().response().as(JsonObject.class);
String emp1Name = responseObject.get("data.find{it.@id=='1'}.employee_name").toString();
Assert.assertEquals(emp1Name, "Tiger Nixon");
}
public static void main(String[] args) {
RestAssuredExample_2 rest2 = new RestAssuredExample_2();
rest2.getResponse();
}
}
Error:
Exception in thread "main" java.lang.NullPointerException
at HTTPz.RestAssuredExample_2.getResponse(RestAssuredExample_2.java:16)