Search in sources :

Example 1 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.

the class LoadQualityProfilesStep method convert.

private static ActiveRule convert(ScannerReport.ActiveRule input) {
    RuleKey key = RuleKey.of(input.getRuleRepository(), input.getRuleKey());
    Map<String, String> params = new HashMap<>(input.getParamsByKey());
    return new ActiveRule(key, input.getSeverity().name(), params, input.getCreatedAt());
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) HashMap(java.util.HashMap) ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule)

Example 2 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule 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 3 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule 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 4 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.

the class CommonRuleTest method getMinDensityParam_fails_if_param_value_is_absent.

@Test
public void getMinDensityParam_fails_if_param_value_is_absent() throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Required parameter [minDensity] is missing on rule [xoo:x1]");
    ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.<String, String>of(), 1_000L);
    CommonRule.getMinDensityParam(activeRule, "minDensity");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) Test(org.junit.Test)

Example 5 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.

the class CommonRuleTest method getMinDensityParam_fails_if_param_value_is_negative.

@Test
public void getMinDensityParam_fails_if_param_value_is_negative() throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Minimum density of rule [xoo:x1] is incorrect. Got [-30.5] but must be between 0 and 100.");
    ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "-30.5"), 1_000L);
    CommonRule.getMinDensityParam(activeRule, "minDensity");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) Test(org.junit.Test)

Aggregations

ActiveRule (org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule)21 Test (org.junit.Test)19 DefaultIssue (org.sonar.core.issue.DefaultIssue)15 RuleKey (org.sonar.api.rule.RuleKey)2 HashMap (java.util.HashMap)1 CheckForNull (javax.annotation.CheckForNull)1