Search in sources :

Example 16 with DefaultActiveRules

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

the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesAndNotFile.

@Test
public void shouldRefuseIssueIfRuleMatchesAndNotFile() throws IOException {
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
    String path = "org/sonar/api/Issue.java";
    RuleKey ruleKey = RuleKey.of("repo", "key");
    when(issue.ruleKey()).thenReturn(ruleKey);
    IssuePattern matching = new IssuePattern(path, ruleKey.toString());
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
    when(issue.getComponent()).thenReturn(TestInputFileBuilder.newDefaultInputProject("foo", tempFolder.newFolder()));
    ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
    assertThat(ignoreFilter.accept(issue, chain)).isFalse();
    verifyNoInteractions(chain, analysisWarnings);
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Example 17 with DefaultActiveRules

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

the class EnforceIssuesFilterTest method shouldPassToChainIfNoConfiguredPatterns.

@Test
public void shouldPassToChainIfNoConfiguredPatterns() {
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
    ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verify(chain).accept(issue);
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) Test(org.junit.Test)

Example 18 with DefaultActiveRules

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

the class EnforceIssuesFilterTest method shouldAcceptIssueIfMatchesDeprecatedRuleKey.

@Test
public void shouldAcceptIssueIfMatchesDeprecatedRuleKey() {
    RuleKey ruleKey = RuleKey.of("repo", "rule");
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of(new NewActiveRule.Builder().setRuleKey(ruleKey).setDeprecatedKeys(singleton(RuleKey.of("repo2", "deprecated"))).build()));
    String path = "org/sonar/api/Issue.java";
    when(issue.ruleKey()).thenReturn(ruleKey);
    IssuePattern matching = new IssuePattern("org/**", "repo2:deprecated");
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
    when(issue.getComponent()).thenReturn(createComponentWithPath(path));
    ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verify(analysisWarnings).addUnique("A multicriteria issue enforce uses the rule key 'repo2:deprecated' that has been changed. The pattern should be updated to 'repo:rule'");
    verifyNoInteractions(chain);
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Aggregations

DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)18 Test (org.junit.Test)15 CheckFactory (org.sonar.api.batch.rule.CheckFactory)5 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)5 RuleKey (org.sonar.api.rule.RuleKey)5 IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)5 SonarRuntime (org.sonar.api.SonarRuntime)4 ActiveRules (org.sonar.api.batch.rule.ActiveRules)3 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)3 WildcardPattern (org.sonar.api.utils.WildcardPattern)3 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 InputFile (org.sonar.api.batch.fs.InputFile)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)2 File (java.io.File)1 LoadedActiveRule (org.sonar.api.batch.rule.LoadedActiveRule)1