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);
}
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");
}
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");
}
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);
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class PersistFileSourcesStepTest method persist_duplication.
@Test
public void persist_duplication() {
DbFileSources.Data dbData = DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().addDuplication(2).build()).build();
setComputedData(dbData);
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
assertThat(fileSourceDto.getSourceData()).isEqualTo(dbData);
verify(fileSourceDataWarnings).commitWarnings();
}
Aggregations