use of org.sonar.scanner.mediumtest.ScannerMediumTester 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();
}
use of org.sonar.scanner.mediumtest.ScannerMediumTester in project sonarqube by SonarSource.
the class FileSystemMediumTest method publishDirsWithIssues.
@Test
public void publishDirsWithIssues() throws IOException {
ScannerMediumTester tester2 = ScannerMediumTester.builder().registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssuePerDirectory", null, "OneIssuePerDirectory", "MAJOR", null, "xoo").build();
tester2.start();
builder = ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.verbose", "true").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project");
Path unknownRelative = Paths.get("src/unknown/file.notanalyzed");
Path unknown = baseDir.toPath().resolve(unknownRelative);
Files.createDirectories(unknown.getParent());
Files.write(unknown, "dummy content".getBytes());
Path emptyDirRelative = Paths.get("src/emptydir");
Files.createDirectories(emptyDirRelative);
TaskResult result = tester2.newTask().properties(builder.put("sonar.sources", "src").build()).start();
DefaultInputFile unknownInputFile = (DefaultInputFile) result.inputFile(unknownRelative.toString());
InputDir unknownInputDir = result.inputDir(unknownRelative.getParent().toString());
assertThat(unknownInputFile.publish()).isFalse();
assertThat(result.getReportComponent(unknownInputDir.key())).isNotNull();
// no issues on empty dir
InputDir emptyInputDir = result.inputDir(emptyDirRelative.toString());
assertThat(emptyInputDir).isNull();
// no issues on parent dir
InputDir parentInputDir = result.inputDir(unknownRelative.getParent().getParent().toString());
assertThat(parentInputDir).isNull();
tester2.stop();
}
use of org.sonar.scanner.mediumtest.ScannerMediumTester in project sonarqube by SonarSource.
the class FileSystemMediumTest method createIssueOnAnyFile.
@Test
public void createIssueOnAnyFile() throws IOException {
LogOutputRecorder logs = new LogOutputRecorder();
ScannerMediumTester tester2 = ScannerMediumTester.builder().registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).setLogOutput(logs).addActiveRule("xoo", "OneIssuePerUnknownFile", null, "OneIssuePerUnknownFile", "MAJOR", null, "xoo").build();
tester2.start();
builder = createBuilder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.unknown");
FileUtils.write(xooFile, "Sample xoo\ncontent");
TaskResult result = tester2.newTask().properties(builder.put("sonar.sources", "src").build()).start();
assertThat(logs.getAllAsString()).contains("1 file indexed");
assertThat(logs.getAllAsString()).contains("'src/sample.unknown' indexed with language 'null'");
assertThat(logs.getAllAsString()).contains("'src/sample.unknown' generated metadata");
DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/sample.unknown");
assertThat(result.getReportComponent(javaInputFile.key())).isNotNull();
tester2.stop();
}
Aggregations