Search in sources :

Example 11 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method persist_scm.

@Test
public void persist_scm() {
    initBasicReport(1);
    scmInfoRepository.setScmInfo(FILE_REF, Changeset.newChangesetBuilder().setAuthor("john").setDate(123456789L).setRevision("rev-1").build());
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    assertThat(fileSourceDto.getRevision()).isEqualTo("rev-1");
    DbFileSources.Data data = fileSourceDto.getSourceData();
    assertThat(data.getLinesList()).hasSize(1);
    assertThat(data.getLines(0).getScmAuthor()).isEqualTo("john");
    assertThat(data.getLines(0).getScmDate()).isEqualTo(123456789L);
    assertThat(data.getLines(0).getScmRevision()).isEqualTo("rev-1");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) Test(org.junit.Test)

Example 12 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method update_sources_when_source_updated.

@Test
public void update_sources_when_source_updated() {
    // Existing sources
    long past = 150000L;
    dbClient.fileSourceDao().insert(dbTester.getSession(), new FileSourceDto().setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setDataType(Type.SOURCE).setSrcHash("5b4bd9815cdb17b8ceae19eb1810c34c").setLineHashes("6438c669e0d0de98e6929c2cc0fac474\n").setDataHash("6cad150e3d065976c230cddc5a09efaa").setSourceData(DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setLine(1).setSource("old line").build()).build()).setCreatedAt(past).setUpdatedAt(past).setRevision("rev-0"));
    dbTester.getSession().commit();
    initBasicReport(1);
    scmInfoRepository.setScmInfo(FILE_REF, Changeset.newChangesetBuilder().setAuthor("john").setDate(123456789L).setRevision("rev-1").build());
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    assertThat(fileSourceDto.getCreatedAt()).isEqualTo(past);
    assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW);
    assertThat(fileSourceDto.getRevision()).isEqualTo("rev-1");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 13 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method update_sources_when_revision_is_missing.

@Test
public void update_sources_when_revision_is_missing() {
    // Existing sources
    long past = 150000L;
    dbClient.fileSourceDao().insert(dbTester.getSession(), new FileSourceDto().setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setDataType(Type.SOURCE).setSrcHash("137f72c3708c6bd0de00a0e5a69c699b").setLineHashes("137f72c3708c6bd0de00a0e5a69c699b").setDataHash("8e84c0d961cfe364e43833c4cc4ddef5").setSourceData(DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setLine(1).setSource("line").build()).build()).setCreatedAt(past).setUpdatedAt(past));
    dbTester.getSession().commit();
    scmInfoRepository.setScmInfo(FILE_REF, Changeset.newChangesetBuilder().setAuthor("john").setDate(123456789L).setRevision("rev-1").build());
    initBasicReport(1);
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    assertThat(fileSourceDto.getCreatedAt()).isEqualTo(past);
    assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW);
    assertThat(fileSourceDto.getRevision()).isEqualTo("rev-1");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 14 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method persist_sources.

@Test
public void persist_sources() {
    initBasicReport(2);
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    assertThat(fileSourceDto.getProjectUuid()).isEqualTo(PROJECT_UUID);
    assertThat(fileSourceDto.getFileUuid()).isEqualTo(FILE_UUID);
    assertThat(fileSourceDto.getBinaryData()).isNotEmpty();
    assertThat(fileSourceDto.getDataHash()).isNotEmpty();
    assertThat(fileSourceDto.getLineHashes()).isNotEmpty();
    assertThat(fileSourceDto.getCreatedAt()).isEqualTo(NOW);
    assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW);
    DbFileSources.Data data = fileSourceDto.getSourceData();
    assertThat(data.getLinesCount()).isEqualTo(2);
    assertThat(data.getLines(0).getLine()).isEqualTo(1);
    assertThat(data.getLines(0).getSource()).isEqualTo("line1");
    assertThat(data.getLines(1).getLine()).isEqualTo(2);
    assertThat(data.getLines(1).getSource()).isEqualTo("line2");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) Test(org.junit.Test)

Example 15 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method save_revision.

@Test
public void save_revision() {
    initBasicReport(1);
    scmInfoRepository.setScmInfo(FILE_REF, Changeset.newChangesetBuilder().setAuthor("john").setDate(123456789L).setRevision("rev-1").build());
    underTest.execute();
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    assertThat(fileSourceDto.getRevision()).isEqualTo("rev-1");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Aggregations

FileSourceDto (org.sonar.db.source.FileSourceDto)24 Test (org.junit.Test)19 DbFileSources (org.sonar.db.protobuf.DbFileSources)8 CoverageDetail (org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail)2 CheckForNull (javax.annotation.CheckForNull)1 Before (org.junit.Before)1 SourceLinesHashesComputer (org.sonar.core.hash.SourceLinesHashesComputer)1 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)1 Duplicate (org.sonar.server.computation.task.projectanalysis.duplication.Duplicate)1 Duplication (org.sonar.server.computation.task.projectanalysis.duplication.Duplication)1 InnerDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate)1 TextBlock (org.sonar.server.computation.task.projectanalysis.duplication.TextBlock)1 File (org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File)1