use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LoggingITest method logBodyPrettyPrintedUsingRequestLogSpecWhenContentTypeDoesntMatchContent.
@Test
public void logBodyPrettyPrintedUsingRequestLogSpecWhenContentTypeDoesntMatchContent() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(config().logConfig(new LogConfig(captor, true))).log().everything().contentType("application/json").body("This is not 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=application/json; charset=" + RestAssured.config().getEncoderConfig().defaultCharsetForContentType(ContentType.JSON) + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\nThis is not JSON" + LINE_SEPARATOR));
}
use of org.apache.commons.io.output.WriterOutputStream 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));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LoggingITest method logNoValueParamsUsingRequestLogSpec.
@Test
public void logNoValueParamsUsingRequestLogSpec() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(config().logConfig(new LogConfig(captor, true))).log().parameters().formParam("formParam").queryParam("queryParam").when().post("/noValueParam");
assertThat(writer.toString(), equalTo("Request params:\t<none>\nQuery params:\tqueryParam\nForm params:\tformParam\nPath params:\t<none>\nMultiparts:\t\t<none>" + LINE_SEPARATOR));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LoggingITest method shows_request_log_as_without_url_encoding_when_explicitly_instructing_request_logging_filter_to_do_so.
@Test
public void shows_request_log_as_without_url_encoding_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, false)).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));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LoggingITest method logOnlyResponseBodyWithPrettyPrintingWhenHtml.
@Test
public void logOnlyResponseBodyWithPrettyPrintingWhenHtml() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(config().logConfig(new LogConfig(captor, true))).expect().log().body().body("html.head.title", is("my title")).when().get("/textHTML-not-formatted");
assertThat(writer.toString(), equalTo("<html>\n <head>\n <title>my title</title>\n </head>\n <body>\n <p>paragraph 1</p>\n <p>paragraph 2</p>\n </body>\n</html>" + LINE_SEPARATOR));
}
Aggregations