Search in sources :

Example 11 with JsonPath

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"));
}
Also used : JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 12 with JsonPath

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);
}
Also used : JsonPath(io.restassured.path.json.JsonPath)

Example 13 with JsonPath

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();
}
Also used : Response(io.restassured.response.Response) JsonPath(io.restassured.path.json.JsonPath) ResponseBuilder(io.restassured.builder.ResponseBuilder)

Example 14 with JsonPath

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"));
}
Also used : JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.Test)

Aggregations

JsonPath (io.restassured.path.json.JsonPath)14 Test (org.junit.Test)12 BigDecimal (java.math.BigDecimal)2 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 Route (io.fabric8.openshift.api.model.Route)1 ResponseBuilder (io.restassured.builder.ResponseBuilder)1 Greeting (io.restassured.examples.springmvc.support.Greeting)1 GreetingController (io.restassured.module.mockmvc.http.GreetingController)1 PostController (io.restassured.module.mockmvc.http.PostController)1 Response (io.restassured.response.Response)1 JsonObject (io.vertx.core.json.JsonObject)1 Transport (io.vertx.ext.web.handler.sockjs.Transport)1 Kube.urlForRoute (io.vertx.it.openshift.utils.Kube.urlForRoute)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1