Search in sources :

Example 1 with JunitSubmitterResult

use of com.qasymphony.ci.plugin.submitter.JunitSubmitterResult in project jenkin-qtest-plugin by QASymphony.

the class PushingResultAction method submitTestResult.

private JunitSubmitterResult submitTestResult(JunitSubmitterRequest submitterRequest, AbstractBuild build, BuildListener listener, JunitSubmitter junitSubmitter, List<AutomationTestResult> automationTestResults) {
    PrintStream logger = listener.getLogger();
    JunitSubmitterResult result = null;
    LoggerUtils.formatInfo(logger, "Begin submit test results to qTest at: " + JsonUtils.getCurrentDateString());
    long start = System.currentTimeMillis();
    try {
        result = junitSubmitter.submit(submitterRequest);
    } catch (SubmittedException e) {
        LoggerUtils.formatError(logger, "Cannot submit test results to qTest:");
        LoggerUtils.formatError(logger, "   status code: " + e.getStatus());
        LoggerUtils.formatError(logger, "   error: " + e.getMessage());
    } catch (Exception e) {
        LoggerUtils.formatError(logger, "Cannot submit test results to qTest:");
        LoggerUtils.formatError(logger, "   error: " + e.getMessage());
    } finally {
        if (null == result) {
            result = new JunitSubmitterResult().setTestSuiteId(null).setSubmittedStatus(JunitSubmitterResult.STATUS_FAILED).setNumberOfTestResult(automationTestResults.size()).setNumberOfTestLog(0);
        }
        Boolean isSuccess = null != result.getTestSuiteId() && result.getTestSuiteId() > 0;
        LoggerUtils.formatHR(logger);
        LoggerUtils.formatInfo(logger, isSuccess ? "SUBMIT SUCCESS" : "SUBMIT FAILED");
        LoggerUtils.formatHR(logger);
        if (isSuccess) {
            LoggerUtils.formatInfo(logger, "   testLogs: %s", result.getNumberOfTestLog());
            LoggerUtils.formatInfo(logger, "   testSuite: name=%s, id=%s", result.getTestSuiteName(), result.getTestSuiteId());
            LoggerUtils.formatInfo(logger, "   link: %s", ConfigService.formatTestSuiteLink(configuration.getUrl(), configuration.getProjectId(), result.getTestSuiteId()));
        }
        LoggerUtils.formatInfo(logger, "Time elapsed: %s", LoggerUtils.elapsedTime(start));
        LoggerUtils.formatInfo(logger, "End submit test results to qTest at: %s", JsonUtils.getCurrentDateString());
        LoggerUtils.formatInfo(logger, "");
    }
    return result;
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) PrintStream(java.io.PrintStream) JunitSubmitterResult(com.qasymphony.ci.plugin.submitter.JunitSubmitterResult) ServletException(javax.servlet.ServletException) SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException)

Example 2 with JunitSubmitterResult

use of com.qasymphony.ci.plugin.submitter.JunitSubmitterResult 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

JunitSubmitterResult (com.qasymphony.ci.plugin.submitter.JunitSubmitterResult)2 PrintStream (java.io.PrintStream)2 StoreResultException (com.qasymphony.ci.plugin.exception.StoreResultException)1 SubmittedException (com.qasymphony.ci.plugin.exception.SubmittedException)1 AutomationTestResult (com.qasymphony.ci.plugin.model.AutomationTestResult)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 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1