Search in sources :

Example 1 with LoadedActiveRule

use of org.sonar.scanner.rule.LoadedActiveRule in project sonarqube by SonarSource.

the class ActiveRulesProviderTest method testCombinationOfRules.

@Test
public void testCombinationOfRules() {
    LoadedActiveRule r1 = mockRule("rule1");
    LoadedActiveRule r2 = mockRule("rule2");
    LoadedActiveRule r3 = mockRule("rule3");
    List<LoadedActiveRule> qp1Rules = ImmutableList.of(r1, r2);
    List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3);
    List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3);
    when(loader.load(eq("qp1"))).thenReturn(qp1Rules);
    when(loader.load(eq("qp2"))).thenReturn(qp2Rules);
    when(loader.load(eq("qp3"))).thenReturn(qp3Rules);
    ModuleQProfiles profiles = mockProfiles("qp1", "qp2", "qp3");
    ActiveRules activeRules = provider.provide(loader, profiles);
    assertThat(activeRules.findAll()).hasSize(3);
    assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly(RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3"));
    verify(loader).load(eq("qp1"));
    verify(loader).load(eq("qp2"));
    verify(loader).load(eq("qp3"));
    verifyNoMoreInteractions(loader);
}
Also used : ActiveRules(org.sonar.api.batch.rule.ActiveRules) LoadedActiveRule(org.sonar.scanner.rule.LoadedActiveRule) ModuleQProfiles(org.sonar.scanner.rule.ModuleQProfiles) Test(org.junit.Test)

Example 2 with LoadedActiveRule

use of org.sonar.scanner.rule.LoadedActiveRule in project sonarqube by SonarSource.

the class ActiveRulesProviderTest method mockRule.

private static LoadedActiveRule mockRule(String name) {
    LoadedActiveRule r = new LoadedActiveRule();
    r.setName(name);
    r.setRuleKey(RuleKey.of(name, name));
    return r;
}
Also used : LoadedActiveRule(org.sonar.scanner.rule.LoadedActiveRule)

Example 3 with LoadedActiveRule

use of org.sonar.scanner.rule.LoadedActiveRule in project sonarqube by SonarSource.

the class ChecksMediumTest method createActiveRuleWithParam.

private LoadedActiveRule createActiveRuleWithParam(String repositoryKey, String ruleKey, @Nullable String templateRuleKey, String name, @Nullable String severity, @Nullable String internalKey, @Nullable String languag, String paramKey, String paramValue) {
    LoadedActiveRule r = new LoadedActiveRule();
    r.setInternalKey(internalKey);
    r.setRuleKey(RuleKey.of(repositoryKey, ruleKey));
    r.setName(name);
    r.setTemplateRuleKey(templateRuleKey);
    r.setLanguage(languag);
    r.setSeverity(severity);
    Map<String, String> params = new HashMap<>();
    params.put(paramKey, paramValue);
    r.setParams(params);
    return r;
}
Also used : HashMap(java.util.HashMap) LoadedActiveRule(org.sonar.scanner.rule.LoadedActiveRule)

Aggregations

LoadedActiveRule (org.sonar.scanner.rule.LoadedActiveRule)3 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ActiveRules (org.sonar.api.batch.rule.ActiveRules)1 ModuleQProfiles (org.sonar.scanner.rule.ModuleQProfiles)1