use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String hotspotKey = request.mandatoryParam(PARAM_HOTSPOT_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto hotspot = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);
Components components = loadComponents(dbSession, hotspot);
Users users = loadUsers(dbSession, hotspot);
RuleDefinitionDto rule = loadRule(dbSession, hotspot);
ShowWsResponse.Builder responseBuilder = ShowWsResponse.newBuilder();
formatHotspot(responseBuilder, hotspot, users);
formatComponents(components, responseBuilder);
formatRule(responseBuilder, rule);
formatTextRange(responseBuilder, hotspot);
formatFlows(dbSession, responseBuilder, hotspot);
FormattingContext formattingContext = formatChangeLogAndComments(dbSession, hotspot, users, components, responseBuilder);
formatUsers(responseBuilder, users, formattingContext);
writeProtobuf(responseBuilder.build(), request, response);
}
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_with_Load_CHANGE_LOG_loads_only_changelog.
@Test
public void newFormattingContext_with_Load_CHANGE_LOG_loads_only_changelog() {
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.CHANGE_LOG);
assertThat(formattingContext.getChanges(issue)).extracting(FieldDiffs::toEncodedString).containsExactlyInAnyOrder(fieldChanges.stream().map(t -> t.toFieldDiffs().toEncodedString()).toArray(String[]::new));
assertThat(formattingContext.getComments(issue)).isEmpty();
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method formatComments_returns_empty_if_context_has_no_comment_for_specified_IssueDto.
@Test
@UseDataProvider("loadAllOrComments")
public void formatComments_returns_empty_if_context_has_no_comment_for_specified_IssueDto(Load load) {
IssueDto issue1 = dbTester.issues().insertIssue();
IssueDto issue2 = dbTester.issues().insertIssue();
IntStream.range(0, 1 + RANDOM.nextInt(22)).forEach(t -> dbTester.issues().insertChange(newComment(issue1)));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue1), load);
assertThat(underTest.formatComments(issue2, Comment.newBuilder(), formattingContext)).isEmpty();
assertThat(underTest.formatComments(issue1, Comment.newBuilder(), formattingContext)).isNotEmpty();
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class ShowActionTest method do_not_duplicate_user_if_author_assignee_ChangeLogComment_user.
@Test
public void do_not_duplicate_user_if_author_assignee_ChangeLogComment_user() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
UserDto author = dbTester.users().insertUser();
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(author.getLogin()).setAssigneeUuid(author.getUuid()));
FormattingContext formattingContext = mockChangelogAndCommentsFormattingContext();
when(formattingContext.getUsers()).thenReturn(ImmutableSet.of(author));
Hotspots.ShowWsResponse response = newRequest(hotspot).executeProtobuf(Hotspots.ShowWsResponse.class);
assertThat(response.getUsersList()).extracting(User::getLogin, User::getName, User::getActive).containsOnly(tuple(author.getLogin(), author.getName(), author.isActive()));
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class ShowActionTest method returns_user_of_users_from_ChangelogAndComments_and_assignee_and_author.
@Test
public void returns_user_of_users_from_ChangelogAndComments_and_assignee_and_author() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
UserDto author = dbTester.users().insertUser();
UserDto assignee = dbTester.users().insertUser();
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(author.getLogin()).setAssigneeUuid(assignee.getUuid()));
FormattingContext formattingContext = mockChangelogAndCommentsFormattingContext();
Set<UserDto> changeLogAndCommentsUsers = IntStream.range(0, 1 + RANDOM.nextInt(14)).mapToObj(i -> UserTesting.newUserDto()).collect(Collectors.toSet());
when(formattingContext.getUsers()).thenReturn(changeLogAndCommentsUsers);
Hotspots.ShowWsResponse response = newRequest(hotspot).executeProtobuf(Hotspots.ShowWsResponse.class);
assertThat(response.getUsersList()).extracting(User::getLogin, User::getName, User::getActive).containsExactlyInAnyOrder(Stream.concat(Stream.of(author, assignee), changeLogAndCommentsUsers.stream()).map(t -> tuple(t.getLogin(), t.getName(), t.isActive())).toArray(Tuple[]::new));
}
Aggregations