Search in sources :

Example 1 with DryRun

use of com.endava.cats.annotations.DryRun in project cats by Endava.

the class ServiceCaller method call.

/**
 * When in dryRun mode ServiceCaller won't do any actual calls.
 *
 * @param data the current context data
 * @return the result of service invocation
 */
@DryRun
public CatsResponse call(ServiceData data) {
    LOGGER.note("Proxy configuration to be used: {}", authArguments.getProxy());
    rateLimiter.acquire();
    String processedPayload = this.replacePayloadWithRefData(data);
    List<CatsRequest.Header> headers = this.buildHeaders(data);
    CatsRequest catsRequest = new CatsRequest();
    catsRequest.setHeaders(headers);
    catsRequest.setPayload(processedPayload);
    catsRequest.setHttpMethod(data.getHttpMethod().name());
    try {
        String url = this.getPathWithRefDataReplacedForHttpEntityRequests(data, apiArguments.getServer() + data.getRelativePath());
        if (!HttpMethod.requiresBody(data.getHttpMethod())) {
            url = this.getPathWithRefDataReplacedForNonHttpEntityRequests(data, apiArguments.getServer() + data.getRelativePath());
            url = this.addUriParams(processedPayload, data, url);
        }
        catsRequest.setUrl(url);
        LOGGER.note("Final list of request headers: {}", headers);
        LOGGER.note("Final payload: {}", processedPayload);
        CatsResponse response = this.callService(catsRequest, data.getFuzzedFields());
        this.recordRequestAndResponse(catsRequest, response, data);
        return response;
    } catch (IOException e) {
        this.recordRequestAndResponse(catsRequest, CatsResponse.empty(), data);
        throw new CatsIOException(e);
    }
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) CatsHeader(com.endava.cats.model.CatsHeader) IOException(java.io.IOException) CatsRequest(com.endava.cats.model.CatsRequest) DryRun(com.endava.cats.annotations.DryRun)

Aggregations

DryRun (com.endava.cats.annotations.DryRun)1 CatsHeader (com.endava.cats.model.CatsHeader)1 CatsRequest (com.endava.cats.model.CatsRequest)1 CatsResponse (com.endava.cats.model.CatsResponse)1 IOException (java.io.IOException)1