Search in sources :

Example 1 with Prettifier

use of io.restassured.internal.support.Prettifier in project rest-assured by rest-assured.

the class RequestPrinter method addMultiParts.

private static void addMultiParts(FilterableRequestSpecification requestSpec, StringBuilder builder) {
    builder.append("Multiparts:");
    final List<MultiPartSpecification> multiParts = requestSpec.getMultiPartParams();
    if (multiParts.isEmpty()) {
        appendTwoTabs(builder).append(NONE).append(NEW_LINE);
    } else {
        for (int i = 0; i < multiParts.size(); i++) {
            MultiPartSpecification multiPart = multiParts.get(i);
            if (i == 0) {
                appendTwoTabs(builder);
            } else {
                appendFourTabs(builder.append(NEW_LINE));
            }
            builder.append("------------");
            appendFourTabs(appendFourTabs(builder.append(NEW_LINE)).append("Content-Disposition: " + requestSpec.getContentType().replace("multipart/", "") + "; name = " + multiPart.getControlName() + (multiPart.hasFileName() ? "; filename = " + multiPart.getFileName() : "")).append(NEW_LINE)).append("Content-Type: " + multiPart.getMimeType());
            if (multiPart.getContent() instanceof InputStream) {
                appendFourTabs(builder.append(NEW_LINE)).append("<inputstream>");
            } else {
                Parser parser = Parser.fromContentType(multiPart.getMimeType());
                String prettified = new Prettifier().prettify(multiPart.getContent().toString(), parser);
                String prettifiedIndented = StringUtils.replace(prettified, NEW_LINE, NEW_LINE + TAB + TAB + TAB + TAB);
                appendFourTabs(builder.append(NEW_LINE)).append(prettifiedIndented);
            }
        }
        builder.append(NEW_LINE);
    }
}
Also used : InputStream(java.io.InputStream) Prettifier(io.restassured.internal.support.Prettifier) MultiPartSpecification(io.restassured.specification.MultiPartSpecification) Parser(io.restassured.parsing.Parser)

Example 2 with Prettifier

use of io.restassured.internal.support.Prettifier in project rest-assured by rest-assured.

the class ResponsePrinter method print.

/**
 * Prints the response to the print stream
 *
 * @return A string of representing the response
 */
public static String print(ResponseOptions responseOptions, ResponseBody responseBody, PrintStream stream, LogDetail logDetail, boolean shouldPrettyPrint) {
    final StringBuilder builder = new StringBuilder();
    if (logDetail == ALL || logDetail == STATUS) {
        builder.append(responseOptions.statusLine());
    }
    if (logDetail == ALL || logDetail == HEADERS) {
        final Headers headers = responseOptions.headers();
        if (headers.exist()) {
            appendNewLineIfAll(logDetail, builder).append(toString(headers));
        }
    } else if (logDetail == COOKIES) {
        final Cookies cookies = responseOptions.detailedCookies();
        if (cookies.exist()) {
            appendNewLineIfAll(logDetail, builder).append(cookies.toString());
        }
    }
    if (logDetail == ALL || logDetail == BODY) {
        String responseBodyToAppend;
        if (shouldPrettyPrint) {
            responseBodyToAppend = new Prettifier().getPrettifiedBodyIfPossible(responseOptions, responseBody);
        } else {
            responseBodyToAppend = responseBody.asString();
        }
        if (logDetail == ALL && !isBlank(responseBodyToAppend)) {
            builder.append("\n\n");
        }
        builder.append(responseBodyToAppend);
    }
    String response = builder.toString();
    stream.println(response);
    return response;
}
Also used : Headers(io.restassured.http.Headers) Cookies(io.restassured.http.Cookies) Prettifier(io.restassured.internal.support.Prettifier)

Aggregations

Prettifier (io.restassured.internal.support.Prettifier)2 Cookies (io.restassured.http.Cookies)1 Headers (io.restassured.http.Headers)1 Parser (io.restassured.parsing.Parser)1 MultiPartSpecification (io.restassured.specification.MultiPartSpecification)1 InputStream (java.io.InputStream)1