use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class LoggingITest method logOnlyResponseBodyWithPrettyPrintingUsingDSLWhenXml.
@Test
public void logOnlyResponseBodyWithPrettyPrintingUsingDSLWhenXml() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(config().logConfig(new LogConfig(captor, false))).expect().log().body(true).body("videos.music[0].title", is("Video Title 1")).when().get("/videos-not-formatted");
assertThat(writer.toString(), equalTo("<videos>\n <music>\n <title>Video Title 1</title>\n <artist>Artist 1</artist>\n </music>\n <music>\n <title>Video Title 2</title>\n <artist>Artist 2</artist>\n <artist>Artist 3</artist>\n </music>\n</videos>" + LINE_SEPARATOR));
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class LoggingITest method logAllUsingRequestLogSpec.
@Test
public void logAllUsingRequestLogSpec() 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().param("firstName", "John").queryParam("lastName", "Doe").when().get("/greetJSON");
assertThat(writer.toString(), equalTo("Request method:\tGET\nRequest URI:\thttp://localhost:8080/greetJSON?firstName=John&lastName=Doe\nProxy:\t\t\t<none>\nRequest params:\tfirstName=John\nQuery params:\tlastName=Doe\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tAccept=*/*\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\t\t\t<none>" + LINE_SEPARATOR));
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class FileDownloadITest method loggingWithBinaryCharsetWorks.
@Test
public void loggingWithBinaryCharsetWorks() throws Exception {
int expectedSize = IOUtils.toByteArray(getClass().getResourceAsStream("/powermock-easymock-junit-1.4.12.zip")).length;
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
final InputStream inputStream = given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, false))).expect().log().all().when().get("http://powermock.googlecode.com/files/powermock-easymock-junit-1.4.12.zip").asInputStream();
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, byteArrayOutputStream);
IOUtils.closeQuietly(byteArrayOutputStream);
IOUtils.closeQuietly(inputStream);
assertThat(writer.toString(), not(isEmptyOrNullString()));
assertThat(byteArrayOutputStream.size(), equalTo(expectedSize));
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class GivenWhenThenLoggingITest method logOnlyHeadersUsingResponseUsingLogSpecWithGivenWhenThenSyntax.
@Test
public void logOnlyHeadersUsingResponseUsingLogSpecWithGivenWhenThenSyntax() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, true))).pathParam("firstName", "John").pathParam("lastName", "Doe").when().get("/{firstName}/{lastName}").then().log().headers().body("fullName", equalTo("John Doe"));
assertThat(writer.toString(), equalTo("Content-Type: application/json;charset=utf-8\nContent-Length: 59\nServer: Jetty(9.3.2.v20150730)" + LINE_SEPARATOR));
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class PathParamITest method urlEncodesNamedPathParametersThatContainsCurlyBracesAndEquals.
@Test
public void urlEncodesNamedPathParametersThatContainsCurlyBracesAndEquals() throws Exception {
// When
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, true))).pathParam("trackingName", "{trackingName='trackingname1'}").pathParam("platform", "platform").log().all().filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).get("/feed?canonicalName={trackingName}&{platform}=ed4");
// Then
assertThat(RequestPathFromLogExtractor.loggedRequestPathIn(writer), equalTo("http://localhost:8080/feed?canonicalName=%7BtrackingName%3D%27trackingname1%27%7D&platform=ed4"));
}
Aggregations