Search in sources :

Example 26 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class LoggingITest method loggingRequestFilterPathParams.

@Test
public void loggingRequestFilterPathParams() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().filter(new RequestLoggingFilter(captor)).pathParam("firstName", "John").pathParam("lastName", "Doe").expect().body("fullName", equalTo("John Doe")).when().get("/{firstName}/{lastName}");
    assertThat(writer.toString(), equalTo("Request method:\tGET\nRequest URI:\thttp://localhost:8080/John/Doe\nProxy:\t\t\t<none>\nRequest params:\t<none>\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\tfirstName=John\n\t\t\t\tlastName=Doe\nHeaders:\t\tAccept=*/*\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 27 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class LoggingITest method doesnt_include_default_charset_in_request_log_when_it_is_configured_not_to_be_added.

@Test
public void doesnt_include_default_charset_in_request_log_when_it_is_configured_not_to_be_added() {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().filter(logRequestTo(captor)).config(RestAssured.config().encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false))).param("foo", "bar").contentType(ContentType.XML).when().post("/contentTypeAsBody").then().statusCode(200);
    assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/contentTypeAsBody\nProxy:\t\t\t<none>\nRequest params:\tfoo=bar\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tAccept=*/*\n\t\t\t\tContent-Type=application/xml\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) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 28 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class LoggingITest method logBodyWithPrettyPrintingUsingRequestLogSpecAndObjectMappingWhenXML.

@Test
public void logBodyWithPrettyPrintingUsingRequestLogSpecAndObjectMappingWhenXML() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    final Greeting greeting = new Greeting();
    greeting.setFirstName("John");
    greeting.setLastName("Doe");
    given().contentType(ContentType.XML).config(config().logConfig(new LogConfig(captor, true))).log().body().body(greeting).when().post("/body");
    assertThat(writer.toString(), equalTo("Body:\n<greeting>\n  <firstName>John</firstName>\n  <lastName>Doe</lastName>\n</greeting>" + LINE_SEPARATOR));
}
Also used : PrintStream(java.io.PrintStream) Greeting(io.restassured.itest.java.objects.Greeting) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 29 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class LoggingITest method loggingResponseFilterDoesntLogWhenSpecifiedMatcherIsNotFulfilled.

@Test
public void loggingResponseFilterDoesntLogWhenSpecifiedMatcherIsNotFulfilled() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().filter(logResponseToIfMatches(captor, equalTo(400))).expect().body("greeting", equalTo("Greetings John Doe")).when().get("/greet?firstName=John&lastName=Doe");
    assertThat(writer.toString(), is(""));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 30 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class LoggingITest method logResponseThatHasCookiesWithLogDetailCookies.

@Test
public void logResponseThatHasCookiesWithLogDetailCookies() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().filter(logResponseTo(captor, COOKIES)).and().expect().body(equalTo("OK")).when().get("/multiCookie");
    assertThat(writer.toString(), allOf(startsWith("cookie1=cookieValue1;Domain=localhost\ncookie1=cookieValue2;Comment=\"My Purpose\";Path=/;Domain=localhost;Max-Age=1234567;Secure;Expires="), endsWith(";Version=1" + LINE_SEPARATOR)));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Aggregations

WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)149 StringWriter (java.io.StringWriter)142 PrintStream (java.io.PrintStream)137 Test (org.junit.Test)132 LogConfig (io.restassured.config.LogConfig)46 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)44 ResponseBuilder (io.restassured.builder.ResponseBuilder)36 Filter (io.restassured.filter.Filter)35 FilterContext (io.restassured.filter.FilterContext)35 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)35 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)35 IOException (java.io.IOException)6 Col (org.apache.karaf.shell.table.Col)6 ShellTable (org.apache.karaf.shell.table.ShellTable)6 OutputStream (java.io.OutputStream)5 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)4 InputStream (java.io.InputStream)4 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)3 ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)3