Search in sources :

Example 16 with DefaultIssue

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

the class EffortAggregatorTest method maintainability_effort_is_only_computed_using_code_smell_issues.

@Test
public void maintainability_effort_is_only_computed_using_code_smell_issues() {
    DefaultIssue codeSmellIssue = newCodeSmellIssue(10);
    // Issues of type BUG and VULNERABILITY should be ignored
    DefaultIssue bugIssue = newBugIssue(15);
    DefaultIssue vulnerabilityIssue = newVulnerabilityIssue(12);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, codeSmellIssue);
    underTest.onIssue(FILE, bugIssue);
    underTest.onIssue(FILE, vulnerabilityIssue);
    underTest.afterComponent(FILE);
    // Only effort of CODE SMELL issue is used
    assertMeasure(FILE, TECHNICAL_DEBT_KEY, 10L);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 17 with DefaultIssue

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

the class EffortAggregatorTest method sum_security_effort_of_unresolved_issues.

@Test
public void sum_security_effort_of_unresolved_issues() {
    DefaultIssue unresolved1 = newVulnerabilityIssue(10);
    DefaultIssue unresolved2 = newVulnerabilityIssue(30);
    DefaultIssue unresolvedWithoutEffort = newVulnerabilityIssueWithoutEffort();
    DefaultIssue resolved = newVulnerabilityIssue(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, SECURITY_REMEDIATION_EFFORT_KEY, 10L + 30L);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 18 with DefaultIssue

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

the class IntegrateIssuesVisitorTest method process_existing_issue.

@Test
public void process_existing_issue() throws Exception {
    componentsWithUnprocessedIssues.setUuids(newHashSet(FILE_UUID));
    RuleKey ruleKey = RuleTesting.XOO_X1;
    // Issue from db has severity major
    addBaseIssue(ruleKey);
    // Issue from report has severity blocker
    ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder().setMsg("the message").setRuleRepository(ruleKey.repository()).setRuleKey(ruleKey.rule()).setSeverity(Constants.Severity.BLOCKER).build();
    reportReader.putIssues(FILE_REF, asList(reportIssue));
    fileSourceRepository.addLine(FILE_REF, "line1");
    underTest.visitAny(FILE);
    ArgumentCaptor<DefaultIssue> rawIssueCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
    ArgumentCaptor<DefaultIssue> baseIssueCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
    verify(issueLifecycle).mergeExistingOpenIssue(rawIssueCaptor.capture(), baseIssueCaptor.capture());
    assertThat(rawIssueCaptor.getValue().severity()).isEqualTo(Severity.BLOCKER);
    assertThat(baseIssueCaptor.getValue().severity()).isEqualTo(Severity.MAJOR);
    verify(issueLifecycle).doAutomaticTransition(defaultIssueCaptor.capture());
    assertThat(defaultIssueCaptor.getValue().ruleKey()).isEqualTo(ruleKey);
    List<DefaultIssue> issues = newArrayList(issueCache.traverse());
    assertThat(issues).hasSize(1);
    assertThat(issues.get(0).severity()).isEqualTo(Severity.BLOCKER);
    assertThat(componentsWithUnprocessedIssues.getUuids()).isEmpty();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 19 with DefaultIssue

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

the class IntegrateIssuesVisitorTest method close_unmatched_base_issue.

@Test
public void close_unmatched_base_issue() throws Exception {
    componentsWithUnprocessedIssues.setUuids(newHashSet(FILE_UUID));
    RuleKey ruleKey = RuleTesting.XOO_X1;
    addBaseIssue(ruleKey);
    // No issue in the report
    underTest.visitAny(FILE);
    verify(issueLifecycle).doAutomaticTransition(defaultIssueCaptor.capture());
    assertThat(defaultIssueCaptor.getValue().isBeingClosed()).isTrue();
    List<DefaultIssue> issues = newArrayList(issueCache.traverse());
    assertThat(issues).hasSize(1);
    assertThat(componentsWithUnprocessedIssues.getUuids()).isEmpty();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 20 with DefaultIssue

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

the class IssueAssignerTest method set_last_committer_when_line_is_bigger_than_changeset_size.

@Test
public void set_last_committer_when_line_is_bigger_than_changeset_size() throws Exception {
    addScmUser("john", "John C");
    Changeset changeset = Changeset.newChangesetBuilder().setAuthor("john").setDate(123456789L).setRevision("rev-1").build();
    scmInfoRepository.setScmInfo(FILE_REF, changeset, changeset);
    DefaultIssue issue = new DefaultIssue().setLine(3);
    underTest.onIssue(FILE, issue);
    assertThat(issue.assignee()).isEqualTo("John C");
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Changeset(org.sonar.server.computation.task.projectanalysis.scm.Changeset) 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