Search in sources :

Example 91 with TestInputFileBuilder

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

the class SvnBlameCommandTest method shouldNotFailOnWrongFilename.

// SONARSCSVN-7
@Test
public void shouldNotFailOnWrongFilename() throws Exception {
    File repoDir = unzip("repo-svn.zip");
    String scmUrl = "file:///" + unixPath(new File(repoDir, "repo-svn"));
    File baseDir = new File(checkout(scmUrl), "dummy-svn");
    when(fs.baseDir()).thenReturn(baseDir);
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA.toLowerCase()).setLines(27).setModuleBaseDir(baseDir.toPath()).build();
    BlameOutput blameResult = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(singletonList(inputFile));
    newSvnBlameCommand().blame(input, blameResult);
    verifyNoInteractions(blameResult);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) ZipFile(java.util.zip.ZipFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 92 with TestInputFileBuilder

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

the class SvnBlameCommandTest method testParsingOfOutputWithMergeHistory.

@Test
public void testParsingOfOutputWithMergeHistory() throws Exception {
    File repoDir = unzip("repo-svn-with-merge.zip");
    String scmUrl = "file:///" + unixPath(new File(repoDir, "repo-svn"));
    File baseDir = new File(checkout(scmUrl), "dummy-svn/trunk");
    when(fs.baseDir()).thenReturn(baseDir);
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).setLines(27).setModuleBaseDir(baseDir.toPath()).build();
    BlameOutput blameResult = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(singletonList(inputFile));
    newSvnBlameCommand().blame(input, blameResult);
    ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
    verify(blameResult).blameResult(eq(inputFile), captor.capture());
    List<BlameLine> result = captor.getValue();
    assertThat(result).hasSize(27);
    Date commitDate = new Date(1342691097393L);
    Date revision6Date = new Date(1415262184300L);
    BlameLine[] expected = IntStream.rangeClosed(1, 27).mapToObj(i -> {
        if (i == 2 || i == 24) {
            return new BlameLine().date(revision6Date).revision("6").author("henryju");
        } else {
            return new BlameLine().date(commitDate).revision("2").author("dgageot");
        }
    }).toArray(BlameLine[]::new);
    assertThat(result).containsExactly(expected);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) Date(java.util.Date) SVNStatus(org.tmatesoft.svn.core.wc.SVNStatus) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BlameInput(org.sonar.api.batch.scm.BlameCommand.BlameInput) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) Parameterized(org.junit.runners.Parameterized) StandardOpenOption(java.nio.file.StandardOpenOption) FileSystem(org.sonar.api.batch.fs.FileSystem) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) List(java.util.List) SVNStatusClient(org.tmatesoft.svn.core.wc.SVNStatusClient) Mockito.any(org.mockito.Mockito.any) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) InputFile(org.sonar.api.batch.fs.InputFile) SVNWCUtil(org.tmatesoft.svn.core.wc.SVNWCUtil) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) SVNDepth(org.tmatesoft.svn.core.SVNDepth) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) SvnCodec(org.tmatesoft.svn.core.internal.wc2.compat.SvnCodec) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) ArgumentCaptor(org.mockito.ArgumentCaptor) Before(org.junit.Before) ISVNOptions(org.tmatesoft.svn.core.wc.ISVNOptions) Files(java.nio.file.Files) SVNStatusType(org.tmatesoft.svn.core.wc.SVNStatusType) SvnCheckout(org.tmatesoft.svn.core.wc2.SvnCheckout) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) File(java.io.File) SVNAuthenticationException(org.tmatesoft.svn.core.SVNAuthenticationException) Mockito.verify(org.mockito.Mockito.verify) ISVNAuthenticationManager(org.tmatesoft.svn.core.auth.ISVNAuthenticationManager) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) Paths(java.nio.file.Paths) SVNURL(org.tmatesoft.svn.core.SVNURL) SVNUpdateClient(org.tmatesoft.svn.core.wc.SVNUpdateClient) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) SvnTarget(org.tmatesoft.svn.core.wc2.SvnTarget) TemporaryFolder(org.junit.rules.TemporaryFolder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) ZipFile(java.util.zip.ZipFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 93 with TestInputFileBuilder

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

the class SvnBlameCommandTest method shouldNotFailOnUncommitedFile.

@Test
public void shouldNotFailOnUncommitedFile() throws Exception {
    File repoDir = unzip("repo-svn.zip");
    String scmUrl = "file:///" + unixPath(new File(repoDir, "repo-svn"));
    File baseDir = new File(checkout(scmUrl), "dummy-svn");
    when(fs.baseDir()).thenReturn(baseDir);
    String relativePath = "src/main/java/org/dummy/Dummy2.java";
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", relativePath).setLines(28).setModuleBaseDir(baseDir.toPath()).build();
    Files.write(baseDir.toPath().resolve(relativePath), "package org.dummy;\npublic class Dummy2 {}".getBytes());
    BlameOutput blameResult = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(singletonList(inputFile));
    newSvnBlameCommand().blame(input, blameResult);
    verifyNoInteractions(blameResult);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) ZipFile(java.util.zip.ZipFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 94 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(projectKey, "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 95 with TestInputFileBuilder

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

the class DefaultBlameOutputTest method addWarningIfFilesMissing.

@Test
public void addWarningIfFilesMissing() {
    InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(10).build();
    new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).finish(true);
    assertThat(analysisWarnings.warnings()).extracting(DefaultAnalysisWarnings.Message::getText).containsOnly("Missing blame information for 1 file. This may lead to some features not working correctly. " + "Please check the analysis logs and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultAnalysisWarnings(org.sonar.scanner.notifications.DefaultAnalysisWarnings) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)199 Test (org.junit.Test)163 File (java.io.File)89 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)88 InputFile (org.sonar.api.batch.fs.InputFile)87 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)41 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)23 Before (org.junit.Before)22 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)16 SonarComponents (org.sonar.java.SonarComponents)13 JavaCheck (org.sonar.plugins.java.api.JavaCheck)13 BlameLine (org.sonar.api.batch.scm.BlameLine)12 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)9 Path (java.nio.file.Path)8 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)8 AnalyzerMessage (org.sonar.java.AnalyzerMessage)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 IOException (java.io.IOException)6 ZipFile (java.util.zip.ZipFile)6 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)6