All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codacy.scoobydoo.RestAssuredWrapperSettings Maven / Gradle / Ivy

There is a newer version: 3.30.0
Show newest version
package com.codacy.scoobydoo;

import com.codacy.scoobydoo.RestAssuredWrapper.AuthType;
import io.restassured.http.ContentType;
import io.restassured.http.Header;
import io.restassured.http.Method;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RestAssuredWrapperSettings {

    private final String accessToken;
    private final String apiToken;
    private final AuthType authType;
    private final Object body;
    private final ContentType contentType;
    private final String endpoint;
    private final List
headerList; private Method method; private final Map queryParameters; private final String requestName; private final boolean shouldLogAll; private final Map userCredentials; public RestAssuredWrapperSettings(Builder builder) { this.accessToken = builder.accessToken; this.apiToken = builder.apiToken; this.authType = builder.authType; this.body = builder.body; this.contentType = builder.contentType; this.endpoint = builder.endpoint; this.headerList = builder.headerList; this.method = builder.method; this.queryParameters = builder.queryParameters; this.requestName = builder.requestName; this.shouldLogAll = builder.shouldLogAll; this.userCredentials = builder.userCredentials; } public RestAssuredWrapperSettings(Method method, Builder builder) { this(builder); this.method = method; } public static class Builder { private String accessToken; private String apiToken; private AuthType authType; private Object body; private ContentType contentType; private String endpoint; private List
headerList; private Method method; private final Map queryParameters; private String requestName; private boolean shouldLogAll = false; private Map userCredentials; public Builder() { headerList = new ArrayList<>(); queryParameters = new HashMap<>(); } public Builder withApiToken(String apiToken) { this.authType = AuthType.API_TOKEN; this.apiToken = apiToken; return this; } public Builder withAuthenticationBasic(Map userCredentials) { this.authType = AuthType.PREEMPTIVE_BASIC; this.userCredentials = userCredentials; return this; } public Builder withAuthenticationToken(String accessToken) { this.authType = AuthType.ACCESS_TOKEN; this.accessToken = accessToken; return this; } public Builder withBody(Object body) { this.body = body; return this; } public Builder withBody(ContentType contentType, String body) { this.body = body; this.contentType = contentType; return this; } public Builder toEndpoint(String endpoint) { this.endpoint = endpoint; return this; } public Builder addHeader(Header header) { this.headerList.add(header); return this; } public Builder addHeaders(Header... headers) { this.headerList.addAll(Arrays.asList(headers)); return this; } public Builder addCookie(String name, String value) { addCookie(name + "=" + value); return this; } public Builder addCookie(String cookie) { boolean foundCookieHeader = false; for (int i = 0; !foundCookieHeader && i < this.headerList.size(); i++) { Header header = this.headerList.get(i); String headerName = header.getName(); if (headerName.equalsIgnoreCase("cookie")) { String existingCookieValue = header.getValue(); this.headerList.set(i, new Header(headerName, existingCookieValue + ";" + cookie)); foundCookieHeader = true; } } if (!foundCookieHeader) { addHeader(new Header("Cookie", cookie)); } return this; } public Builder forAction(Method method) { this.method = method; return this; } public Builder querying(Map queryParameters) { if (queryParameters != null && !queryParameters.isEmpty()) { this.queryParameters.putAll(queryParameters); } return this; } public Builder querying(String key, String value) { this.queryParameters.put(key, value); return this; } public Builder shouldLogAll() { this.shouldLogAll = true; return this; } public Builder withName(String requestName) { this.requestName = requestName; return this; } public RestAssuredWrapperSettings build() { return new RestAssuredWrapperSettings(this); } } public String getAccessToken() { return accessToken; } public String getApiToken() { return apiToken; } public AuthType getAuthType() { return authType; } public Object getBody() { return body; } public ContentType getContentType() { return contentType; } public String getEndpoint() { return endpoint; } public List
getHeaders() { return headerList; } public Method getMethod() { return method; } public Map getQueryParameters() { return queryParameters; } public String getRequestName() { return requestName; } public Map getUserCredentials() { return userCredentials; } public boolean shouldLogAll() { return shouldLogAll; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy