Skip to content

Maybe you can add a RestAssuredConfigFactory to make the usage a bit simpler. #4

@zhtaoang

Description

@zhtaoang

Something like this:

/**
 * To provide cUrl log configuration for RestAssured
 */
public class RestAssuredConfigFactory {


    public static RestAssuredConfig singleLineCurl() {
        return config()
                .httpClient(httpClientConfig()
                        .reuseHttpClientInstance()
                        .httpClientFactory(new SingleCurlLoggingHttpClientFactory()));
    }

    private static class SingleCurlLoggingHttpClientFactory implements HttpClientConfig.HttpClientFactory {
        @Override
        public HttpClient createHttpClient() {
            AbstractHttpClient client = new DefaultHttpClient();
            client.addRequestInterceptor(CurlLoggingInterceptor.defaultBuilder().printSingleliner().build());// singleLine cUrl
            return client;
        }
    }

    public static RestAssuredConfig multiLineCurl() {
        return config()
                .httpClient(httpClientConfig()
                        .reuseHttpClientInstance()
                        .httpClientFactory(new MultiCurlLoggingHttpClientFactory()));
    }

    private static class MultiCurlLoggingHttpClientFactory implements HttpClientConfig.HttpClientFactory {
        @Override
        public HttpClient createHttpClient() {
            AbstractHttpClient client = new DefaultHttpClient();
            client.addRequestInterceptor(CurlLoggingInterceptor.defaultBuilder().printMultiliner().build());// multiLine cUrl
            return client;
        }
    }
}

And to use it:

RestAssured.given()
                .config(RestAssuredConfigFactory.singleLineCurl())// this will log the cUrl to the log print out
                .contentType(ContentType.JSON)
                .body(new LandLord("Tao", "Zhang"))
                .when()
                .post("/landlords")
                .then()
                .statusCode(201);

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions