use of io.restassured.builder.RequestSpecBuilder 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.builder.RequestSpecBuilder in project devonfw-testing by devonfw.
the class SessionManager method initBuilder.
/*
* (non-Javadoc)
* @see com.capgemini.ntc.security.ISessionManager#initBuilder(com.capgemini.ntc.security.SessionEnum)
*/
@Override
public RequestSpecBuilder initBuilder(SessionEnum session) {
Preconditions.checkNotNull(session);
if (!authData.containsKey(session)) {
return initBuilder();
}
RequestSpecBuilder result = new RequestSpecBuilder();
for (Header header : authData.get(session).asList()) {
result.addHeader(header.getName(), header.getValue());
}
return result;
}
use of io.restassured.builder.RequestSpecBuilder in project spring-cloud-netflix by spring-cloud.
the class AbstractDocumentationTests method spec.
private RequestSpecification spec(Object body, Filter... filters) {
RequestSpecBuilder builder = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation).snippets().withAdditionalDefaults(new WireMockSnippet()));
for (Filter filter : filters) {
builder = builder.addFilter(filter);
}
RequestSpecification spec = builder.setPort(this.port).build();
if (body != null) {
spec.contentType("application/json").body(body, new EurekaObjectMapper());
}
return spec;
}
use of io.restassured.builder.RequestSpecBuilder in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method logging_of_both_request_and_response_validation_works_when_test_fails_when_using_static_response_and_request_specs_declared_before_enable_logging.
@Test
public void logging_of_both_request_and_response_validation_works_when_test_fails_when_using_static_response_and_request_specs_declared_before_enable_logging() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).build();
RestAssured.requestSpecification = new RequestSpecBuilder().setConfig(RestAssuredConfig.config().logConfig(new LogConfig(captor, true))).addHeader("Api-Key", "1234").build();
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.HEADERS);
try {
RestAssured.given().param("firstName", "John").param("lastName", "Doe").header("Content-type", "application/json").when().get("/greet").then().body("firstName", equalTo("Hello, Johan2!"));
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), equalTo("Headers:\t\t" + "Api-Key=1234" + LINE_SEPARATOR + "\t\t\t\tAccept=*/*" + LINE_SEPARATOR + "\t\t\t\tContent-Type=application/json; charset=" + RestAssured.config().getEncoderConfig().defaultCharsetForContentType(ContentType.JSON) + LINE_SEPARATOR + LINE_SEPARATOR + "Content-Type: application/json;charset=utf-8\nContent-Length: 33\nServer: Jetty(9.3.2.v20150730)\n"));
}
}
use of io.restassured.builder.RequestSpecBuilder in project rest-assured by rest-assured.
the class SpecificationBuilderITest method supportsSpecifyingQueryParametersInRequestSpecBuilderWhenPost.
@Test
public void supportsSpecifyingQueryParametersInRequestSpecBuilderWhenPost() throws Exception {
final RequestSpecification spec = new RequestSpecBuilder().addQueryParameter("firstName", "John").addQueryParam("lastName", "Doe").build();
given().spec(spec).expect().body("greeting.firstName", equalTo("John")).body("greeting.lastName", equalTo("Doe")).when().post("/greetXML");
}
Aggregations