Search in sources :

Example 16 with FieldDiffs

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

the class IssueChangeDtoTest method create_from_diff.

@Test
public void create_from_diff() {
    FieldDiffs diffs = new FieldDiffs();
    diffs.setDiff("severity", "INFO", "BLOCKER");
    diffs.setUserLogin("emmerik");
    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
    assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER");
    assertThat(dto.getChangeType()).isEqualTo("diff");
    assertThat(dto.getCreatedAt()).isNotNull();
    assertThat(dto.getUpdatedAt()).isNotNull();
    assertThat(dto.getIssueChangeCreationDate()).isNull();
    assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
    assertThat(dto.getUserLogin()).isEqualTo("emmerik");
}
Also used : FieldDiffs(org.sonar.core.issue.FieldDiffs) Test(org.junit.Test)

Example 17 with FieldDiffs

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

the class IssueChangeDtoTest method create_from_diff_with_created_at.

@Test
public void create_from_diff_with_created_at() {
    FieldDiffs diffs = new FieldDiffs();
    diffs.setDiff("severity", "INFO", "BLOCKER");
    diffs.setUserLogin("emmerik");
    diffs.setCreationDate(parseDate("2015-01-13"));
    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
    assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
}
Also used : FieldDiffs(org.sonar.core.issue.FieldDiffs) Test(org.junit.Test)

Example 18 with FieldDiffs

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

the class PersistIssuesStep method insertChanges.

private static void insertChanges(IssueChangeMapper mapper, DefaultIssue issue) {
    for (IssueComment comment : issue.comments()) {
        DefaultIssueComment c = (DefaultIssueComment) comment;
        if (c.isNew()) {
            IssueChangeDto changeDto = IssueChangeDto.of(c);
            mapper.insert(changeDto);
        }
    }
    FieldDiffs diffs = issue.currentChange();
    if (!issue.isNew() && diffs != null) {
        IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), diffs);
        mapper.insert(changeDto);
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) FieldDiffs(org.sonar.core.issue.FieldDiffs) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) IssueComment(org.sonar.api.issue.IssueComment) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment)

Example 19 with FieldDiffs

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

the class IssueStorage method insertChanges.

private void insertChanges(IssueChangeMapper mapper, DefaultIssue issue) {
    for (IssueComment comment : issue.comments()) {
        DefaultIssueComment c = (DefaultIssueComment) comment;
        if (c.isNew()) {
            IssueChangeDto changeDto = IssueChangeDto.of(c);
            mapper.insert(changeDto);
        }
    }
    FieldDiffs diffs = issue.currentChange();
    if (!issue.isNew() && diffs != null) {
        IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), diffs);
        mapper.insert(changeDto);
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) FieldDiffs(org.sonar.core.issue.FieldDiffs) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) IssueComment(org.sonar.api.issue.IssueComment) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment)

Example 20 with FieldDiffs

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

the class IssueChangeNotificationTest method set_issue_with_current_change_having_no_new_value.

@Test
public void set_issue_with_current_change_having_no_new_value() {
    DefaultIssue issue = new DefaultIssue().setKey("ABCD").setAssignee("simon").setMessage("Remove this useless method").setComponentKey("MyService");
    IssueChangeNotification result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("assignee", "john", null)));
    assertThat(result.getFieldValue("old.assignee")).isEqualTo("john");
    assertThat(result.getFieldValue("new.assignee")).isNull();
    result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("assignee", "john", "")));
    assertThat(result.getFieldValue("old.assignee")).isEqualTo("john");
    assertThat(result.getFieldValue("new.assignee")).isNull();
}
Also used : FieldDiffs(org.sonar.core.issue.FieldDiffs) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

FieldDiffs (org.sonar.core.issue.FieldDiffs)27 Test (org.junit.Test)23 IssueDto (org.sonar.db.issue.IssueDto)14 ChangelogWsResponse (org.sonarqube.ws.Issues.ChangelogWsResponse)11 UserDto (org.sonar.db.user.UserDto)8 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)8 DefaultIssue (org.sonar.core.issue.DefaultIssue)4 Map (java.util.Map)2 IssueComment (org.sonar.api.issue.IssueComment)2 DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)2 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)2 Date (java.util.Date)1 ComponentDto (org.sonar.db.component.ComponentDto)1 RuleDto (org.sonar.db.rule.RuleDto)1 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)1