Search in sources :

Example 11 with BlameOutput

use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.

the class SvnBlameCommandTest method blame_givenNoCredentials_logWarning.

@Test
public void blame_givenNoCredentials_logWarning() throws Exception {
    BlameOutput output = mock(BlameOutput.class);
    InputFile inputFile = mock(InputFile.class);
    SvnBlameCommand svnBlameCommand = newSvnBlameCommand();
    SVNClientManager clientManager = mock(SVNClientManager.class);
    SVNLogClient logClient = mock(SVNLogClient.class);
    SVNStatusClient statusClient = mock(SVNStatusClient.class);
    SVNStatus status = mock(SVNStatus.class);
    when(clientManager.getLogClient()).thenReturn(logClient);
    when(clientManager.getStatusClient()).thenReturn(statusClient);
    when(status.getContentsStatus()).thenReturn(SVNStatusType.STATUS_NORMAL);
    when(inputFile.file()).thenReturn(mock(File.class));
    when(statusClient.doStatus(any(File.class), anyBoolean())).thenReturn(status);
    doThrow(SVNAuthenticationException.class).when(logClient).doAnnotate(any(File.class), any(SVNRevision.class), any(SVNRevision.class), any(SVNRevision.class), anyBoolean(), anyBoolean(), any(AnnotationHandler.class), eq(null));
    assertThrows(IllegalStateException.class, () -> {
        svnBlameCommand.blame(clientManager, inputFile, output);
        assertThat(logTester.logs(LoggerLevel.WARN)).contains("Authentication to SVN server is required but no " + "authentication data was passed to the scanner");
    });
}
Also used : SVNStatus(org.tmatesoft.svn.core.wc.SVNStatus) SVNStatusClient(org.tmatesoft.svn.core.wc.SVNStatusClient) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) ZipFile(java.util.zip.ZipFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Example 12 with BlameOutput

use of org.sonar.api.batch.scm.BlameCommand.BlameOutput 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 13 with BlameOutput

use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.

the class XooBlameCommandTest method testBlameWithRelativeDate.

@Test
public void testBlameWithRelativeDate() throws IOException {
    File source = new File(baseDir, "src/foo.xoo");
    FileUtils.write(source, "sample content");
    File scm = new File(baseDir, "src/foo.xoo.scm");
    FileUtils.write(scm, "123,julien,-10\n234,julien,-10");
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
    fs.add(inputFile);
    BlameOutput result = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
    new XooBlameCommand().blame(input, result);
    Predicate<Date> datePredicate = argument -> {
        Date approximate = DateUtils.addDays(new Date(), -10);
        return argument.getTime() > approximate.getTime() - 5000 && argument.getTime() < approximate.getTime() + 5000;
    };
    ArgumentCaptor<List<BlameLine>> blameLinesCaptor = ArgumentCaptor.forClass(List.class);
    verify(result).blameResult(eq(inputFile), blameLinesCaptor.capture());
    assertThat(blameLinesCaptor.getValue()).extracting(BlameLine::date).allMatch(datePredicate);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Arrays(java.util.Arrays) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Date(java.util.Date) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BlameInput(org.sonar.api.batch.scm.BlameCommand.BlameInput) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) DateUtils(org.sonar.api.utils.DateUtils) Xoo(org.sonar.xoo.Xoo) Before(org.junit.Before) Predicate(java.util.function.Predicate) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) File(java.io.File) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Mockito.verify(org.mockito.Mockito.verify) BlameLine(org.sonar.api.batch.scm.BlameLine) List(java.util.List) Rule(org.junit.Rule) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) 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) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 14 with BlameOutput

use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.

the class XooBlameCommandTest method blame_containing_author_with_comma.

@Test
public void blame_containing_author_with_comma() throws IOException {
    File source = new File(baseDir, "src/foo.xoo");
    FileUtils.write(source, "sample content");
    File scm = new File(baseDir, "src/foo.xoo.scm");
    FileUtils.write(scm, "\"123\",\"john,doe\",\"2019-01-22\"");
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
    fs.add(inputFile);
    BlameOutput result = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
    new XooBlameCommand().blame(input, result);
    verify(result).blameResult(inputFile, singletonList(new BlameLine().revision("123").author("john,doe").date(DateUtils.parseDate("2019-01-22"))));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 15 with BlameOutput

use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.

the class XooBlameCommandTest method testBlame.

@Test
public void testBlame() throws IOException {
    File source = new File(baseDir, "src/foo.xoo");
    FileUtils.write(source, "sample content");
    File scm = new File(baseDir, "src/foo.xoo.scm");
    FileUtils.write(scm, "123,julien,2014-12-12\n234,julien,2014-12-24");
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
    fs.add(inputFile);
    BlameOutput result = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
    new XooBlameCommand().blame(input, result);
    verify(result).blameResult(inputFile, Arrays.asList(new BlameLine().revision("123").author("julien").date(DateUtils.parseDate("2014-12-12")), new BlameLine().revision("234").author("julien").date(DateUtils.parseDate("2014-12-24"))));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)18 Test (org.junit.Test)18 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)18 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)18 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)16 InputFile (org.sonar.api.batch.fs.InputFile)15 ZipFile (java.util.zip.ZipFile)8 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)8 BlameLine (org.sonar.api.batch.scm.BlameLine)7 Date (java.util.Date)5 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 Arrays (java.util.Arrays)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Before (org.junit.Before)3 Rule (org.junit.Rule)3 TemporaryFolder (org.junit.rules.TemporaryFolder)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3