use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class AuthenticationITest method formAuthenticationUsingLoggingWithLogDetailEqualToParams.
@Test
public void formAuthenticationUsingLoggingWithLogDetailEqualToParams() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().auth().form("John", "Doe", FormAuthConfig.springSecurity().withLoggingEnabled(LogDetail.PARAMS, new LogConfig(captor, true))).when().get("/formAuth").then().statusCode(200).body(equalTo("OK"));
assertThat(writer.toString(), equalTo("Request params:\t<none>\nQuery params:\t<none>\nForm params:\tj_username=John\n\t\t\t\tj_password=Doe\nPath params:\t<none>\nMultiparts:\t\t<none>\n"));
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class PathParamITest method mixingUnnamedPathParametersAndQueryParametersWorks.
@Test
public void mixingUnnamedPathParametersAndQueryParametersWorks() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, true))).log().all().filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).get("/{channelName}/item-import/rss/import?source={url}", "games", "http://myurl.com");
// Then
assertThat(RequestPathFromLogExtractor.loggedRequestPathIn(writer), equalTo("http://localhost:8080/games/item-import/rss/import?source=http%3A%2F%2Fmyurl.com"));
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class MockMvcRestAssuredResponseImpl method then.
public ValidatableMockMvcResponse then() {
ValidatableMockMvcResponseImpl response = new ValidatableMockMvcResponseImpl(resultActions, getContentType(), getRpr(), getConfig(), this, this, logRepository);
LogConfig logConfig = getConfig().getLogConfig();
if (logConfig.isLoggingOfRequestAndResponseIfValidationFailsEnabled()) {
response.log().ifValidationFails(logConfig.logDetailOfRequestAndResponseIfValidationFails(), logConfig.isPrettyPrintingEnabled());
}
return response;
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class RestAssuredMockMvc method enableLoggingOfRequestAndResponseIfValidationFails.
/**
* Enable logging of both the request and the response if REST Assureds test validation fails with the specified log detail.
* <p/>
* <p>
* This is just a shortcut for:
* </p>
* <pre>
* RestAssured.config = new RestAssuredMockMvcConfig().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail));
* </pre>
*
* @param logDetail The log detail to show in the log
*/
public static void enableLoggingOfRequestAndResponseIfValidationFails(LogDetail logDetail) {
config = config == null ? new RestAssuredMockMvcConfig() : config;
config = config.logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail));
// Note that request spec also influence response spec when it comes to logging if validation fails due to the way filters work
if (requestSpecification != null && requestSpecification instanceof MockMvcRequestSpecificationImpl) {
RestAssuredMockMvcConfig restAssuredConfig = ((MockMvcRequestSpecificationImpl) requestSpecification).getRestAssuredMockMvcConfig();
if (restAssuredConfig == null) {
restAssuredConfig = config;
} else {
LogConfig logConfigForRequestSpec = restAssuredConfig.getLogConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail);
restAssuredConfig = restAssuredConfig.logConfig(logConfigForRequestSpec);
}
requestSpecification.config(restAssuredConfig);
}
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class PutTest method doesnt_automatically_adds_x_www_form_urlencoded_as_content_type_when_putting_params.
@Test
public void doesnt_automatically_adds_x_www_form_urlencoded_as_content_type_when_putting_params() {
StringWriter writer = new StringWriter();
PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssuredMockMvc.given().config(newConfig().logConfig(new LogConfig(captor, true))).param("name", "Johan").when().put("/greetingPut").then().log().all().statusCode(415);
assertThat(writer.toString(), equalTo("415 Content type 'null' not supported\nAccept: application/x-www-form-urlencoded\n"));
}
Aggregations