use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class ComponentsPublisherTest method should_skip_dir_without_published_files.
@Test
public void should_skip_dir_without_published_files() {
ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description");
DefaultInputModule root = new DefaultInputModule(rootDef, 1);
moduleHierarchy = mock(InputModuleHierarchy.class);
when(moduleHierarchy.root()).thenReturn(root);
when(moduleHierarchy.children(root)).thenReturn(Collections.emptyList());
// dir with files
DefaultInputDir dir = new DefaultInputDir("module1", "src", 2);
tree.index(dir, root);
// dir without files and issues
DefaultInputDir dir2 = new DefaultInputDir("module1", "src2", 3);
tree.index(dir2, root);
// dir without files but has issues
DefaultInputDir dir3 = new DefaultInputDir("module1", "src3", 4);
tree.index(dir3, root);
writeIssue(4);
DefaultInputFile file = new TestInputFileBuilder("module1", "src/Foo.java", 5).setLines(2).build();
tree.index(file, dir);
DefaultInputFile file2 = new TestInputFileBuilder("module1", "src2/Foo2.java", 6).setPublish(false).setLines(2).build();
tree.index(file2, dir2);
DefaultInputFile file3 = new TestInputFileBuilder("module1", "src2/Foo3.java", 7).setPublish(false).setLines(2).build();
tree.index(file3, dir3);
ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree);
publisher.publish(writer);
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 2)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 4)).isTrue();
// file was not marked for publishing and directory doesn't contain issues, so directory won't be included as well
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).isFalse();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isFalse();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isFalse();
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class CoveragePublisherTest method prepare.
@Before
public void prepare() throws IOException {
String moduleKey = "foo";
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build();
InputComponentStore componentCache = new InputComponentStore(new PathResolver());
componentCache.put(TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()));
componentCache.put(inputFile);
measureCache = mock(MeasureCache.class);
when(measureCache.byMetric(anyString(), anyString())).thenReturn(null);
publisher = new CoveragePublisher(componentCache, measureCache);
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class MeasuresPublisherTest method prepare.
@Before
public void prepare() throws IOException {
String moduleKey = "foo";
inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build();
InputComponentStore componentCache = new InputComponentStore(new PathResolver());
componentCache.put(inputModule);
componentCache.put(inputFile);
measureCache = mock(MeasureCache.class);
when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList());
publisher = new MeasuresPublisher(componentCache, measureCache, mock(TestPlanBuilder.class));
outputDir = temp.newFolder();
writer = new ScannerReportWriter(outputDir);
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class SourcePublisherTest method prepare.
@Before
public void prepare() throws IOException {
File baseDir = temp.newFolder();
sourceFile = new File(baseDir, "src/Foo.php");
String moduleKey = "foo";
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).setModuleBaseDir(baseDir.toPath()).setCharset(StandardCharsets.ISO_8859_1).build();
InputComponentStore componentStore = new InputComponentStore(new PathResolver());
componentStore.put(TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir));
componentStore.put(inputFile);
publisher = new SourcePublisher(componentStore);
File outputDir = temp.newFolder();
writer = new ScannerReportWriter(outputDir);
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class QProfileVerifierTest method should_fail_if_default_profile_not_used.
@Test
public void should_fail_if_default_profile_not_used() {
fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
settings.setProperty("sonar.profile", "Unknown");
QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles);
thrown.expect(MessageException.class);
thrown.expectMessage("sonar.profile was set to 'Unknown' but didn't match any profile for any language. Please check your configuration.");
profileLogger.execute();
}
Aggregations