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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations