Search in sources :

Example 11 with DefaultIssue

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

the class IssueAssignerTest method set_default_assignee_if_author_not_found.

@Test
public void set_default_assignee_if_author_not_found() throws Exception {
    addScmUser("john", null);
    setSingleChangeset("john", 123456789L, "rev-1");
    when(defaultAssignee.getLogin()).thenReturn("John C");
    DefaultIssue issue = new DefaultIssue().setLine(1);
    underTest.onIssue(FILE, issue);
    assertThat(issue.assignee()).isEqualTo("John C");
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 12 with DefaultIssue

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

the class IssueAssignerTest method nothing_to_do_if_no_changeset.

@Test
public void nothing_to_do_if_no_changeset() throws Exception {
    DefaultIssue issue = new DefaultIssue().setLine(1);
    underTest.onIssue(FILE, issue);
    assertThat(issue.authorLogin()).isNull();
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 13 with DefaultIssue

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

the class IssueLifecycleTest method mergeExistingOpenIssue.

@Test
public void mergeExistingOpenIssue() throws Exception {
    DefaultIssue raw = new DefaultIssue().setNew(true).setKey("RAW_KEY").setCreationDate(parseDate("2015-10-01")).setUpdateDate(parseDate("2015-10-02")).setCloseDate(parseDate("2015-10-03"));
    DbIssues.Locations issueLocations = DbIssues.Locations.newBuilder().setTextRange(DbCommons.TextRange.newBuilder().setStartLine(10).setEndLine(12).build()).build();
    DefaultIssue base = new DefaultIssue().setKey("BASE_KEY").setCreationDate(parseDate("2015-01-01")).setUpdateDate(parseDate("2015-01-02")).setCloseDate(parseDate("2015-01-03")).setResolution(RESOLUTION_FIXED).setStatus(STATUS_CLOSED).setSeverity(BLOCKER).setAssignee("base assignee").setAuthorLogin("base author").setTags(newArrayList("base tag")).setOnDisabledRule(true).setSelectedAt(1000L).setLine(10).setMessage("message").setGap(15d).setEffort(Duration.create(15L)).setManualSeverity(false).setLocations(issueLocations);
    when(debtCalculator.calculate(raw)).thenReturn(DEFAULT_DURATION);
    underTest.mergeExistingOpenIssue(raw, base);
    assertThat(raw.isNew()).isFalse();
    assertThat(raw.key()).isEqualTo("BASE_KEY");
    assertThat(raw.creationDate()).isEqualTo(base.creationDate());
    assertThat(raw.updateDate()).isEqualTo(base.updateDate());
    assertThat(raw.closeDate()).isEqualTo(base.closeDate());
    assertThat(raw.resolution()).isEqualTo(RESOLUTION_FIXED);
    assertThat(raw.status()).isEqualTo(STATUS_CLOSED);
    assertThat(raw.assignee()).isEqualTo("base assignee");
    assertThat(raw.authorLogin()).isEqualTo("base author");
    assertThat(raw.tags()).containsOnly("base tag");
    assertThat(raw.debt()).isEqualTo(DEFAULT_DURATION);
    assertThat(raw.isOnDisabledRule()).isTrue();
    assertThat(raw.selectedAt()).isEqualTo(1000L);
    verify(updater).setPastSeverity(raw, BLOCKER, issueChangeContext);
    verify(updater).setPastLine(raw, 10);
    verify(updater).setPastMessage(raw, "message", issueChangeContext);
    verify(updater).setPastEffort(raw, Duration.create(15L), issueChangeContext);
    verify(updater).setPastLocations(raw, issueLocations);
}
Also used : DbIssues(org.sonar.db.protobuf.DbIssues) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 14 with DefaultIssue

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

the class IssueLifecycleTest method mergeExistingOpenIssue_with_attributes.

@Test
public void mergeExistingOpenIssue_with_attributes() throws Exception {
    DefaultIssue raw = new DefaultIssue().setNew(true).setKey("RAW_KEY");
    DefaultIssue base = new DefaultIssue().setKey("BASE_KEY").setResolution(RESOLUTION_FIXED).setStatus(STATUS_CLOSED).setSeverity(BLOCKER).setAttributes(ImmutableMap.of("JIRA", "SONAR-01"));
    underTest.mergeExistingOpenIssue(raw, base);
    assertThat(raw.attributes()).containsEntry("JIRA", "SONAR-01");
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 15 with DefaultIssue

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

the class EffortAggregatorTest method sum_reliability_effort_of_unresolved_issues.

@Test
public void sum_reliability_effort_of_unresolved_issues() {
    DefaultIssue unresolved1 = newBugIssue(10);
    DefaultIssue unresolved2 = newBugIssue(30);
    DefaultIssue unresolvedWithoutEffort = newBugIssueWithoutEffort();
    DefaultIssue resolved = newBugIssue(50).setResolution(RESOLUTION_FIXED);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, unresolved1);
    underTest.onIssue(FILE, unresolved2);
    underTest.onIssue(FILE, unresolvedWithoutEffort);
    underTest.onIssue(FILE, resolved);
    underTest.afterComponent(FILE);
    assertMeasure(FILE, RELIABILITY_REMEDIATION_EFFORT_KEY, 10L + 30L);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

DefaultIssue (org.sonar.core.issue.DefaultIssue)140 Test (org.junit.Test)120 Date (java.util.Date)27 ActiveRule (org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule)15 IssueChangeContext (org.sonar.core.issue.IssueChangeContext)14 DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)8 IssueDto (org.sonar.db.issue.IssueDto)8 DbSession (org.sonar.db.DbSession)6 ComponentDto (org.sonar.db.component.ComponentDto)5 Issue (org.sonar.api.issue.Issue)4 FieldDiffs (org.sonar.core.issue.FieldDiffs)4 ArrayList (java.util.ArrayList)3 RuleKey (org.sonar.api.rule.RuleKey)3 User (org.sonar.api.user.User)3 IssueChangeMapper (org.sonar.db.issue.IssueChangeMapper)3 IssueMapper (org.sonar.db.issue.IssueMapper)3 RuleDto (org.sonar.db.rule.RuleDto)3 IssueChangeNotification (org.sonar.server.issue.notification.IssueChangeNotification)3 DefaultUser (org.sonar.core.user.DefaultUser)2 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)2