Search in sources :

Example 6 with RequestSpecification

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

use of io.restassured.specification.RequestSpecification 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 8 with RequestSpecification

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

the class SpecificationBuilderITest method supportsSpecifyingQueryParametersInRequestSpecBuilderWhenPost.

@Test
public void supportsSpecifyingQueryParametersInRequestSpecBuilderWhenPost() throws Exception {
    final RequestSpecification spec = new RequestSpecBuilder().addQueryParameter("firstName", "John").addQueryParam("lastName", "Doe").build();
    given().spec(spec).expect().body("greeting.firstName", equalTo("John")).body("greeting.lastName", equalTo("Doe")).when().post("/greetXML");
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 9 with RequestSpecification

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

the class SpecificationBuilderITest method supportsMergingCookiesWhenUsingRequestSpecBuilder.

@Test
public void supportsMergingCookiesWhenUsingRequestSpecBuilder() throws Exception {
    final RequestSpecification spec1 = new RequestSpecBuilder().addCookie("cookie3", "value3").build();
    final RequestSpecification spec2 = new RequestSpecBuilder().addCookie("cookie1", "value1").addRequestSpecification(spec1).build();
    given().spec(spec2).cookie("cookie2", "value2").expect().body(equalTo("cookie1, cookie3, cookie2")).when().get("/cookie");
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 10 with RequestSpecification

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

the class SpecificationBuilderITest method mergesStaticallyDefinedRequestSpecificationsCorrectly.

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

Aggregations

RequestSpecification (io.restassured.specification.RequestSpecification)55 Test (org.junit.Test)47 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)40 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)7 SecurityTest (com.capgemini.ntc.security.SecurityTest)6 ResponseSpecification (io.restassured.specification.ResponseSpecification)5 Filter (io.restassured.filter.Filter)4 Parameters (junitparams.Parameters)4 FilterContext (io.restassured.filter.FilterContext)3 Header (io.restassured.http.Header)3 Response (io.restassured.response.Response)3 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)3 PrintStream (java.io.PrintStream)3 StringWriter (java.io.StringWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 RestDocumentationFilter (org.springframework.restdocs.restassured3.RestDocumentationFilter)3 Headers (io.restassured.http.Headers)2 List (java.util.List)2 MutableObject (org.apache.commons.lang3.mutable.MutableObject)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1