Search in sources :

Example 41 with LogConfig

use of io.restassured.config.LogConfig in project rest-assured by rest-assured.

the class LoggingITest method logOnlyResponseBodyWithPrettyPrintingWhenXml.

@Test
public void logOnlyResponseBodyWithPrettyPrintingWhenXml() 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("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 42 with LogConfig

use of io.restassured.config.LogConfig in project rest-assured by rest-assured.

the class LoggingITest method logBodyUsingRequestLogSpec.

@Test
public void logBodyUsingRequestLogSpec() 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().body().param("firstName", "John").queryParam("lastName", "Doe").when().get("/greetJSON");
    assertThat(writer.toString(), equalTo("Body:\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 43 with LogConfig

use of io.restassured.config.LogConfig in project rest-assured by rest-assured.

the class LoggingITest method logBodyWithPrettyPrintingUsingDslAndRequestLogSpec.

@Test
public void logBodyWithPrettyPrintingUsingDslAndRequestLogSpec() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().contentType(ContentType.JSON).config(config().logConfig(new LogConfig(captor, false))).log().body(true).body("{ \"something\" : \"else\" }").when().post("/body");
    assertThat(writer.toString(), equalTo("Body:\n{\n    \"something\": \"else\"\n}" + 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 44 with LogConfig

use of io.restassured.config.LogConfig in project rest-assured by rest-assured.

the class LoggingITest method logBodyWithPrettyPrintingUsingRequestLogSpecAndObjectMapping.

@Test
public void logBodyWithPrettyPrintingUsingRequestLogSpecAndObjectMapping() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    final Message message = new Message();
    message.setMessage("My message");
    given().contentType(ContentType.JSON).config(config().logConfig(new LogConfig(captor, true))).log().body().body(message).when().post("/body");
    assertThat(writer.toString(), equalTo("Body:\n{\n    \"message\": \"My message\"\n}" + LINE_SEPARATOR));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) Message(io.restassured.itest.java.objects.Message) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 45 with LogConfig

use of io.restassured.config.LogConfig in project rest-assured by rest-assured.

the class LoggingITest method logOnlyHeadersUsingResponseUsingLogSpec.

@Test
public void logOnlyHeadersUsingResponseUsingLogSpec() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().config(config().logConfig(new LogConfig(captor, true))).pathParam("firstName", "John").pathParam("lastName", "Doe").expect().log().headers().body("fullName", equalTo("John Doe")).when().get("/{firstName}/{lastName}");
    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)

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