Search in sources :

Example 1 with AutomationTestResultWrapper

use of com.qasymphony.ci.plugin.model.AutomationTestResultWrapper in project jenkin-qtest-plugin by QASymphony.

the class AutomationTestService method push.

public static ResponseEntity push(String buildNumber, String buildPath, List<AutomationTestResult> testResults, JunitSubmitterRequest request, String accessToken) throws SubmittedException {
    if (testResults.size() <= 0)
        return null;
    String url;
    AutomationTestResultWrapper wrapper = new AutomationTestResultWrapper();
    wrapper.setBuildNumber(buildNumber);
    wrapper.setBuildPath(buildPath);
    wrapper.setSkipCreatingAutomationModule(true);
    Long moduleId = request.getModuleID();
    if (null != moduleId && 0 < moduleId) {
        wrapper.setParent_module(moduleId);
    }
    if (request.getSubmitToExistingContainer()) {
        String fullURL = request.getJenkinsServerURL();
        if (!fullURL.endsWith("/")) {
            fullURL += "/";
        }
        fullURL += buildPath;
        for (int i = 0; i < testResults.size(); i++) {
            AutomationTestResult result = testResults.get(i);
            result.setBuildNumber(buildNumber);
            result.setBuildURL(fullURL);
        }
        url = String.format(AUTO_TEST_LOG_ENDPOINT_V3_1, request.getqTestURL(), request.getProjectID(), 0);
        Long testSuiteId = prepareTestSuite(request, accessToken);
        if (-1 == testSuiteId) {
            throw new SubmittedException("Could not find or create test suite to submit test logs", -1);
        }
        wrapper.setTest_suite(testSuiteId);
        wrapper.setTest_logs(testResults);
    } else {
        /**
         * using {@link String#format(Locale, String, Object...)}  instead {@link java.text.MessageFormat#format(String, Object...)}
         * to avoid unexpected formatted link. see: QTE-2798 for more details.
         */
        url = String.format(AUTO_TEST_LOG_ENDPOINT_V3, request.getqTestURL(), request.getProjectID(), 0, request.getConfigurationID());
        wrapper.setTestResults(testResults);
    }
    Map<String, String> headers = OauthProvider.buildHeaders(accessToken, null);
    ResponseEntity responseEntity = null;
    try {
        String data = JsonUtils.toJson(wrapper);
        responseEntity = HttpClientUtils.post(url, headers, data);
    } catch (ClientRequestException e) {
        throw new SubmittedException(e.getMessage(), null == responseEntity ? 0 : responseEntity.getStatusCode());
    }
    return responseEntity;
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) AutomationTestResultWrapper(com.qasymphony.ci.plugin.model.AutomationTestResultWrapper) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) ResponseEntity(com.qasymphony.ci.plugin.utils.ResponseEntity) ClientRequestException(com.qasymphony.ci.plugin.utils.ClientRequestException)

Aggregations

SubmittedException (com.qasymphony.ci.plugin.exception.SubmittedException)1 AutomationTestResult (com.qasymphony.ci.plugin.model.AutomationTestResult)1 AutomationTestResultWrapper (com.qasymphony.ci.plugin.model.AutomationTestResultWrapper)1 ClientRequestException (com.qasymphony.ci.plugin.utils.ClientRequestException)1 ResponseEntity (com.qasymphony.ci.plugin.utils.ResponseEntity)1