Search in sources :

Example 11 with Rule

use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.

the class MeasureTest method notEqualRuleMeasures.

@Test
public void notEqualRuleMeasures() {
    Measure measure = new Measure(CoreMetrics.VIOLATIONS, 30.0);
    RuleMeasure ruleMeasure = new RuleMeasure(CoreMetrics.VIOLATIONS, new Rule("foo", "bar"), RulePriority.CRITICAL, 3);
    assertThat(measure.equals(ruleMeasure)).isFalse();
    assertThat(ruleMeasure.equals(measure)).isFalse();
}
Also used : Rule(org.sonar.api.rules.Rule) Test(org.junit.Test)

Example 12 with Rule

use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.

the class MeasuresFiltersTest method rule.

@Test
public void rule() {
    Rule rule1 = new Rule("pmd", "key1");
    Rule rule2 = new Rule("pmd", "key2");
    MeasuresFilter<RuleMeasure> filter = MeasuresFilters.rule(CoreMetrics.VIOLATIONS, rule1);
    List<Measure> measures = Arrays.asList(RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule1, 50.0), RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule2, 10.0), RuleMeasure.createForRule(CoreMetrics.INFO_VIOLATIONS, rule2, 3.3), RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 400.0), RuleMeasure.createForPriority(CoreMetrics.COVERAGE, RulePriority.CRITICAL, 400.0), new Measure(CoreMetrics.VIOLATIONS, 500.0));
    assertThat(filter.filter(measures).getValue(), is(50.0));
}
Also used : Rule(org.sonar.api.rules.Rule) Test(org.junit.Test)

Example 13 with Rule

use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.

the class MeasuresFiltersTest method rules.

@Test
public void rules() {
    Rule rule1 = new Rule("pmd", "key1");
    Rule rule2 = new Rule("pmd", "key2");
    MeasuresFilter<Collection<RuleMeasure>> filter = MeasuresFilters.rules(CoreMetrics.VIOLATIONS);
    List<Measure> measures = Arrays.asList(RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule1, 50.0), RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule2, 10.0), RuleMeasure.createForRule(CoreMetrics.INFO_VIOLATIONS, rule2, 3.3), RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 400.0), RuleMeasure.createForPriority(CoreMetrics.COVERAGE, RulePriority.CRITICAL, 400.0), new Measure(CoreMetrics.VIOLATIONS, 500.0));
    assertThat(filter.filter(measures).size(), is(2));
}
Also used : Collection(java.util.Collection) Rule(org.sonar.api.rules.Rule) Test(org.junit.Test)

Example 14 with Rule

use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.

the class RulesProfileTest method fail_to_activate_already_activated_rule.

@Test
public void fail_to_activate_already_activated_rule() {
    RulesProfile profile = RulesProfile.create("Default", "java");
    Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
    profile.activateRule(rule, null);
    try {
        profile.activateRule(rule, null);
        fail();
    } catch (Exception e) {
        assertThat(e).isInstanceOf(MessageException.class).hasMessage("The definition of the profile 'Default' (language 'java') contains multiple occurrences of the 'repo:key1' rule. The plugin which declares this profile should fix this.");
    }
}
Also used : Rule(org.sonar.api.rules.Rule) MessageException(org.sonar.api.utils.MessageException) Test(org.junit.Test)

Example 15 with Rule

use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.

the class RulesProfileTest method activateRuleWithSpecificPriority.

@Test
public void activateRuleWithSpecificPriority() {
    RulesProfile profile = RulesProfile.create();
    Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
    profile.activateRule(rule, RulePriority.MINOR);
    assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.MINOR);
}
Also used : Rule(org.sonar.api.rules.Rule) Test(org.junit.Test)

Aggregations

Rule (org.sonar.api.rules.Rule)16 Test (org.junit.Test)11 ActiveRule (org.sonar.api.rules.ActiveRule)4 Matchers.anyString (org.mockito.Matchers.anyString)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 RuleFinder (org.sonar.api.rules.RuleFinder)3 Map (java.util.Map)2 RulesProfile (org.sonar.api.profiles.RulesProfile)2 RulePriority (org.sonar.api.rules.RulePriority)2 ValidationMessages (org.sonar.api.utils.ValidationMessages)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)1 MessageException (org.sonar.api.utils.MessageException)1 DbSession (org.sonar.db.DbSession)1 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)1 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)1