8000 Maybe you can add a RestAssuredConfigFactory to make the usage a bit simpler. · Issue #4 · dzieciou/curl-logger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zhtaoang opened this issue 8000 May 3, 2017 · 1 comment
Assignees

Comments

@zhtaoang
Copy link
zhtaoang commented May 3, 2017

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);
@dzieciou dzieciou mentioned this issue May 4, 2017
@dzieciou
Copy link
Owner
dzieciou commented May 4, 2017

Resolved in 0.6-SNAPSHOT version.

Thanks for your suggestion.

@dzieciou dzieciou closed this as completed May 4, 2017
@dzieciou dzieciou self-assigned this Jun 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0