use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext 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.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method newFormattingContext_sorts_changes.
@Test
public void newFormattingContext_sorts_changes() {
IssueDto issue = dbTester.issues().insertIssue();
insertFieldChange(issue, c -> c.setCreatedAt(3L));
insertFieldChange(issue, c -> c.setIssueChangeCreationDate(1L));
insertFieldChange(issue, c -> c.setCreatedAt(2L));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), Load.CHANGE_LOG);
assertThat(formattingContext.getChanges(issue)).extracting(FieldDiffs::creationDate).containsExactly(new Date(1L), new Date(2L), new Date(3L));
}
use of org.sonar.server.issue.IssueChangeWSSupport.FormattingContext 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.server.issue.IssueChangeWSSupport.FormattingContext 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.server.issue.IssueChangeWSSupport.FormattingContext in project sonarqube by SonarSource.
the class ShowActionTest method returns_user_details_of_users_from_ChangelogAndComments.
@Test
public void returns_user_details_of_users_from_ChangelogAndComments() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
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(changeLogAndCommentsUsers.stream().map(t -> tuple(t.getLogin(), t.getName(), t.isActive())).toArray(Tuple[]::new));
}
Aggregations