com.epam.jdi.http.cucumber.Utils Maven / Gradle / Ivy
package com.epam.jdi.http.cucumber;
import com.epam.http.annotations.ServiceDomain;
import com.epam.http.performance.PerformanceResult;
import com.epam.http.requests.MethodData;
import com.epam.http.requests.RestMethod;
import com.epam.http.requests.RestMethodTypes;
import com.epam.http.response.RestResponse;
import io.restassured.http.ContentType;
import java.util.HashMap;
import static com.epam.http.ExceptionHandler.exception;
import static com.epam.http.requests.RestMethodTypes.GET;
public class Utils {
public static final ThreadLocal service = new ThreadLocal<>();
public static final ThreadLocal domainUrl = new ThreadLocal<>();
public static final ThreadLocal performanceResult = new ThreadLocal<>();
public static final ThreadLocal restResponse = new ThreadLocal<>();
public static final ThreadLocal requestContentType = new ThreadLocal<>();
public static final ThreadLocal> preparedHeader = new ThreadLocal<>();
public static RestMethod getRestMethod(String restMethodType) {
MethodData mtData = getMethodData(restMethodType);
String url = getUrlFromDomain(domainUrl.get(), mtData.getUrl(), restMethodType);
return new RestMethod(mtData.getType(), url);
}
private static MethodData getMethodData(String type) {
for (RestMethodTypes methodType : RestMethodTypes.values()) {
if(type.equalsIgnoreCase(methodType.name()))
return new MethodData(type.toLowerCase(), methodType);
}
return new MethodData(null, GET);
}
private static String getUrlFromDomain(String domain, String uri, String methodName) {
if (uri == null)
return null;
if (uri.contains("://"))
return uri;
if (domain == null)
throw exception(
"Can't instantiate method '%s' for domain '%s'. " +
"Domain undefined and method url not contains '://'",
methodName, domain);
return domain.replaceAll("/*$", "") + "/" + uri.replaceAll("^/*", "");
}
public static String getDomain(Class c) {
return c.isAnnotationPresent(ServiceDomain.class)
? c.getAnnotation(ServiceDomain.class).value()
: null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy