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() {
List<String> lineHashes = Arrays.asList("137f72c3708c6bd0de00a0e5a69c699b", "e6251bcf1a7dc3ba5e7933e325bbe605");
String sourceHash = "ee5a58024a155466b43bc559d953e018";
setComputedData(DbFileSources.Data.newBuilder().build(), lineHashes, sourceHash, null);
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
assertThat(fileSourceDto.getLineHashes()).containsExactly("137f72c3708c6bd0de00a0e5a69c699b", "e6251bcf1a7dc3ba5e7933e325bbe605");
assertThat(fileSourceDto.getSrcHash()).isEqualTo("ee5a58024a155466b43bc559d953e018");
verify(fileSourceDataWarnings).commitWarnings();
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class PersistFileSourcesStepTest method persist_scm_some_lines.
@Test
public void persist_scm_some_lines() {
DbFileSources.Data dbData = DbFileSources.Data.newBuilder().addAllLines(Arrays.asList(DbFileSources.Line.newBuilder().setScmAuthor("john").setScmDate(123456789L).setScmRevision("rev-1").build(), DbFileSources.Line.newBuilder().setScmDate(223456789L).build(), DbFileSources.Line.newBuilder().build())).build();
setComputedData(dbData);
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
DbFileSources.Data data = fileSourceDto.getSourceData();
assertThat(data.getLinesList()).hasSize(3);
assertThat(data.getLines(0).getScmAuthor()).isEqualTo("john");
assertThat(data.getLines(0).getScmDate()).isEqualTo(123456789L);
assertThat(data.getLines(0).getScmRevision()).isEqualTo("rev-1");
assertThat(data.getLines(1).getScmAuthor()).isEmpty();
assertThat(data.getLines(1).getScmDate()).isEqualTo(223456789L);
assertThat(data.getLines(1).getScmRevision()).isEmpty();
assertThat(data.getLines(2).getScmAuthor()).isEmpty();
assertThat(data.getLines(2).getScmDate()).isZero();
assertThat(data.getLines(2).getScmRevision()).isEmpty();
verify(fileSourceDataWarnings).commitWarnings();
}
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() {
DbFileSources.Data sourceData = DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setLine(1).setSource("line").build()).build();
dbClient.fileSourceDao().insert(dbTester.getSession(), createDto(dto -> dto.setRevision(null)));
dbTester.getSession().commit();
Changeset changeset = Changeset.newChangesetBuilder().setDate(1L).setRevision("revision").build();
setComputedData(sourceData, Collections.singletonList("137f72c3708c6bd0de00a0e5a69c699b"), "29f25900140c94db38035128cb6de6a2", changeset);
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(PAST);
assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW);
assertThat(fileSourceDto.getRevision()).isEqualTo("revision");
verify(fileSourceDataWarnings).commitWarnings();
}
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().setUuid(Uuids.createFast()).setProjectUuid(PROJECT_UUID).setFileUuid(FILE1_UUID).setSrcHash("5b4bd9815cdb17b8ceae19eb1810c34c").setLineHashes(Collections.singletonList("6438c669e0d0de98e6929c2cc0fac474")).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();
DbFileSources.Data newSourceData = DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setLine(1).setSource("old line").setScmDate(123456789L).setScmRevision("rev-1").setScmAuthor("john").build()).build();
Changeset changeset = Changeset.newChangesetBuilder().setDate(1L).setRevision("rev-1").build();
setComputedData(newSourceData, Collections.singletonList("6438c669e0d0de98e6929c2cc0fac474"), "5b4bd9815cdb17b8ceae19eb1810c34c", changeset);
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(past);
assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW);
assertThat(fileSourceDto.getRevision()).isEqualTo("rev-1");
verify(fileSourceDataWarnings).commitWarnings();
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class PersistFileSourcesStepTest method persist_coverage.
@Test
public void persist_coverage() {
DbFileSources.Data dbData = DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setConditions(10).setCoveredConditions(2).setLineHits(1).setLine(1).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