Search in sources :

Example 21 with TaskResult

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

the class IssuesMediumTest method testIssueDetails.

@Test
public void testIssueDetails() throws IOException {
    File baseDir = temp.newFolder();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
    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();
    List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
    assertThat(issues).hasSize(10);
    assertThat(issues).extracting("msg", "textRange.startLine", "gap").contains(tuple("This issue is generated on each line", 1, 0.0));
}
Also used : Issue(org.sonar.scanner.protocol.output.ScannerReport.Issue) TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 22 with TaskResult

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

the class MeasuresMediumTest method deprecatedCoverageMeasuresAreConverted.

@Test
public void deprecatedCoverageMeasuresAreConverted() throws IOException {
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "Sample xoo\n\ncontent");
    File measures = new File(srcDir, "sample.xoo.measures");
    FileUtils.write(measures, "it_lines_to_cover:2");
    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();
    Map<String, List<Measure>> allMeasures = result.allMeasures();
    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value").containsOnly(tuple("lines_to_cover", 2));
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Coverage measure for metric 'lines_to_cover' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.");
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 23 with TaskResult

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

the class FileSystemMediumTest method fileInclusionsExclusions.

@Test
public void fileInclusionsExclusions() throws IOException {
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "Sample xoo\ncontent");
    File xooFile2 = new File(baseDir, "another.xoo");
    FileUtils.write(xooFile2, "Sample xoo 2\ncontent");
    File testDir = new File(baseDir, "test");
    testDir.mkdir();
    File xooTestFile = new File(baseDir, "sampleTest2.xoo");
    FileUtils.write(xooTestFile, "Sample test xoo\ncontent");
    File xooTestFile2 = new File(testDir, "sampleTest.xoo");
    FileUtils.write(xooTestFile2, "Sample test xoo 2\ncontent");
    TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src,another.xoo").put("sonar.tests", "test,sampleTest2.xoo").put("sonar.inclusions", "src/**").put("sonar.exclusions", "**/another.*").put("sonar.test.inclusions", "**/sampleTest*.*").put("sonar.test.exclusions", "**/sampleTest2.xoo").build()).start();
    assertThat(result.inputFiles()).hasSize(2);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 24 with TaskResult

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

the class FileSystemMediumTest method dontPublishFilesWithoutDetectedLanguage.

@Test
public void dontPublishFilesWithoutDetectedLanguage() throws IOException {
    builder = createBuilder();
    Path mainDir = baseDir.toPath().resolve("src").resolve("main");
    Files.createDirectories(mainDir);
    Path testDir = baseDir.toPath().resolve("src").resolve("test");
    Files.createDirectories(testDir);
    Path testXooFile = testDir.resolve("sample.java");
    Files.write(testXooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
    Path xooFile = mainDir.resolve("sample.xoo");
    Files.write(xooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
    Path javaFile = mainDir.resolve("sample.java");
    Files.write(javaFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
    TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src/main").put("sonar.tests", "src/test").build()).start();
    assertThat(logs.getAllAsString()).contains("3 files indexed");
    assertThat(logs.getAllAsString()).contains("'src/main/sample.xoo' generated metadata");
    assertThat(logs.getAllAsString()).doesNotContain("'src/main/sample.java' generated metadata");
    assertThat(logs.getAllAsString()).doesNotContain("'src/test/sample.java' generated metadata");
    DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java");
    assertThat(result.getReportComponent(javaInputFile.key())).isNull();
}
Also used : Path(java.nio.file.Path) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) TaskResult(org.sonar.scanner.mediumtest.TaskResult) Test(org.junit.Test)

Example 25 with TaskResult

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

the class FileSystemMediumTest method publishFilesWithIssues.

@Test
public void publishFilesWithIssues() throws IOException {
    ScannerMediumTester tester2 = ScannerMediumTester.builder().registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo").build();
    tester2.start();
    builder = createBuilder();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "Sample xoo\ncontent");
    TaskResult result = tester2.newTask().properties(builder.put("sonar.sources", "src").build()).start();
    DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
    InputDir dir = result.inputDir("src");
    assertThat(file.publish()).isTrue();
    assertThat(result.getReportComponent(dir.key())).isNotNull();
    assertThat(result.getReportComponent(file.key())).isNotNull();
    tester2.stop();
}
Also used : XooPlugin(org.sonar.xoo.XooPlugin) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) XooRulesDefinition(org.sonar.xoo.rule.XooRulesDefinition) ScannerMediumTester(org.sonar.scanner.mediumtest.ScannerMediumTester) TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputDir(org.sonar.api.batch.fs.InputDir) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) 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