Search in sources :

Example 51 with LogConfig

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));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 52 with LogConfig

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));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 53 with LogConfig

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));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 54 with LogConfig

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));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 55 with LogConfig

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"));
}
Also used : PrintStream(java.io.PrintStream) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) StringWriter(java.io.StringWriter) Filter(io.restassured.filter.Filter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) LogConfig(io.restassured.config.LogConfig) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Aggregations

LogConfig (io.restassured.config.LogConfig)56 PrintStream (java.io.PrintStream)48 Test (org.junit.Test)48 StringWriter (java.io.StringWriter)46 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)46 RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)7 PostController (io.restassured.module.mockmvc.http.PostController)5 ResponseBuilder (io.restassured.builder.ResponseBuilder)4 Filter (io.restassured.filter.Filter)4 FilterContext (io.restassured.filter.FilterContext)4 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)4 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)4 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)3 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)3 Before (org.junit.Before)2 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)1 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)1 Greeting (io.restassured.itest.java.objects.Greeting)1 Message (io.restassured.itest.java.objects.Message)1