Search in sources :

Example 1 with SubmittedTask

use of com.qasymphony.ci.plugin.model.qtest.SubmittedTask 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;
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) ResponseEntity(com.qasymphony.ci.plugin.utils.ResponseEntity) AutomationTestResponse(com.qasymphony.ci.plugin.model.AutomationTestResponse) SubmittedTask(com.qasymphony.ci.plugin.model.qtest.SubmittedTask)

Aggregations

SubmittedException (com.qasymphony.ci.plugin.exception.SubmittedException)1 AutomationTestResponse (com.qasymphony.ci.plugin.model.AutomationTestResponse)1 SubmittedTask (com.qasymphony.ci.plugin.model.qtest.SubmittedTask)1 ResponseEntity (com.qasymphony.ci.plugin.utils.ResponseEntity)1