Search in sources :

Example 6 with ResponseSpecBuilder

use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.

the class ResponseTimeITest method response_time_validation_can_be_specified_in_specification_using_time_unit.

@Test
public void response_time_validation_can_be_specified_in_specification_using_time_unit() {
    ResponseSpecification spec = new ResponseSpecBuilder().expectResponseTime(lessThanOrEqualTo(3L), SECONDS).build();
    given().param("firstName", "John").param("lastName", "Doe").when().get("/greet").then().spec(spec);
}
Also used : ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) ResponseSpecification(io.restassured.specification.ResponseSpecification) Test(org.junit.Test)

Example 7 with ResponseSpecBuilder

use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.

the class SpecificationBuilderITest method responseSpecificationSupportsMergingWithAnotherResponseSpecification.

@Test
public void responseSpecificationSupportsMergingWithAnotherResponseSpecification() throws Exception {
    final ResponseSpecification specification = expect().body("store.book.size()", equalTo(4));
    final ResponseSpecification built = new ResponseSpecBuilder().expectStatusCode(200).addResponseSpecification(specification).build();
    expect().body("store.book.author", hasItems("Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien")).spec(built).body("store.book[0].author", equalTo("Nigel Rees")).when().get("/jsonStore");
}
Also used : ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) ResponseSpecification(io.restassured.specification.ResponseSpecification) Test(org.junit.Test)

Example 8 with ResponseSpecBuilder

use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.

the class SpecificationsDemoITest method demoResponseSpecificationUsingGivenWhenThen.

@Test
public void demoResponseSpecificationUsingGivenWhenThen() throws Exception {
    final ResponseSpecification spec = new ResponseSpecBuilder().expectStatusCode(200).expectBody("responseType", equalTo("simple")).build();
    given().param("name", "John Doe").when().get("/demoResponseSpecification").then().specification(spec).body("firstName", is("John")).body("lastName", is("Doe"));
}
Also used : ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) ResponseSpecification(io.restassured.specification.ResponseSpecification) Test(org.junit.Test)

Example 9 with ResponseSpecBuilder

use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.

the class MockMvcStaticRequestAndResponseSpecTest method request_and_response_spec_can_be_defined_statically.

@Test
public void request_and_response_spec_can_be_defined_statically() {
    RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().addQueryParam("name", "Johan").build();
    RestAssuredMockMvc.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).expectBody("content", equalTo("Hello, Johan!")).build();
    try {
        // When
        RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).when().get("/greeting").then().body("id", equalTo(1));
    } finally {
        RestAssuredMockMvc.reset();
    }
}
Also used : MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) GreetingController(io.restassured.module.mockmvc.http.GreetingController) Test(org.junit.Test)

Example 10 with ResponseSpecBuilder

use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.

the class MockMvcStaticRequestAndResponseSpecTest method response_validation_fails_if_any_property_in_the_response_is_not_valid.

@Test
public void response_validation_fails_if_any_property_in_the_response_is_not_valid() {
    RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().addQueryParam("name", "Johan").build();
    RestAssuredMockMvc.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).expectBody("content", equalTo("Hello, John!")).build();
    exception.expect(AssertionError.class);
    exception.expectMessage("1 expectation failed.\n" + "JSON path content doesn't match.\n" + "Expected: Hello, John!\n" + "  Actual: Hello, Johan!");
    try {
        // When
        RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).when().get("/greeting").then().body("id", equalTo(1));
    } finally {
        RestAssuredMockMvc.reset();
    }
}
Also used : MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) GreetingController(io.restassured.module.mockmvc.http.GreetingController) Test(org.junit.Test)

Aggregations

ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)22 Test (org.junit.Test)22 ResponseSpecification (io.restassured.specification.ResponseSpecification)14 MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)4 LogConfig (io.restassured.config.LogConfig)3 GreetingController (io.restassured.module.mockmvc.http.GreetingController)3 PrintStream (java.io.PrintStream)3 StringWriter (java.io.StringWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 PostController (io.restassured.module.mockmvc.http.PostController)2 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)1 Cookies (io.restassured.http.Cookies)1 RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)1