Search in sources :

Example 21 with ActiveRule

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

the class LoadQualityProfilesStepTest method feed_active_rules.

@Test
public void feed_active_rules() {
    ruleRepository.add(XOO_X1).setPluginKey("xoo");
    ruleRepository.add(XOO_X2).setPluginKey("xoo");
    ScannerReport.ActiveRule.Builder batch1 = ScannerReport.ActiveRule.newBuilder().setRuleRepository(XOO_X1.repository()).setRuleKey(XOO_X1.rule()).setSeverity(Constants.Severity.BLOCKER).setCreatedAt(1000L).setUpdatedAt(1200L);
    batch1.getMutableParamsByKey().put("p1", "v1");
    ScannerReport.ActiveRule.Builder batch2 = ScannerReport.ActiveRule.newBuilder().setRuleRepository(XOO_X2.repository()).setRuleKey(XOO_X2.rule()).setSeverity(Constants.Severity.MAJOR);
    batchReportReader.putActiveRules(asList(batch1.build(), batch2.build()));
    underTest.execute(new TestComputationStepContext());
    assertThat(activeRulesHolder.getAll()).hasSize(2);
    ActiveRule ar1 = activeRulesHolder.get(XOO_X1).get();
    assertThat(ar1.getSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(ar1.getParams()).containsExactly(MapEntry.entry("p1", "v1"));
    assertThat(ar1.getPluginKey()).isEqualTo("xoo");
    assertThat(ar1.getUpdatedAt()).isEqualTo(1200L);
    ActiveRule ar2 = activeRulesHolder.get(XOO_X2).get();
    assertThat(ar2.getSeverity()).isEqualTo(Severity.MAJOR);
    assertThat(ar2.getParams()).isEmpty();
    assertThat(ar2.getPluginKey()).isEqualTo("xoo");
    assertThat(ar1.getUpdatedAt()).isEqualTo(1200L);
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) 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