Search in sources :

Example 46 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs 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();
}
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)

Example 47 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs 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();
}
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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 48 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs 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)

Example 49 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.

the class SetTagsActionTest method insert_entry_in_changelog_when_setting_tags.

@Test
public void insert_entry_in_changelog_when_setting_tags() {
    IssueDto issueDto = insertIssueForPublicProject(i -> i.setTags(singletonList("old-tag")));
    logIn(issueDto);
    call(issueDto.getKey(), "new-tag");
    List<FieldDiffs> fieldDiffs = dbClient.issueChangeDao().selectChangelogByIssue(db.getSession(), issueDto.getKey());
    assertThat(fieldDiffs).hasSize(1);
    assertThat(fieldDiffs.get(0).diffs()).hasSize(1);
    assertThat(fieldDiffs.get(0).diffs().get("tags").oldValue()).isEqualTo("old-tag");
    assertThat(fieldDiffs.get(0).diffs().get("tags").newValue()).isEqualTo("new-tag");
}
Also used : FieldDiffs(org.sonar.core.issue.FieldDiffs) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 50 with FieldDiffs

use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.

the class ChangelogActionTest method return_changelog_when_no_old_value.

@Test
public void return_changelog_when_no_old_value() {
    UserDto user = insertUser();
    IssueDto issueDto = insertNewIssue();
    userSession.logIn("john").addProjectPermission(USER, project, file);
    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", null, "BLOCKER").setCreationDate(new Date()));
    ChangelogWsResponse result = call(issueDto.getKey());
    assertThat(result.getChangelogList()).hasSize(1);
    assertThat(result.getChangelogList().get(0).getDiffsList().get(0).hasOldValue()).isFalse();
}
Also used : ChangelogWsResponse(org.sonarqube.ws.Issues.ChangelogWsResponse) FieldDiffs(org.sonar.core.issue.FieldDiffs) UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) IssueDto(org.sonar.db.issue.IssueDto) Date(java.util.Date) 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