Search in sources :

Example 11 with Header

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

the class MockMvcRequestSpecificationMergingTest method headers_are_merged_when_defined_in_specification.

@Test
public void headers_are_merged_when_defined_in_specification() {
    // Given
    Header otherHeader = new Header("header1", "value1");
    Header thisHeader = new Header("header2", "value2");
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addHeader(otherHeader).build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().header(thisHeader).spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getRequestHeaders()).containsOnly(thisHeader, otherHeader);
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Header(io.restassured.http.Header) Test(org.junit.Test)

Example 12 with Header

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

the class MockMvcRequestSpecificationMergingTest method headers_are_not_overwritten_when_not_defined_in_specification.

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

Example 13 with Header

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

the class ResultHandlerTest method supports_using_result_handlers_using_the_response_dsl.

@Test
public void supports_using_result_handlers_using_the_response_dsl() {
    MutableObject<Boolean> mutableObject = new MutableObject<Boolean>(false);
    RestAssuredMockMvc.given().header(new Header("headerName", "John Doe")).when().get("/header").then().apply(print(), customResultHandler(mutableObject)).statusCode(200).body("headerName", equalTo("John Doe"));
    assertThat(mutableObject.getValue(), is(true));
}
Also used : Header(io.restassured.http.Header) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Test(org.junit.Test)

Example 14 with Header

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

the class RequestPrinter method addHeaders.

private static void addHeaders(FilterableRequestSpecification requestSpec, StringBuilder builder) {
    builder.append("Headers:");
    final Headers headers = requestSpec.getHeaders();
    if (!headers.exist()) {
        appendTwoTabs(builder).append(NONE).append(NEW_LINE);
    } else {
        int i = 0;
        for (Header header : headers) {
            if (i++ == 0) {
                appendTwoTabs(builder);
            } else {
                appendFourTabs(builder);
            }
            builder.append(header).append(NEW_LINE);
        }
    }
}
Also used : Header(io.restassured.http.Header) Headers(io.restassured.http.Headers)

Example 15 with Header

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

the class HeaderTest method validate_may_fail_when_using_mapping_function_when_validating_header_value.

@Test
public void validate_may_fail_when_using_mapping_function_when_validating_header_value() {
    exception.expect(AssertionError.class);
    exception.expectMessage("Expected header \"Content-Length\" was not a value greater than <1000>, was \"45\". Headers are:");
    given().header(new Header("headerName", "200")).when().get("/header").then().header("Content-Length", new RestAssuredFunction<String, Integer>() {

        public Integer apply(String s) {
            return Integer.parseInt(s);
        }
    }, greaterThan(1000));
}
Also used : Header(io.restassured.http.Header) Test(org.junit.Test)

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