use of org.sonar.ce.task.projectanalysis.scm.Changeset in project sonarqube by SonarSource.
the class IssueAssignerTest method assign_to_author_of_the_most_recent_change_in_all_issue_locations.
@Test
public void assign_to_author_of_the_most_recent_change_in_all_issue_locations() {
addScmUser("john", "u1");
addScmUser("jane", "u2");
Changeset commit1 = Changeset.newChangesetBuilder().setAuthor("john").setDate(1_000L).setRevision("rev-1").build();
Changeset commit2 = Changeset.newChangesetBuilder().setAuthor("jane").setDate(2_000L).setRevision("rev-2").build();
scmInfoRepository.setScmInfo(FILE_REF, commit1, commit1, commit2, commit1);
DefaultIssue issue = newIssueOnLines(2, 3, 4);
underTest.onIssue(FILE, issue);
assertThat(issue.authorLogin()).isEqualTo("jane");
assertThat(issue.assignee()).isEqualTo("u2");
}
use of org.sonar.ce.task.projectanalysis.scm.Changeset in project sonarqube by SonarSource.
the class IssueAssignerTest method assign_to_default_assignee_if_no_scm_on_issue_locations.
@Test
public void assign_to_default_assignee_if_no_scm_on_issue_locations() {
addScmUser("john", "John C");
Changeset changeset = Changeset.newChangesetBuilder().setAuthor("john").setDate(123456789L).setRevision("rev-1").build();
scmInfoRepository.setScmInfo(FILE_REF, changeset, changeset);
DefaultIssue issue = newIssueOnLines(3);
underTest.onIssue(FILE, issue);
assertThat(issue.assignee()).isEqualTo("John C");
}
use of org.sonar.ce.task.projectanalysis.scm.Changeset in project sonarqube by SonarSource.
the class IssueAssignerTest method assign_to_last_committer_of_file_if_issue_is_global_to_file.
@Test
public void assign_to_last_committer_of_file_if_issue_is_global_to_file() {
addScmUser("henry", "Henry V");
Changeset changeset1 = Changeset.newChangesetBuilder().setAuthor("john").setDate(1_000L).setRevision("rev-1").build();
// Latest changeset
Changeset changeset2 = Changeset.newChangesetBuilder().setAuthor("henry").setDate(2_000L).setRevision("rev-2").build();
scmInfoRepository.setScmInfo(FILE_REF, changeset1, changeset2, changeset1);
DefaultIssue issue = newIssueOnLines();
underTest.onIssue(FILE, issue);
assertThat(issue.assignee()).isEqualTo("Henry V");
}
use of org.sonar.ce.task.projectanalysis.scm.Changeset in project sonarqube by SonarSource.
the class FileSourceDataComputerTest method compute_builds_data_object_from_lines.
@Test
public void compute_builds_data_object_from_lines() {
int lineCount = 1 + new Random().nextInt(10);
int randomStartPoint = new Random().nextInt(500);
List<String> lines = IntStream.range(0, lineCount).mapToObj(i -> "line" + i).collect(toList());
List<String> expectedLineHashes = IntStream.range(0, 1 + new Random().nextInt(12)).mapToObj(i -> "str_" + i).collect(toList());
Changeset expectedChangeset = Changeset.newChangesetBuilder().setDate((long) new Random().nextInt(9_999)).build();
String expectedSrcHash = computeSrcHash(lines);
CloseableIterator<String> lineIterator = spy(CloseableIterator.from(lines.iterator()));
DbFileSources.Data.Builder expectedLineDataBuilder = DbFileSources.Data.newBuilder();
for (int i = 0; i < lines.size(); i++) {
expectedLineDataBuilder.addLinesBuilder().setSource(lines.get(i)).setLine(i + 1).setScmAuthor("reader_called_" + (randomStartPoint + i));
}
when(sourceLinesRepository.readLines(FILE)).thenReturn(lineIterator);
when(sourceLineReadersFactory.getLineReaders(FILE)).thenReturn(lineReaders);
when(sourceLinesHashRepository.getLineHashesComputerToPersist(FILE)).thenReturn(lineHashesComputer);
when(lineHashesComputer.getResult()).thenReturn(expectedLineHashes);
when(lineReaders.getLatestChangeWithRevision()).thenReturn(expectedChangeset);
// mocked implementation of LineReader.read to ensure changes done by it to the lineBuilder argument actually end
// up in the FileSourceDataComputer.Data object returned
doAnswer(new Answer() {
int i = 0;
@Override
public Object answer(InvocationOnMock invocation) {
DbFileSources.Line.Builder lineBuilder = invocation.getArgument(0);
lineBuilder.setScmAuthor("reader_called_" + (randomStartPoint + i++));
return null;
}
}).when(lineReaders).read(any(), any());
FileSourceDataComputer.Data data = underTest.compute(FILE, fileSourceDataWarnings);
assertThat(data.getLineHashes()).isEqualTo(expectedLineHashes);
assertThat(data.getSrcHash()).isEqualTo(expectedSrcHash);
assertThat(data.getLatestChangeWithRevision()).isSameAs(expectedChangeset);
assertThat(data.getLineData()).isEqualTo(expectedLineDataBuilder.build());
verify(lineIterator).close();
verify(lineReaders).close();
}
use of org.sonar.ce.task.projectanalysis.scm.Changeset 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();
}
Aggregations