Search in sources :

Example 51 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class IssuesMediumTest method testNoIssueCallbackInNonPreview.

@Test
public void testNoIssueCallbackInNonPreview() throws Exception {
    File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
    File tmpDir = temp.getRoot();
    FileUtils.copyDirectory(projectDir, tmpDir);
    IssueRecorder issueListener = new IssueRecorder();
    TaskResult result = tester.newScanTask(new File(tmpDir, "sonar-project.properties")).setIssueListener(issueListener).start();
    assertThat(result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"))).hasSize(8);
    assertThat(issueListener.issueList).hasSize(0);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 52 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class IssuesOnModuleMediumTest method scanTempProject.

@Test
public void scanTempProject() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile1 = new File(srcDir, "sample1.xoo");
    FileUtils.write(xooFile1, "Sample1 xoo\ncontent");
    TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
    assertThat(result.issuesFor(result.getReportComponent("com.foo.project"))).hasSize(1);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 53 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class IssueModeAndReportsMediumTest method testIssueTracking.

@Test
public void testIssueTracking() throws Exception {
    File projectDir = copyProject("/mediumtest/xoo/sample");
    TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).start();
    int newIssues = 0;
    int openIssues = 0;
    int resolvedIssue = 0;
    for (TrackedIssue issue : result.trackedIssues()) {
        System.out.println(issue.getMessage() + " " + issue.key() + " " + issue.getRuleKey() + " " + issue.isNew() + " " + issue.resolution() + " " + issue.componentKey() + " " + issue.startLine());
        if (issue.isNew()) {
            newIssues++;
        } else if (issue.resolution() != null) {
            resolvedIssue++;
        } else {
            openIssues++;
        }
    }
    System.out.println("new: " + newIssues + " open: " + openIssues + " resolved " + resolvedIssue);
    assertThat(newIssues).isEqualTo(16);
    assertThat(openIssues).isEqualTo(2);
    assertThat(resolvedIssue).isEqualTo(1);
    // progress report
    String logs = StringUtils.join(logTester.logs(LoggerLevel.INFO), "\n");
    assertThat(logs).contains("Performing issue tracking");
    assertThat(logs).contains("6/6 components tracked");
    // assert that original fields of a matched issue are kept
    assertThat(result.trackedIssues()).haveExactly(1, new Condition<TrackedIssue>() {

        @Override
        public boolean matches(TrackedIssue value) {
            return value.isNew() == false && "resolved-on-project".equals(value.key()) && "OPEN".equals(value.status()) && new Date(date("14/03/2004")).equals(value.creationDate());
        }
    });
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 54 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class CoveragePerTestMediumTest method coveragePerTestInReport.

@Test
public void coveragePerTestInReport() throws IOException {
    File baseDir = createTestFiles();
    File testDir = new File(baseDir, "test");
    File xooTestExecutionFile = new File(testDir, "sampleTest.xoo.test");
    FileUtils.write(xooTestExecutionFile, "some test:4:::OK:UNIT\n" + "another test:10:::OK:UNIT\n" + "test without coverage:10:::OK:UNIT\n");
    File xooCoveragePerTestFile = new File(testDir, "sampleTest.xoo.testcoverage");
    FileUtils.write(xooCoveragePerTestFile, "some test;src/sample.xoo,10,11;src/sample2.xoo,1,2\n" + "another test;src/sample.xoo,10,20\n");
    TaskResult result = runTask(baseDir);
    InputFile file = result.inputFile("test/sampleTest.xoo");
    org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail someTest = result.coveragePerTestFor(file, "some test");
    assertThat(someTest.getCoveredFileList()).hasSize(2);
    assertThat(someTest.getCoveredFile(0).getFileRef()).isGreaterThan(0);
    assertThat(someTest.getCoveredFile(0).getCoveredLineList()).containsExactly(10, 11);
    assertThat(someTest.getCoveredFile(1).getFileRef()).isGreaterThan(0);
    assertThat(someTest.getCoveredFile(1).getCoveredLineList()).containsExactly(1, 2);
    org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail anotherTest = result.coveragePerTestFor(file, "another test");
    assertThat(anotherTest.getCoveredFileList()).hasSize(1);
    assertThat(anotherTest.getCoveredFile(0).getFileRef()).isGreaterThan(0);
    assertThat(anotherTest.getCoveredFile(0).getCoveredLineList()).containsExactly(10, 20);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 55 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class GenericTestExecutionMediumTest method unitTests.

@Test
public void unitTests() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File testDir = new File(baseDir, "test");
    testDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "foo");
    File xooTestFile = new File(testDir, "sampleTest.xoo");
    FileUtils.write(xooTestFile, "failure\nerror\nok\nskipped");
    File xooTestExecutionFile = new File(testDir, "sampleTest.xoo.test");
    FileUtils.write(xooTestExecutionFile, "skipped::::SKIPPED:UNIT\n" + "failure:2:Failure::FAILURE:UNIT\n" + "error:2:Error:The stack:ERROR:UNIT\n" + "success:4:::OK:INTEGRATION");
    TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").put("sonar.tests", "test").build()).start();
    InputFile file = result.inputFile("test/sampleTest.xoo");
    org.sonar.scanner.protocol.output.ScannerReport.Test success = result.firstTestExecutionForName(file, "success");
    assertThat(success.getDurationInMs()).isEqualTo(4);
    assertThat(success.getStatus()).isEqualTo(TestStatus.OK);
    org.sonar.scanner.protocol.output.ScannerReport.Test error = result.firstTestExecutionForName(file, "error");
    assertThat(error.getDurationInMs()).isEqualTo(2);
    assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR);
    assertThat(error.getMsg()).isEqualTo("Error");
    assertThat(error.getStacktrace()).isEqualTo("The stack");
}
Also used : ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)61 TaskResult (org.sonar.scanner.mediumtest.TaskResult)61 File (java.io.File)59 InputFile (org.sonar.api.batch.fs.InputFile)31 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)21 List (java.util.List)8 Issue (org.sonar.scanner.protocol.output.ScannerReport.Issue)7 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)6 Path (java.nio.file.Path)3 InputDir (org.sonar.api.batch.fs.InputDir)3 ScannerMediumTester (org.sonar.scanner.mediumtest.ScannerMediumTester)3 XooPlugin (org.sonar.xoo.XooPlugin)3 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)3 TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)2 Date (java.util.Date)1 LogOutputRecorder (org.sonar.scanner.mediumtest.LogOutputRecorder)1