Search in sources :

Example 16 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class ModuleInputComponentStoreTest method should_get_empty_iterable_on_cache_miss.

@Test
public void should_get_empty_iterable_on_cache_miss() {
    ModuleInputComponentStore store = newModuleInputComponentStore();
    String ext = "java";
    String filename = "Program." + ext;
    InputFile inputFile = new TestInputFileBuilder(moduleKey, "some/path/" + filename).build();
    store.doAdd(inputFile);
    assertThat(store.getFilesByName("nonexistent")).isEmpty();
    assertThat(store.getFilesByExtension("nonexistent")).isEmpty();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 17 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class ConsoleReportTest method testOneNewIssue.

@Test
public void testOneNewIssue() {
    settings.setProperty(ConsoleReport.CONSOLE_REPORT_ENABLED_KEY, "true");
    when(inputPathCache.allFilesToPublish()).thenReturn(Collections.singleton(new TestInputFileBuilder("foo", "src/Foo.php").build()));
    when(issueCache.all()).thenReturn(Arrays.asList(createIssue(true, Severity.BLOCKER)));
    report.execute();
    assertDeprecated();
    assertThat(getReportLog()).isEqualTo("\n\n-------------  Issues Report  -------------\n\n" + "        +1 issue\n\n" + "        +1 blocker\n" + "\n-------------------------------------------\n\n");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Test(org.junit.Test)

Example 18 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class MetadataGeneratorTest method createInputFileWithMetadata.

private DefaultInputFile createInputFileWithMetadata(MetadataGenerator generator, Path baseDir, String relativePath) {
    DefaultInputFile inputFile = new TestInputFileBuilder("struts", relativePath).setModuleBaseDir(baseDir).build();
    generator.setMetadata(inputFile, StandardCharsets.US_ASCII);
    return inputFile;
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 19 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class JSONReportTest method before.

@Before
public void before() throws Exception {
    moduleHierarchy = mock(InputModuleHierarchy.class);
    userRepository = mock(UserRepositoryLoader.class);
    File projectBaseDir = temp.newFolder();
    fs = new DefaultFileSystem(projectBaseDir.toPath());
    SIMPLE_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+02:00"));
    when(server.getVersion()).thenReturn("3.6");
    InputComponentStore inputComponentStore = new InputComponentStore(new PathResolver());
    DefaultComponentTree inputComponentTree = new DefaultComponentTree();
    DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(projectBaseDir).setKey("struts"), 1);
    inputComponentStore.put(rootModule);
    DefaultInputModule moduleA = new DefaultInputModule("struts-core");
    inputComponentTree.index(moduleA, rootModule);
    DefaultInputModule moduleB = new DefaultInputModule("struts-ui");
    inputComponentTree.index(moduleB, rootModule);
    DefaultInputDir inputDir = new DefaultInputDir("struts", "src/main/java/org/apache/struts", TestInputFileBuilder.nextBatchId()).setModuleBaseDir(projectBaseDir.toPath());
    DefaultInputFile inputFile = new TestInputFileBuilder("struts", "src/main/java/org/apache/struts/Action.java").setModuleBaseDir(projectBaseDir.toPath()).build();
    inputFile.setStatus(InputFile.Status.CHANGED);
    inputFile.setPublish(true);
    inputComponentStore.put(inputFile);
    inputComponentStore.put(inputDir);
    inputComponentTree.index(inputDir, rootModule);
    inputComponentTree.index(inputFile, inputDir);
    when(moduleHierarchy.children(rootModule)).thenReturn(Arrays.asList(moduleA, moduleB));
    when(moduleHierarchy.parent(moduleA)).thenReturn(rootModule);
    when(moduleHierarchy.parent(moduleB)).thenReturn(rootModule);
    when(moduleHierarchy.relativePath(moduleA)).thenReturn("core");
    when(moduleHierarchy.relativePath(moduleB)).thenReturn("ui");
    RulesBuilder builder = new RulesBuilder();
    builder.add(RuleKey.of("squid", "AvoidCycles")).setName("Avoid Cycles");
    rules = builder.build();
    jsonReport = new JSONReport(moduleHierarchy, settings, fs, server, rules, issueCache, rootModule, inputComponentStore, userRepository, inputComponentTree);
}
Also used : PathResolver(org.sonar.api.scan.filesystem.PathResolver) RulesBuilder(org.sonar.api.batch.rule.internal.RulesBuilder) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) UserRepositoryLoader(org.sonar.scanner.repository.user.UserRepositoryLoader) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) DefaultComponentTree(org.sonar.scanner.scan.DefaultComponentTree) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 20 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class DefaultBlameOutputTest method shouldNotFailIfNotSameNumberOfLines.

@Test
public void shouldNotFailIfNotSameNumberOfLines() {
    InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(10).build();
    new DefaultBlameOutput(null, Arrays.asList(file)).blameResult(file, Arrays.asList(new BlameLine().revision("1").author("guy")));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultBlameOutput(org.sonar.scanner.scm.DefaultBlameOutput) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)87 Test (org.junit.Test)77 InputFile (org.sonar.api.batch.fs.InputFile)41 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)23 File (java.io.File)19 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)9 Before (org.junit.Before)7 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)6 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)5 BlameLine (org.sonar.api.batch.scm.BlameLine)5 AnalysisMode (org.sonar.api.batch.AnalysisMode)4 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)4 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)4 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)4 Issue (org.sonar.api.batch.sensor.issue.Issue)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)4 DefaultBlameOutput (org.sonar.scanner.scm.DefaultBlameOutput)4 DefaultTextPointer (org.sonar.api.batch.fs.internal.DefaultTextPointer)3 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)3