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();
}
}
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();
}
}
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")));
}
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);
}
}
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()));
}
Aggregations