Search in sources :

Example 21 with DefaultIssue

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

the class TestErrorRuleTest method issue_if_errors_or_failures.

@Test
public void issue_if_errors_or_failures() throws Exception {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.TEST_ERRORS_KEY, Measure.newMeasureBuilder().create(2));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.TEST_FAILURES_KEY, Measure.newMeasureBuilder().create(1));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    assertThat(issue.effortToFix()).isEqualTo(3.0);
    assertThat(issue.message()).isEqualTo("Fix failing unit tests on file \"FooTest.java\".");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 22 with DefaultIssue

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

the class TestErrorRuleTest method no_issues_if_zero_errors_and_failures.

@Test
public void no_issues_if_zero_errors_and_failures() throws Exception {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.TEST_ERRORS_KEY, Measure.newMeasureBuilder().create(0));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.TEST_FAILURES_KEY, Measure.newMeasureBuilder().create(0));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue).isNull();
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 23 with DefaultIssue

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

the class CommonRuleEngineImplTest method do_not_process_files_with_unknown_language.

@Test
public void do_not_process_files_with_unknown_language() throws Exception {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, null, 1)).build();
    Collection<DefaultIssue> issues = underTest.process(file);
    assertThat(issues).isEmpty();
    verifyZeroInteractions(rule1, rule2);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.server.computation.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 24 with DefaultIssue

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

the class CoverageRuleTest method issue_if_coverage_is_too_low.

@Test
public void issue_if_coverage_is_too_low() {
    activeRuleHolder.put(new ActiveRule(getRuleKey(), Severity.CRITICAL, ImmutableMap.of(getMinPropertyKey(), "65"), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), getCoverageMetricKey(), Measure.newMeasureBuilder().create(20.0, 1));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), getUncoveredMetricKey(), Measure.newMeasureBuilder().create(40));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), getToCoverMetricKey(), Measure.newMeasureBuilder().create(50));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(getRuleKey());
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    // FIXME explain
    assertThat(issue.effortToFix()).isEqualTo(23.0);
    assertThat(issue.message()).isEqualTo(getExpectedIssueMessage());
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 25 with DefaultIssue

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

the class CoverageRuleTest method no_issue_if_coverage_is_not_set.

@Test
public void no_issue_if_coverage_is_not_set() {
    activeRuleHolder.put(new ActiveRule(getRuleKey(), Severity.CRITICAL, ImmutableMap.of(getMinPropertyKey(), "65"), 1_000L));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue).isNull();
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) 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