Search in sources :

Example 6 with AutomationTestResult

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

the class CommonParsingUtils method useClassNameAsTestCase.

/**
 * Class name as a testCase in qTest
 *
 * @param request     parse request
 * @param testResults testResults
 * @param startTime   start build time
 * @return
 * @throws Exception
 */
private static List<AutomationTestResult> useClassNameAsTestCase(ParseRequest request, List<TestResult> testResults, Date startTime) throws Exception {
    Map<String, AutomationTestResult> map = new HashMap<>();
    int currentTestLogOrder = 0;
    for (TestResult testResult : testResults) {
        for (SuiteResult suite : testResult.getSuites()) {
            if (suite.getCases() == null) {
                continue;
            }
            Date startDate = JsonUtils.parseTimestamp(suite.getTimestamp());
            startDate = startDate == null ? startTime : startDate;
            for (CaseResult caseResult : suite.getCases()) {
                AutomationTestResult testLog = null;
                if (map.containsKey(caseResult.getClassName())) {
                    testLog = map.get(caseResult.getClassName());
                } else {
                    testLog = new AutomationTestResult();
                    testLog.setOrder(currentTestLogOrder++);
                    testLog.setAutomationContent(caseResult.getClassName());
                    testLog.setExecutedStartDate(startDate);
                    testLog.setExecutedEndDate(computeEndTime(startDate, suite.getDuration()));
                    map.put(caseResult.getClassName(), testLog);
                }
                testLog.addTestStepLog(new AutomationTestStepLog(caseResult), request.getOverwriteExistingTestSteps());
                if (caseResult.isFailed()) {
                    testLog.addAttachment(new AutomationAttachment(caseResult));
                }
            }
        }
    }
    map = processAttachment(map);
    return new ArrayList<>(map.values());
}
Also used : AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) AutomationAttachment(com.qasymphony.ci.plugin.model.AutomationAttachment) AutomationTestStepLog(com.qasymphony.ci.plugin.model.AutomationTestStepLog) CaseResult(hudson.tasks.junit.CaseResult) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) SuiteResult(hudson.tasks.junit.SuiteResult)

Example 7 with AutomationTestResult

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

the class PublishResultParser method parse.

@Override
public List<AutomationTestResult> parse(ParseRequest request) throws Exception {
    Run<?, ?> build = request.getBuild();
    TestResultAction resultAction = build.getAction(TestResultAction.class);
    List<TestResult> testResults = new ArrayList<>();
    if (resultAction != null) {
        testResults.add(resultAction.getResult());
    } else {
        AggregatedTestResultAction aggregatedTestResultAction = build.getAction(AggregatedTestResultAction.class);
        if (aggregatedTestResultAction != null) {
            List<ChildReport> childReports = aggregatedTestResultAction.getResult();
            if (childReports != null) {
                for (ChildReport childReport : childReports) {
                    if (childReport.result instanceof TestResult) {
                        testResults.add((TestResult) childReport.result);
                    }
                }
            }
        } else {
            LoggerUtils.formatWarn(request.getListener().getLogger(), "No testResult action was added to project.");
        }
    }
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTimeInMillis(build.getStartTimeInMillis());
    return CommonParsingUtils.toAutomationTestResults(request, testResults, gregorianCalendar.getTime());
}
Also used : AggregatedTestResultAction(hudson.tasks.test.AggregatedTestResultAction) ChildReport(hudson.tasks.test.AggregatedTestResultAction.ChildReport) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) TestResultAction(hudson.tasks.junit.TestResultAction) AggregatedTestResultAction(hudson.tasks.test.AggregatedTestResultAction)

Example 8 with AutomationTestResult

use of com.qasymphony.ci.plugin.model.AutomationTestResult 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)

Example 9 with AutomationTestResult

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

the class PushingResultAction method perform.

@SuppressWarnings("rawtypes")
@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    PrintStream logger = listener.getLogger();
    JunitSubmitterRequest submitterRequest = configuration.createJunitSubmitRequest();
    if (null == submitterRequest) {
        LoggerUtils.formatError(logger, "Could not create JUnitSumitterRequest");
        return true;
    }
    submitterRequest.setBuildNumber(build.getNumber() + "").setBuildPath(build.getUrl()).setListener(listener);
    JunitSubmitter junitSubmitter = new JunitQtestSubmitterImpl();
    String buildResult = build.getResult() + "";
    if (Result.ABORTED.equals(build.getResult())) {
        LoggerUtils.formatWarn(logger, "Abort build action.");
        storeWhenNotSuccess(submitterRequest, junitSubmitter, build, buildResult, logger, JunitSubmitterResult.STATUS_CANCELED);
        return true;
    }
    showInfo(logger);
    if (!validateConfig(configuration)) {
        LoggerUtils.formatWarn(logger, "Invalid configuration to qTest, reject submit test results.");
        storeWhenNotSuccess(submitterRequest, junitSubmitter, build, buildResult, logger, JunitSubmitterResult.STATUS_FAILED);
        return true;
    }
    if (null == checkProjectNameChanged(build, listener)) {
        storeWhenNotSuccess(submitterRequest, junitSubmitter, build, buildResult, logger, JunitSubmitterResult.STATUS_CANCELED);
        return true;
    }
    List<AutomationTestResult> automationTestResults = readTestResults(build, launcher, listener, logger);
    if (automationTestResults.isEmpty()) {
        LoggerUtils.formatWarn(logger, "No JUnit test result found.");
        storeWhenNotSuccess(submitterRequest, junitSubmitter, build, buildResult, logger, JunitSubmitterResult.STATUS_SKIPPED);
        LoggerUtils.formatHR(logger);
        return true;
    }
    submitterRequest.setTestResults(automationTestResults);
    JunitSubmitterResult result = submitTestResult(submitterRequest, build, listener, junitSubmitter, automationTestResults);
    if (null == result) {
        // if have no test result, we do not break build flow
        return true;
    }
    saveConfiguration(build, result, logger);
    storeResult(submitterRequest, build, buildResult, junitSubmitter, result, logger);
    LoggerUtils.formatHR(logger);
    return true;
}
Also used : PrintStream(java.io.PrintStream) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) JunitSubmitterResult(com.qasymphony.ci.plugin.submitter.JunitSubmitterResult) JunitSubmitter(com.qasymphony.ci.plugin.submitter.JunitSubmitter) JunitQtestSubmitterImpl(com.qasymphony.ci.plugin.submitter.JunitQtestSubmitterImpl) JunitSubmitterRequest(com.qasymphony.ci.plugin.submitter.JunitSubmitterRequest)

Aggregations

AutomationTestResult (com.qasymphony.ci.plugin.model.AutomationTestResult)9 TestResult (hudson.tasks.junit.TestResult)4 AutomationAttachment (com.qasymphony.ci.plugin.model.AutomationAttachment)3 AutomationTestStepLog (com.qasymphony.ci.plugin.model.AutomationTestStepLog)3 CaseResult (hudson.tasks.junit.CaseResult)2 SuiteResult (hudson.tasks.junit.SuiteResult)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 GregorianCalendar (java.util.GregorianCalendar)2 SubmittedException (com.qasymphony.ci.plugin.exception.SubmittedException)1 AutomationTestResultWrapper (com.qasymphony.ci.plugin.model.AutomationTestResultWrapper)1 JunitQtestSubmitterImpl (com.qasymphony.ci.plugin.submitter.JunitQtestSubmitterImpl)1 JunitSubmitter (com.qasymphony.ci.plugin.submitter.JunitSubmitter)1 JunitSubmitterRequest (com.qasymphony.ci.plugin.submitter.JunitSubmitterRequest)1 JunitSubmitterResult (com.qasymphony.ci.plugin.submitter.JunitSubmitterResult)1 ClientRequestException (com.qasymphony.ci.plugin.utils.ClientRequestException)1 ResponseEntity (com.qasymphony.ci.plugin.utils.ResponseEntity)1 Launcher (hudson.Launcher)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1