Search in sources :

Example 11 with Cookie

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

the class MockMvcRequestSpecificationMergingTest method cookies_are_not_overwritten_when_not_defined_in_specification.

@Test
public void cookies_are_not_overwritten_when_not_defined_in_specification() {
    // Given
    Cookie thisCookie = new Cookie.Builder("cookie2", "value2").build();
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().cookie(thisCookie).spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getCookies()).containsOnly(thisCookie);
    Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
Also used : Cookie(io.restassured.http.Cookie) MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 12 with Cookie

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

the class CookieITest method removesDoubleQuotesFromCookieWithExpiresDate.

@Test
public void removesDoubleQuotesFromCookieWithExpiresDate() throws Exception {
    Cookies cookies = when().get("/cookieWithDoubleQuoteExpiresDate").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 13 with Cookie

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

the class CookieITest method setsExpiresPropertyToNullWhenCookieHasInvalidExpiresDate.

@Test
public void setsExpiresPropertyToNullWhenCookieHasInvalidExpiresDate() throws Exception {
    Cookies cookies = when().get("/cookieWithInvalidExpiresDate").then().extract().detailedCookies();
    assertThat(cookies.asList(), hasSize(1));
    Cookie cookie = cookies.get("name");
    assertThat(cookie.getExpiryDate(), nullValue());
}
Also used : Cookie(io.restassured.http.Cookie) RestAssuredMatchers.detailedCookie(io.restassured.matcher.RestAssuredMatchers.detailedCookie) Cookies(io.restassured.http.Cookies) Test(org.junit.Test)

Example 14 with Cookie

use of io.restassured.http.Cookie in project tutorials by eugenp.

the class RestAssuredAdvancedLiveTest method whenUseCookieBuilder_thenOK.

@Test
public void whenUseCookieBuilder_thenOK() {
    Cookie myCookie = new Cookie.Builder("session_id", "1234").setSecured(true).setComment("session id cookie").build();
    given().cookie(myCookie).when().get("/users/eugenp").then().statusCode(200);
}
Also used : Cookie(io.restassured.http.Cookie) Test(org.junit.Test)

Aggregations

Cookie (io.restassured.http.Cookie)14 Test (org.junit.Test)13 RestAssuredMatchers.detailedCookie (io.restassured.matcher.RestAssuredMatchers.detailedCookie)6 Cookies (io.restassured.http.Cookies)5 MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)2 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)2 Response (io.restassured.response.Response)2 SimpleDateFormat (java.text.SimpleDateFormat)1 VerifyTest (org.apache.knox.test.category.VerifyTest)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)1