Search in sources :

Example 1 with ResponseSpecification

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

the class AssertionsInTestsCheckTest method test_specification.

@Test
public void test_specification() {
    // Compliant
    ResponseSpecification spec = new ResponseSpecBuilder().expectStatusCode(200).expectBody("content", equalTo("Hello, Johan!")).build();
    RestAssured.given().get("http://url.com").then().specification(spec);
}
Also used : ResponseSpecification(io.restassured.specification.ResponseSpecification) Test(org.junit.Test)

Example 2 with ResponseSpecification

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

the class JSONGetITest method contentTypeSpecification.

@Test
public void contentTypeSpecification() throws Exception {
    final RequestSpecification requestSpecification = given().contentType(ContentType.TEXT).with().parameters("firstName", "John", "lastName", "Doe");
    final ResponseSpecification responseSpecification = expect().contentType(ContentType.JSON).and().body("greeting", equalTo("Greetings John Doe"));
    given(requestSpecification, responseSpecification).get("/greet");
}
Also used : ResponseSpecification(io.restassured.specification.ResponseSpecification) RequestSpecification(io.restassured.specification.RequestSpecification) Test(org.junit.Test)

Example 3 with ResponseSpecification

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

the class JSONGetITest method contentTypeSpecificationWithHamcrestMatcher.

@Test
public void contentTypeSpecificationWithHamcrestMatcher() throws Exception {
    final RequestSpecification requestSpecification = given().contentType(ContentType.TEXT).with().parameters("firstName", "John", "lastName", "Doe");
    final ResponseSpecification responseSpecification = expect().contentType(equalTo("application/json;charset=utf-8")).and().body("greeting", equalTo("Greetings John Doe"));
    given(requestSpecification, responseSpecification).get("/greet");
}
Also used : ResponseSpecification(io.restassured.specification.ResponseSpecification) RequestSpecification(io.restassured.specification.RequestSpecification) Test(org.junit.Test)

Example 4 with ResponseSpecification

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

the class SpecificationBuilderITest method mergesStaticallyDefinedResponseSpecificationsCorrectly.

@Test
public void mergesStaticallyDefinedResponseSpecificationsCorrectly() throws Exception {
    RestAssured.responseSpecification = new ResponseSpecBuilder().expectCookie("Cookie1", "Value1").build();
    ResponseSpecification reqSpec1 = new ResponseSpecBuilder().expectCookie("Cookie2", "Value2").build();
    ResponseSpecification reqSpec2 = new ResponseSpecBuilder().expectCookie("Cookie3", "Value3").build();
    try {
        Cookies cookies = given().cookie("Cookie1", "Value1").cookie("Cookie2", "Value2").when().get("/reflect").then().assertThat().spec(reqSpec1).extract().detailedCookies();
        assertThat(cookies.size(), is(2));
        assertThat(cookies.hasCookieWithName("Cookie1"), is(true));
        assertThat(cookies.hasCookieWithName("Cookie2"), is(true));
        cookies = given().cookie("Cookie1", "Value1").cookie("Cookie3", "Value3").when().get("/reflect").then().assertThat().spec(reqSpec2).extract().detailedCookies();
        assertThat(cookies.size(), is(2));
        assertThat(cookies.hasCookieWithName("Cookie1"), is(true));
        assertThat(cookies.hasCookieWithName("Cookie3"), is(true));
    } finally {
        RestAssured.reset();
    }
}
Also used : ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) ResponseSpecification(io.restassured.specification.ResponseSpecification) Cookies(io.restassured.http.Cookies) Test(org.junit.Test)

Example 5 with ResponseSpecification

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

the class SpecificationBuilderITest method expectingSpecificationMergesTheCurrentSpecificationWithTheSuppliedOne.

@Test
public void expectingSpecificationMergesTheCurrentSpecificationWithTheSuppliedOne() throws Exception {
    final ResponseSpecBuilder builder = new ResponseSpecBuilder();
    builder.expectBody("store.book.size()", is(4)).expectStatusCode(200);
    final ResponseSpecification responseSpecification = builder.build();
    expect().specification(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)

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