Search in sources :

Example 11 with LogConfig

use of io.restassured.config.LogConfig 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));
}
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 12 with LogConfig

use of io.restassured.config.LogConfig 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));
}
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 13 with LogConfig

use of io.restassured.config.LogConfig 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));
}
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 14 with LogConfig

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

the class LoggingITest method logOnlyBodyUsingResponseUsingLogSpec.

@Test
public void logOnlyBodyUsingResponseUsingLogSpec() 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().body().body("fullName", equalTo("John Doe")).when().get("/{firstName}/{lastName}");
    assertThat(writer.toString(), equalTo("{\"firstName\":\"John\",\"lastName\":\"Doe\",\"fullName\":\"John Doe\"}" + 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 15 with LogConfig

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

the class LoggingITest method logBodyWithPrettyPrintingUsingRequestLogSpec.

@Test
public void logBodyWithPrettyPrintingUsingRequestLogSpec() 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, true))).log().body().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)

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