Search in sources :

Example 21 with RequestLoggingFilter

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"));
}
Also used : PrintStream(java.io.PrintStream) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) StringWriter(java.io.StringWriter) Filter(io.restassured.filter.Filter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 22 with RequestLoggingFilter

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/"));
}
Also used : PrintStream(java.io.PrintStream) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) StringWriter(java.io.StringWriter) Filter(io.restassured.filter.Filter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 23 with RequestLoggingFilter

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=&param3=3").then().statusCode(200).body(equalTo("http://localhost:8080/requestUrl?param1=1&voidparam=&param3=3"));
    // Then
    assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/requestUrl?param1=1&voidparam=&param3=3"));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 24 with RequestLoggingFilter

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));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 25 with RequestLoggingFilter

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;
}
Also used : PrintStream(java.io.PrintStream) RestAssuredConfig(io.restassured.config.RestAssuredConfig) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) LogConfig(io.restassured.config.LogConfig)

Aggregations

RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)47 PrintStream (java.io.PrintStream)45 StringWriter (java.io.StringWriter)43 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)43 Test (org.junit.Test)43 ResponseBuilder (io.restassured.builder.ResponseBuilder)31 Filter (io.restassured.filter.Filter)31 FilterContext (io.restassured.filter.FilterContext)31 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)31 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)31 ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)3 Response (io.restassured.response.Response)3 LogConfig (io.restassured.config.LogConfig)2 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)2 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 AsyncConfig (io.restassured.module.mockmvc.config.AsyncConfig)1 MockHttpServletRequestBuilderInterceptor (io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor)1