Search in sources :

Example 46 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() {
    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();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 47 with FileSourceDto

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();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 48 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() {
    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();
}
Also used : Arrays(java.util.Arrays) DbFileSources(org.sonar.db.protobuf.DbFileSources) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) DbSession(org.sonar.db.DbSession) Uuids(org.sonar.core.util.Uuids) ComputationStep(org.sonar.ce.task.step.ComputationStep) LineHashVersion(org.sonar.db.source.LineHashVersion) Before(org.junit.Before) Component(org.sonar.ce.task.projectanalysis.component.Component) DbTester(org.sonar.db.DbTester) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) System2(org.sonar.api.utils.System2) FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SequenceUuidFactory(org.sonar.core.util.SequenceUuidFactory) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) DbClient(org.sonar.db.DbClient) List(java.util.List) Rule(org.junit.Rule) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TreeRootHolderRule(org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 49 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().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();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 50 with FileSourceDto

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();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Aggregations

FileSourceDto (org.sonar.db.source.FileSourceDto)58 Test (org.junit.Test)46 DbFileSources (org.sonar.db.protobuf.DbFileSources)19 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Changeset (org.sonar.ce.task.projectanalysis.scm.Changeset)5 ComponentDto (org.sonar.db.component.ComponentDto)5 Before (org.junit.Before)3 DbSession (org.sonar.db.DbSession)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 DigestUtils (org.apache.commons.codec.digest.DigestUtils)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 Mockito (org.mockito.Mockito)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2