use of com.qasymphony.ci.plugin.model.AutomationTestResponse in project jenkin-qtest-plugin by QASymphony.
the class JunitQtestSubmitterImpl method getSubmitLogResponse.
private AutomationTestResponse getSubmitLogResponse(JunitSubmitterRequest request, SubmittedTask task) throws InterruptedException, SubmittedException {
if (task == null || task.getId() <= 0)
return null;
AutomationTestResponse response = null;
PrintStream logger = request.getListener().getLogger();
Map<String, String> headers = OauthProvider.buildHeaders(request.getqTestURL(), request.getApiKey(), null);
Boolean mustRetry = true;
String previousState = "";
while (mustRetry) {
response = getTaskResponse(request, task, headers);
if (null == response) {
mustRetry = false;
} else {
if (!previousState.equalsIgnoreCase(response.getState())) {
LoggerUtils.formatInfo(logger, "%s: Submission status: %s", JsonUtils.getCurrentDateString(), response.getState());
previousState = StringUtils.isEmpty(response.getState()) ? "" : response.getState();
}
if (response.hasError()) {
// if has error while get task status
LoggerUtils.formatError(logger, " %s", ConfigService.getErrorMessage(response.getContent()));
}
if (Constants.LIST_FINISHED_STATE.contains(response.getState())) {
// if finished, we do not retry more
mustRetry = false;
} else {
// sleep in interval to get status of task
Thread.sleep(Constants.RETRY_INTERVAL);
}
}
}
return response;
}
use of com.qasymphony.ci.plugin.model.AutomationTestResponse in project jenkin-qtest-plugin by QASymphony.
the class JunitQtestSubmitterImpl method getTaskResponse.
private AutomationTestResponse getTaskResponse(JunitSubmitterRequest request, SubmittedTask task, Map<String, String> headers) throws SubmittedException {
ResponseEntity responseEntity;
try {
// get task status
responseEntity = AutomationTestService.getTaskStatus(request.getqTestURL(), task.getId(), headers);
} catch (ClientRequestException e) {
LoggerUtils.formatError(request.getListener().getLogger(), "Cannot get response of taskId: %s, error: %s", task.getId(), e.getMessage());
throw new SubmittedException(e.getMessage(), -1);
}
LOG.info(String.format("project:%s, status:%s, body:%s", request.getJenkinsProjectName(), null == responseEntity ? -1 : responseEntity.getStatusCode(), null == responseEntity ? "" : responseEntity.getBody()));
if ((null == responseEntity) || (responseEntity.getStatusCode() != HttpStatus.SC_OK)) {
throw new SubmittedException(ConfigService.getErrorMessage(responseEntity.getBody()), responseEntity.getStatusCode());
}
return new AutomationTestResponse(responseEntity.getBody());
}
use of com.qasymphony.ci.plugin.model.AutomationTestResponse in project jenkin-qtest-plugin by QASymphony.
the class JunitQtestSubmitterImpl method submit.
@Override
public JunitSubmitterResult submit(JunitSubmitterRequest request) throws Exception {
String accessToken = OauthProvider.getAccessToken(request.getqTestURL(), request.getApiKey());
if (StringUtils.isEmpty(accessToken))
throw new SubmittedException(String.format("Cannot get access token from: %s, API key is: %s", request.getqTestURL(), request.getApiKey()));
ResponseEntity responseEntity = AutomationTestService.push(request.getBuildNumber(), request.getBuildPath(), request.getTestResults(), request, accessToken);
AutomationTestResponse response = null;
if (responseEntity.getStatusCode() == HttpStatus.SC_CREATED) {
// receive task response
SubmittedTask task = JsonUtils.fromJson(responseEntity.getBody(), SubmittedTask.class);
if (task == null || task.getId() <= 0)
throw new SubmittedException(responseEntity.getBody(), responseEntity.getStatusCode());
response = getSubmitLogResponse(request, task);
} else {
// if cannot passed validation from qTest
throw new SubmittedException(ConfigService.getErrorMessage(responseEntity.getBody()), responseEntity.getStatusCode());
}
Boolean nullResponse = (null == response);
Boolean isSubmitSuccess = ((!nullResponse && response.getTestSuiteId() > 0) ? true : false);
JunitSubmitterResult result = new JunitSubmitterResult().setNumberOfTestResult(request.getTestResults().size()).setTestSuiteId(nullResponse ? null : response.getTestSuiteId()).setTestSuiteName(nullResponse ? "" : response.getTestSuiteName()).setNumberOfTestLog(nullResponse ? 0 : response.getTotalTestLogs()).setSubmittedStatus(isSubmitSuccess ? JunitSubmitterResult.STATUS_SUCCESS : JunitSubmitterResult.STATUS_FAILED);
return result;
}
Aggregations