use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.
the class SimplePathITest method simpleJsonValidationWithJsonPath.
@Test
public void simpleJsonValidationWithJsonPath() throws Exception {
final String body = get("/greetJSON?firstName=John&lastName=Doe").asString();
final JsonPath json = new JsonPath(body).setRoot("greeting");
final String firstName = json.getString("firstName");
final String lastName = json.getString("lastName");
assertThat(firstName, equalTo("John"));
assertThat(lastName, equalTo("Doe"));
}
use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.
the class CustomAuthFilter method filter.
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
final String loginResponse = post("/custom-auth/login").asString();
final JsonPath jsonPath = new JsonPath(loginResponse);
final int operandA = jsonPath.getInt("operandA");
final int operandB = jsonPath.getInt("operandB");
final String sessionId = jsonPath.getString("id");
requestSpec.param("sum", operandA + operandB);
requestSpec.param("id", sessionId);
return ctx.next(requestSpec, responseSpec);
}
use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.
the class SpookyGreetJsonResponseFilter method filter.
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
final Response response = ctx.next(requestSpec, responseSpec);
final String responseAsString = response.asString();
final JsonPath jsonPath = new JsonPath(responseAsString);
final String firstName = jsonPath.getString("greeting.firstName");
final String updatedResponse = responseAsString.replace(firstName, "Spooky");
return new ResponseBuilder().clone(response).setBody(updatedResponse).build();
}
use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.
the class JSONPostITest method supportsReturningPostBody.
@Test
public void supportsReturningPostBody() throws Exception {
final String body = with().parameters("firstName", "John", "lastName", "Doe").when().post("/greet").asString();
final JsonPath jsonPath = new JsonPath(body);
assertThat(jsonPath.getString("greeting"), equalTo("Greetings John Doe"));
}
Aggregations