Search in sources :

Example 6 with Header

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

the class HeaderITest method requestSpecificationAllowsSpecifyingHeadersObject.

@Test
public void requestSpecificationAllowsSpecifyingHeadersObject() throws Exception {
    final Header header1 = new Header("MyHeader", "Something");
    final Header header2 = new Header("MyHeader", "Something else");
    final Headers headers = new Headers(header1, header2);
    final List<String> myHeaderValues = given().headers(headers).when().get("/multiHeaderReflect").headers().getValues("MyHeader");
    assertThat(myHeaderValues.size(), is(2));
    assertThat(myHeaderValues, hasItems("Something", "Something else"));
}
Also used : Header(io.restassured.http.Header) Headers(io.restassured.http.Headers) Test(org.junit.Test)

Example 7 with Header

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

the class HeaderITest method orderIsMaintainedForMultiValueHeaders.

@Test
public void orderIsMaintainedForMultiValueHeaders() throws Exception {
    Headers headers = when().get("/multiValueHeader").headers();
    final List<String> headerListString = headers.getValues("MultiHeader");
    final String firstValue = headers.getValue("MultiHeader");
    final List<Header> headerListHeader = headers.getList("MultiHeader");
    assertThat(headerListString, contains("Value 1", "Value 2"));
    assertThat(headerListHeader, contains(new Header("MultiHeader", "Value 1"), new Header("MultiHeader", "Value 2")));
    assertThat(firstValue, equalTo("Value 2"));
}
Also used : Header(io.restassured.http.Header) Headers(io.restassured.http.Headers) Test(org.junit.Test)

Example 8 with Header

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

the class HeaderConfigITest method request_spec_overwrites_headers_when_configured_in_header_config.

@Test
public void request_spec_overwrites_headers_when_configured_in_header_config() {
    RequestSpecification specification = new RequestSpecBuilder().addHeader("header1", "value2").build();
    List<Header> list = given().config(RestAssuredConfig.config().headerConfig(HeaderConfig.headerConfig().overwriteHeadersWithName("header1"))).header("header1", "value1").spec(specification).when().get("/multiHeaderReflect").then().extract().headers().getList("header1");
    assertThat(list, hasSize(1));
    assertThat(list.get(0).getValue(), equalTo("value2"));
}
Also used : Header(io.restassured.http.Header) RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 9 with Header

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

the class HeaderConfigITest method request_spec_merges_headers_by_default.

@Test
public void request_spec_merges_headers_by_default() {
    RequestSpecification specification = new RequestSpecBuilder().addHeader("header1", "value2").build();
    List<Header> list = given().header("header1", "value1").spec(specification).when().get("/multiHeaderReflect").then().extract().headers().getList("header1");
    assertThat(list, hasSize(2));
}
Also used : Header(io.restassured.http.Header) RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 10 with Header

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

the class ResponsePrinter method toString.

private static String toString(Headers headers) {
    if (!headers.exist()) {
        return "";
    }
    final StringBuilder builder = new StringBuilder();
    for (Header header : headers) {
        builder.append(header.getName()).append(HEADER_NAME_AND_VALUE_SEPARATOR).append(header.getValue()).append("\n");
    }
    builder.deleteCharAt(builder.length() - 1);
    return builder.toString();
}
Also used : Header(io.restassured.http.Header)

Aggregations

Header (io.restassured.http.Header)19 Test (org.junit.Test)11 Headers (io.restassured.http.Headers)6 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)4 ContentTypeHeader (com.github.tomakehurst.wiremock.http.ContentTypeHeader)3 HttpHeader (com.github.tomakehurst.wiremock.http.HttpHeader)3 RequestSpecification (io.restassured.specification.RequestSpecification)3 MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)2 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)2 ArrayList (java.util.ArrayList)2 MutableObject (org.apache.commons.lang3.mutable.MutableObject)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 HttpHeaders (com.github.tomakehurst.wiremock.http.HttpHeaders)1 RestAssuredClient (guru.nidi.ramltester.restassured3.RestAssuredClient)1 Response (io.restassured.response.Response)1 ValidatableResponse (io.restassured.response.ValidatableResponse)1 LinkedHashSet (java.util.LinkedHashSet)1 VerifyTest (org.apache.knox.test.category.VerifyTest)1 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)1 JSONObject (org.json.JSONObject)1