use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project cats by Endava.
the class ServiceCaller method initHttpClient.
@PostConstruct
public void initHttpClient() {
try {
final TrustManager[] trustAllCerts = this.buildTrustAllManager();
final SSLSocketFactory sslSocketFactory = this.buildSslSocketFactory(trustAllCerts);
okHttpClient = new OkHttpClient.Builder().proxy(authArguments.getProxy()).connectTimeout(apiArguments.getConnectionTimeout(), TimeUnit.SECONDS).readTimeout(apiArguments.getReadTimeout(), TimeUnit.SECONDS).writeTimeout(apiArguments.getWriteTimeout(), TimeUnit.SECONDS).connectionPool(new ConnectionPool(10, 15, TimeUnit.MINUTES)).sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]).hostnameVerifier((hostname, session) -> true).build();
} catch (GeneralSecurityException | IOException e) {
LOGGER.warning("Failed to configure HTTP CLIENT", e);
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project xray-maven-plugin by Xray-App.
the class XrayFeaturesExporter method submitStandardServerDC.
public String submitStandardServerDC(String outputPath) throws Exception {
OkHttpClient client = CommonUtils.getHttpClient(this.useInternalTestProxy, this.ignoreSslErrors, this.timeout);
String credentials;
if (jiraPersonalAccessToken != null) {
credentials = "Bearer " + jiraPersonalAccessToken;
} else {
credentials = Credentials.basic(jiraUsername, jiraPassword);
}
String endpointUrl = jiraBaseUrl + "/rest/raven/2.0/export/test";
Request request;
Response response = null;
HttpUrl url = HttpUrl.get(endpointUrl);
HttpUrl.Builder builder = url.newBuilder();
builder.addQueryParameter("fz", "true");
if (issueKeys != null) {
builder.addQueryParameter("keys", this.issueKeys);
}
if (filterId != null) {
builder.addQueryParameter("filter", this.filterId);
}
request = new Request.Builder().url(builder.build()).get().addHeader("Authorization", credentials).build();
try {
response = client.newCall(request).execute();
// String responseBody = response.body().string();
if (response.isSuccessful()) {
unzipContentsToFolder(response.body().byteStream(), outputPath);
return ("ok");
} else {
throw new IOException("Unexpected HTTP code " + response);
}
} catch (IOException e) {
e.printStackTrace();
throw (e);
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project xray-maven-plugin by Xray-App.
the class XrayResultsImporter method submitStandardCloud.
public String submitStandardCloud(String format, String reportFile) throws Exception {
OkHttpClient client = CommonUtils.getHttpClient(useInternalTestProxy, ignoreSslErrors, this.timeout);
String authenticationPayload = "{ \"client_id\": \"" + clientId + "\", \"client_secret\": \"" + clientSecret + "\" }";
RequestBody body = RequestBody.create(authenticationPayload, MEDIA_TYPE_JSON);
Request request = new Request.Builder().url(xrayCloudAuthenticateUrl).post(body).build();
Response response = null;
String authToken = null;
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
authToken = responseBody.replace("\"", "");
} else {
throw new IOException("failed to authenticate " + response);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
String credentials = "Bearer " + authToken;
String[] supportedFormats = new String[] { XRAY_FORMAT, JUNIT_FORMAT, TESTNG_FORMAT, ROBOT_FORMAT, NUNIT_FORMAT, XUNIT_FORMAT, CUCUMBER_FORMAT };
if (!Arrays.asList(supportedFormats).contains(format)) {
throw new Exception("unsupported report format: " + format);
}
MediaType mediaType;
String[] xmlBasedFormats = new String[] { JUNIT_FORMAT, TESTNG_FORMAT, ROBOT_FORMAT, NUNIT_FORMAT, XUNIT_FORMAT };
if (Arrays.asList(xmlBasedFormats).contains(format)) {
mediaType = MEDIA_TYPE_XML;
} else {
mediaType = MEDIA_TYPE_JSON;
}
String endpointUrl;
if (XRAY_FORMAT.equals(format)) {
endpointUrl = xrayCloudApiBaseUrl + "/import/execution";
} else {
endpointUrl = xrayCloudApiBaseUrl + "/import/execution/" + format;
}
RequestBody requestBody = null;
try {
String reportContent = new String(Files.readAllBytes(Paths.get(reportFile)));
requestBody = RequestBody.create(reportContent, mediaType);
} catch (Exception e1) {
e1.printStackTrace();
throw e1;
}
HttpUrl url = HttpUrl.get(endpointUrl);
HttpUrl.Builder builder = url.newBuilder();
if (projectKey != null) {
builder.addQueryParameter("projectKey", this.projectKey);
}
if (fixVersion != null) {
builder.addQueryParameter("fixVersion", this.fixVersion);
}
if (revision != null) {
builder.addQueryParameter("revision", this.revision);
}
if (testPlanKey != null) {
builder.addQueryParameter("testPlanKey", this.testPlanKey);
}
if (testExecKey != null) {
builder.addQueryParameter("testExecKey", this.testExecKey);
}
if (testEnvironment != null) {
builder.addQueryParameter("testEnvironment", this.testEnvironment);
}
request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build();
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
JSONObject responseObj = new JSONObject(responseBody);
// System.out.println("Test Execution: "+((JSONObject)(responseObj.get("testExecIssue"))).get("key"));
return (responseBody);
} else {
// System.err.println(responseBody);
throw new IOException("Unexpected HTTP code " + response);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project xray-maven-plugin by Xray-App.
the class XrayResultsImporter method submitMultipartCloud.
public String submitMultipartCloud(String format, String reportFile, JSONObject testExecInfo, JSONObject testInfo) throws Exception {
OkHttpClient client = CommonUtils.getHttpClient(this.useInternalTestProxy, this.ignoreSslErrors, this.timeout);
String authenticationPayload = "{ \"client_id\": \"" + clientId + "\", \"client_secret\": \"" + clientSecret + "\" }";
RequestBody body = RequestBody.create(authenticationPayload, MEDIA_TYPE_JSON);
Request request = new Request.Builder().url(xrayCloudAuthenticateUrl).post(body).build();
Response response = null;
String authToken = null;
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
authToken = responseBody.replace("\"", "");
} else {
throw new IOException("failed to authenticate " + response);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
String credentials = "Bearer " + authToken;
String[] supportedFormats = new String[] { XRAY_FORMAT, JUNIT_FORMAT, TESTNG_FORMAT, ROBOT_FORMAT, NUNIT_FORMAT, XUNIT_FORMAT, CUCUMBER_FORMAT };
if (!Arrays.asList(supportedFormats).contains(format)) {
throw new Exception("unsupported report format: " + format);
}
MediaType mediaType;
String[] xmlBasedFormats = new String[] { JUNIT_FORMAT, TESTNG_FORMAT, ROBOT_FORMAT, NUNIT_FORMAT, XUNIT_FORMAT };
if (Arrays.asList(xmlBasedFormats).contains(format)) {
mediaType = MEDIA_TYPE_XML;
} else {
mediaType = MEDIA_TYPE_JSON;
}
String endpointUrl;
if ("xray".equals(format)) {
endpointUrl = xrayCloudApiBaseUrl + "/import/execution/multipart";
} else {
endpointUrl = xrayCloudApiBaseUrl + "/import/execution/" + format + "/multipart";
}
HttpUrl url = HttpUrl.get(endpointUrl);
HttpUrl.Builder builder = url.newBuilder();
MultipartBody requestBody = null;
try {
requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("results", reportFile, RequestBody.create(new File(reportFile), mediaType)).addFormDataPart("info", "info.json", RequestBody.create(testExecInfo.toString(), MEDIA_TYPE_JSON)).build();
} catch (Exception e1) {
e1.printStackTrace();
throw e1;
}
request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build();
response = null;
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
JSONObject responseObj = new JSONObject(responseBody);
// System.out.println("Test Execution: "+responseObj.get("key"));
return responseBody;
} else {
// System.err.println(responseBody);
throw new IOException("Unexpected HTTP code " + response);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project xray-maven-plugin by Xray-App.
the class XrayResultsImporter method submitStandardServerDC.
public String submitStandardServerDC(String format, String reportFile) throws Exception {
OkHttpClient client = CommonUtils.getHttpClient(this.useInternalTestProxy, this.ignoreSslErrors, this.timeout);
String credentials;
if (jiraPersonalAccessToken != null) {
credentials = "Bearer " + jiraPersonalAccessToken;
} else {
credentials = Credentials.basic(jiraUsername, jiraPassword);
}
String[] supportedFormats = new String[] { XRAY_FORMAT, JUNIT_FORMAT, TESTNG_FORMAT, ROBOT_FORMAT, NUNIT_FORMAT, XUNIT_FORMAT, CUCUMBER_FORMAT, BEHAVE_FORMAT };
if (!Arrays.asList(supportedFormats).contains(format)) {
throw new Exception("unsupported report format: " + format);
}
MediaType mediaType;
String[] xmlBasedFormats = new String[] { JUNIT_FORMAT, TESTNG_FORMAT, ROBOT_FORMAT, NUNIT_FORMAT, XUNIT_FORMAT };
if (Arrays.asList(xmlBasedFormats).contains(format)) {
mediaType = MEDIA_TYPE_XML;
} else {
mediaType = MEDIA_TYPE_JSON;
}
String endpointUrl;
if (XRAY_FORMAT.equals(format)) {
endpointUrl = jiraBaseUrl + "/rest/raven/2.0/import/execution";
} else {
endpointUrl = jiraBaseUrl + "/rest/raven/2.0/import/execution/" + format;
}
Request request;
HttpUrl url = HttpUrl.get(endpointUrl);
HttpUrl.Builder builder = url.newBuilder();
// for cucumber and behave reports send the report directly on the body
try {
if (XRAY_FORMAT.equals(format) || CUCUMBER_FORMAT.equals(format) || BEHAVE_FORMAT.equals(format)) {
String reportContent = new String(Files.readAllBytes(Paths.get(reportFile)));
RequestBody requestBody = RequestBody.create(reportContent, mediaType);
request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build();
} else {
MultipartBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("file", reportFile, RequestBody.create(new File(reportFile), mediaType)).build();
// for cucumber and behave formats, these URL parameters are not yet available
if (projectKey != null) {
builder.addQueryParameter("projectKey", this.projectKey);
}
if (fixVersion != null) {
builder.addQueryParameter("fixVersion", this.fixVersion);
}
if (revision != null) {
builder.addQueryParameter("revision", this.revision);
}
if (testPlanKey != null) {
builder.addQueryParameter("testPlanKey", this.testPlanKey);
}
if (testExecKey != null) {
builder.addQueryParameter("testExecKey", this.testExecKey);
}
if (testEnvironment != null) {
builder.addQueryParameter("testEnvironment", this.testEnvironment);
}
request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build();
}
} catch (Exception e1) {
e1.printStackTrace();
throw e1;
}
Response response = null;
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
JSONObject responseObj = new JSONObject(responseBody);
// System.out.println("Test Execution: "+((JSONObject)(responseObj.get("testExecIssue"))).get("key"));
return (responseBody);
} else {
// System.err.println(responseBody);
throw new IOException("Unexpected HTTP code " + response);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
Aggregations