Search in sources :

Example 6 with ResponseSpecification

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

the class GivenWhenThenResponseSpecITest method simple_given_when_then_works.

@Test
public void simple_given_when_then_works() {
    exception.expect(AssertionError.class);
    exception.expectMessage("2 expectations failed.\n" + "Expected status code <201> but was <200>.\n" + "\n" + "JSON path greeting doesn't match.\n" + "Expected: Greetings John Doo\n" + "  Actual: Greetings John Doe");
    ResponseSpecification specification = new ResponseSpecBuilder().expectStatusCode(201).expectBody("greeting", equalTo("Greetings John Doo")).build();
    given().param("firstName", "John").param("lastName", "Doe").when().get("/greet").then().spec(specification);
}
Also used : ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) ResponseSpecification(io.restassured.specification.ResponseSpecification) Test(org.junit.Test)

Example 7 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_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 8 with ResponseSpecification

use of io.restassured.specification.ResponseSpecification 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 9 with ResponseSpecification

use of io.restassured.specification.ResponseSpecification 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 10 with ResponseSpecification

use of io.restassured.specification.ResponseSpecification in project sonar-java by SonarSource.

the class AssertionsInTestsCheckTest method test_spec.

@Test
public void test_spec() {
    // Compliant
    ResponseSpecification spec = new ResponseSpecBuilder().expectStatusCode(200).expectBody("content", equalTo("Hello, Johan!")).build();
    RestAssured.given().get("http://url.com").then().spec(spec);
}
Also used : 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