Search in sources :

Example 1 with RequestSpecificationImpl

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

the class RequestSpecBuilder method addRequestSpecification.

/**
 * Merge this builder with settings from another specification. Note that the supplied specification
 * can overwrite data in the current specification. The following settings are overwritten:
 * <ul>
 * <li>Port</li>
 * <li>Authentication scheme</
 * <li>Content type</li>
 * <li>Request body</li>
 * </ul>
 * The following settings are merged:
 * <ul>
 * <li>Parameters</li>
 * <li>Cookies</li>
 * <li>Headers</li>
 * <li>Filters</li>
 * </ul>
 *
 * @param specification The specification to add
 * @return The request specification builder
 */
public RequestSpecBuilder addRequestSpecification(RequestSpecification specification) {
    if (!(specification instanceof RequestSpecificationImpl)) {
        throw new IllegalArgumentException("Specification must be of type " + RequestSpecificationImpl.class.getClass() + ".");
    }
    RequestSpecificationImpl rs = (RequestSpecificationImpl) specification;
    SpecificationMerger.merge((RequestSpecificationImpl) spec, rs);
    return this;
}
Also used : RequestSpecificationImpl(io.restassured.internal.RequestSpecificationImpl)

Example 2 with RequestSpecificationImpl

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

the class MockMvcRequestSenderImpl method logRequestIfApplicable.

private void logRequestIfApplicable(HttpMethod method, String uri, String originalPath, Object[] unnamedPathParams) {
    if (requestLoggingFilter == null) {
        return;
    }
    final RequestSpecificationImpl reqSpec = new RequestSpecificationImpl("http://localhost", RestAssured.UNDEFINED_PORT, "", new NoAuthScheme(), Collections.<Filter>emptyList(), null, true, ConfigConverter.convertToRestAssuredConfig(config), logRepository, null);
    reqSpec.setMethod(method.toString());
    reqSpec.path(uri);
    reqSpec.buildUnnamedPathParameterTuples(unnamedPathParams);
    if (params != null) {
        new ParamLogger(params) {

            protected void logParam(String paramName, Object paramValue) {
                reqSpec.param(paramName, paramValue);
            }
        }.logParams();
    }
    if (queryParams != null) {
        new ParamLogger(queryParams) {

            protected void logParam(String paramName, Object paramValue) {
                reqSpec.queryParam(paramName, paramValue);
            }
        }.logParams();
    }
    if (formParams != null) {
        new ParamLogger(formParams) {

            protected void logParam(String paramName, Object paramValue) {
                reqSpec.formParam(paramName, paramValue);
            }
        }.logParams();
    }
    if (headers != null) {
        for (Header header : headers) {
            reqSpec.header(header);
        }
    }
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            reqSpec.cookie(cookie);
        }
    }
    if (requestBody != null) {
        if (requestBody instanceof byte[]) {
            reqSpec.body((byte[]) requestBody);
        } else if (requestBody instanceof File) {
            String contentType = findContentType();
            String charset = null;
            if (StringUtils.isNotBlank(contentType)) {
                charset = CharsetExtractor.getCharsetFromContentType(contentType);
            }
            if (charset == null) {
                charset = Charset.defaultCharset().toString();
            }
            String string = fileToString((File) requestBody, charset);
            reqSpec.body(string);
        } else {
            reqSpec.body(requestBody);
        }
    }
    if (multiParts != null) {
        for (MockMvcMultiPart multiPart : multiParts) {
            reqSpec.multiPart(new MultiPartSpecBuilder(multiPart.getContent()).controlName(multiPart.getControlName()).fileName(multiPart.getFileName()).mimeType(multiPart.getMimeType()).build());
        }
    }
    String uriPath = PathSupport.getPath(uri);
    String originalUriPath = PathSupport.getPath(originalPath);
    requestLoggingFilter.filter(reqSpec, null, new FilterContextImpl(uri, originalUriPath, uriPath, uri, uri, new Object[0], method.toString(), null, Collections.<Filter>emptyList().iterator(), new HashMap<String, Object>()));
}
Also used : FilterContextImpl(io.restassured.internal.filter.FilterContextImpl) NoAuthScheme(io.restassured.authentication.NoAuthScheme) RequestSpecificationImpl(io.restassured.internal.RequestSpecificationImpl) MultiPartSpecBuilder(io.restassured.builder.MultiPartSpecBuilder) MockMultipartFile(org.springframework.mock.web.MockMultipartFile)

Aggregations

RequestSpecificationImpl (io.restassured.internal.RequestSpecificationImpl)2 NoAuthScheme (io.restassured.authentication.NoAuthScheme)1 MultiPartSpecBuilder (io.restassured.builder.MultiPartSpecBuilder)1 FilterContextImpl (io.restassured.internal.filter.FilterContextImpl)1 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)1