Search in sources :

Example 16 with LogConfig

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

the class LoggingITest method logCookiesUsingRequestLogSpec.

@Test
public void logCookiesUsingRequestLogSpec() 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().cookies().cookie("myCookie1", "myCookieValue1").cookie("myCookie2", "myCookieValue2").cookie("myMultiCookie", "myMultiCookieValue1", "myMultiCookieValue2").when().post("/reflect");
    assertThat(writer.toString(), equalTo("Cookies:\t\tmyCookie1=myCookieValue1\n\t\t\t\tmyCookie2=myCookieValue2\n\t\t\t\tmyMultiCookie=myMultiCookieValue1\n\t\t\t\tmyMultiCookie=myMultiCookieValue2" + 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 17 with LogConfig

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

the class LoggingITest method logParamsUsingRequestLogSpec.

@Test
public void logParamsUsingRequestLogSpec() 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().param("firstName", "John").queryParam("lastName", "Doe").when().get("/greetJSON");
    assertThat(writer.toString(), equalTo("Request params:\tfirstName=John\nQuery params:\tlastName=Doe\nForm params:\t<none>\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 18 with LogConfig

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

the class LoggingITest method logAllWhenBaseURIIsDefinedUsingRequestLogSpec.

@Test
public void logAllWhenBaseURIIsDefinedUsingRequestLogSpec() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    RestAssured.baseURI = "http://localhost:8080/reflect";
    try {
        given().config(config().logConfig(new LogConfig(captor, true))).log().all().body("hello").when().post("/");
    } finally {
        RestAssured.reset();
    }
    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=text/plain; charset=" + RestAssured.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\nhello" + 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 19 with LogConfig

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

the class AuthenticationITest method formAuthenticationUsingLogging.

@Test
public void formAuthenticationUsingLogging() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().auth().form("John", "Doe", FormAuthConfig.springSecurity().withLoggingEnabled(new LogConfig(captor, true))).when().get("/formAuth").then().statusCode(200).body(equalTo("OK"));
    assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/j_spring_security_check\nProxy:\t\t\t<none>\nRequest params:\t<none>\nQuery params:\t<none>\nForm params:\tj_username=John\n\t\t\t\tj_password=Doe\nPath params:\t<none>\nHeaders:\t\tAccept=*/*\n\t\t\t\tContent-Type=application/x-www-form-urlencoded; charset=" + RestAssured.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\t\t\t<none>\nHTTP/1.1 200 OK\nContent-Type: text/plain;charset=utf-8\nSet-Cookie: jsessionid=1234\nContent-Length: 0\nServer: Jetty(9.3.2.v20150730)\n"));
}
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 20 with LogConfig

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

the class AuthenticationITest method formAuthenticationUsingLoggingWithLogDetailEqualToStatus.

@Test
public void formAuthenticationUsingLoggingWithLogDetailEqualToStatus() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().auth().form("John", "Doe", FormAuthConfig.springSecurity().withLoggingEnabled(LogDetail.STATUS, new LogConfig(captor, true))).when().get("/formAuth").then().statusCode(200).body(equalTo("OK"));
    assertThat(writer.toString(), equalTo("HTTP/1.1 200 OK\n"));
}
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