Search in sources :

Example 41 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class MockMvcRequestLogSpecificationImpl method logWith.

private MockMvcRequestSpecification logWith(LogDetail logDetail, boolean prettyPrintingEnabled, PrintStream printStream) {
    boolean shouldUrlEncodeRequestUri = requestSpecification.getRestAssuredMockMvcConfig().getLogConfig().shouldUrlEncodeRequestUri();
    requestSpecification.setRequestLoggingFilter(new RequestLoggingFilter(logDetail, prettyPrintingEnabled, printStream, shouldUrlEncodeRequestUri));
    return requestSpecification;
}
Also used : RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter)

Example 42 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class LoggingITest method loggingRequestAndResponseAtTheSameTimeWhenRequestFilterIsAddedBeforeResponseFilter.

@Test
public void loggingRequestAndResponseAtTheSameTimeWhenRequestFilterIsAddedBeforeResponseFilter() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    final ScalatraObject object = new ScalatraObject();
    object.setHello("Hello world");
    given().filters(new RequestLoggingFilter(captor), new ResponseLoggingFilter(captor)).body(object).expect().defaultParser(JSON).when().post("/reflect");
    assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/reflect\nProxy:\t\t\t<none>\nRequest params:\t<none>\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tAccept=*/*\n\t\t\t\tContent-Type=text/plain; charset=" + RestAssured.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\n{\"hello\":\"Hello world\"}" + LINE_SEPARATOR + "HTTP/1.1 200 OK\nContent-Type: text/plain;charset=iso-8859-1\nContent-Length: 23\nServer: Jetty(9.3.2.v20150730)\n\n{\"hello\":\"Hello world\"}" + LINE_SEPARATOR));
}
Also used : PrintStream(java.io.PrintStream) ScalatraObject(io.restassured.itest.java.objects.ScalatraObject) StringWriter(java.io.StringWriter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Example 43 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class LoggingITest method loggingRequestFilterWithExplicitContentType.

@Test
public void loggingRequestFilterWithExplicitContentType() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().filter(new RequestLoggingFilter(captor)).param("firstName", "John").param("lastName", "Doe").header("Content-type", "application/json").expect().body("greeting", equalTo("Greetings John Doe")).when().get("/greet");
    assertThat(writer.toString(), equalTo("Request method:\tGET\nRequest URI:\thttp://localhost:8080/greet?firstName=John&lastName=Doe\nProxy:\t\t\t<none>\nRequest params:\tfirstName=John\n\t\t\t\tlastName=Doe\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tAccept=*/*\n\t\t\t\tContent-Type=application/json; charset=" + RestAssured.config().getEncoderConfig().defaultCharsetForContentType(ContentType.JSON) + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\t\t\t<none>" + 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 44 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class LoggingITest method using_log_detail_uri_only_logs_the_request_uri.

@Test
public void using_log_detail_uri_only_logs_the_request_uri() {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().filter(new RequestLoggingFilter(LogDetail.URI, captor)).queryParam("firstName", "John").queryParam("lastName", "Doe").when().get("/greet").then().statusCode(200);
    assertThat(writer.toString(), equalTo("Request URI:\thttp://localhost:8080/greet?firstName=John&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 45 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class LoggingITest method using_log_detail_method_only_logs_the_request_method.

@Test
public void using_log_detail_method_only_logs_the_request_method() {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().filter(new RequestLoggingFilter(LogDetail.METHOD, captor)).queryParam("firstName", "John").queryParam("lastName", "Doe").when().get("/greet").then().statusCode(200);
    assertThat(writer.toString(), equalTo("Request method:\tGET" + 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)

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