Search in sources :

Example 1 with ResponseLoggingFilter

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

the class LoggingITest method prettifying_empty_xml_body_doesnt_log_premature_end_of_file.

// This was previously a bug (https://github.com/rest-assured/rest-assured/issues/960)
@Test
public void prettifying_empty_xml_body_doesnt_log_premature_end_of_file() {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().filter(new ResponseLoggingFilter(LogDetail.ALL, true, captor)).filter((requestSpec, responseSpec, ctx) -> new ResponseBuilder().setStatusCode(200).setContentType(ContentType.XML).setBody("").build()).when().get("/xml-empty-body").then().statusCode(200);
    assertThat(writer.toString(), equalTo("200" + LINE_SEPARATOR + "Content-Type: application/xml" + LINE_SEPARATOR));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) ResponseBuilder(io.restassured.builder.ResponseBuilder) Test(org.junit.Test)

Example 2 with ResponseLoggingFilter

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

the class LoggingITest method loggingRequestAndResponseAtTheSameTimeWhenResponseFilterIsAddedBeforeRequestFilter.

@Test
public void loggingRequestAndResponseAtTheSameTimeWhenResponseFilterIsAddedBeforeRequestFilter() 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 ResponseLoggingFilter(captor), new RequestLoggingFilter(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 3 with ResponseLoggingFilter

use of io.restassured.filter.log.ResponseLoggingFilter 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)

Aggregations

ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)3 PrintStream (java.io.PrintStream)3 StringWriter (java.io.StringWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 Test (org.junit.Test)3 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)2 ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)2 ResponseBuilder (io.restassured.builder.ResponseBuilder)1