Search in sources :

Example 1 with Cookie

use of io.restassured.http.Cookie in project knox by apache.

the class GatewayBasicFuncTest method testBasicJsonUseCase.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testBasicJsonUseCase() throws IOException {
    LOG_ENTER();
    String root = "/tmp/GatewayBasicFuncTest/testBasicJsonUseCase";
    String username = "hdfs";
    String password = "hdfs-password";
    /* Create a directory.
    curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=MKDIRS[&permission=<OCTAL>]"

    The client receives a respond with a boolean JSON object:
    HTTP/1.1 HttpStatus.SC_OK OK
    Content-Type: application/json
    Transfer-Encoding: chunked

    {"boolean": true}
    */
    driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("/v1" + root + "/dir").queryParam("op", "MKDIRS").queryParam("user.name", username).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes("webhdfs-success.json")).contentType("application/json");
    Cookie cookie = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").queryParam("op", "MKDIRS").then().statusCode(HttpStatus.SC_OK).contentType("application/json").body("boolean", is(true)).when().put(driver.getUrl("WEBHDFS") + "/v1" + root + "/dir").getDetailedCookie("JSESSIONID");
    assertThat(cookie.isSecured(), is(true));
    assertThat(cookie.isHttpOnly(), is(true));
    assertThat(cookie.getPath(), is("/gateway/cluster"));
    assertThat(cookie.getValue().length(), greaterThan(16));
    driver.assertComplete();
    LOG_EXIT();
}
Also used : Cookie(io.restassured.http.Cookie) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) VerifyTest(org.apache.knox.test.category.VerifyTest) Test(org.junit.Test)

Example 2 with Cookie

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

the class CookieITest method getDetailedCookieWorks.

@Test
public void getDetailedCookieWorks() throws Exception {
    final Response response = get("/html_with_cookie");
    final Cookie detailedCookieJsessionId = response.getDetailedCookie("JSESSIONID");
    assertThat(detailedCookieJsessionId, notNullValue());
    assertThat(detailedCookieJsessionId.getPath(), equalTo("/"));
    assertThat(detailedCookieJsessionId.getValue(), equalTo("B3134D534F40968A3805968207273EF5"));
}
Also used : Response(io.restassured.response.Response) Cookie(io.restassured.http.Cookie) RestAssuredMatchers.detailedCookie(io.restassured.matcher.RestAssuredMatchers.detailedCookie) Test(org.junit.Test)

Example 3 with Cookie

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

the class CookieITest method canGetCookieDetails.

@Test
public void canGetCookieDetails() throws Exception {
    final List<Cookie> cookies = get("/multiCookie").detailedCookies().getList("cookie1");
    assertThat(cookies.size(), is(2));
    final Cookie firstCookie = cookies.get(0);
    assertThat(firstCookie.getValue(), equalTo("cookieValue1"));
    assertThat(firstCookie.getDomain(), equalTo("localhost"));
    final Cookie secondCookie = cookies.get(1);
    assertThat(secondCookie.getValue(), equalTo("cookieValue2"));
    assertThat(secondCookie.getDomain(), equalTo("localhost"));
    assertThat(secondCookie.getPath(), equalTo("/"));
    assertThat(secondCookie.getMaxAge(), is(1234567));
    assertThat(secondCookie.isSecured(), is(true));
    assertThat(secondCookie.getVersion(), is(1));
}
Also used : Cookie(io.restassured.http.Cookie) RestAssuredMatchers.detailedCookie(io.restassured.matcher.RestAssuredMatchers.detailedCookie) Test(org.junit.Test)

Example 4 with Cookie

use of io.restassured.http.Cookie 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 5 with Cookie

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

the class CookieITest method detailedCookieWorks.

@Test
public void detailedCookieWorks() throws Exception {
    final Response response = get("/html_with_cookie");
    final Cookie detailedCookieJsessionId = response.detailedCookie("JSESSIONID");
    assertThat(detailedCookieJsessionId, notNullValue());
    assertThat(detailedCookieJsessionId.getPath(), equalTo("/"));
    assertThat(detailedCookieJsessionId.getValue(), equalTo("B3134D534F40968A3805968207273EF5"));
}
Also used : Response(io.restassured.response.Response) Cookie(io.restassured.http.Cookie) RestAssuredMatchers.detailedCookie(io.restassured.matcher.RestAssuredMatchers.detailedCookie) 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