use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.
the class URLITest method fullyQualifiedUrlIsHandledCorrectlyInLogWithNoValueParam.
@Test
public void fullyQualifiedUrlIsHandledCorrectlyInLogWithNoValueParam() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().filter(new RequestLoggingFilter(captor)).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).expect().statusCode(200).body(equalTo("changed")).when().get("http://ya.ru/bla/?param=value=&ikk");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://ya.ru/bla/?param=value%3D&ikk"));
}
use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.
the class URLITest method takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedEndingWithSlash.
@Test
public void takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedEndingWithSlash() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().port(8084).contentType(JSON).filter(new RequestLoggingFilter(captor)).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).expect().statusCode(200).body(equalTo("changed")).when().get("http://localhost/");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8084/"));
}
use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.
the class URLITest method query_param_name_with_empty_value_is_not_treated_as_no_value_query_param.
/**
* Asserts that issue 314 is resolved
*/
@Test
public void query_param_name_with_empty_value_is_not_treated_as_no_value_query_param() {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().filter(new RequestLoggingFilter(captor)).when().get("/requestUrl?param1=1&voidparam=¶m3=3").then().statusCode(200).body(equalTo("http://localhost:8080/requestUrl?param1=1&voidparam=¶m3=3"));
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/requestUrl?param1=1&voidparam=¶m3=3"));
}
use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.
the class LoggingITest method shows_request_log_as_url_encoded_when_explicitly_instructing_request_logging_filter_to_do_so.
@Test
public void shows_request_log_as_url_encoded_when_explicitly_instructing_request_logging_filter_to_do_so() throws UnsupportedEncodingException {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().filter(new RequestLoggingFilter(LogDetail.URI, true, captor, true)).queryParam("firstName", "John#€").queryParam("lastName", "Doe").when().get("/greet").then().statusCode(200);
assertThat(writer.toString(), equalTo("Request URI:\thttp://localhost:8080/greet?firstName=John" + URLEncoder.encode("#€", "UTF-8") + "&lastName=Doe" + LINE_SEPARATOR));
}
use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.
the class RequestSpecBuilder method log.
/**
* Enabled logging with the specified log detail. Set a {@link LogConfig} to configure the print stream and pretty printing options.
*
* @param logDetail The log detail.
* @return RequestSpecBuilder
*/
public RequestSpecBuilder log(LogDetail logDetail) {
notNull(logDetail, LogDetail.class);
RestAssuredConfig restAssuredConfig = spec.getConfig();
LogConfig logConfig;
if (restAssuredConfig == null) {
logConfig = new RestAssuredConfig().getLogConfig();
} else {
logConfig = restAssuredConfig.getLogConfig();
}
PrintStream printStream = logConfig.defaultStream();
boolean prettyPrintingEnabled = logConfig.isPrettyPrintingEnabled();
boolean shouldUrlEncodeRequestUri = logConfig.shouldUrlEncodeRequestUri();
spec.filter(new RequestLoggingFilter(logDetail, prettyPrintingEnabled, printStream, shouldUrlEncodeRequestUri));
return this;
}
Aggregations