Search in sources :

Example 11 with Changeset

use of org.sonar.ce.task.projectanalysis.scm.Changeset 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 12 with Changeset

use of org.sonar.ce.task.projectanalysis.scm.Changeset in project sonarqube by SonarSource.

the class LineReadersImplTest method getLatestChangeWithRevision_delegates_to_ScmLineReader_if_non_null.

@Test
public void getLatestChangeWithRevision_delegates_to_ScmLineReader_if_non_null() {
    ScmLineReader scmLineReader = mock(ScmLineReader.class);
    Changeset changeset = Changeset.newChangesetBuilder().setDate(0L).build();
    when(scmLineReader.getLatestChangeWithRevision()).thenReturn(changeset);
    SourceLineReadersFactory.LineReaders lineReaders = new SourceLineReadersFactory.LineReadersImpl(Collections.emptyList(), scmLineReader, Collections.emptyList());
    assertThat(lineReaders.getLatestChangeWithRevision()).isEqualTo(changeset);
    verify(scmLineReader).getLatestChangeWithRevision();
    verifyNoMoreInteractions(scmLineReader);
}
Also used : ScmLineReader(org.sonar.ce.task.projectanalysis.source.linereader.ScmLineReader) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) Test(org.junit.Test)

Example 13 with Changeset

use of org.sonar.ce.task.projectanalysis.scm.Changeset in project sonarqube by SonarSource.

the class ScmLineReaderTest method getLatestChange_returns_changeset_with_highest_date_of_read_lines.

@Test
public void getLatestChange_returns_changeset_with_highest_date_of_read_lines() {
    long refDate = 123_456_789L;
    Changeset changeset0 = Changeset.newChangesetBuilder().setDate(refDate - 636).setRevision("rev-1").build();
    Changeset changeset1 = Changeset.newChangesetBuilder().setDate(refDate + 1).setRevision("rev-2").build();
    Changeset changeset2 = Changeset.newChangesetBuilder().setDate(refDate + 2).build();
    ScmInfo scmInfo = new ScmInfoImpl(setup8LinesChangeset(changeset0, changeset1, changeset2));
    ScmLineReader lineScm = new ScmLineReader(scmInfo);
    // before any line is read, the latest changes are null
    assertThat(lineScm.getLatestChange()).isNull();
    assertThat(lineScm.getLatestChangeWithRevision()).isNull();
    // read line 1, only one changeset => 0
    readLineAndAssertLatestChanges(lineScm, 1, changeset0, changeset0);
    // read line 2, latest changeset is 1
    readLineAndAssertLatestChanges(lineScm, 2, changeset1, changeset1);
    // read line 3, latest changeset is still 1
    readLineAndAssertLatestChanges(lineScm, 3, changeset1, changeset1);
    // read line 4, latest changeset is now 2
    readLineAndAssertLatestChanges(lineScm, 4, changeset2, changeset1);
    // read line 5 to 8, there will never be any changeset more recent than 2
    readLineAndAssertLatestChanges(lineScm, 5, changeset2, changeset1);
    readLineAndAssertLatestChanges(lineScm, 6, changeset2, changeset1);
    readLineAndAssertLatestChanges(lineScm, 7, changeset2, changeset1);
    readLineAndAssertLatestChanges(lineScm, 8, changeset2, changeset1);
}
Also used : ScmInfoImpl(org.sonar.ce.task.projectanalysis.scm.ScmInfoImpl) ScmInfo(org.sonar.ce.task.projectanalysis.scm.ScmInfo) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) Test(org.junit.Test)

Example 14 with Changeset

use of org.sonar.ce.task.projectanalysis.scm.Changeset in project sonarqube by SonarSource.

the class IssueCreationDateCalculatorTest method setDateOfChangetsetAtLine.

private static void setDateOfChangetsetAtLine(ScmInfo scmInfo, int line, long date) {
    Changeset changeset = Changeset.newChangesetBuilder().setDate(date).setRevision("1").build();
    when(scmInfo.hasChangesetForLine(line)).thenReturn(true);
    when(scmInfo.getChangesetForLine(line)).thenReturn(changeset);
}
Also used : Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset)

Example 15 with Changeset

use of org.sonar.ce.task.projectanalysis.scm.Changeset in project sonarqube by SonarSource.

the class IssueCreationDateCalculatorTest method setDateOfLatestScmChangeset.

private static void setDateOfLatestScmChangeset(ScmInfo scmInfo, long date) {
    Changeset changeset = Changeset.newChangesetBuilder().setDate(date).setRevision("1").build();
    when(scmInfo.getLatestChangeset()).thenReturn(changeset);
}
Also used : Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset)

Aggregations

Changeset (org.sonar.ce.task.projectanalysis.scm.Changeset)15 Test (org.junit.Test)10 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)4 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)4 FileSourceDto (org.sonar.db.source.FileSourceDto)4 DefaultIssue (org.sonar.core.issue.DefaultIssue)3 DbFileSources (org.sonar.db.protobuf.DbFileSources)3 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Before (org.junit.Before)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 Component (org.sonar.ce.task.projectanalysis.component.Component)2 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)2 ScmInfo (org.sonar.ce.task.projectanalysis.scm.ScmInfo)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1