use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method doesntLogResponseSpecUsingLegacySyntaxWhenValidationSucceeds.
@Test
public void doesntLogResponseSpecUsingLegacySyntaxWhenValidationSucceeds() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, false))).pathParam("firstName", "John").pathParam("lastName", "Doe").expect().log().ifValidationFails(LogDetail.BODY).body("fullName", equalTo("John Doe")).when().get("/{firstName}/{lastName}");
assertThat(writer.toString(), isEmptyString());
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method configuringLogConfigToEnableLoggingOfRequestAndResponseIfValidationFailsWorksAsExpected2.
@Test
public void configuringLogConfigToEnableLoggingOfRequestAndResponseIfValidationFailsWorksAsExpected2() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
try {
RestAssured.given().config(RestAssured.config().logConfig(LogConfig.logConfig().defaultStream(captor).and().enableLoggingOfRequestAndResponseIfValidationFails())).param("firstName", "John").param("lastName", "Doe").header("Content-type", "application/json").when().get("/greet").then().body("room.size()", is(2));
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertThat(writer.toString(), equalTo("Request method:\tGET" + LINE_SEPARATOR + "Request URI:\thttp://localhost:8080/greet?firstName=John&lastName=Doe" + LINE_SEPARATOR + "Proxy:\t\t\t<none>" + LINE_SEPARATOR + "Request params:\tfirstName=John" + LINE_SEPARATOR + "\t\t\t\tlastName=Doe" + LINE_SEPARATOR + "Query params:\t<none>" + LINE_SEPARATOR + "Form params:\t<none>" + LINE_SEPARATOR + "Path params:\t<none>" + LINE_SEPARATOR + "Headers:\t\tAccept=*/*" + LINE_SEPARATOR + "\t\t\t\tContent-Type=application/json; charset=" + RestAssured.config().getEncoderConfig().defaultCharsetForContentType(ContentType.JSON) + LINE_SEPARATOR + "Cookies:\t\t<none>" + LINE_SEPARATOR + "Multiparts:\t\t<none>" + LINE_SEPARATOR + "Body:\t\t\t<none>" + LINE_SEPARATOR + LINE_SEPARATOR + "HTTP/1.1 200 OK" + LINE_SEPARATOR + "Content-Type: application/json;charset=utf-8" + LINE_SEPARATOR + "Content-Length: 33" + LINE_SEPARATOR + "Server: Jetty(9.3.2.v20150730)" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "{" + LINE_SEPARATOR + " \"greeting\": \"Greetings John Doe\"" + LINE_SEPARATOR + "}" + LINE_SEPARATOR + ""));
}
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method logging_is_applied_when_using_non_static_response_specifications.
@Test
public void logging_is_applied_when_using_non_static_response_specifications() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
try {
RestAssured.given().config(RestAssured.config().logConfig(LogConfig.logConfig().defaultStream(captor).and().enableLoggingOfRequestAndResponseIfValidationFails())).param("firstName", "John").param("lastName", "Doe").when().get("/greet").then().spec(new ResponseSpecBuilder().expectStatusCode(400).build());
fail("Test out to have failed by now");
} catch (AssertionError e) {
assertThat(writer.toString(), not(isEmptyOrNullString()));
}
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LoggingITest method logOnlyResponseBodyWithNoPrettyPrintingUsingDSLWhenXml.
@Test
public void logOnlyResponseBodyWithNoPrettyPrintingUsingDSLWhenXml() 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(false).body("videos.music[0].title", is("Video Title 1")).when().get("/videos-not-formatted");
assertThat(writer.toString(), equalTo("<videos><music><title>Video Title 1</title><artist>Artist 1</artist></music><music><title>Video Title 2</title><artist>Artist 2</artist><artist>Artist 3</artist></music></videos>" + LINE_SEPARATOR));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LoggingITest method logAllWithPrettyPrintingUsingDSLWhenJson.
@Test
public void logAllWithPrettyPrintingUsingDSLWhenJson() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(config().logConfig(new LogConfig(captor, false))).pathParam("firstName", "John").pathParam("lastName", "Doe").expect().log().all(true).body("fullName", equalTo("John Doe")).when().get("/{firstName}/{lastName}");
assertThat(writer.toString(), equalTo("HTTP/1.1 200 OK\nContent-Type: application/json;charset=utf-8\nContent-Length: 59\nServer: Jetty(9.3.2.v20150730)\n\n{\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"fullName\": \"John Doe\"\n}" + LINE_SEPARATOR));
}
Aggregations