use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_with_load_COMMENTS_loads_users_of_comments.
@Test
public void newFormattingContext_with_load_COMMENTS_loads_users_of_comments() {
IssueDto issue = dbTester.issues().insertIssue();
UserDto user1 = dbTester.users().insertUser();
UserDto user2 = dbTester.users().insertUser();
UserDto user3 = dbTester.users().insertUser();
String uuid = randomAlphabetic(30);
IssueChangeDto issueChangeUser1 = newComment(issue).setUserUuid(user1.getUuid());
IssueChangeDto issueChangeUser2a = newComment(issue).setUserUuid(user2.getUuid());
IssueChangeDto issueChangeUser2b = newComment(issue).setUserUuid(user2.getUuid());
IssueChangeDto issueChangeNonExistingUser = newComment(issue).setUserUuid(uuid);
insertInRandomOrder(Arrays.asList(issueChangeUser1, issueChangeUser2a, issueChangeUser2b, issueChangeNonExistingUser));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), Load.COMMENTS);
assertThat(formattingContext.getUsers()).extracting(UserDto::getUuid).containsExactlyInAnyOrder(user1.getUuid(), user2.getUuid());
assertThat(formattingContext.getUserByUuid(user1.getUuid())).isNotEmpty();
assertThat(formattingContext.getUserByUuid(user2.getUuid())).isNotEmpty();
assertThat(formattingContext.getUserByUuid(user3.getUuid())).isEmpty();
assertThat(formattingContext.getUserByUuid(uuid)).isEmpty();
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method formatChangelog_returns_no_avatar_if_email_is_not_set.
@Test
@UseDataProvider("loadAllOrChangelog")
public void formatChangelog_returns_no_avatar_if_email_is_not_set(Load load) {
IssueDto issue1 = dbTester.issues().insertIssue();
UserDto user1 = dbTester.users().insertUser(t -> t.setEmail(null));
dbTester.issues().insertChange(newFieldChange(issue1).setUserUuid(user1.getUuid()).setChangeData(new FieldDiffs().setDiff("f_change_1", "a", "b").toEncodedString()));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue1), load);
List<Changelog> wsChangelogList = underTest.formatChangelog(issue1, formattingContext).collect(Collectors.toList());
assertThat(wsChangelogList).hasSize(1);
assertThat(wsChangelogList.iterator().next().hasAvatar()).isFalse();
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_comments_with_userUuid_are_not_updatable_if_no_user_is_logged_in.
@Test
@UseDataProvider("loadAllOrComments")
public void newFormattingContext_comments_with_userUuid_are_not_updatable_if_no_user_is_logged_in(Load load) {
IssueDto issue = dbTester.issues().insertIssue();
UserDto user1 = dbTester.users().insertUser();
UserDto user2 = dbTester.users().insertUser();
String uuid = randomAlphabetic(30);
IssueChangeDto issueChangeUser1 = newComment(issue).setUserUuid(user1.getUuid());
IssueChangeDto issueChangeUser2 = newComment(issue).setUserUuid(user2.getUuid());
IssueChangeDto issueChangeUserUnknown = newComment(issue).setUserUuid(uuid);
insertInRandomOrder(Arrays.asList(issueChangeUser1, issueChangeUser2, issueChangeUserUnknown));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), load);
assertThat(formattingContext.isUpdatableComment(issueChangeUser1)).isFalse();
assertThat(formattingContext.isUpdatableComment(issueChangeUser2)).isFalse();
assertThat(formattingContext.isUpdatableComment(issueChangeUserUnknown)).isFalse();
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method formatChangelog_returns_user_details_if_exists.
@Test
@UseDataProvider("loadAllOrChangelog")
public void formatChangelog_returns_user_details_if_exists(Load load) {
IssueDto issue1 = dbTester.issues().insertIssue();
UserDto user1 = dbTester.users().insertUser();
UserDto user2 = dbTester.users().insertUser(t -> t.setActive(false));
String uuid = randomAlphabetic(22);
dbTester.issues().insertChange(newFieldChange(issue1).setUserUuid(user1.getUuid()).setChangeData(new FieldDiffs().setDiff("f_change_1", "a", "b").toEncodedString()));
dbTester.issues().insertChange(newFieldChange(issue1).setUserUuid(uuid).setChangeData(new FieldDiffs().setDiff("f_change_2", "a", "b").toEncodedString()));
dbTester.issues().insertChange(newFieldChange(issue1).setUserUuid(user2.getUuid()).setChangeData(new FieldDiffs().setDiff("f_change_3", "a", "b").toEncodedString()));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue1), load);
List<Changelog> wsChangelogList = underTest.formatChangelog(issue1, formattingContext).collect(Collectors.toList());
assertThat(wsChangelogList).extracting(Changelog::hasUser, t -> t.getDiffsList().iterator().next().getKey()).containsExactlyInAnyOrder(tuple(true, "f_change_1"), tuple(false, "f_change_2"), tuple(true, "f_change_3"));
assertThat(wsChangelogList.stream().filter(Changelog::hasUser)).extracting(Changelog::getUser, Changelog::getUserName, Changelog::getIsUserActive, Changelog::getAvatar).containsExactlyInAnyOrder(tuple(user1.getLogin(), user1.getName(), true, avatarResolver.create(user1)), tuple(user2.getLogin(), user2.getName(), false, avatarResolver.create(user2)));
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_with_Load_ALL_loads_changelog_and_comments.
@Test
public void newFormattingContext_with_Load_ALL_loads_changelog_and_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.ALL);
assertThat(formattingContext.getComments(issue)).extracting(IssueChangeDto::getKey).containsExactlyInAnyOrder(comments.stream().map(IssueChangeDto::getKey).toArray(String[]::new));
assertThat(formattingContext.getComments(issue)).extracting(IssueChangeDto::getKey).containsExactlyInAnyOrder(comments.stream().map(IssueChangeDto::getKey).toArray(String[]::new));
}
Aggregations