Search in sources :

Example 1 with Cookies

use of io.restassured.http.Cookies 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 2 with Cookies

use of io.restassured.http.Cookies 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)

Example 3 with Cookies

use of io.restassured.http.Cookies in project rest-assured by rest-assured.

the class CookieITest method parsesValidExpiresDateCorrectly.

@Test
public void parsesValidExpiresDateCorrectly() throws Exception {
    Cookies cookies = when().get("/cookieWithValidExpiresDate").then().extract().detailedCookies();
    assertThat(cookies.asList(), hasSize(1));
    Cookie cookie = cookies.get("name");
    assertThat(cookie.getExpiryDate(), equalTo(DateUtils.parseDate("Sat, 02 May 2009 23:38:25 GMT")));
}
Also used : Cookie(io.restassured.http.Cookie) RestAssuredMatchers.detailedCookie(io.restassured.matcher.RestAssuredMatchers.detailedCookie) Cookies(io.restassured.http.Cookies) Test(org.junit.Test)

Example 4 with Cookies

use of io.restassured.http.Cookies in project rest-assured by rest-assured.

the class RequestPrinter method addCookies.

private static void addCookies(FilterableRequestSpecification requestSpec, StringBuilder builder) {
    builder.append("Cookies:");
    final Cookies cookies = requestSpec.getCookies();
    if (!cookies.exist()) {
        appendTwoTabs(builder).append(NONE).append(NEW_LINE);
    }
    int i = 0;
    for (Cookie cookie : cookies) {
        if (i++ == 0) {
            appendTwoTabs(builder);
        } else {
            appendFourTabs(builder);
        }
        builder.append(cookie).append(NEW_LINE);
    }
}
Also used : Cookie(io.restassured.http.Cookie) Cookies(io.restassured.http.Cookies)

Example 5 with Cookies

use of io.restassured.http.Cookies in project rest-assured by rest-assured.

the class CookieMatcherTest method deals_with_empty_cookie_values.

@Test
public void deals_with_empty_cookie_values() {
    // Given
    String[] cookiesAsString = new String[] { "un=bob; domain=bob.com; path=/", "", "_session_id=asdfwerwersdfwere; domain=bob.com; path=/; HttpOnly" };
    // When
    Cookies cookies = CookieMatcher.getCookies(cookiesAsString);
    // Then
    assertThat(cookies.size(), is(3));
    assertThat(cookies, Matchers.<Cookie>hasItem(nullValue()));
}
Also used : Cookies(io.restassured.http.Cookies) Test(org.junit.Test)

Aggregations

Cookies (io.restassured.http.Cookies)10 Test (org.junit.Test)8 Cookie (io.restassured.http.Cookie)5 RestAssuredMatchers.detailedCookie (io.restassured.matcher.RestAssuredMatchers.detailedCookie)3 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)1 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)1 Headers (io.restassured.http.Headers)1 Prettifier (io.restassured.internal.support.Prettifier)1 RequestSpecification (io.restassured.specification.RequestSpecification)1 ResponseSpecification (io.restassured.specification.ResponseSpecification)1 SimpleDateFormat (java.text.SimpleDateFormat)1