Search in sources :

Example 21 with LogConfig

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

the class AuthenticationITest method formAuthenticationUsingLoggingWithLogDetailEqualToParams.

@Test
public void formAuthenticationUsingLoggingWithLogDetailEqualToParams() 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.PARAMS, new LogConfig(captor, true))).when().get("/formAuth").then().statusCode(200).body(equalTo("OK"));
    assertThat(writer.toString(), equalTo("Request params:\t<none>\nQuery params:\t<none>\nForm params:\tj_username=John\n\t\t\t\tj_password=Doe\nPath params:\t<none>\nMultiparts:\t\t<none>\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 22 with LogConfig

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

the class PathParamITest method mixingUnnamedPathParametersAndQueryParametersWorks.

@Test
public void mixingUnnamedPathParametersAndQueryParametersWorks() 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))).log().all().filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
        }
    }).get("/{channelName}/item-import/rss/import?source={url}", "games", "http://myurl.com");
    // Then
    assertThat(RequestPathFromLogExtractor.loggedRequestPathIn(writer), equalTo("http://localhost:8080/games/item-import/rss/import?source=http%3A%2F%2Fmyurl.com"));
}
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)

Example 23 with LogConfig

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

the class MockMvcRestAssuredResponseImpl method then.

public ValidatableMockMvcResponse then() {
    ValidatableMockMvcResponseImpl response = new ValidatableMockMvcResponseImpl(resultActions, getContentType(), getRpr(), getConfig(), this, this, logRepository);
    LogConfig logConfig = getConfig().getLogConfig();
    if (logConfig.isLoggingOfRequestAndResponseIfValidationFailsEnabled()) {
        response.log().ifValidationFails(logConfig.logDetailOfRequestAndResponseIfValidationFails(), logConfig.isPrettyPrintingEnabled());
    }
    return response;
}
Also used : LogConfig(io.restassured.config.LogConfig)

Example 24 with LogConfig

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

the class RestAssuredMockMvc method enableLoggingOfRequestAndResponseIfValidationFails.

/**
 * Enable logging of both the request and the response if REST Assureds test validation fails with the specified log detail.
 * <p/>
 * <p>
 * This is just a shortcut for:
 * </p>
 * <pre>
 * RestAssured.config = new RestAssuredMockMvcConfig().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail));
 * </pre>
 *
 * @param logDetail The log detail to show in the log
 */
public static void enableLoggingOfRequestAndResponseIfValidationFails(LogDetail logDetail) {
    config = config == null ? new RestAssuredMockMvcConfig() : config;
    config = config.logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail));
    // Note that request spec also influence response spec when it comes to logging if validation fails due to the way filters work
    if (requestSpecification != null && requestSpecification instanceof MockMvcRequestSpecificationImpl) {
        RestAssuredMockMvcConfig restAssuredConfig = ((MockMvcRequestSpecificationImpl) requestSpecification).getRestAssuredMockMvcConfig();
        if (restAssuredConfig == null) {
            restAssuredConfig = config;
        } else {
            LogConfig logConfigForRequestSpec = restAssuredConfig.getLogConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail);
            restAssuredConfig = restAssuredConfig.logConfig(logConfigForRequestSpec);
        }
        requestSpecification.config(restAssuredConfig);
    }
}
Also used : MockMvcRequestSpecificationImpl(io.restassured.module.mockmvc.internal.MockMvcRequestSpecificationImpl) RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) LogConfig(io.restassured.config.LogConfig)

Example 25 with LogConfig

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

the class PutTest method doesnt_automatically_adds_x_www_form_urlencoded_as_content_type_when_putting_params.

@Test
public void doesnt_automatically_adds_x_www_form_urlencoded_as_content_type_when_putting_params() {
    StringWriter writer = new StringWriter();
    PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    RestAssuredMockMvc.given().config(newConfig().logConfig(new LogConfig(captor, true))).param("name", "Johan").when().put("/greetingPut").then().log().all().statusCode(415);
    assertThat(writer.toString(), equalTo("415 Content type 'null' not supported\nAccept: application/x-www-form-urlencoded\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