Search in sources :

Example 1 with AutomationTestResult

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

the class MavenJunitParseTests method testParseMavenProject.

@LocalData
@Test
public void testParseMavenProject() throws InterruptedException, ExecutionException, TimeoutException, IOException {
    project = j.createFreeStyleProject("maven-project");
    automationTestResultList = null;
    project.getBuildersList().add(new MavenParseTestMavenProject());
    FreeStyleBuild build = project.scheduleBuild2(0).get(100, TimeUnit.MINUTES);
    assertNotNull("Build is: ", build);
    assertEquals("", 8, automationTestResultList.size());
    AutomationTestResult calculateTest = null;
    for (AutomationTestResult automationTestResult : automationTestResultList) {
        if (automationTestResult.getName().equalsIgnoreCase("sample.junit.CalculateTest")) {
            calculateTest = automationTestResult;
            break;
        }
    }
    assertNotNull("Calculate test is:", calculateTest);
    assertEquals("Test log size is ", 4, calculateTest.getTestLogs().size());
    AutomationTestStepLog first = calculateTest.getTestLogs().get(0);
    assertEquals("Description 1 is ", "testSum_second", first.getDescription());
    assertEquals("Status 1 is ", "FAILED", first.getStatus());
    AutomationTestStepLog second = calculateTest.getTestLogs().get(1);
    assertEquals("Description 2 is ", "testSum_one", second.getDescription());
    assertEquals("Status 2 is ", "PASSED", second.getStatus());
}
Also used : AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) AutomationTestStepLog(com.qasymphony.ci.plugin.model.AutomationTestStepLog) FreeStyleBuild(hudson.model.FreeStyleBuild) LocalData(org.jvnet.hudson.test.recipes.LocalData) Test(org.junit.Test)

Example 2 with AutomationTestResult

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

the class CommonParsingUtils method processAttachment.

/**
 * Process attachment
 *
 * @param map automationTestResultMap
 */
private static Map<String, AutomationTestResult> processAttachment(Map<String, AutomationTestResult> map) throws Exception {
    Iterator<String> keys = map.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        AutomationTestResult testLog = map.get(key);
        int totalAttachments = testLog.getAttachments().size();
        if (totalAttachments > LIMIT_TXT_FILES) {
            File zipFile = File.createTempFile(testLog.getName(), Extension.ZIP_FILE);
            ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFile));
            Map<String, Integer> attachmentNames = new HashMap<>();
            for (int i = 0; i < totalAttachments; i++) {
                AutomationAttachment attachment = testLog.getAttachments().get(i);
                String attachmentName = attachment.getName();
                if (attachmentNames.containsKey(attachment.getName())) {
                    Integer count = attachmentNames.get(attachment.getName());
                    attachmentName = attachmentName.replace(Extension.TEXT_FILE, "_" + count + Extension.TEXT_FILE);
                    attachmentNames.put(attachment.getName(), ++count);
                } else {
                    attachmentNames.put(attachment.getName(), 1);
                }
                zipOutputStream.putNextEntry(new ZipEntry(attachmentName));
                zipOutputStream.write(attachment.getData().getBytes());
                zipOutputStream.closeEntry();
            }
            zipOutputStream.close();
            // get zipFile stream
            BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(zipFile));
            int zipFileLength = (int) zipFile.length();
            byte[] zipFileBytes = new byte[zipFileLength];
            bufferedInputStream.read(zipFileBytes, 0, zipFileLength);
            bufferedInputStream.close();
            AutomationAttachment attachment = new AutomationAttachment();
            attachment.setData(Base64.encodeBase64String(zipFileBytes));
            attachment.setContentType(CONTENT_TYPE_ZIP);
            attachment.setName(testLog.getName() + Extension.ZIP_FILE);
            // add zip file
            testLog.setAttachments(Arrays.asList(attachment));
            // remove zip tmp file
            zipFile.delete();
        } else {
            for (int i = 0; i < totalAttachments; i++) {
                AutomationAttachment attachment = testLog.getAttachments().get(i);
                attachment.setContentType(CONTENT_TYPE_TEXT);
                attachment.setData(Base64.encodeBase64String(attachment.getData().getBytes()));
            }
        }
    }
    return map;
}
Also used : AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) ZipEntry(java.util.zip.ZipEntry) FileInputStream(java.io.FileInputStream) AutomationAttachment(com.qasymphony.ci.plugin.model.AutomationAttachment) BufferedInputStream(java.io.BufferedInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 3 with AutomationTestResult

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

the class AutoScanParser method parse.

/**
 * @param request request
 * @return list of {@link AutomationTestResult}
 * @throws Exception Exception
 */
@Override
public List<AutomationTestResult> parse(ParseRequest request) throws Exception {
    PrintStream logger = request.getListener().getLogger();
    LoggerUtils.formatInfo(logger, "Auto scan JUnit test results files.");
    Run<?, ?> build = request.getBuild();
    // otherwise auto scan test result
    String basedDir = request.getWorkSpace().toURI().getPath();
    List<String> resultFolders = CommonParsingUtils.scanJunitTestResultFolder(basedDir);
    LOG.info("Scanning junit test result in dir:" + basedDir + String.format(".Found: %s dirs, %s", resultFolders.size(), resultFolders));
    List<AutomationTestResult> result = new LinkedList<>();
    if (request.isMavenProject() && resultFolders.size() <= 1) {
        // if pom file is located at workspace, we do not scan to detect junit result
        FileSet fs = Util.createFileSet(new File(basedDir), AutoScanParser.TEST_RESULT_LOCATIONS);
        DirectoryScanner ds = fs.getDirectoryScanner();
        if (ds.getIncludedFiles().length > 0)
            return parse(request, TEST_RESULT_LOCATIONS);
    } else if (request.isMavenProject()) {
        // if is maven project, we only scan surefire report folder
        for (String res : resultFolders) {
            if (res.contains(AutoScanParser.SUREFIRE_REPORT)) {
                try {
                    result.addAll(parse(request, res + Constants.JUNIT_SUFFIX));
                } catch (Exception e) {
                    LoggerUtils.formatWarn(logger, "Try to scan test result in: %s, error: %s", res, e.getMessage());
                }
            }
        }
        return result;
    }
    for (String res : resultFolders) {
        try {
            result.addAll(parse(request, res + Constants.JUNIT_SUFFIX));
        } catch (Exception e) {
            LoggerUtils.formatWarn(logger, "Try to scan test result in: %s, error: %s", res, e.getMessage());
        }
    }
    return result;
}
Also used : PrintStream(java.io.PrintStream) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File) LinkedList(java.util.LinkedList)

Example 4 with AutomationTestResult

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

the class PatternScanParser method parse.

/**
 * Read test results with test result location pattern
 *
 * @param request            request
 * @param testResultLocation testResultLocation
 * @return a list of {@link AutomationTestResult}
 * @throws Exception Exception
 */
public List<AutomationTestResult> parse(ParseRequest request, String testResultLocation) throws Exception {
    JUnitParser jUnitParser = new JUnitParser(true);
    Run<?, ?> build = request.getBuild();
    Launcher launcher = request.getLauncher();
    TaskListener listener = request.getListener();
    List<TestResult> testResults = new ArrayList<>();
    testResults.add(jUnitParser.parseResult(testResultLocation, build, request.getWorkSpace(), launcher, listener));
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTimeInMillis(build.getStartTimeInMillis());
    return CommonParsingUtils.toAutomationTestResults(request, testResults, gregorianCalendar.getTime());
}
Also used : TaskListener(hudson.model.TaskListener) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) JUnitParser(hudson.tasks.junit.JUnitParser) Launcher(hudson.Launcher) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult)

Example 5 with AutomationTestResult

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

the class CommonParsingUtils method useTestMethodAsTestCase.

/**
 * Each method as a testCase in qTest
 *
 * @param request     parse request
 * @param testResults testResults
 * @param startTime   start build time
 * @return
 * @throws Exception
 */
private static List<AutomationTestResult> useTestMethodAsTestCase(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()) {
                String automationContent = caseResult.getClassName() + "#" + caseResult.getName();
                if (!map.containsKey(automationContent)) {
                    AutomationTestResult testLog = new AutomationTestResult();
                    testLog.setOrder(currentTestLogOrder++);
                    testLog.setAutomationContent(automationContent);
                    testLog.setExecutedStartDate(startDate);
                    testLog.setExecutedEndDate(computeEndTime(startDate, caseResult.getDuration()));
                    testLog.addTestStepLog(new AutomationTestStepLog(caseResult), request.getOverwriteExistingTestSteps());
                    if (caseResult.isFailed()) {
                        try {
                            AutomationAttachment attachment = new AutomationAttachment(caseResult);
                            attachment.setData(Base64.encodeBase64String(attachment.getData().getBytes()));
                            testLog.addAttachment(attachment);
                        } catch (Exception e) {
                            LoggerUtils.formatError(request.getListener().getLogger(), "Error while build attachment: %s, %s", e.getMessage(), e.getStackTrace());
                        }
                    }
                    map.put(automationContent, testLog);
                }
            }
        }
    }
    return new ArrayList<>(map.values());
}
Also used : AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) AutomationTestStepLog(com.qasymphony.ci.plugin.model.AutomationTestStepLog) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) SuiteResult(hudson.tasks.junit.SuiteResult) AutomationAttachment(com.qasymphony.ci.plugin.model.AutomationAttachment) CaseResult(hudson.tasks.junit.CaseResult)

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