Search in sources :

Example 21 with FileSourceDto

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

the class PersistFileSourcesStepTest method not_update_sources_when_nothing_has_changed.

@Test
public void not_update_sources_when_nothing_has_changed() {
    // Existing sources
    long past = 150000L;
    String srcHash = "137f72c3708c6bd0de00a0e5a69c699b";
    String lineHashes = "137f72c3708c6bd0de00a0e5a69c699b";
    String dataHash = "29f25900140c94db38035128cb6de6a2";
    dbClient.fileSourceDao().insert(dbTester.getSession(), new FileSourceDto().setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setSrcHash(srcHash).setLineHashes(lineHashes).setDataHash(dataHash).setSourceData(DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setLine(1).setSource("line1").build()).build()).setCreatedAt(past).setUpdatedAt(past));
    dbTester.getSession().commit();
    // Sources from the report
    initBasicReport(1);
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    assertThat(fileSourceDto.getSrcHash()).isEqualTo(srcHash);
    assertThat(fileSourceDto.getLineHashes()).isEqualTo(lineHashes);
    assertThat(fileSourceDto.getDataHash()).isEqualTo(dataHash);
    assertThat(fileSourceDto.getCreatedAt()).isEqualTo(past);
    assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(past);
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 22 with FileSourceDto

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

the class PersistFileSourcesStepTest method persist_highlighting.

@Test
public void persist_highlighting() {
    initBasicReport(1);
    reportReader.putSyntaxHighlighting(FILE_REF, newArrayList(ScannerReport.SyntaxHighlightingRule.newBuilder().setRange(ScannerReport.TextRange.newBuilder().setStartLine(1).setEndLine(1).setStartOffset(2).setEndOffset(4).build()).setType(HighlightingType.ANNOTATION).build()));
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    DbFileSources.Data data = fileSourceDto.getSourceData();
    assertThat(data.getLinesList()).hasSize(1);
    assertThat(data.getLines(0).getHighlighting()).isEqualTo("2,4,a");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) Test(org.junit.Test)

Example 23 with FileSourceDto

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

the class PersistFileSourcesStepTest method persist_source_hashes.

@Test
public void persist_source_hashes() {
    initBasicReport(2);
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, "FILE");
    assertThat(fileSourceDto.getLineHashes()).isEqualTo("137f72c3708c6bd0de00a0e5a69c699b\ne6251bcf1a7dc3ba5e7933e325bbe605");
    assertThat(fileSourceDto.getSrcHash()).isEqualTo("ee5a58024a155466b43bc559d953e018");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 24 with FileSourceDto

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

the class PersistFileSourcesStepTest method persist_duplication.

@Test
public void persist_duplication() {
    initBasicReport(1);
    duplicationRepository.add(FILE_REF, new Duplication(new TextBlock(1, 2), Arrays.<Duplicate>asList(new InnerDuplicate(new TextBlock(3, 4)))));
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    DbFileSources.Data data = fileSourceDto.getSourceData();
    assertThat(data.getLinesList()).hasSize(1);
    assertThat(data.getLines(0).getDuplicationList()).hasSize(1);
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Duplication(org.sonar.server.computation.task.projectanalysis.duplication.Duplication) InnerDuplicate(org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate) Duplicate(org.sonar.server.computation.task.projectanalysis.duplication.Duplicate) InnerDuplicate(org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate) DbFileSources(org.sonar.db.protobuf.DbFileSources) TextBlock(org.sonar.server.computation.task.projectanalysis.duplication.TextBlock) 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