Search in sources :

Example 91 with DefaultInputFile

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

the class GenericTestExecutionReportParserTest method file_without_language_should_be_skipped.

@Test
public void file_without_language_should_be_skipped() throws Exception {
    String filePath = "src/main/java/com/example/EmptyClass.java";
    DefaultInputFile file = new TestInputFileBuilder(context.module().key(), filePath).setLanguage(null).setType(InputFile.Type.TEST).initMetadata("1\n2\n3\n4\n5\n6").build();
    addFileToFs(file);
    GenericTestExecutionReportParser parser = parseReportFile("unittest.xml");
    assertThat(parser.numberOfMatchedFiles()).isZero();
    assertThat(parser.numberOfUnknownFiles()).isEqualTo(2);
    assertThat(parser.firstUnknownFiles()).hasSize(2);
    assertThat(logs.logs()).contains("Skipping file 'src/main/java/com/example/EmptyClass.java' in the generic test execution report because it doesn't have a known language");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 92 with DefaultInputFile

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

the class SvnBlameCommandTest method shouldNotFailIfFileContainsLocalModification.

@Test
public void shouldNotFailIfFileContainsLocalModification() 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).setLines(28).setModuleBaseDir(baseDir.toPath()).build();
    Files.write(baseDir.toPath().resolve(DUMMY_JAVA), "\n//foo".getBytes(), StandardOpenOption.APPEND);
    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 93 with DefaultInputFile

use of org.sonar.api.batch.fs.internal.DefaultInputFile 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 94 with DefaultInputFile

use of org.sonar.api.batch.fs.internal.DefaultInputFile 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 95 with DefaultInputFile

use of org.sonar.api.batch.fs.internal.DefaultInputFile 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)

Aggregations

DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)173 Test (org.junit.Test)117 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)75 File (java.io.File)63 InputFile (org.sonar.api.batch.fs.InputFile)46 Path (java.nio.file.Path)25 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)18 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)17 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)16 FileMetadata (org.sonar.api.batch.fs.internal.FileMetadata)14 IOException (java.io.IOException)13 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)11 Metadata (org.sonar.api.batch.fs.internal.Metadata)11 Before (org.junit.Before)10 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)10 BlameLine (org.sonar.api.batch.scm.BlameLine)9 List (java.util.List)8 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)8 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)7 TextRange (org.sonar.api.batch.fs.TextRange)7