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");
}
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());
}
Aggregations