Search in sources :

Example 41 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs 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();
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) FieldDiffs(org.sonar.core.issue.FieldDiffs) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto)

Example 42 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs 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();
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) FieldDiffs(org.sonar.core.issue.FieldDiffs) UserDto(org.sonar.db.user.UserDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 43 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs 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();
}
Also used : FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) FieldDiffs(org.sonar.core.issue.FieldDiffs) UserDto(org.sonar.db.user.UserDto) IssueDto(org.sonar.db.issue.IssueDto) Changelog(org.sonarqube.ws.Common.Changelog) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 44 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs 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)));
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) IssueDto(org.sonar.db.issue.IssueDto) UserDto(org.sonar.db.user.UserDto) Markdown(org.sonar.markdown.Markdown) Date(java.util.Date) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) Changelog(org.sonarqube.ws.Common.Changelog) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) TYPE_COMMENT(org.sonar.db.issue.IssueChangeDto.TYPE_COMMENT) ArrayList(java.util.ArrayList) Collections.singleton(java.util.Collections.singleton) Load(org.sonar.server.issue.IssueChangeWSSupport.Load) TYPE_FIELD_CHANGE(org.sonar.db.issue.IssueChangeDto.TYPE_FIELD_CHANGE) ComponentTesting(org.sonar.db.component.ComponentTesting) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) IssueChangeDto(org.sonar.db.issue.IssueChangeDto) ImmutableSet(com.google.common.collect.ImmutableSet) Collections.emptySet(java.util.Collections.emptySet) System2(org.sonar.api.utils.System2) IssueTesting(org.sonar.db.issue.IssueTesting) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Assertions.tuple(org.assertj.core.api.Assertions.tuple) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Collection(java.util.Collection) Test(org.junit.Test) Comment(org.sonarqube.ws.Common.Comment) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) FieldDiffs(org.sonar.core.issue.FieldDiffs) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Collections(java.util.Collections) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) FieldDiffs(org.sonar.core.issue.FieldDiffs) UserDto(org.sonar.db.user.UserDto) IssueDto(org.sonar.db.issue.IssueDto) Changelog(org.sonarqube.ws.Common.Changelog) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 45 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs 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));
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) IssueDto(org.sonar.db.issue.IssueDto) UserDto(org.sonar.db.user.UserDto) Markdown(org.sonar.markdown.Markdown) Date(java.util.Date) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) Changelog(org.sonarqube.ws.Common.Changelog) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) TYPE_COMMENT(org.sonar.db.issue.IssueChangeDto.TYPE_COMMENT) ArrayList(java.util.ArrayList) Collections.singleton(java.util.Collections.singleton) Load(org.sonar.server.issue.IssueChangeWSSupport.Load) TYPE_FIELD_CHANGE(org.sonar.db.issue.IssueChangeDto.TYPE_FIELD_CHANGE) ComponentTesting(org.sonar.db.component.ComponentTesting) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) IssueChangeDto(org.sonar.db.issue.IssueChangeDto) ImmutableSet(com.google.common.collect.ImmutableSet) Collections.emptySet(java.util.Collections.emptySet) System2(org.sonar.api.utils.System2) IssueTesting(org.sonar.db.issue.IssueTesting) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Assertions.tuple(org.assertj.core.api.Assertions.tuple) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Collection(java.util.Collection) Test(org.junit.Test) Comment(org.sonarqube.ws.Common.Comment) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) FieldDiffs(org.sonar.core.issue.FieldDiffs) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Collections(java.util.Collections) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) FieldDiffs(org.sonar.core.issue.FieldDiffs) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Aggregations

FieldDiffs (org.sonar.core.issue.FieldDiffs)57 Test (org.junit.Test)42 IssueDto (org.sonar.db.issue.IssueDto)31 Date (java.util.Date)25 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)18 UserDto (org.sonar.db.user.UserDto)18 DefaultIssue (org.sonar.core.issue.DefaultIssue)12 FormattingContext (org.sonar.server.issue.IssueChangeWSSupport.FormattingContext)12 ChangelogWsResponse (org.sonarqube.ws.Issues.ChangelogWsResponse)12 ComponentDto (org.sonar.db.component.ComponentDto)11 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)9 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)8 DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)8 ArrayList (java.util.ArrayList)6 Random (java.util.Random)6 Changelog (org.sonarqube.ws.Common.Changelog)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)5 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)5 Arrays (java.util.Arrays)5