Search in sources :

Example 1 with ActiveRule

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

the class LoadQualityProfilesStep method convert.

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

Example 2 with ActiveRule

use of org.sonar.ce.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() {
    assertThatThrownBy(() -> {
        ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of(), 1_000L, PLUGIN_KEY, QP_KEY);
        CommonRule.getMinDensityParam(activeRule, "minDensity");
    }).isInstanceOf(IllegalStateException.class).hasMessage("Required parameter [minDensity] is missing on rule [xoo:x1]");
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) Test(org.junit.Test)

Example 3 with ActiveRule

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

the class DuplicatedBlockRuleTest method no_issue_if_no_duplicated_blocks.

@Test
public void no_issue_if_no_duplicated_blocks() {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.emptyMap(), 1_000L, PLUGIN_KEY, QP_KEY));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.DUPLICATED_BLOCKS_KEY, Measure.newMeasureBuilder().create(0));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue).isNull();
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 4 with ActiveRule

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

the class DuplicatedBlockRuleTest method issue_if_duplicated_blocks.

@Test
public void issue_if_duplicated_blocks() {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.emptyMap(), 1_000L, PLUGIN_KEY, QP_KEY));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.DUPLICATED_BLOCKS_KEY, Measure.newMeasureBuilder().create(3));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    assertThat(issue.gap()).isEqualTo(3.0);
    assertThat(issue.message()).isEqualTo("3 duplicated blocks of code must be removed.");
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 5 with ActiveRule

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

the class SkippedTestRuleTest method no_issues_if_zero_skipped_tests.

@Test
public void no_issues_if_zero_skipped_tests() {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.emptyMap(), 1_000L, PLUGIN_KEY, QP_KEY));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.SKIPPED_TESTS_KEY, Measure.newMeasureBuilder().create(0));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue).isNull();
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

ActiveRule (org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule)21 Test (org.junit.Test)17 DefaultIssue (org.sonar.core.issue.DefaultIssue)13 RuleKey (org.sonar.api.rule.RuleKey)2 HashMap (java.util.HashMap)1 CheckForNull (javax.annotation.CheckForNull)1 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)1