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));
}
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));
}
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));
}
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(""));
}
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)));
}
Aggregations