Search in sources :

Example 16 with DefaultIssueComment

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

the class IssueChangeDtoTest method to_comment.

@Test
public void to_comment() {
    IssueChangeDto changeDto = new IssueChangeDto().setKey("EFGH").setUserUuid("user_uuid").setChangeData("Some text").setIssueKey("ABCDE").setCreatedAt(System2.INSTANCE.now()).setUpdatedAt(System2.INSTANCE.now());
    DefaultIssueComment comment = changeDto.toComment();
    assertThat(comment.key()).isEqualTo("EFGH");
    assertThat(comment.markdownText()).isEqualTo("Some text");
    assertThat(comment.createdAt()).isNotNull();
    assertThat(comment.updatedAt()).isNotNull();
    assertThat(comment.userUuid()).isEqualTo("user_uuid");
    assertThat(comment.issueKey()).isEqualTo("ABCDE");
}
Also used : DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) Test(org.junit.Test)

Example 17 with DefaultIssueComment

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

the class IssueChangeDtoTest method create_from_comment.

@Test
public void create_from_comment() {
    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
    IssueChangeDto dto = IssueChangeDto.of(comment, "project_uuid");
    assertThat(dto.getChangeData()).isEqualTo("the comment");
    assertThat(dto.getChangeType()).isEqualTo("comment");
    assertThat(dto.getCreatedAt()).isNotNull();
    assertThat(dto.getUpdatedAt()).isNotNull();
    assertThat(dto.getIssueChangeCreationDate()).isNotNull();
    assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
    assertThat(dto.getUserUuid()).isEqualTo("user_uuid");
    assertThat(dto.getProjectUuid()).isEqualTo("project_uuid");
}
Also used : DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) Test(org.junit.Test)

Example 18 with DefaultIssueComment

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

the class PersistIssuesStepTest method add_comment.

@Test
public void add_comment() {
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule = db.rules().insert();
    IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setCreatedAt(NOW - 1_000_000_000L).setUpdatedAt(NOW - 1_000_000_000L));
    DiskCache.CacheAppender issueCacheAppender = protoIssueCache.newAppender();
    issueCacheAppender.append(issue.toDefaultIssue().setStatus(STATUS_CLOSED).setResolution(RESOLUTION_FIXED).setSelectedAt(NOW).setNew(false).setChanged(true).addComment(new DefaultIssueComment().setKey("COMMENT").setIssueKey(issue.getKey()).setUserUuid("john_uuid").setMarkdownText("Some text").setCreatedAt(new Date(NOW)).setUpdatedAt(new Date(NOW)).setNew(true))).close();
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0);
    assertThat(issueChangeDto).extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserUuid, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey, IssueChangeDto::getIssueChangeCreationDate).containsOnly(IssueChangeDto.TYPE_COMMENT, "john_uuid", "Some text", issue.getKey(), NOW);
    assertThat(context.getStatistics().getAll()).contains(entry("inserts", "0"), entry("updates", "1"), entry("merged", "0"));
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) DiskCache(org.sonar.ce.task.projectanalysis.util.cache.DiskCache) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) Date(java.util.Date) Test(org.junit.Test)

Example 19 with DefaultIssueComment

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

the class PersistIssuesStepTest method insert_copied_issue.

@Test
public void insert_copied_issue() {
    RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
    db.rules().insert(rule);
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
    when(system2.now()).thenReturn(NOW);
    String issueKey = "ISSUE-1";
    protoIssueCache.newAppender().append(new DefaultIssue().setKey(issueKey).setType(RuleType.CODE_SMELL).setRuleKey(rule.getKey()).setComponentUuid(file.uuid()).setComponentKey(file.getKey()).setProjectUuid(project.uuid()).setProjectKey(project.getKey()).setSeverity(BLOCKER).setStatus(STATUS_OPEN).setTags(singletonList("test")).setNew(false).setCopied(true).setType(RuleType.BUG).setCreationDate(new Date(NOW)).setSelectedAt(NOW).addComment(new DefaultIssueComment().setKey("COMMENT").setIssueKey(issueKey).setUserUuid("john_uuid").setMarkdownText("Some text").setCreatedAt(new Date(NOW)).setUpdatedAt(new Date(NOW)).setNew(true)).setCurrentChange(new FieldDiffs().setIssueKey(issueKey).setUserUuid("john_uuid").setDiff("technicalDebt", null, 1L).setCreationDate(new Date(NOW)))).close();
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    IssueDto result = dbClient.issueDao().selectOrFailByKey(session, issueKey);
    assertThat(result.getKey()).isEqualTo(issueKey);
    assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
    assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
    assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
    assertThat(result.getSeverity()).isEqualTo(BLOCKER);
    assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
    assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
    assertThat(result.getTags()).containsExactlyInAnyOrder("test");
    assertThat(result.isNewCodeReferenceIssue()).isFalse();
    List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList(issueKey));
    assertThat(changes).extracting(IssueChangeDto::getChangeType).containsExactly(IssueChangeDto.TYPE_COMMENT, IssueChangeDto.TYPE_FIELD_CHANGE);
    assertThat(context.getStatistics().getAll()).contains(entry("inserts", "1"), entry("updates", "0"), entry("merged", "0"));
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) FieldDiffs(org.sonar.core.issue.FieldDiffs) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) Test(org.junit.Test)

Example 20 with DefaultIssueComment

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

the class IssueLifecycleTest method mergeIssueFromPRIntoBranch.

@Test
public void mergeIssueFromPRIntoBranch() {
    DefaultIssue raw = new DefaultIssue().setKey("raw");
    DefaultIssue fromShort = new DefaultIssue().setKey("short").setIsNewCodeReferenceIssue(true);
    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"));
    Branch branch = mock(Branch.class);
    when(branch.getName()).thenReturn("master");
    analysisMetadataHolder.setBranch(branch);
    underTest.mergeConfirmedOrResolvedFromPrOrBranch(raw, fromShort, BranchType.PULL_REQUEST, "2");
    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("#2");
    assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).newValue()).isEqualTo("master");
    assertThat(raw.isNewCodeReferenceIssue()).isTrue();
}
Also used : FieldDiffs(org.sonar.core.issue.FieldDiffs) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) 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)

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