use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_comments_without_userUuid_or_with_unknown_userUuid_are_not_updatable.
@Test
@UseDataProvider("loadAllOrComments")
public void newFormattingContext_comments_without_userUuid_or_with_unknown_userUuid_are_not_updatable(Load load) {
IssueDto issue = dbTester.issues().insertIssue();
UserDto user1 = dbTester.users().insertUser();
String uuid = randomAlphabetic(30);
IssueChangeDto issueChangeUser1 = newComment(issue);
IssueChangeDto issueChangeUserUnknown = newComment(issue).setUserUuid(uuid);
insertInRandomOrder(Arrays.asList(issueChangeUser1, issueChangeUserUnknown));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), load);
assertThat(formattingContext.isUpdatableComment(issueChangeUser1)).isFalse();
assertThat(formattingContext.isUpdatableComment(issueChangeUserUnknown)).isFalse();
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_does_not_load_preloaded_files_from_DB.
@Test
@UseDataProvider("loadAllOrChangelog")
public void newFormattingContext_does_not_load_preloaded_files_from_DB(Load load) {
IssueDto issue = dbTester.issues().insertIssue();
ComponentDto file1 = insertFile();
ComponentDto file2 = insertFile();
ComponentDto file3 = insertFile();
ComponentDto file4 = insertFile();
IssueChangeDto fileChangeFile1 = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", file1.uuid(), null).toEncodedString());
IssueChangeDto fileChangeFile2 = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", file2.uuid(), null).toEncodedString());
IssueChangeDto fileChangeFile3 = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", null, file3.uuid()).toEncodedString());
IssueChangeDto fileChangeFile4 = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", file4.uuid(), file4.uuid()).toEncodedString());
insertInRandomOrder(Arrays.asList(fileChangeFile1, fileChangeFile2, fileChangeFile3, fileChangeFile4));
file1.setName("preloaded_name" + file1.uuid());
file2.setName("preloaded_name" + file2.uuid());
file3.setName("preloaded_name" + file3.uuid());
file4.setName("preloaded_name" + file4.uuid());
// no files are preloaded
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), load, emptySet(), emptySet());
assertThat(formattingContext.getFileByUuid(file1.uuid()).get().name()).isNotEqualTo(file1.name());
assertThat(formattingContext.getFileByUuid(file2.uuid()).get().name()).isNotEqualTo(file2.name());
assertThat(formattingContext.getFileByUuid(file3.uuid()).get().name()).isNotEqualTo(file3.name());
assertThat(formattingContext.getFileByUuid(file4.uuid()).get().name()).isNotEqualTo(file4.name());
// some files are preloaded
formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), load, emptySet(), ImmutableSet.of(file2, file3));
assertThat(formattingContext.getFileByUuid(file1.uuid()).get().name()).isNotEqualTo(file1.name());
assertThat(formattingContext.getFileByUuid(file2.uuid()).get().name()).isEqualTo(file2.name());
assertThat(formattingContext.getFileByUuid(file3.uuid()).get().name()).isEqualTo(file3.name());
assertThat(formattingContext.getFileByUuid(file4.uuid()).get().name()).isNotEqualTo(file4.name());
// all files are preloaded
formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), load, emptySet(), ImmutableSet.of(file1, file2, file3, file4));
assertThat(formattingContext.getFileByUuid(file1.uuid()).get().name()).isEqualTo(file1.name());
assertThat(formattingContext.getFileByUuid(file2.uuid()).get().name()).isEqualTo(file2.name());
assertThat(formattingContext.getFileByUuid(file3.uuid()).get().name()).isEqualTo(file3.name());
assertThat(formattingContext.getFileByUuid(file4.uuid()).get().name()).isEqualTo(file4.name());
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class ShowAction method formatChangeLogAndComments.
private FormattingContext formatChangeLogAndComments(DbSession dbSession, IssueDto hotspot, Users users, Components components, ShowWsResponse.Builder responseBuilder) {
Set<UserDto> preloadedUsers = Stream.of(users.getAssignee(), users.getAuthor()).filter(Optional::isPresent).map(Optional::get).collect(toSet());
Set<ComponentDto> preloadedComponents = ImmutableSet.of(components.project, components.component);
FormattingContext formattingContext = issueChangeSupport.newFormattingContext(dbSession, singleton(hotspot), Load.ALL, preloadedUsers, preloadedComponents);
issueChangeSupport.formatChangelog(hotspot, formattingContext).forEach(responseBuilder::addChangelog);
issueChangeSupport.formatComments(hotspot, Common.Comment.newBuilder(), formattingContext).forEach(responseBuilder::addComment);
return formattingContext;
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_loads_files_of_file_fieldChanges.
private void newFormattingContext_loads_files_of_file_fieldChanges(Load load) {
IssueDto issue = dbTester.issues().insertIssue();
ComponentDto file1 = insertFile();
ComponentDto file2 = insertFile();
ComponentDto file3 = insertFile();
ComponentDto file4 = insertFile();
ComponentDto file5 = insertFile();
String uuid = randomAlphabetic(30);
IssueChangeDto fileChangeFile1 = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", file1.uuid(), null).toEncodedString());
IssueChangeDto fileChangeFile2 = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", file2.uuid(), null).toEncodedString());
IssueChangeDto fileChangeFile3 = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", null, file3.uuid()).toEncodedString());
IssueChangeDto fileChangeFile4 = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", file4.uuid(), file4.uuid()).toEncodedString());
IssueChangeDto fileChangeNotExistingFile = newFieldChange(issue).setChangeData(new FieldDiffs().setDiff("file", uuid, uuid).toEncodedString());
insertInRandomOrder(Arrays.asList(fileChangeFile1, fileChangeFile2, fileChangeFile3, fileChangeFile4, fileChangeNotExistingFile));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), load);
assertThat(formattingContext.getFileByUuid(file1.uuid())).isNotEmpty();
assertThat(formattingContext.getFileByUuid(file2.uuid())).isNotEmpty();
assertThat(formattingContext.getFileByUuid(file3.uuid())).isNotEmpty();
assertThat(formattingContext.getFileByUuid(file4.uuid())).isNotEmpty();
assertThat(formattingContext.getFileByUuid(file5.uuid())).isEmpty();
assertThat(formattingContext.getFileByUuid(uuid)).isEmpty();
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_with_load_ALL_loads_users_of_fieldChanges_and_comments.
@Test
public void newFormattingContext_with_load_ALL_loads_users_of_fieldChanges_and_comments() {
IssueDto issue = dbTester.issues().insertIssue();
UserDto user1 = dbTester.users().insertUser();
UserDto user2 = dbTester.users().insertUser();
UserDto user3 = dbTester.users().insertUser();
UserDto user4 = 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);
IssueChangeDto fieldChangeUser1 = newFieldChange(issue).setUserUuid(user1.getUuid()).setChangeData(new FieldDiffs().setDiff("f_change_user_1", null, null).toEncodedString());
IssueChangeDto fieldChangeUser4 = newFieldChange(issue).setUserUuid(user4.getUuid()).setChangeData(new FieldDiffs().setDiff("f_change_user_4", null, null).toEncodedString());
IssueChangeDto fieldChangeNonExistingUser = newFieldChange(issue).setUserUuid(uuid).setChangeData(new FieldDiffs().setDiff("f_change_user_unknown", null, null).toEncodedString());
insertInRandomOrder(Arrays.asList(issueChangeUser1, issueChangeUser2a, issueChangeUser2b, issueChangeNonExistingUser), Arrays.asList(fieldChangeUser1, fieldChangeUser4, fieldChangeNonExistingUser));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), Load.ALL);
assertThat(formattingContext.getUsers()).extracting(UserDto::getUuid).containsExactlyInAnyOrder(user1.getUuid(), user2.getUuid(), user4.getUuid());
assertThat(formattingContext.getUserByUuid(user1.getUuid())).isNotEmpty();
assertThat(formattingContext.getUserByUuid(user2.getUuid())).isNotEmpty();
assertThat(formattingContext.getUserByUuid(user3.getUuid())).isEmpty();
assertThat(formattingContext.getUserByUuid(user4.getUuid())).isNotEmpty();
assertThat(formattingContext.getUserByUuid(uuid)).isEmpty();
}
Aggregations