Search in sources :

Example 1 with Rules

use of org.sonar.api.batch.rule.Rules in project sonarqube by SonarSource.

the class RulesProviderTest method testRuleTranslation.

@Test
public void testRuleTranslation() {
    RulesLoader loader = mock(RulesLoader.class);
    when(loader.load()).thenReturn(Lists.newArrayList(getTestRule()));
    RulesProvider provider = new RulesProvider();
    Rules rules = provider.provide(loader);
    assertThat(rules.findAll()).hasSize(1);
    assertRule(rules.findAll().iterator().next());
}
Also used : RulesProvider(org.sonar.scanner.rule.RulesProvider) RulesLoader(org.sonar.scanner.rule.RulesLoader) Rules(org.sonar.api.batch.rule.Rules) Test(org.junit.Test)

Example 2 with Rules

use of org.sonar.api.batch.rule.Rules in project sonarqube by SonarSource.

the class RuleNameProviderTest method setUp.

@Before
public void setUp() {
    ruleKey = mock(RuleKey.class);
    rule = mock(Rule.class);
    rules = mock(Rules.class);
    provider = new RuleNameProvider(rules);
    when(ruleKey.rule()).thenReturn("ruleKey");
    when(ruleKey.repository()).thenReturn("repoKey");
    when(rule.name()).thenReturn("name");
    when(rule.key()).thenReturn(ruleKey);
    when(rules.find(any(RuleKey.class))).thenReturn(rule);
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) RuleNameProvider(org.sonar.scanner.scan.report.RuleNameProvider) Rule(org.sonar.api.batch.rule.Rule) Rules(org.sonar.api.batch.rule.Rules) Before(org.junit.Before)

Example 3 with Rules

use of org.sonar.api.batch.rule.Rules in project sonarqube by SonarSource.

the class RulesBuilderTest method build_rules.

@Test
public void build_rules() {
    RulesBuilder builder = new RulesBuilder();
    NewRule newSquid1 = builder.add(RuleKey.of("squid", "S0001"));
    newSquid1.setName("Detect bug");
    newSquid1.setDescription("Detect potential bug");
    newSquid1.setInternalKey("foo=bar");
    newSquid1.setSeverity(Severity.CRITICAL);
    newSquid1.setStatus(RuleStatus.BETA);
    newSquid1.addParam("min");
    newSquid1.addParam("max").setDescription("Maximum");
    // most simple rule
    builder.add(RuleKey.of("squid", "S0002"));
    builder.add(RuleKey.of("findbugs", "NPE"));
    Rules rules = builder.build();
    assertThat(rules.findAll()).hasSize(3);
    assertThat(rules.findByRepository("squid")).hasSize(2);
    assertThat(rules.findByRepository("findbugs")).hasSize(1);
    assertThat(rules.findByRepository("unknown")).isEmpty();
    Rule squid1 = rules.find(RuleKey.of("squid", "S0001"));
    assertThat(squid1.key().repository()).isEqualTo("squid");
    assertThat(squid1.key().rule()).isEqualTo("S0001");
    assertThat(squid1.name()).isEqualTo("Detect bug");
    assertThat(squid1.description()).isEqualTo("Detect potential bug");
    assertThat(squid1.internalKey()).isEqualTo("foo=bar");
    assertThat(squid1.status()).isEqualTo(RuleStatus.BETA);
    assertThat(squid1.severity()).isEqualTo(Severity.CRITICAL);
    assertThat(squid1.params()).hasSize(2);
    assertThat(squid1.param("min").key()).isEqualTo("min");
    assertThat(squid1.param("min").description()).isNull();
    assertThat(squid1.param("max").key()).isEqualTo("max");
    assertThat(squid1.param("max").description()).isEqualTo("Maximum");
    Rule squid2 = rules.find(RuleKey.of("squid", "S0002"));
    assertThat(squid2.key().repository()).isEqualTo("squid");
    assertThat(squid2.key().rule()).isEqualTo("S0002");
    assertThat(squid2.description()).isNull();
    assertThat(squid2.internalKey()).isNull();
    assertThat(squid2.status()).isEqualTo(RuleStatus.defaultStatus());
    assertThat(squid2.severity()).isEqualTo(Severity.defaultSeverity());
    assertThat(squid2.params()).isEmpty();
}
Also used : Rule(org.sonar.api.batch.rule.Rule) Rules(org.sonar.api.batch.rule.Rules) Test(org.junit.Test)

Example 4 with Rules

use of org.sonar.api.batch.rule.Rules in project sonarqube by SonarSource.

the class RulesBuilderTest method no_rules.

@Test
public void no_rules() {
    RulesBuilder builder = new RulesBuilder();
    Rules rules = builder.build();
    assertThat(rules.findAll()).isEmpty();
}
Also used : Rules(org.sonar.api.batch.rule.Rules) Test(org.junit.Test)

Aggregations

Rules (org.sonar.api.batch.rule.Rules)4 Test (org.junit.Test)3 Rule (org.sonar.api.batch.rule.Rule)2 Before (org.junit.Before)1 RuleKey (org.sonar.api.rule.RuleKey)1 RulesLoader (org.sonar.scanner.rule.RulesLoader)1 RulesProvider (org.sonar.scanner.rule.RulesProvider)1 RuleNameProvider (org.sonar.scanner.scan.report.RuleNameProvider)1