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