use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_with_Load_COMMENTS_loads_only_comments.
@Test
public void newFormattingContext_with_Load_COMMENTS_loads_only_comments() {
IssueDto issue = dbTester.issues().insertIssue();
List<IssueChangeDto> comments = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> newComment(issue).setKey("comment_" + i)).collect(Collectors.toList());
List<IssueChangeDto> fieldChanges = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("f_change_" + i, null, null).toEncodedString())).collect(Collectors.toList());
insertInRandomOrder(comments, fieldChanges);
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), Load.COMMENTS);
assertThat(formattingContext.getComments(issue)).extracting(IssueChangeDto::getKey).containsExactlyInAnyOrder(comments.stream().map(IssueChangeDto::getKey).toArray(String[]::new));
assertThat(formattingContext.getChanges(issue)).isEmpty();
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method formatChangelog_returns_empty_if_context_has_no_changeLog_for_specified_IssueDto.
@Test
@UseDataProvider("loadAllOrChangelog")
public void formatChangelog_returns_empty_if_context_has_no_changeLog_for_specified_IssueDto(Load load) {
IssueDto issue1 = dbTester.issues().insertIssue();
IssueDto issue2 = dbTester.issues().insertIssue();
List<IssueChangeDto> comments = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> newComment(issue1).setKey("comment_" + i)).collect(Collectors.toList());
List<IssueChangeDto> fieldChanges = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> newFieldChange(issue1).setChangeData(new FieldDiffs().setDiff("f_change_" + i, null, null).toEncodedString())).collect(Collectors.toList());
insertInRandomOrder(comments, fieldChanges);
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue1), Load.CHANGE_LOG);
assertThat(underTest.formatChangelog(issue2, formattingContext)).isEmpty();
assertThat(underTest.formatChangelog(issue1, formattingContext)).isNotEmpty();
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method formatChangelog_returns_field_diff_details.
@Test
@UseDataProvider("loadAllOrChangelog")
public void formatChangelog_returns_field_diff_details(Load load) {
IssueDto issue1 = dbTester.issues().insertIssue();
int createdAt = 2_333_999;
IssueChangeDto issueChangeDto = dbTester.issues().insertChange(newFieldChange(issue1).setIssueChangeCreationDate(createdAt).setChangeData(new FieldDiffs().setDiff("f_change_1", "a", "b").setDiff("f_change_2", "c", null).setDiff("f_change_3", null, null).setDiff("f_change_4", null, "e").toEncodedString()));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue1), load);
List<Changelog> wsChangelogList = underTest.formatChangelog(issue1, formattingContext).collect(Collectors.toList());
assertThat(wsChangelogList).hasSize(1);
Changelog wsChangelog = wsChangelogList.iterator().next();
assertThat(wsChangelog.getCreationDate()).isEqualTo(formatDateTime(createdAt));
assertThat(wsChangelog.getDiffsList()).hasSize(4);
assertThat(wsChangelog.getDiffsList().get(0).getKey()).isEqualTo("f_change_1");
assertThat(wsChangelog.getDiffsList().get(0).getOldValue()).isEqualTo("a");
assertThat(wsChangelog.getDiffsList().get(0).getNewValue()).isEqualTo("b");
assertThat(wsChangelog.getDiffsList().get(1).getKey()).isEqualTo("f_change_2");
assertThat(wsChangelog.getDiffsList().get(1).getOldValue()).isEqualTo("c");
assertThat(wsChangelog.getDiffsList().get(1).hasNewValue()).isFalse();
assertThat(wsChangelog.getDiffsList().get(2).getKey()).isEqualTo("f_change_3");
assertThat(wsChangelog.getDiffsList().get(2).hasOldValue()).isFalse();
assertThat(wsChangelog.getDiffsList().get(2).hasNewValue()).isFalse();
assertThat(wsChangelog.getDiffsList().get(3).getKey()).isEqualTo("f_change_4");
assertThat(wsChangelog.getDiffsList().get(3).hasOldValue()).isFalse();
assertThat(wsChangelog.getDiffsList().get(3).getNewValue()).isEqualTo("e");
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class SetTagsActionTest method insert_entry_in_changelog_when_setting_tags.
@Test
public void insert_entry_in_changelog_when_setting_tags() {
IssueDto issueDto = insertIssueForPublicProject(i -> i.setTags(singletonList("old-tag")));
logIn(issueDto);
call(issueDto.getKey(), "new-tag");
List<FieldDiffs> fieldDiffs = dbClient.issueChangeDao().selectChangelogByIssue(db.getSession(), issueDto.getKey());
assertThat(fieldDiffs).hasSize(1);
assertThat(fieldDiffs.get(0).diffs()).hasSize(1);
assertThat(fieldDiffs.get(0).diffs().get("tags").oldValue()).isEqualTo("old-tag");
assertThat(fieldDiffs.get(0).diffs().get("tags").newValue()).isEqualTo("new-tag");
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class ChangelogActionTest method return_changelog_when_no_old_value.
@Test
public void return_changelog_when_no_old_value() {
UserDto user = insertUser();
IssueDto issueDto = insertNewIssue();
userSession.logIn("john").addProjectPermission(USER, project, file);
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", null, "BLOCKER").setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
assertThat(result.getChangelogList()).hasSize(1);
assertThat(result.getChangelogList().get(0).getDiffsList().get(0).hasOldValue()).isFalse();
}
Aggregations