Search in sources :

Example 16 with ResponseSpecification

use of io.restassured.specification.ResponseSpecification in project rest-assured by rest-assured.

the class XMLGetITest method supportsRegisteringCustomParserForAGivenMimeTypeUsingResponseSpec.

@Test
public void supportsRegisteringCustomParserForAGivenMimeTypeUsingResponseSpec() throws Exception {
    final String mimeType = "application/something-custom";
    final ResponseSpecification specification = new ResponseSpecBuilder().registerParser(mimeType, Parser.XML).build();
    RestAssured.expect().specification(specification).and().body("body.message", equalTo("Custom mime-type")).when().get("/customMimeType");
}
Also used : ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) ResponseSpecification(io.restassured.specification.ResponseSpecification) Test(org.junit.Test)

Example 17 with ResponseSpecification

use of io.restassured.specification.ResponseSpecification in project rest-assured by rest-assured.

the class ResponseTimeITest method response_time_validation_can_be_specified_in_specification.

@Test
public void response_time_validation_can_be_specified_in_specification() {
    ResponseSpecification spec = new ResponseSpecBuilder().expectResponseTime(lessThanOrEqualTo(3000L)).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 18 with ResponseSpecification

use of io.restassured.specification.ResponseSpecification in project rest-assured by rest-assured.

the class ResponseTimeITest method response_time_validation_can_fail_when_specified_in_specification.

@Test
public void response_time_validation_can_fail_when_specified_in_specification() {
    exception.expect(AssertionError.class);
    exception.expectMessage("Expected response time was not a value less than or equal to <3L> nanoseconds, was");
    ResponseSpecification spec = new ResponseSpecBuilder().expectResponseTime(lessThanOrEqualTo(3L), NANOSECONDS).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 19 with ResponseSpecification

use of io.restassured.specification.ResponseSpecification in project rest-assured by rest-assured.

the class SpecificationBuilderITest method bodyExpectationsAreNotOverwritten.

@Test
public void bodyExpectationsAreNotOverwritten() throws Exception {
    final ResponseSpecBuilder builder = new ResponseSpecBuilder();
    builder.expectBody("store.book.size()", is(4)).expectStatusCode(200);
    final ResponseSpecification responseSpecification = builder.build();
    expect().body("store.book.author", hasItems("Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien")).spec(responseSpecification).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 20 with ResponseSpecification

use of io.restassured.specification.ResponseSpecification in project rest-assured by rest-assured.

the class SpecificationsDemoITest method demoResponseSpecification.

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

Aggregations

ResponseSpecification (io.restassured.specification.ResponseSpecification)23 Test (org.junit.Test)20 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)14 RequestSpecification (io.restassured.specification.RequestSpecification)5 Matchers.containsString (org.hamcrest.Matchers.containsString)2 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)2 Cookies (io.restassured.http.Cookies)1 Response (io.restassured.response.Response)1 StringWriter (java.io.StringWriter)1 InetSocketAddress (java.net.InetSocketAddress)1 HttpResponse (org.apache.http.HttpResponse)1 MockRequestMatcher (org.apache.knox.test.mock.MockRequestMatcher)1 Template (org.apache.velocity.Template)1 VelocityContext (org.apache.velocity.VelocityContext)1 VelocityEngine (org.apache.velocity.app.VelocityEngine)1 ClasspathResourceLoader (org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader)1 Matcher (org.hamcrest.Matcher)1