Search in sources :

Example 31 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)

Aggregations

Rule (org.sonar.api.rules.Rule)31 Test (org.junit.Test)22 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)11 RuleParamDto (org.sonar.db.rule.RuleParamDto)10 List (java.util.List)9 DbSession (org.sonar.db.DbSession)9 Arrays (java.util.Arrays)8 Consumer (java.util.function.Consumer)8 Collectors.toList (java.util.stream.Collectors.toList)8 Nullable (javax.annotation.Nullable)8 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Before (org.junit.Before)8 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)8 Mockito.mock (org.mockito.Mockito.mock)8 Mockito.verify (org.mockito.Mockito.verify)8 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)8 Mockito.when (org.mockito.Mockito.when)8 AlwaysIncreasingSystem2 (org.sonar.api.impl.utils.AlwaysIncreasingSystem2)8 RuleKey (org.sonar.api.rule.RuleKey)8