use of io.restassured.http.Headers in project devonfw-testing by devonfw.
the class SessionManager method authenticateSession.
/**
* Authenticates a single user session and stores the session related identifiers (headers) localy.
*
* @param session
* Session name.
* @param user
* User name.
* @param password
* User password.
*/
private void authenticateSession(SessionEnum session, EnvironmentParam user, EnvironmentParam password) {
RestAssured.defaultParser = Parser.TEXT;
JSONObject request = new JSONObject();
request.put("username", user);
request.put("password", password);
RequestSpecification rs = new RequestSpecBuilder().setBody(request.toString()).setBaseUri(EnvironmentParam.SECURITY_SERVER_ORIGIN.getValue()).setBasePath(SubUrlEnum.LOGIN.getValue()).build();
Headers headers = given(rs).when().post().getHeaders();
if (!headers.hasHeaderWithName(AUTHORIZATION_HEADER)) {
throw new RuntimeException("No authorization header found. " + "Expected a header 'Authorization' holding a Bearer token.");
}
Header authHeader = headers.get(AUTHORIZATION_HEADER);
Headers authHeaders = new Headers(authHeader);
authData.put(session, authHeaders);
}
use of io.restassured.http.Headers 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"));
}
use of io.restassured.http.Headers 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"));
}
use of io.restassured.http.Headers in project rest-assured by rest-assured.
the class RequestSpecMergingITest method mergesHeadersCorrectlyWhenOnlyStaticMerging.
@Test
public void mergesHeadersCorrectlyWhenOnlyStaticMerging() {
given().filter((requestSpec, responseSpec, ctx) -> {
Headers headers = requestSpec.getHeaders();
assertThat(requestSpec.getContentType(), nullValue());
assertThat(headers.getValue("authorization"), equalTo("abracadabra"));
assertThat(headers.getValue("accept"), equalTo("*/*"));
assertThat(headers.size(), is(2));
return new ResponseBuilder().setStatusCode(200).build();
}).when().get();
}
use of io.restassured.http.Headers 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);
}
}
}
Aggregations