Package org.sonar.api.batch.rule

Examples of org.sonar.api.batch.rule.ActiveRules


public class ActiveRulesBuilderTest {
  @Test
  public void no_rules() throws Exception {
    ActiveRulesBuilder builder = new ActiveRulesBuilder();
    ActiveRules rules = builder.build();
    assertThat(rules.findAll()).isEmpty();
  }
View Full Code Here


    assertThat(rules.findAll()).isEmpty();
  }

  @Test
  public void build_rules() throws Exception {
    ActiveRules activeRules = new ActiveRulesBuilder()
      .create(RuleKey.of("squid", "S0001"))
      .setName("My Rule")
      .setSeverity(Severity.CRITICAL)
      .setInternalKey("__S0001__")
      .setParam("min", "20")
      .activate()
      // most simple rule
      .create(RuleKey.of("squid", "S0002")).activate()
      .create(RuleKey.of("findbugs", "NPE")).setInternalKey(null).setSeverity(null).setParam("foo", null).activate()
      .build();

    assertThat(activeRules.findAll()).hasSize(3);
    assertThat(activeRules.findByRepository("squid")).hasSize(2);
    assertThat(activeRules.findByRepository("findbugs")).hasSize(1);
    assertThat(activeRules.findByInternalKey("squid", "__S0001__")).isNotNull();
    assertThat(activeRules.findByRepository("unknown")).isEmpty();

    ActiveRule squid1 = activeRules.find(RuleKey.of("squid", "S0001"));
    assertThat(squid1.ruleKey().repository()).isEqualTo("squid");
    assertThat(squid1.ruleKey().rule()).isEqualTo("S0001");
    assertThat(((DefaultActiveRule) squid1).name()).isEqualTo("My Rule");
    assertThat(squid1.severity()).isEqualTo(Severity.CRITICAL);
    assertThat(squid1.internalKey()).isEqualTo("__S0001__");
    assertThat(squid1.params()).hasSize(1);
    assertThat(squid1.param("min")).isEqualTo("20");

    ActiveRule squid2 = activeRules.find(RuleKey.of("squid", "S0002"));
    assertThat(squid2.ruleKey().repository()).isEqualTo("squid");
    assertThat(squid2.ruleKey().rule()).isEqualTo("S0002");
    assertThat(squid2.severity()).isEqualTo(Severity.defaultSeverity());
    assertThat(squid2.params()).isEmpty();

    ActiveRule findbugsRule = activeRules.find(RuleKey.of("findbugs", "NPE"));
    assertThat(findbugsRule.severity()).isEqualTo(Severity.defaultSeverity());
    assertThat(findbugsRule.internalKey()).isNull();
    assertThat(findbugsRule.params()).isEmpty();
  }
View Full Code Here

  public void should_optimize_on_repository() throws Exception {
    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
      .createIssuesForRuleRepositories("squid");
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();

    ActiveRules activeRules = new ActiveRulesBuilder()
      .create(RuleKey.of("repo1", "foo"))
      .activate()
      .build();
    optimizer = new AnalyzerOptimizer(fs, activeRules);
View Full Code Here

TOP

Related Classes of org.sonar.api.batch.rule.ActiveRules

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.