Search in sources :

Example 1 with Changelog

use of org.sonarqube.ws.Common.Changelog 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 2 with Changelog

use of org.sonarqube.ws.Common.Changelog 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 3 with Changelog

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

Aggregations

UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 Test (org.junit.Test)3 FieldDiffs (org.sonar.core.issue.FieldDiffs)3 IssueDto (org.sonar.db.issue.IssueDto)3 FormattingContext (org.sonar.server.issue.IssueChangeWSSupport.FormattingContext)3 Changelog (org.sonarqube.ws.Common.Changelog)3 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)2 UserDto (org.sonar.db.user.UserDto)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singleton (java.util.Collections.singleton)1 Date (java.util.Date)1 List (java.util.List)1 Random (java.util.Random)1