Search in sources :

Example 21 with DefaultIssueComment

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

the class IssueLifecycleTest method copyExistingIssuesFromSourceBranchOfPullRequest.

@Test
public void copyExistingIssuesFromSourceBranchOfPullRequest() {
    String pullRequestKey = "1";
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(BranchType.PULL_REQUEST);
    when(branch.getName()).thenReturn("sourceBranch-1");
    when(branch.getPullRequestKey()).thenReturn(pullRequestKey);
    analysisMetadataHolder.setBranch(branch);
    analysisMetadataHolder.setPullRequestKey(pullRequestKey);
    DefaultIssue raw = new DefaultIssue().setKey("raw");
    DefaultIssue fromShort = new DefaultIssue().setKey("short");
    fromShort.setResolution("resolution");
    fromShort.setStatus("status");
    Date commentDate = new Date();
    fromShort.addComment(new DefaultIssueComment().setIssueKey("short").setCreatedAt(commentDate).setUserUuid("user_uuid").setMarkdownText("A comment"));
    Date diffDate = new Date();
    // file diff alone
    fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("file", "uuidA1", "uuidB1"));
    // file diff with another field
    fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("severity", "MINOR", "MAJOR").setDiff("file", "uuidA2", "uuidB2"));
    underTest.copyExistingIssueFromSourceBranchToPullRequest(raw, fromShort);
    assertThat(raw.resolution()).isEqualTo("resolution");
    assertThat(raw.status()).isEqualTo("status");
    assertThat(raw.defaultIssueComments()).extracting(DefaultIssueComment::issueKey, DefaultIssueComment::createdAt, DefaultIssueComment::userUuid, DefaultIssueComment::markdownText).containsOnly(tuple("raw", commentDate, "user_uuid", "A comment"));
    assertThat(raw.changes()).hasSize(2);
    assertThat(raw.changes().get(0).creationDate()).isEqualTo(diffDate);
    assertThat(raw.changes().get(0).userUuid()).isEqualTo("user_uuid");
    assertThat(raw.changes().get(0).issueKey()).isEqualTo("raw");
    assertThat(raw.changes().get(0).diffs()).containsOnlyKeys("severity");
    assertThat(raw.changes().get(1).userUuid()).isEqualTo("default_user_uuid");
    assertThat(raw.changes().get(1).diffs()).containsOnlyKeys(IssueFieldsSetter.FROM_BRANCH);
    assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).oldValue()).isEqualTo("sourceBranch-1");
    assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).newValue()).isEqualTo("#1");
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) FieldDiffs(org.sonar.core.issue.FieldDiffs) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) DateUtils.parseDate(org.sonar.api.utils.DateUtils.parseDate) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) Test(org.junit.Test)

Example 22 with DefaultIssueComment

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

the class WebIssueStorageTest method insert_new_issues.

@Test
public void insert_new_issues() {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto file = db.components().insertComponent(newFileDto(module));
    String issueKey = "ABCDE";
    DefaultIssueComment comment = DefaultIssueComment.create(issueKey, "user_uuid", "the comment");
    // override generated key
    comment.setKey("FGHIJ");
    Date date = DateUtils.parseDateTime("2013-05-18T12:00:00+0000");
    DefaultIssue issue = new DefaultIssue().setKey(issueKey).setType(RuleType.BUG).setNew(true).setRuleKey(rule.getKey()).setProjectUuid(project.uuid()).setComponentUuid(file.uuid()).setLine(5000).setEffort(Duration.create(10L)).setResolution("OPEN").setStatus("OPEN").setSeverity("BLOCKER").addComment(comment).setCreationDate(date).setUpdateDate(date).setCloseDate(date);
    underTest.save(db.getSession(), singletonList(issue));
    assertThat(db.countRowsOfTable("issues")).isOne();
    assertThat(db.selectFirst("select * from issues")).containsEntry("PROJECT_UUID", project.uuid()).containsEntry("COMPONENT_UUID", file.uuid()).containsEntry("KEE", issue.key()).containsEntry("RESOLUTION", issue.resolution()).containsEntry("STATUS", issue.status()).containsEntry("SEVERITY", issue.severity());
    assertThat(db.countRowsOfTable("issue_changes")).isOne();
    assertThat(db.selectFirst("select * from issue_changes")).containsEntry("KEE", comment.key()).containsEntry("ISSUE_KEY", issue.key()).containsEntry("CHANGE_DATA", comment.markdownText()).containsEntry("USER_LOGIN", comment.userUuid());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)22 Test (org.junit.Test)18 Date (java.util.Date)13 DefaultIssue (org.sonar.core.issue.DefaultIssue)13 FieldDiffs (org.sonar.core.issue.FieldDiffs)7 ComponentDto (org.sonar.db.component.ComponentDto)6 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)6 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)4 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)3 IssueDto (org.sonar.db.issue.IssueDto)3 IssueComment (org.sonar.api.issue.IssueComment)2 DateUtils.parseDate (org.sonar.api.utils.DateUtils.parseDate)2 Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)2 DiskCache (org.sonar.ce.task.projectanalysis.util.cache.DiskCache)1 IssueChangeContext (org.sonar.core.issue.IssueChangeContext)1